Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Namespaces | |
namespace | mod_quiz |
| |
namespace | mod_quiz\admin |
| |
namespace | mod_quiz\adminpresets |
| |
namespace | mod_quiz\analytics\indicator |
| |
namespace | mod_quiz\cache |
| |
namespace | mod_quiz\completion |
| |
namespace | mod_quiz\event |
| |
namespace | mod_quiz\external |
| |
namespace | mod_quiz\form |
| |
namespace | mod_quiz\hook |
| |
namespace | mod_quiz\local |
| |
namespace | mod_quiz\local\reports |
| |
namespace | mod_quiz\local\structure |
| |
namespace | mod_quiz\navigation\views |
| |
namespace | mod_quiz\output |
| |
namespace | mod_quiz\output\grades |
| |
namespace | mod_quiz\plugininfo |
| |
namespace | mod_quiz\privacy |
| |
namespace | mod_quiz\question |
| |
namespace | mod_quiz\question\bank |
| |
namespace | mod_quiz\question\bank\filter |
| |
namespace | mod_quiz\search |
| |
namespace | mod_quiz\task |
| |
Functions | |
add_one_random_question ($questiongenerator, stdClass $quiz, $override=[]) | |
Helper method to add random question to quiz. | |
add_random_questions (int $quizid, int $page, int $categoryid, int $number) | |
Add random questions to a quiz, with a filter condition based on a category ID. | |
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. | |
add_two_regular_questions ($questiongenerator, stdClass $quiz, $override=null) | |
Helper method to add regular questions in quiz. | |
attempt_quiz (\stdClass $quiz, stdClass $user, $attemptnumber=1) | |
Attempt questions for a quiz and user. | |
backup_quiz (\stdClass $quiz, stdClass $user) | |
A helper method to backup test quiz. | |
build_required_parameters_for_custom_view (array $params, array $extraparams) | |
Build required parameters for question bank custom view. | |
mod_quiz::can_add_random_questions () | |
Whether the current user can add random questions to the quiz or not. | |
mod_quiz::create_grade_item (stdClass $gradeitemdata) | |
Create a grade item. | |
create_test_quiz (\stdClass $course) | |
Create a test quiz for the specified course. | |
mod_quiz::delete_grade_item (int $gradeitemid) | |
Delete a grade item (only if it is not used). | |
duplicate_quiz ($course, $quiz) | |
A helper method to emulate duplication of the quiz. | |
mod_quiz::formatted_grade_item_sum_marks (int $gradeitemid) | |
Get the total of marks of all questions assigned to this grade item, formatted for display. | |
mod_quiz::get_grade_items () | |
Get the grade items defined for this quiz. | |
mod_quiz::get_slot_tags_for_slot_id () | |
mod_quiz::is_grade_item_used (int $gradeitemid) | |
Is a particular quiz grade item used by any slots? | |
mod_quiz_calculate_question_stats (context $context) | |
Implement the calculate_question_stats callback. | |
mod_quiz_cm_info_dynamic (cm_info $cm) | |
Sets dynamic information about a course module. | |
mod_quiz_core_calendar_event_timestart_updated (\calendar_event $event, stdClass $quiz) | |
This function will update the quiz module according to the event that has been modified. | |
mod_quiz_core_calendar_get_event_action_string (string $eventtype) | |
Callback to fetch the activity event type lang string. | |
mod_quiz_core_calendar_get_valid_event_timestart_range (\calendar_event $event, stdClass $quiz) | |
Returns the min and max values for the timestart property of a quiz activity event. | |
mod_quiz_core_calendar_provide_event_action (calendar_event $event, core_calendar\action_factory $factory, int $userid=0) | |
This function receives a calendar event and returns the action associated with it, or null if there is none. | |
mod_quiz_get_completion_active_rule_descriptions ($cm) | |
Callback which returns human-readable strings describing the active completion custom rules for the module instance. | |
mod_quiz_get_fontawesome_icon_map () | |
Get icon mapping for font-awesome. | |
mod_quiz_inplace_editable (string $itemtype, int $itemid, string $newvalue) | |
In place editable callback for slot displaynumber. | |
mod_quiz_output_fragment_add_random_question_form ($args) | |
Generates the add random question in a fragment output. | |
mod_quiz_output_fragment_question_data (array $args) | |
Question data fragment to get the question html via ajax call. | |
mod_quiz_output_fragment_quiz_question_bank ($args) | |
Generates the question bank in a fragment output. | |
mod_quiz_user_preferences () | |
Return a list of all the user preferences used by mod_quiz. | |
quiz_add_instance ($quiz) | |
Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will create a new instance and return the id number of the new instance. | |
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_after_add_or_update ($quiz) | |
This function is called at the end of quiz_add_instance and quiz_update_instance, to do the common processing. | |
quiz_allows_multiple_tries ($quiz) | |
Does this quiz allow multiple tries? | |
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_attempt_summary_link_to_reports ($quiz, $cm, $context, $returnzero=false, $currentgroup=0) | |
Returns the same as quiz_num_attempt_summary() but wrapped in a link to the quiz reports. | |
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_check_updates_since (cm_info $cm, $from, $filter=[]) | |
Check if the module has any update that affects the current user since a given time. | |
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_all_attempts ($quiz) | |
Delete all the attempts belonging to a quiz. | |
quiz_delete_all_overrides ($quiz, $log=true) | |
Deletes all quiz overrides from the database and clears any corresponding calendar events. | |
quiz_delete_attempt ($attempt, $quiz) | |
Delete a quiz attempt. | |
quiz_delete_instance ($id) | |
Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it. | |
quiz_delete_override ($quiz, $overrideid, $log=true) | |
Deletes a quiz override from the database and clears any corresponding calendar events. | |
quiz_delete_previews ($quiz, $userid=null) | |
Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user. | |
quiz_delete_references ($quizid) | |
Delete all question references for a quiz. | |
quiz_delete_user_attempts ($quiz, $user) | |
Delete all the attempts belonging to a user in a particular quiz. | |
quiz_extend_settings_navigation (settings_navigation $settings, navigation_node $quiznode) | |
This function extends the settings navigation block for the site. | |
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_format_grade ($quiz, $grade) | |
Round a grade to the correct number of decimal places, and format it for display. | |
quiz_format_question_grade ($quiz, $grade) | |
Round a grade to the correct number of decimal places, and format it for display. | |
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_best_grade ($quiz, $userid) | |
Get the best current grade for a particular user in a quiz. | |
quiz_get_combined_reviewoptions ($quiz, $attempts) | |
Combines the review options from a number of different quiz attempts. | |
quiz_get_completion_state () | |
quiz_get_coursemodule_info ($coursemodule) | |
Add a get_coursemodule_info function in case any quiz type wants to add 'extra' information for the course (see resource). | |
quiz_get_extra_capabilities () | |
quiz_get_flag_option ($attempt, $context) | |
quiz_get_grade_format ($quiz) | |
Determine the correct number of decimal places required to format a grade. | |
quiz_get_grading_option_name ($option) | |
quiz_get_grading_options () | |
quiz_get_group_override_priorities ($quizid) | |
Calculates the priorities of timeopen and timeclose values for group overrides for a quiz. | |
quiz_get_js_module () | |
Get the information about the standard quiz JavaScript module. | |
quiz_get_navigation_options () | |
quiz_get_overdue_handling_options () | |
quiz_get_post_actions () | |
List the actions that correspond to a post of this module. | |
quiz_get_recent_mod_activity (&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) | |
Returns all quiz graded users since a given time for specified quiz. | |
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_attempts ($quizids, $userid, $status='finished', $includepreviews=false) | |
quiz_get_user_grades ($quiz, $userid=0) | |
Return grade for given user or all users. | |
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_get_view_actions () | |
List the actions that correspond to a view of this module. | |
quiz_grade_item_delete ($quiz) | |
Delete grade item for given quiz. | |
quiz_grade_item_update ($quiz, $grades=null) | |
Create or update the grade item for given quiz. | |
quiz_has_attempts ($quizid) | |
quiz_has_feedback ($quiz) | |
quiz_has_grades ($quiz) | |
Is this a graded quiz? If this method returns true, you can assume that $quiz->grade and $quiz->sumgrades are non-zero (for example, if you want to divide by them). | |
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_num_attempt_summary ($quiz, $cm, $returnzero=false, $currentgroup=0) | |
Return a textual summary of the number of attempts that have been made at a particular quiz, returns '' if no attempts have been made yet, unless $returnzero is passed as true. | |
quiz_override_summary (stdClass $quiz, cm_info|stdClass $cm, int $currentgroup=0) | |
Return summary of the number of settings override that exist. | |
quiz_page_type_list ($pagetype, $parentcontext, $currentcontext) | |
Return a list of page types. | |
quiz_pluginfile ($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) | |
Serves the quiz files. | |
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_print_recent_mod_activity ($activity, $courseid, $detail, $modnames) | |
quiz_process_group_deleted_in_course ($courseid) | |
Logic to happen when a/some group(s) has/have been deleted in a course. | |
quiz_process_options ($quiz) | |
Pre-process the quiz options form data, making any necessary adjustments. | |
quiz_question_action_icons ($quiz, $cmid, $question, $returnurl, $variant=null) | |
quiz_question_edit_button ($cmid, $question, $returnurl, $contentaftericon='') | |
quiz_question_pluginfile ($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload, array $options=[]) | |
Called via pluginfile.php -> question_pluginfile to serve files belonging to a question in a question_attempt when that attempt is a quiz attempt. | |
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_in_use ($questionids) | |
Standard callback used by questions_in_use. | |
quiz_questions_per_page_options () | |
Get the choices to offer for the 'Questions per page' option. | |
quiz_refresh_events ($courseid=0, $instance=null, $cm=null) | |
This standard function will check all instances of this module and make sure there are up-to-date events created for each of them. | |
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_reset_course_form_defaults ($course) | |
Course reset form defaults. | |
quiz_reset_course_form_definition ($mform) | |
Implementation of the function for printing the form elements that control whether the course reset functionality affects the quiz. | |
quiz_reset_gradebook ($courseid, $type='') | |
Removes all grades from gradebook. | |
quiz_reset_userdata ($data) | |
Actual implementation of the reset course functionality, delete all the quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is set and true. | |
quiz_retrieve_tags_for_slot_ids () | |
quiz_review_option_form_to_db ($fromform, $field) | |
Helper function for quiz_process_options(). | |
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_supports ($feature) | |
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_effective_access ($quiz, $userid) | |
Updates a quiz object with override information for a user. | |
quiz_update_events ($quiz, $override=null) | |
This function updates the events associated to the quiz. | |
quiz_update_grades ($quiz, $userid=0, $nullifnone=true) | |
Update grades in central gradebook. | |
quiz_update_instance ($quiz, $mform) | |
Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will update an existing instance with new data. | |
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_user_complete ($course, $user, $mod, $quiz) | |
Print a detailed representation of what a user has done with a given particular instance of this module, for user activity reports. | |
quiz_user_outline ($course, $user, $mod, $quiz) | |
Return a small object with summary information about what a user has done with a given particular instance of this module Used for user activity reports. | |
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. | |
restore_quiz (string $backupid, stdClass $course, stdClass $user) | |
A helper method to restore provided backup. | |
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_grade_item (stdClass $gradeitemdata) | |
Update a grade item. | |
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_grade_item (stdClass $slot, ?int $gradeitemid) | |
Change which grade this slot contributes to, for quizzes with multiple grades. | |
mod_quiz::update_slot_maxmark ($slot, $maxmark) | |
Change the max mark for a slot. | |
mod_quiz::verify_grade_item_is_ours (int $gradeitemid) | |
Check the grade item with the given id belongs to this quiz. | |
xmldb_quiz_upgrade ($oldversion) | |
Quiz module upgrade function. | |
Variables | |
$capabilities | |
global | mod_quiz\task::$CFG |
$definitions | |
$functions | |
$logs | |
$messageproviders | |
$observers | |
$plugin = 2024041600 | |
stdClass | $quiz |
$quiz A test quiz. | |
$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 |
$tasks | |
stdClass | $user |
$user A test logged-in user. | |
$plugin | component = 'mod_quiz' |
if(empty($reportsbyname) &&empty($rulesbyname)) | else |
if (!defined( 'MOODLE_INTERNAL')) | |
const | QUIZ_ATTEMPTFIRST '3' |
const | QUIZ_ATTEMPTLAST '4' |
const | QUIZ_EVENT_TYPE_CLOSE 'close' |
const | QUIZ_EVENT_TYPE_OPEN 'open' |
#- | |
const | QUIZ_GRADEAVERAGE '2' |
const | QUIZ_GRADEHIGHEST '1' |
#- | |
const | QUIZ_MAX_ATTEMPT_OPTION 10 |
#+ Option controlling what options are offered on the quiz settings form. | |
const | QUIZ_MAX_DECIMAL_OPTION 5 |
const | QUIZ_MAX_EVENT_LENGTH 5*24*60*60 |
#- | |
const | QUIZ_MAX_Q_DECIMAL_OPTION 7 |
const | QUIZ_MAX_QPP_OPTION 50 |
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_NAVMETHOD_FREE 'free' |
#+ Options for navigation method within quizzes. | |
const | QUIZ_NAVMETHOD_SEQ 'sequential' |
trait | quiz_question_helper_test_trait |
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 = 2024042200 |
|
protected |
Helper method to add random question to quiz.
component_generator_base | $questiongenerator | |
stdClass | $quiz | |
array | $override |
|
protected |
Add random questions to a quiz, with a filter condition based on a category ID.
int | $quizid | The quiz to add the questions to. |
int | $page | The page number to add the questions to. |
int | $categoryid | The category ID to use for the filter condition. |
int | $number | The number of questions to add. |
void |
mod_quiz\add_random_questions | ( | int | $addonpage, |
int | $number, | ||
array | $filtercondition ) |
Add a random question to the quiz at a given point.
int | $addonpage | the page on which to add the question. |
int | $number | the number of random questions to add. |
array | $filtercondition | the filter condition. Must contain at least a category filter. |
mod_quiz\add_section_heading | ( | $pagenumber, | |
$heading = null ) |
Add a section heading on a given page and return the sectionid.
int | $pagenumber | the number of the page where the section heading begins. |
string | null | $heading | the heading to add. If not given, a default is used. |
|
protected |
Helper method to add regular questions in quiz.
component_generator_base | $questiongenerator | |
stdClass | $quiz | |
array | $override |
|
protected |
Attempt questions for a quiz and user.
stdClass | $quiz | Quiz to attempt. |
stdClass | $user | A user to attempt the quiz. |
int | $attemptnumber |
array |
|
protected |
A helper method to backup test quiz.
stdClass | $quiz | Quiz to attempt. |
stdClass | $user | A user to attempt the quiz. |
string | A backup ID ready to be restored. |
build_required_parameters_for_custom_view | ( | array | $params, |
array | $extraparams ) |
Build required parameters for question bank custom view.
array | $params | the page parameters |
array | $extraparams | additional parameters |
array |
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.
bool |
mod_quiz\create_grade_item | ( | stdClass | $gradeitemdata | ) |
Create a grade item.
The new grade item is added at the end of the order.
stdClass | $gradeitemdata | must have property name - updated with the inserted data (sortorder and id). |
|
protected |
Create a test quiz for the specified course.
stdClass | $course |
stdClass |
mod_quiz\delete_grade_item | ( | int | $gradeitemid | ) |
Delete a grade item (only if it is not used).
int | $gradeitemid | id of the grade item to delete. Must belong to this quiz. |
|
protected |
A helper method to emulate duplication of the quiz.
stdClass | $course | |
stdClass | $quiz |
cm_info|null |
mod_quiz\formatted_grade_item_sum_marks | ( | int | $gradeitemid | ) |
Get the total of marks of all questions assigned to this grade item, formatted for display.
int | $gradeitemid | id of a quiz grade item belonging to this quiz. |
string | total of marks of all questions assigned to this grade item. |
mod_quiz\get_grade_items | ( | ) |
Get the grade items defined for this quiz.
stdClass[] | quiz_grade_item rows, indexed by id. |
mod_quiz\get_slot_tags_for_slot_id | ( | ) |
mod_quiz\is_grade_item_used | ( | int | $gradeitemid | ) |
Is a particular quiz grade item used by any slots?
int | $gradeitemid | id of a quiz grade item belonging to this quiz. |
bool | true if it is used. |
mod_quiz_calculate_question_stats | ( | context | $context | ) |
Implement the calculate_question_stats callback.
This enables quiz statistics to be shown in statistics columns in the database.
context | $context | return the statistics related to this context (which will be a quiz context). |
all_calculated_for_qubaid_condition|null | The statistics for this quiz, if available, else null. |
mod_quiz_cm_info_dynamic | ( | cm_info | $cm | ) |
mod_quiz_core_calendar_event_timestart_updated | ( | \calendar_event | $event, |
stdClass | $quiz ) |
This function will update the quiz module according to the event that has been modified.
It will set the timeopen or timeclose value of the quiz instance according to the type of event provided.
moodle_exception |
calendar_event | $event | A quiz activity calendar event |
stdClass | $quiz | A quiz activity instance |
mod_quiz_core_calendar_get_event_action_string | ( | string | $eventtype | ) |
Callback to fetch the activity event type lang string.
string | $eventtype | The event type. |
lang_string | The event type lang string. |
mod_quiz_core_calendar_get_valid_event_timestart_range | ( | \calendar_event | $event, |
stdClass | $quiz ) |
Returns the min and max values for the timestart property of a quiz activity event.
The min and max values will be the timeopen and timeclose properties of the quiz, respectively, if they are set.
If either value isn't set then null will be returned instead to indicate that there is no cutoff for that value.
If the vent has no valid timestart range then [false, false] will be returned. This is the case for overriden events.
A minimum and maximum cutoff return value will look like: [ [1505704373, 'The date must be after this date'], [1506741172, 'The date must be before this date'] ]
moodle_exception |
calendar_event | $event | The calendar event to get the time range for |
stdClass | $quiz | The module instance to get the range from |
array |
mod_quiz_core_calendar_provide_event_action | ( | calendar_event | $event, |
core_calendar\action_factory | $factory, | ||
int | $userid = 0 ) |
This function receives a calendar event and returns the action associated with it, or null if there is none.
This is used by block_myoverview in order to display the event appropriately. If null is returned then the event is not displayed on the block.
calendar_event | $event | |
core_calendar\action_factory | $factory | |
int | $userid | User id to use for all capability checks, etc. Set to 0 for current user (default). |
core_calendar\local\event\entities\action_interface|null |
mod_quiz_get_completion_active_rule_descriptions | ( | $cm | ) |
Callback which returns human-readable strings describing the active completion custom rules for the module instance.
cm_info | stdClass | $cm | object with fields ->completion and ->customdata['customcompletionrules'] |
array\$descriptions | the array of descriptions for the custom rules. |
mod_quiz_inplace_editable | ( | string | $itemtype, |
int | $itemid, | ||
string | $newvalue ) |
In place editable callback for slot displaynumber.
string | $itemtype | slotdisplarnumber |
int | $itemid | the id of the slot in the quiz_slots table |
string | $newvalue | the new value for displaynumber field for a given slot in the quiz_slots table |
core\output\inplace_editable|void |
mod_quiz_output_fragment_add_random_question_form | ( | $args | ) |
Generates the add random question in a fragment output.
This allows the form to be rendered in javascript, for example inside a modal.
The required arguments as keys in the $args array are: cat {string} The category and category context ids comma separated. addonpage {int} The page id to add this question to. returnurl {string} URL to return to after form submission. cmid {int} The course module id the questions are being added to.
array | $args | The fragment arguments. |
string | The rendered mform fragment. |
mod_quiz_output_fragment_question_data | ( | array | $args | ) |
Question data fragment to get the question html via ajax call.
array | $args |
string |
mod_quiz_output_fragment_quiz_question_bank | ( | $args | ) |
Generates the question bank in a fragment output.
This allows the question bank to be displayed in a modal.
The only expected argument provided in the $args array is 'querystring'. The value should be the list of parameters URL encoded and used to build the question bank page.
The individual list of parameters expected can be found in question_build_edit_resources.
array | $args | The fragment arguments. |
string | The rendered mform fragment. |
mod_quiz_user_preferences | ( | ) |
Return a list of all the user preferences used by mod_quiz.
@uses core_user\is_current_user
array[] |
quiz_add_instance | ( | $quiz | ) |
Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will create a new instance and return the id number of the new instance.
stdClass | $quiz | the data that came from the form. |
mixed | the id of the new instance on success, false or a string error message on failure. |
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.
int | $questionid | The id of the question to be added |
stdClass | $quiz | The extended quiz object as used by edit.php This is updated by this function |
int | $page | Which page in quiz to add the question on. If 0 (default), add at the end |
float | $maxmark | The maximum mark to set for this question. (Optional, defaults to question.defaultmark. |
bool | false if the question was already in the quiz |
quiz_add_random_questions | ( | stdClass | $quiz, |
int | $addonpage, | ||
int | $categoryid, | ||
int | $number ) |
Add a random question to the quiz at a given point.
stdClass | $quiz | the quiz settings. |
int | $addonpage | the page on which to add the question. |
int | $categoryid | the question category to add the question from. |
int | $number | the number of random questions to add. |
quiz_after_add_or_update | ( | $quiz | ) |
This function is called at the end of quiz_add_instance and quiz_update_instance, to do the common processing.
stdClass | $quiz | the quiz object. |
quiz_allows_multiple_tries | ( | $quiz | ) |
Does this quiz allow multiple tries?
bool |
quiz_attempt_save_started | ( | $quizobj, | |
$quba, | |||
$attempt ) |
The save started question usage and quiz attempt in db and log the started attempt.
quiz_settings | $quizobj | |
question_usage_by_activity | $quba | |
stdClass | $attempt |
stdClass | attempt object with uniqueid and id set. |
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.
stdClass | $quiz | the quiz settings |
stdClass | $attempt | the quiz_attempt database row. |
int | one of the display_options\DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants. |
quiz_attempt_state_name | ( | $state | ) |
Get the human-readable name for a quiz attempt state.
string | $state | one of the state constants like { |
string | The lang string to describe that state. |
quiz_attempt_submitted_handler | ( | $event | ) |
Handle the quiz_attempt_submitted event.
This sends the confirmation and notification messages, if required.
attempt_submitted | $event | the event object. |
quiz_attempt_summary_link_to_reports | ( | $quiz, | |
$cm, | |||
$context, | |||
$returnzero = false, | |||
$currentgroup = 0 ) |
Returns the same as quiz_num_attempt_summary() but wrapped in a link to the quiz reports.
stdClass | $quiz | the quiz object. Only $quiz->id is used at the moment. |
stdClass | $cm | the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment. |
stdClass | $context | the quiz context. |
bool | $returnzero | if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'. |
int | $currentgroup | if 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. |
string | HTML fragment for the link. |
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.
stdClass | The attempt with the best grade |
stdClass | $quiz | The quiz for which the best grade is to be calculated |
array | $attempts | An array of all the attempts of the user at the quiz |
quiz_calculate_best_grade | ( | $quiz, | |
$attempts ) |
Calculate the overall grade for a quiz given a number of attempts by a particular user.
stdClass | $quiz | the quiz settings object. |
array | $attempts | an array of all the user's attempts at this quiz in order. |
float | the overall grade |
quiz_check_updates_since | ( | cm_info | $cm, |
$from, | |||
$filter = [] ) |
Check if the module has any update that affects the current user since a given time.
cm_info | $cm | course module data |
int | $from | the time to check updates from |
array | $filter | if we need to check only specific updates |
stdClass | an object with the different type of areas indicating if they were updated or not |
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.
quiz_settings | $quizobj | the quiz object to create an attempt for. |
int | $attemptnumber | the sequence number for the attempt. |
stdClass | false | $lastattempt | the previous attempt by this user, if any. Only needed if $attemptnumber > 1 and $quiz->attemptonlast is true. |
int | $timenow | the time the attempt was started at. |
bool | $ispreview | whether this new attempt is a preview. |
int | null | $userid | the id of the user attempting this quiz. |
stdClass | the newly created attempt object. |
quiz_create_attempt_handling_errors | ( | $attemptid, | |
$cmid = null ) |
Get quiz attempt and handling error.
int | $attemptid | the id of the current attempt. |
int | null | $cmid | the course_module id for this quiz. |
quiz_attempt | all the data about the quiz attempt. |
quiz_delete_all_attempts | ( | $quiz | ) |
Delete all the attempts belonging to a quiz.
stdClass | $quiz | The quiz object. |
quiz_delete_all_overrides | ( | $quiz, | |
$log = true ) |
Deletes all quiz overrides from the database and clears any corresponding calendar events.
stdClass | $quiz | The quiz object. |
bool | $log | Whether to trigger logs. |
quiz_delete_attempt | ( | $attempt, | |
$quiz ) |
Delete a quiz attempt.
mixed | $attempt | an integer attempt id or an attempt object (row of the quiz_attempts table). |
stdClass | $quiz | the quiz object. |
quiz_delete_instance | ( | $id | ) |
Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.
int | $id | the id of the quiz to delete. |
bool | success or failure. |
quiz_delete_override | ( | $quiz, | |
$overrideid, | |||
$log = true ) |
Deletes a quiz override from the database and clears any corresponding calendar events.
stdClass | $quiz | The quiz object. |
int | $overrideid | The id of the override being deleted |
bool | $log | Whether to trigger logs. |
bool | true on success |
quiz_delete_previews | ( | $quiz, | |
$userid = null ) |
Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user.
stdClass | $quiz | the quiz object. |
int | $userid | (optional) if given, only delete the previews belonging to this user. |
quiz_delete_references | ( | $quizid | ) |
Delete all question references for a quiz.
int | $quizid | The id of quiz. |
quiz_delete_user_attempts | ( | $quiz, | |
$user ) |
Delete all the attempts belonging to a user in a particular quiz.
mod_quiz\quiz_settings | $quiz | The quiz object. |
stdClass | $user | The user object. |
quiz_extend_settings_navigation | ( | settings_navigation | $settings, |
navigation_node | $quiznode ) |
This function extends the settings navigation block for the site.
It is safe to rely on PAGE here as we will only ever be within the module context when this is called
settings_navigation | $settings | |
navigation_node | $quiznode |
void |
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.
float | $grade | a grade on this quiz. |
stdClass | $quiz | the quiz settings. |
context_module | $context | the quiz context. |
string | the comment that corresponds to this grade (empty string if there is not one. |
quiz_feedback_record_for_grade | ( | $grade, | |
$quiz ) |
Get the feedback object for this grade on this quiz.
float | $grade | a grade on this quiz. |
stdClass | $quiz | the quiz settings. |
false|stdClass | the record object or false if there is not feedback for the given grade |
quiz_format_grade | ( | $quiz, | |
$grade ) |
Round a grade to the correct number of decimal places, and format it for display.
stdClass | $quiz | The quiz table row, only $quiz->decimalpoints is used. |
float | null | $grade | The grade to round and display (or null meaning no grade). |
string |
quiz_format_question_grade | ( | $quiz, | |
$grade ) |
Round a grade to the correct number of decimal places, and format it for display.
stdClass | $quiz | The quiz table row, only $quiz->decimalpoints is used. |
float | $grade | The grade to round. |
string |
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.
string | $redundantwhereclauses | extra where clauses to add to the subquery for performance. These can use the table alias iquiza for the quiz attempts table. |
string | SQL select with columns attempt.id, usertimeclose, usertimelimit. |
quiz_get_best_grade | ( | $quiz, | |
$userid ) |
Get the best current grade for a particular user in a quiz.
stdClass | $quiz | the quiz settings. |
int | $userid | the id of the user. |
float | the user's current grade for this quiz, or null if this user does not have a grade on this quiz. |
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(...)
stdClass | $quiz | the quiz instance. |
array | $attempts | an array of attempt objects. |
array | of 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_coursemodule_info | ( | $coursemodule | ) |
Add a get_coursemodule_info function in case any quiz type wants to add 'extra' information for the course (see resource).
Given a course_module object, this function returns any "extra" information that may be needed when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
stdClass | $coursemodule | The coursemodule object (record). |
cached_cm_info|false | An object on information that the courses will know about (most noticeably, an icon). |
quiz_get_extra_capabilities | ( | ) |
array | all other caps used in module |
quiz_get_flag_option | ( | $attempt, | |
$context ) |
stdClass | $attempt | the attempt. |
stdClass | $context | the quiz context. |
int | whether flags should be shown/editable to the current user for this attempt. |
quiz_get_grade_format | ( | $quiz | ) |
Determine the correct number of decimal places required to format a grade.
stdClass | $quiz | The quiz table row, only $quiz->decimalpoints and ->questiondecimalpoints are used. |
integer |
quiz_get_grading_option_name | ( | $option | ) |
int | $option | one of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE, QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST. |
the | lang string for that option. |
quiz_get_grading_options | ( | ) |
array | int => lang string the options for calculating the quiz grade from the individual attempt grades. |
quiz_get_group_override_priorities | ( | $quizid | ) |
Calculates the priorities of timeopen and timeclose values for group overrides for a quiz.
int | $quizid | The quiz ID. |
array|null | Array of group override priorities for open and close times. Null if there are no group overrides. |
quiz_get_js_module | ( | ) |
Get the information about the standard quiz JavaScript module.
array | a standard jsmodule structure. |
quiz_get_navigation_options | ( | ) |
the | options for quiz navigation. |
quiz_get_overdue_handling_options | ( | ) |
array | string => lang string the options for handling overdue quiz attempts. |
quiz_get_post_actions | ( | ) |
List the actions that correspond to a post of this module.
This is used by the participation report.
Note: This is not used by new logging system. Event with crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING will be considered as post action.
array |
quiz_get_review_options | ( | $quiz, | |
$attempt, | |||
$context ) |
The appropriate display_options object for this attempt at this quiz right now.
stdClass | $quiz | the quiz instance. |
stdClass | $attempt | the attempt in question. |
context | $context | the quiz context. |
display_options |
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.
int | $quizid | the id of the quiz. |
int | $userid | the id of the user. |
mixed | the unfinished attempt if there is one, false if not. |
quiz_get_user_attempts | ( | $quizids, | |
$userid, | |||
$status = 'finished', | |||
$includepreviews = false ) |
int | array | $quizids | A quiz ID, or an array of quiz IDs. |
int | $userid | the userid. |
string | $status | 'all', 'finished' or 'unfinished' to control |
bool | $includepreviews |
array | of all the user's attempts at this quiz. Returns an empty array if there are none. |
quiz_get_user_grades | ( | $quiz, | |
$userid = 0 ) |
Return grade for given user or all users.
int | $quizid | id of quiz |
int | $userid | optional user id, 0 means all users |
array | array of grades, false if none. These are raw grades. They should be processed with quiz_format_grade for display. |
quiz_get_user_image_options | ( | ) |
Get the choices for what size user picture to show.
array | string => lang string the options for whether to display the user's picture. |
quiz_get_user_timeclose | ( | $courseid | ) |
Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides.
int | $courseid | the course id. |
stdClass | An 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_get_view_actions | ( | ) |
List the actions that correspond to a view of this module.
This is used by the participation report.
Note: This is not used by new logging system. Event with crud = 'r' and edulevel = LEVEL_PARTICIPATING will be considered as view action.
array |
quiz_grade_item_delete | ( | $quiz | ) |
Delete grade item for given quiz.
stdClass | $quiz | object |
int |
quiz_grade_item_update | ( | $quiz, | |
$grades = null ) |
Create or update the grade item for given quiz.
stdClass | $quiz | object with extra cmidnumber |
mixed | $grades | optional array/object of grade(s); 'reset' means reset grades in gradebook |
int | 0 if ok, error code otherwise |
quiz_has_attempts | ( | $quizid | ) |
int | $quizid | The quiz id. |
bool | whether this quiz has any (non-preview) attempts. |
quiz_has_feedback | ( | $quiz | ) |
stdClass | $quiz | the quiz database row. |
bool | Whether this quiz has any non-blank feedback text. |
quiz_has_grades | ( | $quiz | ) |
Is this a graded quiz? If this method returns true, you can assume that $quiz->grade and $quiz->sumgrades are non-zero (for example, if you want to divide by them).
stdClass | $quiz | a row from the quiz table. |
bool | whether this is a graded quiz. |
quiz_has_question_use | ( | $quiz, | |
$slot ) |
Verify that the question exists, and the user has permission to use it.
stdClass | $quiz | the quiz settings. |
int | $slot | which question in the quiz to test. |
bool | whether the user can use this question. |
quiz_has_questions | ( | $quizid | ) |
Are there any questions in this quiz?
int | $quizid | the quiz id. |
quiz_is_overriden_calendar_event | ( | \calendar_event | $event | ) |
Check if the given calendar_event is either a user or group override event for quiz.
calendar_event | $event | The calendar event to check |
bool |
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.
stdClass | $quiz | the quiz settings. |
stdClass | $cm | the course_module object. |
stdClass | $context | the quiz context. |
string | HTML to output. |
quiz_num_attempt_summary | ( | $quiz, | |
$cm, | |||
$returnzero = false, | |||
$currentgroup = 0 ) |
Return a textual summary of the number of attempts that have been made at a particular quiz, returns '' if no attempts have been made yet, unless $returnzero is passed as true.
stdClass | $quiz | the quiz object. Only $quiz->id is used at the moment. |
stdClass | $cm | the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment. |
bool | $returnzero | if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'. |
int | $currentgroup | if 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. |
string | a string like "Attempts: 123", "Attemtps 123 (45 from your groups)" or "Attemtps 123 (45 from this group)". |
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.
stdClass | $quiz | the quiz settings. Only $quiz->id is used at the moment. |
cm_info | stdClass | $cm | the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment. |
int | $currentgroup | if 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. |
array | like 'group' => 3, 'user' => 12] where 3 is the number of group overrides, and 12 is the number of user ones. |
quiz_page_type_list | ( | $pagetype, | |
$parentcontext, | |||
$currentcontext ) |
Return a list of page types.
string | $pagetype | current page type |
stdClass | $parentcontext | Block's parent context |
stdClass | $currentcontext | Current context of block |
quiz_pluginfile | ( | $course, | |
$cm, | |||
$context, | |||
$filearea, | |||
$args, | |||
$forcedownload, | |||
array | $options = [] ) |
Serves the quiz files.
stdClass | $course | course object |
stdClass | $cm | course module object |
stdClass | $context | context object |
string | $filearea | file area |
array | $args | extra arguments |
bool | $forcedownload | whether or not force download |
array | $options | additional options affecting the file serving |
bool | false if file not found, does not return if found - justsend the file |
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_settings | $quizobj | quiz object |
int | $attemptnumber | the attempt number |
stdClass | $lastattempt | last attempt object |
bool | $offlineattempt | whether is an offline attempt or not |
array | $forcedrandomquestions | slot number => question id. Used for random questions, to force the choice of a particular actual question. Intended for testing purposes only. |
array | $forcedvariants | slot number => variant. Used for questions with variants, to force the choice of a particular variant. Intended for testing purposes only. |
int | $userid | Specific user id to create an attempt for that user, null for current logged in user |
stdClass | the new attempt |
quiz_process_group_deleted_in_course | ( | $courseid | ) |
Logic to happen when a/some group(s) has/have been deleted in a course.
int | $courseid | The course ID. |
void |
quiz_process_options | ( | $quiz | ) |
Pre-process the quiz options form data, making any necessary adjustments.
Called by add/update instance in this file.
stdClass | $quiz | The variables set on the form. |
quiz_question_action_icons | ( | $quiz, | |
$cmid, | |||
$question, | |||
$returnurl, | |||
$variant = null ) |
stdClass | $quiz | the quiz. |
int | $cmid | the course_module object for this quiz. |
stdClass | $question | the question. |
string | $returnurl | url to return to after action is done. |
int | $variant | which question variant to preview (optional). |
string | html 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 | ( | $cmid, | |
$question, | |||
$returnurl, | |||
$contentaftericon = '' ) |
int | $cmid | the course_module.id for this quiz. |
stdClass | $question | the question. |
string | $returnurl | url to return to after action is done. |
string | $contentbeforeicon | some HTML content to be added inside the link, before the icon. |
the | HTML for an edit icon, view icon, or nothing for a question (depending on permissions). |
quiz_question_pluginfile | ( | $course, | |
$context, | |||
$component, | |||
$filearea, | |||
$qubaid, | |||
$slot, | |||
$args, | |||
$forcedownload, | |||
array | $options = [] ) |
Called via pluginfile.php -> question_pluginfile to serve files belonging to a question in a question_attempt when that attempt is a quiz attempt.
stdClass | $course | course settings object |
stdClass | $context | context object |
string | $component | the name of the component we are serving files for. |
string | $filearea | the name of the file area. |
int | $qubaid | the attempt usage id. |
int | $slot | the id of a question in this quiz attempt. |
array | $args | the remaining bits of the file path. |
bool | $forcedownload | whether the user must be forced to download the file. |
array | $options | additional options affecting the file serving |
bool | false if file not found, does not return if found - justsend the file |
quiz_question_preview_button | ( | $quiz, | |
$question, | |||
$label = false, | |||
$variant = null, | |||
$random = null ) |
stdClass | $quiz | the quiz settings |
stdClass | $question | the question |
bool | $label | if true, show the preview question label after the icon |
int | $variant | which question variant to preview (optional). |
bool | $random | if question is random, true. |
string | the HTML for a preview question icon. |
quiz_question_preview_url | ( | $quiz, | |
$question, | |||
$variant = null, | |||
$restartversion = null ) |
stdClass | $quiz | the quiz settings |
stdClass | $question | the question |
int | $variant | which question variant to preview (optional). |
int | $restartversion | version of the question to use when restarting the preview. |
moodle_url | to preview this question with the options from this quiz. |
quiz_question_tostring | ( | $question, | |
$showicon = false, | |||
$showquestiontext = true, | |||
$showidnumber = false, | |||
$showtags = false ) |
Creates a textual representation of a question for display.
stdClass | $question | A question object from the database questions table |
bool | $showicon | If true, show the question's icon with the question. False by default. |
bool | $showquestiontext | If true (default), show question text after question name. If false, show only question name. |
bool | $showidnumber | If true, show the question's idnumber, if any. False by default. |
core_tag_tag[] | bool | $showtags | if array passed, show those tags. Else, if true, get and show tags, else, don't show tags (which is the default). |
string | HTML fragment. |
quiz_questions_in_use | ( | $questionids | ) |
Standard callback used by questions_in_use.
array | $questionids | of question ids. |
bool | whether any of these questions are used by any instance of this module. |
quiz_questions_per_page_options | ( | ) |
Get the choices to offer for the 'Questions per page' option.
array | int => string. |
quiz_refresh_events | ( | $courseid = 0, | |
$instance = null, | |||
$cm = null ) |
This standard function will check all instances of this module and make sure there are up-to-date events created for each of them.
If courseid = 0, then every quiz event in the site is checked, else only quiz events belonging to the course specified are checked. This function is used, in its new format, by restore_refresh_events()
int | $courseid | |
int | stdClass | $instance | Quiz module instance or ID. |
int | stdClass | $cm | Course module object or ID (not used in this module). |
bool |
quiz_repaginate_questions | ( | $quizid, | |
$slotsperpage ) |
Repaginate the questions in a quiz.
int | $quizid | the id of the quiz to repaginate. |
int | $slotsperpage | number of items to put on each page. 0 means unlimited. |
quiz_report_can_filter_only_graded | ( | $quiz | ) |
stdClass | $quiz | the quiz settings. |
bool | whether, for this quiz, it is possible to filter attempts to show only those that gave the final grade. |
quiz_report_default_report | ( | $context | ) |
Get the default report for the current user.
stdClass | $context | the quiz context. |
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.
string | $report | the type of report. |
string | $courseshortname | the course shortname. |
string | $quizname | the quiz name. |
string | the filename. |
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.
float | $grade | a grade on this quiz. |
int | $quizid | the id of the quiz object. |
string | the comment that corresponds to this grade (empty string if there is not one. |
quiz_report_get_significant_questions | ( | $quiz | ) |
Get the slots of real questions (not descriptions) in this quiz, in order.
stdClass | $quiz | the quiz. |
array | of slot => objects with fields ->slot, ->id, ->qtype, ->length, ->number, ->maxmark, ->category (for random questions). |
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.
number | $bandwidth | the width of each band. |
int | $bands | the number of bands |
int | $quizid | the quiz id. |
core\dml\sql_join | $usersjoins | (joins, wheres, params) to get enrolled users |
array | band number => number of users with scores in that band. |
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.
string | $grademethod | quiz grading method. |
string | $quizattemptsalias | sql alias for 'quiz_attempts' table |
string | sql to test if this is an attempt that will contribute towards the graded of the user |
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.
array | $datum | an array of objects with properties on the object including the keys passed as the next param. |
array | $keys | Array of strings with the names of the properties on the objects in datum that you want to index the multidimensional array by. |
bool | $keysunique | If 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. |
array | multidimensional array properly indexed. |
quiz_report_list | ( | $context | ) |
Returns an array of reports to which the current user has access to.
array | reports are ordered as they should be for display in tabs. |
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.
stdClass | $quiz | |
string | $quizattemptsalias | sql alias for 'quiz_attempts' table |
string | sql to test if this is an attempt that will contribute towards the grade of the user |
quiz_report_scale_summarks_as_percentage | ( | $rawmark, | |
$quiz, | |||
$round = true ) |
Format a number as a percentage out of $quiz->sumgrades.
number | $rawgrade | the mark to format. |
stdClass | $quiz | the quiz settings |
bool | $round | whether to round the results ot $quiz->decimalpoints. |
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.
stdClass | $quiz | the quiz settings. |
context | $context | the quiz context. |
bool |
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.
int | $questionid | The id of the question. |
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.
float | $rawgrade | the unadjusted grade, fof example $attempt->sumgrades |
stdClass | $quiz | the quiz object. Only the fields grade, sumgrades and decimalpoints are used. |
bool | string | $format | whether to format the results for display or 'question' to format a question grade (different number of decimal places. |
float|string | the rescaled grade, or null/the lang string 'notyetgraded' if the $grade is null. |
quiz_reset_course_form_defaults | ( | $course | ) |
Course reset form defaults.
array | the defaults. |
quiz_reset_course_form_definition | ( | $mform | ) |
Implementation of the function for printing the form elements that control whether the course reset functionality affects the quiz.
MoodleQuickForm | $mform | the course reset form that is being built. |
quiz_reset_gradebook | ( | $courseid, | |
$type = '' ) |
Removes all grades from gradebook.
int | $courseid | |
string | optional type |
quiz_reset_userdata | ( | $data | ) |
Actual implementation of the reset course functionality, delete all the quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is set and true.
Also, move the quiz open and close dates, if the course start date is changing.
stdClass | $data | the data submitted from the reset course. |
array | status array |
quiz_retrieve_tags_for_slot_ids | ( | ) |
quiz_review_option_form_to_db | ( | $fromform, | |
$field ) |
Helper function for quiz_process_options().
stdClass | $fromform | the sumbitted form date. |
string | $field | one of the review option field names. |
quiz_save_best_grade | ( | $quiz, | |
$userid = null, | |||
$attempts = [] ) |
Save the overall grade for a user at a quiz in the quiz_grades table.
stdClass | $quiz | The quiz for which the best grade is to be calculated and then saved. |
int | $userid | The userid to calculate the grade for. Defaults to the current user. |
array | $attempts | The attempts of this user. Useful if you are looping through many users. Attempts can be fetched in one master query to avoid repeated querying. |
bool | Indicates success or failure. |
quiz_send_confirmation | ( | $recipient, | |
$a, | |||
$studentisonline ) |
Sends a confirmation message to the student confirming that the attempt was processed.
stdClass | $recipient | user object for the recipient. |
stdClass | $a | lots of useful information that can be used in the message subject and body. |
bool | $studentisonline | is the student currently interacting with Moodle? |
int|false | as for message_send(). |
quiz_send_notification | ( | $recipient, | |
$submitter, | |||
$a ) |
Sends notification messages to the interested parties that assign the role capability.
stdClass | $recipient | user object of the intended recipient |
stdClass | $submitter | user object for the user who submitted the attempt. |
stdClass | $a | associative array of replaceable fields for the templates |
int|false | as for message_send(). |
quiz_send_notification_messages | ( | $course, | |
$quiz, | |||
$attempt, | |||
$context, | |||
$cm, | |||
$studentisonline ) |
Send all the requried messages when a quiz attempt is submitted.
stdClass | $course | the course |
stdClass | $quiz | the quiz |
stdClass | $attempt | this attempt just finished |
stdClass | $context | the quiz context |
stdClass | $cm | the coursemodule for this quiz |
bool | $studentisonline | is the student currently interacting with Moodle? |
bool | true if all necessary messages were sent successfully, else false. |
quiz_send_notify_manual_graded_message | ( | quiz_attempt | $attemptobj, |
object | $userto ) |
Send the notification message when a quiz attempt has been manual graded.
quiz_attempt | $attemptobj | Some data about the quiz attempt. |
stdClass | $userto |
int|false | As for message_send. |
quiz_send_overdue_message | ( | $attemptobj | ) |
Send the notification message when a quiz attempt becomes overdue.
quiz_attempt | $attemptobj | all the data about the quiz attempt. |
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.)
float | $newgrade | the new maximum grade for the quiz. |
stdClass | $quiz | the quiz we are updating. Passed by reference so its grade field can be updated too. |
bool | indicating success or failure. |
quiz_start_attempt_built_on_last | ( | $quba, | |
$attempt, | |||
$lastattempt ) |
Start a subsequent new attempt, in each attempt builds on last mode.
question_usage_by_activity | $quba | this question usage |
stdClass | $attempt | this attempt |
stdClass | $lastattempt | last attempt |
stdClass | modified attempt object |
quiz_start_new_attempt | ( | $quizobj, | |
$quba, | |||
$attempt, | |||
$attemptnumber, | |||
$timenow, | |||
$questionids = [], | |||
$forcedvariantsbyslot = [] ) |
Start a normal, new, quiz attempt.
quiz_settings | $quizobj | the quiz object to start an attempt for. |
question_usage_by_activity | $quba | |
stdClass | $attempt | |
integer | $attemptnumber | starting from 1 |
integer | $timenow | the attempt start time |
array | $questionids | slot number => question id. Used for random questions, to force the choice of a particular actual question. Intended for testing purposes only. |
array | $forcedvariantsbyslot | slot number => variant. Used for questions with variants, to force the choice of a particular variant. Intended for testing purposes only. |
stdClass | modified attempt object |
quiz_supports | ( | $feature | ) |
string | $feature | FEATURE_xx constant for requested feature |
mixed | True if module supports feature, false if not, null if doesn't know or string for the module purpose. |
quiz_update_all_attempt_sumgrades | ( | $quiz | ) |
Update the sumgrades field of the attempts at a quiz.
stdClass | $quiz | a quiz. |
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.
stdClass | $quiz | the quiz settings. |
quiz_update_effective_access | ( | $quiz, | |
$userid ) |
Updates a quiz object with override information for a user.
Algorithm: For each quiz setting, if there is a matching user-specific override, then use that otherwise, if there are group-specific overrides, return the most lenient combination of them. If neither applies, leave the quiz setting unchanged.
Special case: if there is more than one password that applies to the user, then quiz->extrapasswords will contain an array of strings giving the remaining passwords.
stdClass | $quiz | The quiz object. |
int | $userid | The userid. |
stdClass\$quiz | The updated quiz object. |
quiz_update_events | ( | $quiz, | |
$override = null ) |
This function updates the events associated to the quiz.
If $override is non-zero, then it updates only the events associated with the specified override.
stdClass | $quiz | the quiz object. |
stdClass | null | $override | limit to a specific override |
quiz_update_grades | ( | $quiz, | |
$userid = 0, | |||
$nullifnone = true ) |
Update grades in central gradebook.
stdClass | $quiz | the quiz settings. |
int | $userid | specific user only, 0 means all users. |
bool | $nullifnone | If a single user is specified and $nullifnone is true a grade item with a null rawgrade will be inserted |
quiz_update_instance | ( | $quiz, | |
$mform ) |
Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will update an existing instance with new data.
stdClass | $quiz | the data that came from the form. |
stdClass | $mform | no longer used. |
mixed | true on success, false or a string error message on failure. |
quiz_update_open_attempts | ( | array | $conditions | ) |
Efficiently update check state time on all open attempts.
array | $conditions | optional 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 | ( | $quizid, | |
$direction, | |||
$afterslot, | |||
$beforeslot = null ) |
Move all the section headings in a certain slot range by a certain offset.
int | $quizid | the id of a quiz |
int | $direction | amount to adjust section heading positions. Normally +1 or -1. |
int | $afterslot | adjust headings that start after this slot. |
int | null | $beforeslot | optionally, only adjust headings before this slot. |
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 {
stdClass | $quiz | a quiz. |
quiz_user_complete | ( | $course, | |
$user, | |||
$mod, | |||
$quiz ) |
Print a detailed representation of what a user has done with a given particular instance of this module, for user activity reports.
stdClass | $course | |
stdClass | $user | |
stdClass | $mod | |
stdClass | $quiz |
bool |
quiz_user_outline | ( | $course, | |
$user, | |||
$mod, | |||
$quiz ) |
Return a small object with summary information about what a user has done with a given particular instance of this module Used for user activity reports.
$return->time = the time they did it $return->info = a short text description
stdClass | $course | |
stdClass | $user | |
stdClass | $mod | |
stdClass | $quiz |
stdClass|null |
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_settings | $quizobj | quiz object |
access_manager | $accessmanager | quiz access manager |
bool | $forcenew | whether was required to start a new preview attempt |
int | $page | page to jump to in the attempt |
bool | $redirect | whether to redirect or throw exceptions (for web or ws usage) |
array | an array containing the attempt information, access error messages and the page to jump to in the attempt |
quiz_view | ( | $quiz, | |
$course, | |||
$cm, | |||
$context ) |
Mark the activity completed (if required) and trigger the course_module_viewed event.
stdClass | $quiz | quiz object |
stdClass | $course | course object |
stdClass | $cm | course module object |
stdClass | $context | context object |
mod_quiz\refresh_page_numbers | ( | $slots = [] | ) |
Refresh page numbering of quiz slots.
stdClass[] | $slots | (optional) array of slot objects. |
stdClass[] | array of slot objects. |
mod_quiz\refresh_page_numbers_and_update_db | ( | ) |
Refresh page numbering of quiz slots and save to the database.
stdClass[] | array of slot objects. |
mod_quiz\remove_section_heading | ( | $sectionid | ) |
Remove the section heading with the given id.
int | $sectionid | the section to remove. |
mod_quiz\remove_slot | ( | $slotnumber | ) |
Remove a slot from a quiz.
int | $slotnumber | The number of the slot to be deleted. |
coding_exception |
|
protected |
A helper method to restore provided backup.
string | $backupid | Backup ID to restore. |
stdClass | $course | |
stdClass | $user |
mod_quiz\set_section_heading | ( | $id, | |
$newheading ) |
Change the heading for a section.
int | $id | the id of the section to change. |
string | $newheading | the new heading for this section. |
mod_quiz\set_section_shuffle | ( | $id, | |
$shuffle ) |
Change the shuffle setting for a section.
int | $id | the id of the section to change. |
bool | $shuffle | whether this section should be shuffled. |
mod_quiz\unset_question | ( | $slotid | ) |
Unset the question object after deletion.
int | $slotid |
mod_quiz\update_grade_item | ( | stdClass | $gradeitemdata | ) |
Update a grade item.
stdClass | $gradeitemdata | must have properties id and name. |
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.
int | $slotid | id of slot which we will add/remove the page break before. |
int | $type | repaginate\LINK or repaginate\UNLINK. |
stdClass[] | array of slot objects. |
mod_quiz\update_question_dependency | ( | $slotid, | |
$requireprevious ) |
Set whether the question in a particular slot requires the previous one.
int | $slotid | id of slot. |
bool | $requireprevious | if true, set this question to require 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.
When the field displaynumber is set to empty string, the automated numbering is used. Log the updated displatnumber field.
int | $slotid | id of slot. |
string | $displaynumber | set to customised string as question number or empty string fo autonumbering. |
mod_quiz\update_slot_grade_item | ( | stdClass | $slot, |
?int | $gradeitemid ) |
Change which grade this slot contributes to, for quizzes with multiple grades.
It does not update 'sumgrades' in the quiz table. If this method returns true, it will be necessary to recompute all the quiz grades.
stdClass | $slot | row from the quiz_slots table. |
int | null | $gradeitemid | id of the grade item this slot should contribute to. 0 or null means none. |
bool | true if the new $gradeitemid is different from the previous one. |
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.
stdClass | $slot | row from the quiz_slots table. |
float | $maxmark | the new maxmark. |
bool | true if the new grade is different from the old one. |
mod_quiz\verify_grade_item_is_ours | ( | int | $gradeitemid | ) |
Check the grade item with the given id belongs to this quiz.
int | $gradeitemid | id of a quiz grade item. |
coding_exception | if the grade item does not belong to this quiz. |
xmldb_quiz_upgrade | ( | $oldversion | ) |
Quiz module upgrade function.
string | $oldversion | the version we are upgrading from. |
$definitions |
$logs |
$tasks |
if($ADMIN->fulltree) if (empty( $reportsbyname) &&empty( $rulesbyname)) else |
if | ( | ! | defined 'MOODLE_INTERNAL' | ) |
const QUIZ_EVENT_TYPE_OPEN 'open' |
#-
Event types.
const QUIZ_GRADEHIGHEST '1' |
#-
#+ Options determining how the grades from individual attempts are combined to give the overall grade for a user
const QUIZ_MAX_EVENT_LENGTH 5*24*60*60 |
#-
If start and end date for the quiz are more than this many seconds apart they will be represented by two separate events in the calendar
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.
trait quiz_question_helper_test_trait |
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)