Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Classes | Functions | Variables
locallib.php File Reference

Library of functions used by the quiz module. More...

Classes

class  mod_quiz_display_options
 An extension of question_display_options that includes the extra options used by the quiz. More...
 
class  qubaids_for_quiz
 A qubaid_condition for finding all the question usages belonging to a particular quiz. More...
 
class  qubaids_for_quiz_user
 A qubaid_condition for finding all the question usages belonging to a particular user and quiz combination. More...
 

Functions

 quiz_add_quiz_question ($questionid, $quiz, $page=0, $maxmark=null)
 Add a question to a quiz. More...
 
 quiz_add_random_questions ($quiz, $addonpage, $categoryid, $number, $includesubcategories, $tagids=[])
 Add a random question to the quiz at a given point. More...
 
 quiz_attempt_save_started ($quizobj, $quba, $attempt)
 The save started question usage and quiz attempt in db and log the started attempt. More...
 
 quiz_attempt_state ($quiz, $attempt)
 Work out what state this quiz attempt is in - in the sense used by quiz_get_review_options, not in the sense of $attempt->state. More...
 
 quiz_attempt_state_name ($state)
 Get the human-readable name for a quiz attempt state. More...
 
 quiz_attempt_submitted_handler ($event)
 Handle the quiz_attempt_submitted event. More...
 
 quiz_calculate_best_attempt ($quiz, $attempts)
 Return the attempt with the best grade for a quiz. More...
 
 quiz_calculate_best_grade ($quiz, $attempts)
 Calculate the overall grade for a quiz given a number of attempts by a particular user. More...
 
 quiz_create_attempt (quiz $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview=false, $userid=null)
 Creates an object to represent a new attempt at a quiz. More...
 
 quiz_create_attempt_handling_errors ($attemptid, $cmid=null)
 Get quiz attempt and handling error. More...
 
 quiz_delete_attempt ($attempt, $quiz)
 Delete a quiz attempt. More...
 
 quiz_delete_previews ($quiz, $userid=null)
 Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user. More...
 
 quiz_feedback_for_grade ($grade, $quiz, $context)
 Get the feedback text that should be show to a student who got this grade on this quiz. More...
 
 quiz_feedback_record_for_grade ($grade, $quiz)
 Get the feedback object for this grade on this quiz. More...
 
 quiz_get_attempt_usertime_sql ($redundantwhereclauses='')
 Returns SQL to compute timeclose and timelimit for every attempt, taking into account user and group overrides. More...
 
 quiz_get_combined_reviewoptions ($quiz, $attempts)
 Combines the review options from a number of different quiz attempts. More...
 
 quiz_get_flag_option ($attempt, $context)
 
 quiz_get_grading_option_name ($option)
 
 quiz_get_grading_options ()
 
 quiz_get_js_module ()
 Get the information about the standard quiz JavaScript module. More...
 
 quiz_get_overdue_handling_options ()
 
 quiz_get_review_options ($quiz, $attempt, $context)
 The the appropraite mod_quiz_display_options object for this attempt at this quiz right now. More...
 
 quiz_get_user_attempt_unfinished ($quizid, $userid)
 Returns an unfinished attempt (if there is one) for the given user on the given quiz. More...
 
 quiz_get_user_image_options ()
 Get the choices for what size user picture to show. More...
 
 quiz_get_user_timeclose ($courseid)
 Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides. More...
 
 quiz_groups_group_deleted_handler ($event)
 Handle groups_group_deleted event. More...
 
 quiz_groups_member_added_handler ($event)
 Handle groups_member_added event. More...
 
 quiz_groups_member_removed_handler ($event)
 Handle groups_member_removed event. More...
 
 quiz_groups_members_removed_handler ($event)
 Handle groups_members_removed event. More...
 
 quiz_has_attempts ($quizid)
 
 quiz_has_feedback ($quiz)
 
 quiz_has_question_use ($quiz, $slot)
 Verify that the question exists, and the user has permission to use it. More...
 
 quiz_is_overriden_calendar_event (\calendar_event $event)
 Check if the given calendar_event is either a user or group override event for quiz. More...
 
 quiz_prepare_and_start_new_attempt (quiz $quizobj, $attemptnumber, $lastattempt, $offlineattempt=false, $forcedrandomquestions=[], $forcedvariants=[], $userid=null)
 Prepare and start a new attempt deleting the previous preview attempts. More...
 
 quiz_process_group_deleted_in_course ($courseid)
 Logic to happen when a/some group(s) has/have been deleted in a course. More...
 
 quiz_question_action_icons ($quiz, $cmid, $question, $returnurl, $variant=null)
 
 quiz_question_edit_button ($cmid, $question, $returnurl, $contentaftericon='')
 
 quiz_question_preview_button ($quiz, $question, $label=false, $variant=null)
 
 quiz_question_preview_url ($quiz, $question, $variant=null)
 
 quiz_question_tostring ($question, $showicon=false, $showquestiontext=true, $showidnumber=false, $showtags=false)
 Creates a textual representation of a question for display. More...
 
 quiz_questions_per_page_options ()
 Get the choices to offer for the 'Questions per page' option. More...
 
 quiz_repaginate_questions ($quizid, $slotsperpage)
 Repaginate the questions in a quiz. More...
 
 quiz_require_question_use ($questionid)
 Verify that the question exists, and the user has permission to use it. More...
 
 quiz_rescale_grade ($rawgrade, $quiz, $format=true)
 Convert the raw grade stored in $attempt into a grade out of the maximum grade for this quiz. More...
 
 quiz_retrieve_slot_tag_ids ($slotid)
 Retrieves tag ids for the given quiz slot. More...
 
 quiz_retrieve_slot_tags ($slotid)
 Retrieves tag information for the given quiz slot. More...
 
 quiz_retrieve_tags_for_slot_ids ($slotids)
 Retrieves tag information for the given list of quiz slot ids. More...
 
 quiz_save_best_grade ($quiz, $userid=null, $attempts=array())
 Save the overall grade for a user at a quiz in the quiz_grades table. More...
 
 quiz_send_confirmation ($recipient, $a)
 Sends a confirmation message to the student confirming that the attempt was processed. More...
 
 quiz_send_notification ($recipient, $submitter, $a)
 Sends notification messages to the interested parties that assign the role capability. More...
 
 quiz_send_notification_messages ($course, $quiz, $attempt, $context, $cm)
 Send all the requried messages when a quiz attempt is submitted. More...
 
 quiz_send_overdue_message ($attemptobj)
 Send the notification message when a quiz attempt becomes overdue. More...
 
 quiz_set_grade ($newgrade, $quiz)
 The quiz grade is the maximum that student's results are marked out of. More...
 
 quiz_start_attempt_built_on_last ($quba, $attempt, $lastattempt)
 Start a subsequent new attempt, in each attempt builds on last mode. More...
 
 quiz_start_new_attempt ($quizobj, $quba, $attempt, $attemptnumber, $timenow, $questionids=array(), $forcedvariantsbyslot=array())
 Start a normal, new, quiz attempt. More...
 
 quiz_update_all_attempt_sumgrades ($quiz)
 Update the sumgrades field of the attempts at a quiz. More...
 
 quiz_update_all_final_grades ($quiz)
 Update the final grade at this quiz for all students. More...
 
 quiz_update_open_attempts (array $conditions)
 Efficiently update check state time on all open attempts. More...
 
 quiz_update_section_firstslots ($quizid, $direction, $afterslot, $beforeslot=null)
 Move all the section headings in a certain slot range by a certain offset. More...
 
 quiz_update_sumgrades ($quiz)
 Update the sumgrades field of the quiz. More...
 
 quiz_validate_new_attempt (quiz $quizobj, quiz_access_manager $accessmanager, $forcenew, $page, $redirect)
 Validate permissions for creating a new attempt and start a new preview attempt if required. More...
 
 quiz_view ($quiz, $course, $cm, $context)
 Mark the activity completed (if required) and trigger the course_module_viewed event. More...
 

Variables

const QUIZ_MIN_TIME_TO_CONTINUE '2'
 If there are fewer than this many seconds left when the student submits a page of the quiz, then do not take them to the next page of the quiz. More...
 
const QUIZ_SHOW_TIME_BEFORE_DEADLINE '3600'
 We show the countdown timer if there is less than this amount of time left before the the quiz close date. More...
 
const QUIZ_SHOWIMAGE_LARGE 2
 We show Large image when user selects Large image from dropdown menu in quiz settings.
 
const QUIZ_SHOWIMAGE_NONE 0
 We show no image when user selects No image from dropdown menu in quiz settings.
 
const QUIZ_SHOWIMAGE_SMALL 1
 We show small image when user selects small image from dropdown menu in quiz settings.
 

Detailed Description

Library of functions used by the quiz module.

This contains functions that are called from within the quiz module only Functions that are also called by core Moodle are in } * This script also loads the code in questionlib.php which holds the module-indpendent code for handling questions and which in turn initialises all the questiontype classes.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later