Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
mod_quiz

Topics

 admin
 
 
 backup
 
 
 event
 
 
 external
 
 
 grade
 
 
 log
 
 
 navigation
 
 
 output
 
 
 privacy
 
 
 question
 
 
 task
 
 
 test
 
 

Directories

directory analytics
  
 
directory navigation
  
 

Namespaces

namespace  mod_quiz
  
 
namespace  mod_quiz\adminpresets
  
 
namespace  mod_quiz\analytics\indicator
 Activity base class.
 
namespace  mod_quiz\cache
  
 
namespace  mod_quiz\completion
  
 
namespace  mod_quiz\event
 The mod_quiz attempt abandoned event.
 
namespace  mod_quiz\external
  
 
namespace  mod_quiz\form
  
 
namespace  mod_quiz\local
  
 
namespace  mod_quiz\local\reports
  
 
namespace  mod_quiz\local\structure
  
 
namespace  mod_quiz\output
 Renderer outputting the quiz editing UI.
 
namespace  mod_quiz\plugininfo
 Subplugin info class.
 
namespace  mod_quiz\privacy
 Privacy Subsystem helper for mod_quiz.
 
namespace  mod_quiz\question\bank
  
 
namespace  mod_quiz\search
 Search area for mod_quiz activities.
 
namespace  mod_quiz\task
  
 

Classes

class  backup_mod_quiz_access_subplugin
 Base class for backing up all the quiz settings and attempt data for an access rule quiz sub-plugin. More...
 
class  backup_quiz_activity_structure_step
 Define all the backup steps that will be used by the backup_quiz_activity_task. More...
 
class  mod_quiz\access_manager
 This class aggregates the access rules that apply to a particular quiz. More...
 
class  mod_quiz\adminpresets\adminpresets_browser_security_setting
 Admin settings class for the quiz browser security option. More...
 
class  mod_quiz\adminpresets\adminpresets_grade_method_setting
 Admin settings class for the quiz grading method. More...
 
class  mod_quiz\adminpresets\adminpresets_overdue_handling_setting
 Admin settings class for the quiz overdue attempt handling method. More...
 
class  mod_quiz\adminpresets\adminpresets_review_setting
 Admin settings class for the quiz review options. More...
 
class  mod_quiz\adminpresets\adminpresets_user_image_setting
 Admin settings class for the choices for how to display the user's image. More...
 
class  mod_quiz\analytics\indicator\activity_base
 Activity base class. More...
 
class  mod_quiz\analytics\indicator\cognitive_depth
 Cognitive depth indicator - quiz. More...
 
class  mod_quiz\analytics\indicator\social_breadth
 Social breadth indicator - quiz. More...
 
class  mod_quiz\cache\overrides
 Class quiz_overrides. More...
 
class  mod_quiz\completion\custom_completion
 Activity custom completion subclass for the quiz activity. More...
 
class  mod_quiz\dates
 Class for fetching the important dates in mod_quiz for a given module instance and a user. More...
 
class  mod_quiz\event\attempt_abandoned
 The mod_quiz attempt abandoned event class. More...
 
class  mod_quiz\event\attempt_becameoverdue
 The mod_quiz attempt became overdue event class. More...
 
class  mod_quiz\event\attempt_deleted
 The mod_quiz attempt deleted event class. More...
 
class  mod_quiz\event\attempt_manual_grading_completed
 The mod_quiz attempt manual grading complete event. More...
 
class  mod_quiz\event\attempt_preview_started
 The mod_quiz attempt preview started event class. More...
 
class  mod_quiz\event\attempt_reopened
 Event fired when a quiz attempt is reopened. More...
 
class  mod_quiz\event\attempt_reviewed
 The mod_quiz attempt reviewed event class. More...
 
class  mod_quiz\event\attempt_submitted
 The mod_quiz attempt submitted event class. More...
 
class  mod_quiz\event\attempt_summary_viewed
 The mod_quiz attempt summary viewed event class. More...
 
class  mod_quiz\event\course_module_instance_list_viewed
 The mod_quiz instance list viewed event class. More...
 
class  mod_quiz\event\course_module_viewed
 The mod_quiz course module viewed event class. More...
 
class  mod_quiz\event\group_override_created
 The mod_quiz group override created event class. More...
 
class  mod_quiz\event\group_override_deleted
 The mod_quiz group override deleted event class. More...
 
class  mod_quiz\event\group_override_updated
 The mod_quiz group override updated event class. More...
 
class  mod_quiz\event\page_break_created
 The mod_quiz page break created event class. More...
 
class  mod_quiz\event\page_break_deleted
 The mod_quiz page break deleted event class. More...
 
class  mod_quiz\event\quiz_grade_updated
 The mod_quiz quiz grade updated event class. More...
 
class  mod_quiz\event\report_viewed
 The mod_quiz report viewed event class. More...
 
class  mod_quiz\event\section_break_created
 The mod_quiz section break created event class. More...
 
class  mod_quiz\event\section_title_updated
 The mod_quiz section title updated event class. More...
 
class  mod_quiz\event\slot_deleted
 The mod_quiz slot deleted event class. More...
 
class  mod_quiz\event\slot_displaynumber_updated
 The mod_quiz slot display updated event class. More...
 
class  mod_quiz\event\slot_moved
 The mod_quiz slot moved event class. More...
 
class  mod_quiz\event\slot_requireprevious_updated
 The mod_quiz slot require previous updated event class. More...
 
class  mod_quiz\event\user_override_created
 The mod_quiz user override created event class. More...
 
class  mod_quiz\event\user_override_deleted
 The mod_quiz user override deleted event class. More...
 
class  mod_quiz\event\user_override_updated
 The mod_quiz user override updated event class. More...
 
class  mod_quiz\external\add_random_questions
 Add random questions to a quiz. More...
 
class  mod_quiz\external\get_reopen_attempt_confirmation
 Web service to check a quiz attempt state, and return a confirmation message if it can be reopened now. More...
 
class  mod_quiz\external\reopen_attempt
 Web service method for re-opening a quiz attempt. More...
 
class  mod_quiz\external\submit_question_version
 External api for changing the question version in the quiz. More...
 
class  mod_quiz\external\update_filter_condition
 Update the filter condition for a random question. More...
 
class  mod_quiz\form\add_random_form
 The add random questions form. More...
 
class  mod_quiz\form\edit_override_form
 Form for editing quiz settings overrides. More...
 
class  mod_quiz\form\preflight_check_form
 A form that limits student's access to attempt a quiz. More...
 
class  mod_quiz\form\randomquestion_form
 Class randomquestion_form. More...
 
class  mod_quiz\grade_calculator
 This class contains all the logic for computing the grade of a quiz. More...
 
class  mod_quiz\group_observers
 Group observers class. More...
 
class  mod_quiz\local\access_rule_base
 Base class for rules that restrict the ability to attempt a quiz. More...
 
class  mod_quiz\local\reports\attempts_report
 Base class for quiz reports that are basically a table with one row for each attempt. More...
 
class  mod_quiz\local\reports\attempts_report_options
 Base class for the options that control what is visible in an {. More...
 
class  mod_quiz\local\reports\attempts_report_options_form
 Base class for the settings form for {. More...
 
class  mod_quiz\local\reports\attempts_report_table
 Base class for the table used by a {. More...
 
class  mod_quiz\local\reports\report_base
 Base class for quiz report plugins. More...
 
class  mod_quiz\local\structure\slot_random
 Class slot_random, represents a random question slot type. More...
 
class  mod_quiz\output\edit_renderer
 Renderer outputting the quiz editing UI. More...
 
class  mod_quiz\output\overrides_actions
 Render overrides action in the quiz secondary navigation. More...
 
class  mod_quiz\output\question_chooser
 The question_chooser renderable class. More...
 
class  mod_quiz\plugininfo\quiz
 
class  mod_quiz\plugininfo\quizaccess
 
class  mod_quiz\privacy\helper
 Privacy Subsystem implementation for mod_quiz. More...
 
interface  mod_quiz\privacy\quizaccess_provider
 The quizaccess_provider interface provides the expected interface for all 'quizaccess' quizaccesss. More...
 
interface  mod_quiz\privacy\quizaccess_user_provider
 
class  mod_quiz\question\bank\quiz_managecategories_feature
 Class quiz_managecategories_feature. More...
 
class  mod_quiz\question\bank\random_question_view
 Subclass to customise the view of the question bank for the quiz editing screen. More...
 
class  mod_quiz\quiz_attempt
 This class represents one user's attempt at a particular quiz. More...
 
class  mod_quiz\quiz_settings
 A class encapsulating the settings for a quiz. More...
 
class  mod_quiz\repaginate
 The repaginate class will rearrange questions in pages. More...
 
class  mod_quiz\search\activity
 Search area for mod_quiz activities. More...
 
class  mod_quiz\structure
 Quiz structure class. More...
 
class  mod_quiz\task\quiz_notify_attempt_manual_grading_completed
 Cron Quiz Notify Attempts Graded Task. More...
 
class  mod_quiz\task\update_overdue_attempts
 Update Overdue Attempts Task. More...
 
class  mod_quiz_generator
 Quiz module test data generator class. More...
 
class  mod_quiz_mod_form
 Settings form for the quiz module. More...
 
class  mod_quiz_overdue_attempt_updater
 
class  moodle1_mod_quiz_handler
 Quiz conversion handler. More...
 
class  moodle_quiz_exception
 Class for quiz exceptions. More...
 
class  restore_mod_quiz_access_subplugin
 Base class for restoring up all the quiz settings and attempt data for an access rule quiz sub-plugin. More...
 
class  restore_quiz_activity_structure_step
 Structure step to restore one quiz activity. More...
 
class  restore_quiz_activity_task
 quiz restore task that provides all the settings and steps to perform one complete restore of the activity More...
 

Functions

 mod_quiz::add_random_questions (int $addonpage, int $number, array $filtercondition)
 Add a random question to the quiz at a given point.
 
 mod_quiz::add_section_heading ($pagenumber, $heading=null)
 Add a section heading on a given page and return the sectionid.
 
 mod_quiz::can_add_random_questions ()
 Whether the current user can add random questions to the quiz or not.
 
 mod_quiz::can_add_section_heading ($pagenumber)
 Check whether adding a section heading is possible.
 
 mod_quiz::formatted_question_grade ($slotnumber)
 Get the maximum mark for a question, formatted for display.
 
 mod_quiz::formatted_quiz_grade ()
 Get the overall quiz grade formatted for display.
 
 mod_quiz::get_dates_summary ()
 Get the date information about the current state of the quiz.
 
 mod_quiz::get_decimal_places_for_grades ()
 Get the number of decimal places for displaying overall quiz grades or marks.
 
 mod_quiz::get_decimal_places_for_question_marks ()
 Get the number of decimal places for displaying question marks.
 
 mod_quiz::get_edit_page_warnings ()
 Get any warnings to show at the top of the edit page.
 
 mod_quiz::get_section_by_id ($sectionid)
 Get a particular section by id.
 
 mod_quiz::get_section_count ()
 Get the number of questions in the quiz.
 
 mod_quiz::get_sections ()
 Get all the sections of the quiz.
 
 mod_quiz::get_slot_tags_for_slot_id ($slotid)
 Retrieve the list of slot tags for the given slot id.
 
 mod_quiz::get_slots_in_section ($sectionid)
 Get all the slots in a section of the quiz.
 
 mod_quiz::get_version_choices_for_slot (int $slotnumber)
 Get the version options to show on the 'Questions' page for a particular question.
 
 mod_quiz::move_slot ($idmove, $idmoveafter, $page)
 Move a slot from its current location to a new location.
 
 mod_quiz::populate_question_numbers ()
 Number the questions.
 
 mod_quiz::populate_slots_with_sections ()
 Fill in the section ids for each slot.
 
 mod_quiz::populate_structure ()
 Set up this class with the structure for a given quiz.
 
 quiz_add_quiz_question ($questionid, $quiz, $page=0, $maxmark=null)
 Add a question to a quiz.
 
 quiz_add_random_questions (stdClass $quiz, int $addonpage, int $categoryid, int $number)
 Add a random question to the quiz at a given point.
 
 quiz_attempt_save_started ($quizobj, $quba, $attempt)
 The save started question usage and quiz attempt in db and log the started attempt.
 
 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.
 
 quiz_attempt_state_name ($state)
 Get the human-readable name for a quiz attempt state.
 
 quiz_attempt_submitted_handler ($event)
 Handle the quiz_attempt_submitted event.
 
 quiz_calculate_best_attempt ($quiz, $attempts)
 Return the attempt with the best grade for a quiz.
 
 quiz_calculate_best_grade ($quiz, $attempts)
 Calculate the overall grade for a quiz given a number of attempts by a particular user.
 
 quiz_create_attempt (quiz_settings $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview=false, $userid=null)
 Creates an object to represent a new attempt at a quiz.
 
 quiz_create_attempt_handling_errors ($attemptid, $cmid=null)
 Get quiz attempt and handling error.
 
 quiz_delete_attempt ($attempt, $quiz)
 Delete a quiz attempt.
 
 quiz_delete_previews ($quiz, $userid=null)
 Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user.
 
 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.
 
 quiz_feedback_record_for_grade ($grade, $quiz)
 Get the feedback object for this grade on this quiz.
 
 quiz_get_attempt_usertime_sql ($redundantwhereclauses='')
 Returns SQL to compute timeclose and timelimit for every attempt, taking into account user and group overrides.
 
 quiz_get_combined_reviewoptions ($quiz, $attempts)
 Combines the review options from a number of different quiz attempts.
 
 quiz_get_completion_state ()
 
 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.
 
 quiz_get_overdue_handling_options ()
 
 quiz_get_review_options ($quiz, $attempt, $context)
 The appropriate display_options object for this attempt at this quiz right now.
 
 quiz_get_user_attempt_unfinished ($quizid, $userid)
 Returns an unfinished attempt (if there is one) for the given user on the given quiz.
 
 quiz_get_user_image_options ()
 Get the choices for what size user picture to show.
 
 quiz_get_user_timeclose ($courseid)
 Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides.
 
 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.
 
 quiz_has_questions ($quizid)
 Are there any questions in this quiz?
 
 quiz_is_overriden_calendar_event (\calendar_event $event)
 Check if the given calendar_event is either a user or group override event for quiz.
 
 quiz_no_questions_message ($quiz, $cm, $context)
 Generate a message saying that this quiz has no questions, with a button to go to the edit page, if the user has the right capability.
 
 quiz_override_summary (stdClass $quiz, cm_info|stdClass $cm, int $currentgroup=0)
 Return summary of the number of settings override that exist.
 
 quiz_prepare_and_start_new_attempt (quiz_settings $quizobj, $attemptnumber, $lastattempt, $offlineattempt=false, $forcedrandomquestions=[], $forcedvariants=[], $userid=null)
 Prepare and start a new attempt deleting the previous preview attempts.
 
 quiz_process_group_deleted_in_course ($courseid)
 Logic to happen when a/some group(s) has/have been deleted in a course.
 
 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, $random=null)
 
 quiz_question_preview_url ($quiz, $question, $variant=null, $restartversion=null)
 
 quiz_question_tostring ($question, $showicon=false, $showquestiontext=true, $showidnumber=false, $showtags=false)
 Creates a textual representation of a question for display.
 
 quiz_questions_per_page_options ()
 Get the choices to offer for the 'Questions per page' option.
 
 quiz_repaginate_questions ($quizid, $slotsperpage)
 Repaginate the questions in a quiz.
 
 quiz_report_can_filter_only_graded ($quiz)
 
 quiz_report_default_report ($context)
 Get the default report for the current user.
 
 quiz_report_download_filename ($report, $courseshortname, $quizname)
 Create a filename for use when downloading data from a quiz report.
 
 quiz_report_feedback_for_grade ($grade, $quizid, $context)
 Get the feedback text for a grade on this quiz.
 
 quiz_report_get_significant_questions ($quiz)
 Get the slots of real questions (not descriptions) in this quiz, in order.
 
 quiz_report_grade_bands ($bandwidth, $bands, $quizid, core\dml\sql_join $usersjoins=null)
 Get the number of students whose score was in a particular band for this quiz.
 
 quiz_report_grade_method_sql ($grademethod, $quizattemptsalias='quiza')
 Given a quiz grading method return sql to test if this is an attempt that will be contribute towards the grade of the user.
 
 quiz_report_highlighting_grading_method ($quiz, $qmsubselect, $qmfilter)
 
 quiz_report_index_by_keys ($datum, $keys, $keysunique=true)
 Takes an array of objects and constructs a multidimensional array keyed by the keys it finds on the object.
 
 quiz_report_list ($context)
 Returns an array of reports to which the current user has access to.
 
 quiz_report_qm_filter_select ($quiz, $quizattemptsalias='quiza')
 This is a wrapper for quiz_report_grade_method_sql that takes the whole quiz object instead of just the grading method as a param.
 
 quiz_report_scale_summarks_as_percentage ($rawmark, $quiz, $round=true)
 Format a number as a percentage out of $quiz->sumgrades.
 
 quiz_report_should_show_grades ($quiz, context $context)
 Should the grades be displayed in this report.
 
 quiz_report_unindex ($datum)
 
 quiz_require_question_use ($questionid)
 Verify that the question exists, and the user has permission to use it.
 
 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.
 
 quiz_retrieve_tags_for_slot_ids ($slotids)
 Retrieves tag information for the given list of quiz slot ids.
 
 quiz_save_best_grade ($quiz, $userid=null, $attempts=[])
 Save the overall grade for a user at a quiz in the quiz_grades table.
 
 quiz_send_confirmation ($recipient, $a, $studentisonline)
 Sends a confirmation message to the student confirming that the attempt was processed.
 
 quiz_send_notification ($recipient, $submitter, $a)
 Sends notification messages to the interested parties that assign the role capability.
 
 quiz_send_notification_messages ($course, $quiz, $attempt, $context, $cm, $studentisonline)
 Send all the requried messages when a quiz attempt is submitted.
 
 quiz_send_notify_manual_graded_message (quiz_attempt $attemptobj, object $userto)
 Send the notification message when a quiz attempt has been manual graded.
 
 quiz_send_overdue_message ($attemptobj)
 Send the notification message when a quiz attempt becomes overdue.
 
 quiz_set_grade ($newgrade, $quiz)
 The quiz grade is the maximum that student's results are marked out of.
 
 quiz_start_attempt_built_on_last ($quba, $attempt, $lastattempt)
 Start a subsequent new attempt, in each attempt builds on last mode.
 
 quiz_start_new_attempt ($quizobj, $quba, $attempt, $attemptnumber, $timenow, $questionids=[], $forcedvariantsbyslot=[])
 Start a normal, new, quiz attempt.
 
 quiz_update_all_attempt_sumgrades ($quiz)
 Update the sumgrades field of the attempts at a quiz.
 
 quiz_update_all_final_grades ($quiz)
 Update the final grade at this quiz for all students.
 
 quiz_update_open_attempts (array $conditions)
 Efficiently update check state time on all open attempts.
 
 quiz_update_section_firstslots ($quizid, $direction, $afterslot, $beforeslot=null)
 Move all the section headings in a certain slot range by a certain offset.
 
 quiz_update_sumgrades ($quiz)
 Update the sumgrades field of the quiz.
 
 quiz_validate_new_attempt (quiz_settings $quizobj, access_manager $accessmanager, $forcenew, $page, $redirect)
 Validate permissions for creating a new attempt and start a new preview attempt if required.
 
 quiz_view ($quiz, $course, $cm, $context)
 Mark the activity completed (if required) and trigger the course_module_viewed event.
 
 mod_quiz::refresh_page_numbers ($slots=[])
 Refresh page numbering of quiz slots.
 
 mod_quiz::refresh_page_numbers_and_update_db ()
 Refresh page numbering of quiz slots and save to the database.
 
 mod_quiz::remove_section_heading ($sectionid)
 Remove the section heading with the given id.
 
 mod_quiz::remove_slot ($slotnumber)
 Remove a slot from a quiz.
 
 mod_quiz::set_section_heading ($id, $newheading)
 Change the heading for a section.
 
 mod_quiz::set_section_shuffle ($id, $shuffle)
 Change the shuffle setting for a section.
 
 mod_quiz::unset_question ($slotid)
 Unset the question object after deletion.
 
 mod_quiz::update_page_break ($slotid, $type)
 Add/Remove a pagebreak.
 
 mod_quiz::update_question_dependency ($slotid, $requireprevious)
 Set whether the question in a particular slot requires the previous one.
 
 mod_quiz::update_slot_display_number (int $slotid, string $displaynumber)
 Update the question display number when is set as customised display number or empy string.
 
 mod_quiz::update_slot_maxmark ($slot, $maxmark)
 Change the max mark for a slot.
 
 xmldb_quiz_upgrade ($oldversion)
 Upgrade script for the quiz module.
 

Variables

 $capabilities
 
global mod_quiz\task::$CFG
 
 $definitions
 
 $messageproviders
 
 $plugin = 2023100400
 
 $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config')
 
 $renamedclasses
 
 $reports = core_component::get_plugin_list_with_file('quiz', 'settings.php', false)
 
 $reportsbyname = []
 
 $rules = core_component::get_plugin_list_with_file('quizaccess', 'settings.php', false)
 
 $rulesbyname = []
 
foreach( $reportsbyname as $strreportname=> $report) foreach($rulesbyname as $strrulename=> $rule) $settings = null
 
$plugin component = 'mod_quiz'
 
if(empty($reportsbyname) &&empty($rulesbyname)) else
 
 if (!defined( 'MOODLE_INTERNAL'))
 
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.
 
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.
 
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.
 
$plugin version = 2023100901
 

Detailed Description

Function Documentation

◆ add_random_questions()

mod_quiz\add_random_questions ( int $addonpage,
int $number,
array $filtercondition )

Add a random question to the quiz at a given point.

Parameters
int$addonpagethe page on which to add the question.
int$numberthe number of random questions to add.
array$filterconditionthe filter condition. Must contain at least a category filter.

◆ add_section_heading()

mod_quiz\add_section_heading ( $pagenumber,
$heading = null )

Add a section heading on a given page and return the sectionid.

Parameters
int$pagenumberthe number of the page where the section heading begins.
string | null$headingthe heading to add. If not given, a default is used.

◆ can_add_random_questions()

mod_quiz\can_add_random_questions ( )

Whether the current user can add random questions to the quiz or not.

It is only possible to add a random question if the user has the moodle/question:useall capability on at least one of the contexts related to the one where we are currently editing questions.

Return values
bool

◆ can_add_section_heading()

mod_quiz\can_add_section_heading ( $pagenumber)

Check whether adding a section heading is possible.

Parameters
int$pagenumberthe number of the page.
Return values
boolean

◆ formatted_question_grade()

mod_quiz\formatted_question_grade ( $slotnumber)

Get the maximum mark for a question, formatted for display.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stringthe maximum mark for the question in this slot.

◆ formatted_quiz_grade()

mod_quiz\formatted_quiz_grade ( )

Get the overall quiz grade formatted for display.

Return values
stringthe maximum grade for this quiz.

◆ get_dates_summary()

mod_quiz\get_dates_summary ( )

Get the date information about the current state of the quiz.

Return values
string[]array of two strings. First a short summary, then a longer explanation of the current state, e.g. for a tool-tip.

◆ get_decimal_places_for_grades()

mod_quiz\get_decimal_places_for_grades ( )

Get the number of decimal places for displaying overall quiz grades or marks.

Return values
intthe number of decimal places.

◆ get_decimal_places_for_question_marks()

mod_quiz\get_decimal_places_for_question_marks ( )

Get the number of decimal places for displaying question marks.

Return values
intthe number of decimal places.

◆ get_edit_page_warnings()

mod_quiz\get_edit_page_warnings ( )

Get any warnings to show at the top of the edit page.

Return values
string[]array of strings.

◆ get_section_by_id()

mod_quiz\get_section_by_id ( $sectionid)

Get a particular section by id.

Return values
stdClassthe section.

◆ get_section_count()

mod_quiz\get_section_count ( )

Get the number of questions in the quiz.

Return values
intthe number of questions in the quiz.

◆ get_sections()

mod_quiz\get_sections ( )

Get all the sections of the quiz.

Return values
stdClass[]the sections in this quiz.

◆ get_slot_tags_for_slot_id()

mod_quiz\get_slot_tags_for_slot_id ( $slotid)

Retrieve the list of slot tags for the given slot id.

Parameters
int$slotidThe id for the slot
Return values
stdClass[]The list of slot tag records
Deprecated
since Moodle 4.0 MDL-71573
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ get_slots_in_section()

mod_quiz\get_slots_in_section ( $sectionid)

Get all the slots in a section of the quiz.

Parameters
int$sectionidthe section id.
Return values
int[]slot numbers.

◆ get_version_choices_for_slot()

mod_quiz\get_version_choices_for_slot ( int $slotnumber)

Get the version options to show on the 'Questions' page for a particular question.

Parameters
int$slotnumberwhich slot to get the choices for.
Return values
stdClass[]other versions of this question. Each object has fields versionid, version and selected. Array is returned most recent version first.

◆ move_slot()

mod_quiz\move_slot ( $idmove,
$idmoveafter,
$page )

Move a slot from its current location to a new location.

After calling this method, this class will be in an invalid state, and should be discarded if you want to manipulate the structure further.

Parameters
int$idmoveid of slot to be moved
int$idmoveafterid of slot to come before slot being moved
int$pagenew page number of slot being moved

◆ quiz_add_quiz_question()

quiz_add_quiz_question ( $questionid,
$quiz,
$page = 0,
$maxmark = null )

Add a question to a quiz.

Adds a question to a quiz by updating $quiz as well as the quiz and quiz_slots tables. It also adds a page break if required.

Parameters
int$questionidThe id of the question to be added
stdClass$quizThe extended quiz object as used by edit.php This is updated by this function
int$pageWhich page in quiz to add the question on. If 0 (default), add at the end
float$maxmarkThe maximum mark to set for this question. (Optional, defaults to question.defaultmark.
Return values
boolfalse if the question was already in the quiz

◆ quiz_add_random_questions()

quiz_add_random_questions ( stdClass $quiz,
int $addonpage,
int $categoryid,
int $number )

Add a random question to the quiz at a given point.

Parameters
stdClass$quizthe quiz settings.
int$addonpagethe page on which to add the question.
int$categoryidthe question category to add the question from.
int$numberthe number of random questions to add.
Deprecated
Since Moodle 4.3 MDL-72321
Todo
Final deprecation in Moodle 4.7 MDL-78091

◆ quiz_attempt_save_started()

quiz_attempt_save_started ( $quizobj,
$quba,
$attempt )

The save started question usage and quiz attempt in db and log the started attempt.

Parameters
quiz_settings$quizobj
question_usage_by_activity$quba
stdClass$attempt
Return values
stdClassattempt object with uniqueid and id set.

◆ quiz_attempt_state()

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.

Parameters
stdClass$quizthe quiz settings
stdClass$attemptthe quiz_attempt database row.
Return values
intone of the display_options\DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.

◆ quiz_attempt_state_name()

quiz_attempt_state_name ( $state)

Get the human-readable name for a quiz attempt state.

Parameters
string$stateone of the state constants like {
See also
quiz_attempt\IN_PROGRESS}.
Return values
stringThe lang string to describe that state.

◆ quiz_attempt_submitted_handler()

quiz_attempt_submitted_handler ( $event)

Handle the quiz_attempt_submitted event.

This sends the confirmation and notification messages, if required.

Parameters
attempt_submitted$eventthe event object.

◆ quiz_calculate_best_attempt()

quiz_calculate_best_attempt ( $quiz,
$attempts )

Return the attempt with the best grade for a quiz.

Which attempt is the best depends on $quiz->grademethod. If the grade method is GRADEAVERAGE then this function simply returns the last attempt.

Return values
stdClassThe attempt with the best grade
Parameters
stdClass$quizThe quiz for which the best grade is to be calculated
array$attemptsAn array of all the attempts of the user at the quiz
Deprecated
since Moodle 4.2. No direct replacement.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_calculate_best_grade()

quiz_calculate_best_grade ( $quiz,
$attempts )

Calculate the overall grade for a quiz given a number of attempts by a particular user.

Parameters
stdClass$quizthe quiz settings object.
array$attemptsan array of all the user's attempts at this quiz in order.
Return values
floatthe overall grade
Deprecated
since Moodle 4.2. No direct replacement.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_create_attempt()

quiz_create_attempt ( quiz_settings $quizobj,
$attemptnumber,
$lastattempt,
$timenow,
$ispreview = false,
$userid = null )

Creates an object to represent a new attempt at a quiz.

Creates an attempt object to represent an attempt at the quiz by the current user starting at the current time. The ->id field is not set. The object is NOT written to the database.

Parameters
quiz_settings$quizobjthe quiz object to create an attempt for.
int$attemptnumberthe sequence number for the attempt.
stdClass | false$lastattemptthe previous attempt by this user, if any. Only needed if $attemptnumber > 1 and $quiz->attemptonlast is true.
int$timenowthe time the attempt was started at.
bool$ispreviewwhether this new attempt is a preview.
int | null$useridthe id of the user attempting this quiz.
Return values
stdClassthe newly created attempt object.

◆ quiz_create_attempt_handling_errors()

quiz_create_attempt_handling_errors ( $attemptid,
$cmid = null )

Get quiz attempt and handling error.

Parameters
int$attemptidthe id of the current attempt.
int | null$cmidthe course_module id for this quiz.
Return values
quiz_attemptall the data about the quiz attempt.

◆ quiz_delete_attempt()

quiz_delete_attempt ( $attempt,
$quiz )

Delete a quiz attempt.

Parameters
mixed$attemptan integer attempt id or an attempt object (row of the quiz_attempts table).
stdClass$quizthe quiz object.

◆ quiz_delete_previews()

quiz_delete_previews ( $quiz,
$userid = null )

Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user.

Parameters
stdClass$quizthe quiz object.
int$userid(optional) if given, only delete the previews belonging to this user.

◆ quiz_feedback_for_grade()

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.

The feedback is processed ready for diplay.

Parameters
float$gradea grade on this quiz.
stdClass$quizthe quiz settings.
context_module$contextthe quiz context.
Return values
stringthe comment that corresponds to this grade (empty string if there is not one.

◆ quiz_feedback_record_for_grade()

quiz_feedback_record_for_grade ( $grade,
$quiz )

Get the feedback object for this grade on this quiz.

Parameters
float$gradea grade on this quiz.
stdClass$quizthe quiz settings.
Return values
false|stdClassthe record object or false if there is not feedback for the given grade
Since
Moodle 3.1

◆ quiz_get_attempt_usertime_sql()

quiz_get_attempt_usertime_sql ( $redundantwhereclauses = '')

Returns SQL to compute timeclose and timelimit for every attempt, taking into account user and group overrides.

The query used herein is very similar to the one in function quiz_get_user_timeclose, so, in case you would change either one of them, make sure to apply your changes to both.

Parameters
string$redundantwhereclausesextra where clauses to add to the subquery for performance. These can use the table alias iquiza for the quiz attempts table.
Return values
stringSQL select with columns attempt.id, usertimeclose, usertimelimit.

◆ quiz_get_combined_reviewoptions()

quiz_get_combined_reviewoptions ( $quiz,
$attempts )

Combines the review options from a number of different quiz attempts.

Returns an array of two ojects, so the suggested way of calling this funciton is: list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)

Parameters
stdClass$quizthe quiz instance.
array$attemptsan array of attempt objects.
Return values
arrayof two options objects, one showing which options are true for at least one of the attempts, the other showing which options are true for all attempts.

◆ quiz_get_completion_state()

quiz_get_completion_state ( )
Deprecated
since Moodle 3.11

◆ quiz_get_flag_option()

quiz_get_flag_option ( $attempt,
$context )
Parameters
stdClass$attemptthe attempt.
stdClass$contextthe quiz context.
Return values
intwhether flags should be shown/editable to the current user for this attempt.

◆ quiz_get_grading_option_name()

quiz_get_grading_option_name ( $option)
Parameters
int$optionone of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE, QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST.
Return values
thelang string for that option.

◆ quiz_get_grading_options()

quiz_get_grading_options ( )
Return values
arrayint => lang string the options for calculating the quiz grade from the individual attempt grades.

◆ quiz_get_js_module()

quiz_get_js_module ( )

Get the information about the standard quiz JavaScript module.

Return values
arraya standard jsmodule structure.

◆ quiz_get_overdue_handling_options()

quiz_get_overdue_handling_options ( )
Return values
arraystring => lang string the options for handling overdue quiz attempts.

◆ quiz_get_review_options()

quiz_get_review_options ( $quiz,
$attempt,
$context )

The appropriate display_options object for this attempt at this quiz right now.

Parameters
stdClass$quizthe quiz instance.
stdClass$attemptthe attempt in question.
context$contextthe quiz context.
Return values
display_options

◆ quiz_get_user_attempt_unfinished()

quiz_get_user_attempt_unfinished ( $quizid,
$userid )

Returns an unfinished attempt (if there is one) for the given user on the given quiz.

This function does not return preview attempts.

Parameters
int$quizidthe id of the quiz.
int$useridthe id of the user.
Return values
mixedthe unfinished attempt if there is one, false if not.

◆ quiz_get_user_image_options()

quiz_get_user_image_options ( )

Get the choices for what size user picture to show.

Return values
arraystring => lang string the options for whether to display the user's picture.

◆ quiz_get_user_timeclose()

quiz_get_user_timeclose ( $courseid)

Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides.

Parameters
int$courseidthe course id.
Return values
stdClassAn object with of all quizids and close unixdates in this course, taking into account the most lenient overrides, if existing and 0 if no close date is set.

◆ quiz_has_attempts()

quiz_has_attempts ( $quizid)
Parameters
int$quizidThe quiz id.
Return values
boolwhether this quiz has any (non-preview) attempts.

◆ quiz_has_feedback()

quiz_has_feedback ( $quiz)
Parameters
stdClass$quizthe quiz database row.
Return values
boolWhether this quiz has any non-blank feedback text.

◆ quiz_has_question_use()

quiz_has_question_use ( $quiz,
$slot )

Verify that the question exists, and the user has permission to use it.

Deprecated
in 4.1 use mod_quiz\structure\has_use_capability(...) instead.
Parameters
stdClass$quizthe quiz settings.
int$slotwhich question in the quiz to test.
Return values
boolwhether the user can use this question.

◆ quiz_has_questions()

quiz_has_questions ( $quizid)

Are there any questions in this quiz?

Parameters
int$quizidthe quiz id.

◆ quiz_is_overriden_calendar_event()

quiz_is_overriden_calendar_event ( \calendar_event $event)

Check if the given calendar_event is either a user or group override event for quiz.

Parameters
calendar_event$eventThe calendar event to check
Return values
bool

◆ quiz_no_questions_message()

quiz_no_questions_message ( $quiz,
$cm,
$context )

Generate a message saying that this quiz has no questions, with a button to go to the edit page, if the user has the right capability.

Parameters
stdClass$quizthe quiz settings.
stdClass$cmthe course_module object.
stdClass$contextthe quiz context.
Return values
stringHTML to output.

◆ quiz_override_summary()

quiz_override_summary ( stdClass $quiz,
cm_info|stdClass $cm,
int $currentgroup = 0 )

Return summary of the number of settings override that exist.

To get a nice display of this, see the quiz_override_summary_links() quiz renderer method.

Parameters
stdClass$quizthe quiz settings. Only $quiz->id is used at the moment.
cm_info | stdClass$cmthe cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
int$currentgroupif there is a concept of current group where this method is being called (e.g. a report) pass it in here. Default 0 which means no current group.
Return values
arraylike 'group' => 3, 'user' => 12] where 3 is the number of group overrides, and 12 is the number of user ones.

◆ quiz_prepare_and_start_new_attempt()

quiz_prepare_and_start_new_attempt ( quiz_settings $quizobj,
$attemptnumber,
$lastattempt,
$offlineattempt = false,
$forcedrandomquestions = [],
$forcedvariants = [],
$userid = null )

Prepare and start a new attempt deleting the previous preview attempts.

Parameters
quiz_settings$quizobjquiz object
int$attemptnumberthe attempt number
stdClass$lastattemptlast attempt object
bool$offlineattemptwhether is an offline attempt or not
array$forcedrandomquestionsslot number => question id. Used for random questions, to force the choice of a particular actual question. Intended for testing purposes only.
array$forcedvariantsslot number => variant. Used for questions with variants, to force the choice of a particular variant. Intended for testing purposes only.
int$useridSpecific user id to create an attempt for that user, null for current logged in user
Return values
stdClassthe new attempt
Since
Moodle 3.1

◆ quiz_process_group_deleted_in_course()

quiz_process_group_deleted_in_course ( $courseid)

Logic to happen when a/some group(s) has/have been deleted in a course.

Parameters
int$courseidThe course ID.
Return values
void

◆ quiz_question_action_icons()

quiz_question_action_icons ( $quiz,
$cmid,
$question,
$returnurl,
$variant = null )
Parameters
stdClass$quizthe quiz.
int$cmidthe course_module object for this quiz.
stdClass$questionthe question.
string$returnurlurl to return to after action is done.
int$variantwhich question variant to preview (optional).
Return values
stringhtml for a number of icons linked to action pages for a question - preview and edit / view icons depending on user capabilities.

◆ quiz_question_edit_button()

quiz_question_edit_button ( $cmid,
$question,
$returnurl,
$contentaftericon = '' )
Parameters
int$cmidthe course_module.id for this quiz.
stdClass$questionthe question.
string$returnurlurl to return to after action is done.
string$contentbeforeiconsome HTML content to be added inside the link, before the icon.
Return values
theHTML for an edit icon, view icon, or nothing for a question (depending on permissions).

◆ quiz_question_preview_button()

quiz_question_preview_button ( $quiz,
$question,
$label = false,
$variant = null,
$random = null )
Parameters
stdClass$quizthe quiz settings
stdClass$questionthe question
bool$labelif true, show the preview question label after the icon
int$variantwhich question variant to preview (optional).
bool$randomif question is random, true.
Return values
stringthe HTML for a preview question icon.

◆ quiz_question_preview_url()

quiz_question_preview_url ( $quiz,
$question,
$variant = null,
$restartversion = null )
Parameters
stdClass$quizthe quiz settings
stdClass$questionthe question
int$variantwhich question variant to preview (optional).
int$restartversionversion of the question to use when restarting the preview.
Return values
moodle_urlto preview this question with the options from this quiz.

◆ quiz_question_tostring()

quiz_question_tostring ( $question,
$showicon = false,
$showquestiontext = true,
$showidnumber = false,
$showtags = false )

Creates a textual representation of a question for display.

Parameters
stdClass$questionA question object from the database questions table
bool$showiconIf true, show the question's icon with the question. False by default.
bool$showquestiontextIf true (default), show question text after question name. If false, show only question name.
bool$showidnumberIf true, show the question's idnumber, if any. False by default.
core_tag_tag[] | bool$showtagsif array passed, show those tags. Else, if true, get and show tags, else, don't show tags (which is the default).
Return values
stringHTML fragment.

◆ quiz_questions_per_page_options()

quiz_questions_per_page_options ( )

Get the choices to offer for the 'Questions per page' option.

Return values
arrayint => string.

◆ quiz_repaginate_questions()

quiz_repaginate_questions ( $quizid,
$slotsperpage )

Repaginate the questions in a quiz.

Parameters
int$quizidthe id of the quiz to repaginate.
int$slotsperpagenumber of items to put on each page. 0 means unlimited.

◆ quiz_report_can_filter_only_graded()

quiz_report_can_filter_only_graded ( $quiz)
Parameters
stdClass$quizthe quiz settings.
Return values
boolwhether, for this quiz, it is possible to filter attempts to show only those that gave the final grade.

◆ quiz_report_default_report()

quiz_report_default_report ( $context)

Get the default report for the current user.

Parameters
stdClass$contextthe quiz context.

◆ quiz_report_download_filename()

quiz_report_download_filename ( $report,
$courseshortname,
$quizname )

Create a filename for use when downloading data from a quiz report.

It is expected that this will be passed to flexible_table\is_downloading, which cleans the filename of bad characters and adds the file extension.

Parameters
string$reportthe type of report.
string$courseshortnamethe course shortname.
string$quiznamethe quiz name.
Return values
stringthe filename.

◆ quiz_report_feedback_for_grade()

quiz_report_feedback_for_grade ( $grade,
$quizid,
$context )

Get the feedback text for a grade on this quiz.

The feedback is processed ready for display.

Parameters
float$gradea grade on this quiz.
int$quizidthe id of the quiz object.
Return values
stringthe comment that corresponds to this grade (empty string if there is not one.

◆ quiz_report_get_significant_questions()

quiz_report_get_significant_questions ( $quiz)

Get the slots of real questions (not descriptions) in this quiz, in order.

Parameters
stdClass$quizthe quiz.
Return values
arrayof slot => objects with fields ->slot, ->id, ->qtype, ->length, ->number, ->maxmark, ->category (for random questions).

◆ quiz_report_grade_bands()

quiz_report_grade_bands ( $bandwidth,
$bands,
$quizid,
core\dml\sql_join $usersjoins = null )

Get the number of students whose score was in a particular band for this quiz.

Parameters
number$bandwidththe width of each band.
int$bandsthe number of bands
int$quizidthe quiz id.
core\dml\sql_join$usersjoins(joins, wheres, params) to get enrolled users
Return values
arrayband number => number of users with scores in that band.

◆ quiz_report_grade_method_sql()

quiz_report_grade_method_sql ( $grademethod,
$quizattemptsalias = 'quiza' )

Given a quiz grading method return sql to test if this is an attempt that will be contribute towards the grade of the user.

Or return an empty string if the grading method is QUIZ_GRADEAVERAGE and thus all attempts contribute to final grade.

Parameters
string$grademethodquiz grading method.
string$quizattemptsaliassql alias for 'quiz_attempts' table
Return values
stringsql to test if this is an attempt that will contribute towards the graded of the user

◆ quiz_report_index_by_keys()

quiz_report_index_by_keys ( $datum,
$keys,
$keysunique = true )

Takes an array of objects and constructs a multidimensional array keyed by the keys it finds on the object.

Parameters
array$datuman array of objects with properties on the object including the keys passed as the next param.
array$keysArray of strings with the names of the properties on the objects in datum that you want to index the multidimensional array by.
bool$keysuniqueIf there is not only one object for each combination of keys you are using you should set $keysunique to true. Otherwise all the object will be added to a zero based array. So the array returned will have count($keys) + 1 indexs.
Return values
arraymultidimensional array properly indexed.

◆ quiz_report_list()

quiz_report_list ( $context)

Returns an array of reports to which the current user has access to.

Return values
arrayreports are ordered as they should be for display in tabs.

◆ quiz_report_qm_filter_select()

quiz_report_qm_filter_select ( $quiz,
$quizattemptsalias = 'quiza' )

This is a wrapper for quiz_report_grade_method_sql that takes the whole quiz object instead of just the grading method as a param.

See definition for quiz_report_grade_method_sql below.

Parameters
stdClass$quiz
string$quizattemptsaliassql alias for 'quiz_attempts' table
Return values
stringsql to test if this is an attempt that will contribute towards the grade of the user

◆ quiz_report_scale_summarks_as_percentage()

quiz_report_scale_summarks_as_percentage ( $rawmark,
$quiz,
$round = true )

Format a number as a percentage out of $quiz->sumgrades.

Parameters
number$rawgradethe mark to format.
stdClass$quizthe quiz settings
bool$roundwhether to round the results ot $quiz->decimalpoints.

◆ quiz_report_should_show_grades()

quiz_report_should_show_grades ( $quiz,
context $context )

Should the grades be displayed in this report.

That depends on the quiz display options, and whether the quiz is graded.

Parameters
stdClass$quizthe quiz settings.
context$contextthe quiz context.
Return values
bool

◆ quiz_require_question_use()

quiz_require_question_use ( $questionid)

Verify that the question exists, and the user has permission to use it.

Does not return. Throws an exception if the question cannot be used.

Parameters
int$questionidThe id of the question.

◆ quiz_rescale_grade()

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.

Parameters
float$rawgradethe unadjusted grade, fof example $attempt->sumgrades
stdClass$quizthe quiz object. Only the fields grade, sumgrades and decimalpoints are used.
bool | string$formatwhether to format the results for display or 'question' to format a question grade (different number of decimal places.
Return values
float|stringthe rescaled grade, or null/the lang string 'notyetgraded' if the $grade is null.

◆ quiz_retrieve_tags_for_slot_ids()

quiz_retrieve_tags_for_slot_ids ( $slotids)

Retrieves tag information for the given list of quiz slot ids.

Currently the only slots that have tags are random question slots.

Example: If we have 3 slots with id 1, 2, and 3. The first slot has two tags, the second has one tag, and the third has zero tags. The return structure will look like: [ 1 => [ quiz_slot_tags.id => { ...tag data... }, quiz_slot_tags.id => { ...tag data... }, ], 2 => [ quiz_slot_tags.id => { ...tag data... }, ], 3 => [], ]

Parameters
int[]$slotidsThe list of id for the quiz slots.
Return values
array[]List of quiz_slot_tags records indexed by slot id.
Deprecated
since Moodle 4.0
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ quiz_save_best_grade()

quiz_save_best_grade ( $quiz,
$userid = null,
$attempts = [] )

Save the overall grade for a user at a quiz in the quiz_grades table.

Parameters
stdClass$quizThe quiz for which the best grade is to be calculated and then saved.
int$useridThe userid to calculate the grade for. Defaults to the current user.
array$attemptsThe attempts of this user. Useful if you are looping through many users. Attempts can be fetched in one master query to avoid repeated querying.
Return values
boolIndicates success or failure.
Deprecated
since Moodle 4.2. Please use grade_calculator\update_quiz_maximum_grade.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_send_confirmation()

quiz_send_confirmation ( $recipient,
$a,
$studentisonline )

Sends a confirmation message to the student confirming that the attempt was processed.

Parameters
stdClass$recipientuser object for the recipient.
stdClass$alots of useful information that can be used in the message subject and body.
bool$studentisonlineis the student currently interacting with Moodle?
Return values
int|falseas for message_send().

◆ quiz_send_notification()

quiz_send_notification ( $recipient,
$submitter,
$a )

Sends notification messages to the interested parties that assign the role capability.

Parameters
stdClass$recipientuser object of the intended recipient
stdClass$submitteruser object for the user who submitted the attempt.
stdClass$aassociative array of replaceable fields for the templates
Return values
int|falseas for message_send().

◆ quiz_send_notification_messages()

quiz_send_notification_messages ( $course,
$quiz,
$attempt,
$context,
$cm,
$studentisonline )

Send all the requried messages when a quiz attempt is submitted.

Parameters
stdClass$coursethe course
stdClass$quizthe quiz
stdClass$attemptthis attempt just finished
stdClass$contextthe quiz context
stdClass$cmthe coursemodule for this quiz
bool$studentisonlineis the student currently interacting with Moodle?
Return values
booltrue if all necessary messages were sent successfully, else false.

◆ quiz_send_notify_manual_graded_message()

quiz_send_notify_manual_graded_message ( quiz_attempt $attemptobj,
object $userto )

Send the notification message when a quiz attempt has been manual graded.

Parameters
quiz_attempt$attemptobjSome data about the quiz attempt.
stdClass$userto
Return values
int|falseAs for message_send.

◆ quiz_send_overdue_message()

quiz_send_overdue_message ( $attemptobj)

Send the notification message when a quiz attempt becomes overdue.

Parameters
quiz_attempt$attemptobjall the data about the quiz attempt.

◆ quiz_set_grade()

quiz_set_grade ( $newgrade,
$quiz )

The quiz grade is the maximum that student's results are marked out of.

When it changes, the corresponding data in quiz_grades and quiz_feedback needs to be rescaled. After calling this function, you probably need to call quiz_update_all_attempt_sumgrades, grade_calculator\recompute_all_final_grades(); quiz_update_grades. (At least, that is what this comment has said for years, but it seems to call recompute_all_final_grades itself.)

Parameters
float$newgradethe new maximum grade for the quiz.
stdClass$quizthe quiz we are updating. Passed by reference so its grade field can be updated too.
Return values
boolindicating success or failure.
Deprecated
since Moodle 4.2. Please use grade_calculator\update_quiz_maximum_grade.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_start_attempt_built_on_last()

quiz_start_attempt_built_on_last ( $quba,
$attempt,
$lastattempt )

Start a subsequent new attempt, in each attempt builds on last mode.

Parameters
question_usage_by_activity$qubathis question usage
stdClass$attemptthis attempt
stdClass$lastattemptlast attempt
Return values
stdClassmodified attempt object

◆ quiz_start_new_attempt()

quiz_start_new_attempt ( $quizobj,
$quba,
$attempt,
$attemptnumber,
$timenow,
$questionids = [],
$forcedvariantsbyslot = [] )

Start a normal, new, quiz attempt.

Parameters
quiz_settings$quizobjthe quiz object to start an attempt for.
question_usage_by_activity$quba
stdClass$attempt
integer$attemptnumberstarting from 1
integer$timenowthe attempt start time
array$questionidsslot number => question id. Used for random questions, to force the choice of a particular actual question. Intended for testing purposes only.
array$forcedvariantsbyslotslot number => variant. Used for questions with variants, to force the choice of a particular variant. Intended for testing purposes only.
Return values
stdClassmodified attempt object

◆ quiz_update_all_attempt_sumgrades()

quiz_update_all_attempt_sumgrades ( $quiz)

Update the sumgrades field of the attempts at a quiz.

Parameters
stdClass$quiza quiz.
Deprecated
since Moodle 4.2. Please use grade_calculator\recompute_all_attempt_sumgrades.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_update_all_final_grades()

quiz_update_all_final_grades ( $quiz)

Update the final grade at this quiz for all students.

This function is equivalent to calling quiz_save_best_grade for all users, but much more efficient.

Parameters
stdClass$quizthe quiz settings.
Deprecated
since Moodle 4.2. Please use grade_calculator\recompute_all_final_grades.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_update_open_attempts()

quiz_update_open_attempts ( array $conditions)

Efficiently update check state time on all open attempts.

Parameters
array$conditionsoptional restrictions on which attempts to update Allowed conditions: courseid => (array|int) attempts in given course(s) userid => (array|int) attempts for given user(s) quizid => (array|int) attempts in given quiz(s) groupid => (array|int) quizzes with some override for given group(s)

◆ quiz_update_section_firstslots()

quiz_update_section_firstslots ( $quizid,
$direction,
$afterslot,
$beforeslot = null )

Move all the section headings in a certain slot range by a certain offset.

Parameters
int$quizidthe id of a quiz
int$directionamount to adjust section heading positions. Normally +1 or -1.
int$afterslotadjust headings that start after this slot.
int | null$beforeslotoptionally, only adjust headings before this slot.

◆ quiz_update_sumgrades()

quiz_update_sumgrades ( $quiz)

Update the sumgrades field of the quiz.

This needs to be called whenever the grading structure of the quiz is changed. For example if a question is added or removed, or a question weight is changed.

You should call {

See also
quiz_delete_previews()} before you call this function.
Parameters
stdClass$quiza quiz.
Deprecated
since Moodle 4.2. Please use grade_calculator\recompute_quiz_sumgrades.
Todo
MDL-76612 Final deprecation in Moodle 4.6

◆ quiz_validate_new_attempt()

quiz_validate_new_attempt ( quiz_settings $quizobj,
access_manager $accessmanager,
$forcenew,
$page,
$redirect )

Validate permissions for creating a new attempt and start a new preview attempt if required.

Parameters
quiz_settings$quizobjquiz object
access_manager$accessmanagerquiz access manager
bool$forcenewwhether was required to start a new preview attempt
int$pagepage to jump to in the attempt
bool$redirectwhether to redirect or throw exceptions (for web or ws usage)
Return values
arrayan array containing the attempt information, access error messages and the page to jump to in the attempt
Since
Moodle 3.1

◆ quiz_view()

quiz_view ( $quiz,
$course,
$cm,
$context )

Mark the activity completed (if required) and trigger the course_module_viewed event.

Parameters
stdClass$quizquiz object
stdClass$coursecourse object
stdClass$cmcourse module object
stdClass$contextcontext object
Since
Moodle 3.1

◆ refresh_page_numbers()

mod_quiz\refresh_page_numbers ( $slots = [])

Refresh page numbering of quiz slots.

Parameters
stdClass[]$slots(optional) array of slot objects.
Return values
stdClass[]array of slot objects.

◆ refresh_page_numbers_and_update_db()

mod_quiz\refresh_page_numbers_and_update_db ( )

Refresh page numbering of quiz slots and save to the database.

Return values
stdClass[]array of slot objects.

◆ remove_section_heading()

mod_quiz\remove_section_heading ( $sectionid)

Remove the section heading with the given id.

Parameters
int$sectionidthe section to remove.

◆ remove_slot()

mod_quiz\remove_slot ( $slotnumber)

Remove a slot from a quiz.

Parameters
int$slotnumberThe number of the slot to be deleted.
Exceptions
coding_exception

◆ set_section_heading()

mod_quiz\set_section_heading ( $id,
$newheading )

Change the heading for a section.

Parameters
int$idthe id of the section to change.
string$newheadingthe new heading for this section.

◆ set_section_shuffle()

mod_quiz\set_section_shuffle ( $id,
$shuffle )

Change the shuffle setting for a section.

Parameters
int$idthe id of the section to change.
bool$shufflewhether this section should be shuffled.

◆ unset_question()

mod_quiz\unset_question ( $slotid)

Unset the question object after deletion.

Parameters
int$slotid

◆ update_page_break()

mod_quiz\update_page_break ( $slotid,
$type )

Add/Remove a pagebreak.

Save changes to the slot page relationship in the quiz_slots table and reorders the paging for subsequent slots.

Parameters
int$slotidid of slot which we will add/remove the page break before.
int$typerepaginate\LINK or repaginate\UNLINK.
Return values
stdClass[]array of slot objects.

◆ update_question_dependency()

mod_quiz\update_question_dependency ( $slotid,
$requireprevious )

Set whether the question in a particular slot requires the previous one.

Parameters
int$slotidid of slot.
bool$requirepreviousif true, set this question to require the previous one.

◆ update_slot_display_number()

mod_quiz\update_slot_display_number ( int $slotid,
string $displaynumber )

Update the question display number when is set as customised display number or empy string.

When the field displaynumber is set to empty string, the automated numbering is used. Log the updated displatnumber field.

Parameters
int$slotidid of slot.
string$displaynumberset to customised string as question number or empty string fo autonumbering.

◆ update_slot_maxmark()

mod_quiz\update_slot_maxmark ( $slot,
$maxmark )

Change the max mark for a slot.

Save changes to the question grades in the quiz_slots table and any corresponding question_attempts.

It does not update 'sumgrades' in the quiz table.

Parameters
stdClass$slotrow from the quiz_slots table.
float$maxmarkthe new maxmark.
Return values
booltrue if the new grade is different from the old one.

◆ xmldb_quiz_upgrade()

xmldb_quiz_upgrade ( $oldversion)

Upgrade script for the quiz module.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later Quiz module upgrade function.
Parameters
string$oldversionthe version we are upgrading from.

Variable Documentation

◆ $definitions

$definitions
Initial value:
= [
'overrides' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'datasource' => '\mod_quiz\cache\overrides',
],
]

◆ $messageproviders

$messageproviders
Initial value:
= [
'submission' => [
'capability' => 'mod/quiz:emailnotifysubmission'
],
'confirmation' => [
'capability' => 'mod/quiz:emailconfirmsubmission',
'defaults' => [
'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
],
'attempt_overdue' => [
'capability' => 'mod/quiz:emailwarnoverdue',
'defaults' => [
'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
],
'attempt_grading_complete' => [
'capability' => 'mod/quiz:emailnotifyattemptgraded',
'defaults' => [
'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
],
]

◆ else

if($ADMIN->fulltree) if (empty( $reportsbyname) &&empty( $rulesbyname)) else
Initial value:
{
$pagetitle = get_string('generalsettings', 'admin')

◆ if

if ( ! defined 'MOODLE_INTERNAL')
Initial value:
{
$ADMIN->add('modsettings', new admin_category('modsettingsquizcat',
get_string('modulename', 'quiz'), $module->is_enabled() === false))
The object used to represent folders (a.k.a.
Definition adminlib.php:785

◆ QUIZ_MIN_TIME_TO_CONTINUE

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.

Instead close the quiz immediately.

◆ QUIZ_SHOW_TIME_BEFORE_DEADLINE

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.

(1 hour)