Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
A class encapsulating a quiz and the questions it contains, and making the information available to scripts like view.php. More...
Public Member Functions | |
__construct ($quiz, $cm, $course, $getcontext=true) | |
Constructor, assuming we already have the necessary data loaded. More... | |
attempt_url ($attemptid, $page=0) | |
cannot_review_message ($when, $short=false) | |
If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why. More... | |
confirm_start_attempt_message ($notused) | |
create_attempt_object ($attemptdata) | |
Create a quiz_attempt for an attempt at this quiz. More... | |
edit_url () | |
get_access_manager ($timenow) | |
Return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time. More... | |
get_all_question_types_used ($includepotential=false) | |
Return all the question types used in this quiz. More... | |
get_cm () | |
Get the course-module object for this quiz. More... | |
get_cmid () | |
Get the course-module id for this quiz. More... | |
get_context () | |
Get the quiz context. More... | |
get_course () | |
Get the course settings object that this quiz belongs to. More... | |
get_courseid () | |
Get the id of the course this quiz belongs to. More... | |
get_navigation_method () | |
Get the navigation method in use. More... | |
get_num_attempts_allowed () | |
get_question ($id) | |
get_questions ($questionids=null) | |
get_quiz () | |
Get the quiz settings object. More... | |
get_quiz_name () | |
Get the quiz name. More... | |
get_quizid () | |
Get this quiz's id (in the quiz table). More... | |
get_sections () | |
Get all the sections in this quiz. More... | |
get_structure () | |
Get an instance of the mod_quiz::structure class for this quiz. More... | |
has_capability ($capability, $userid=null, $doanything=true) | |
Wrapper round the has_capability funciton that automatically passes in the quiz context. More... | |
has_questions () | |
is_participant ($userid) | |
Checks user enrollment in the current course. More... | |
is_preview_user () | |
load_questions ($questionids=null) | |
Fully load some or all of the questions for this quiz. More... | |
navigation ($title) | |
Probably not used any more, but left for backwards compatibility. More... | |
preload_questions () | |
Load just basic information about all the questions in this quiz. | |
require_capability ($capability, $userid=null, $doanything=true) | |
Wrapper round the require_capability function that automatically passes in the quiz context. More... | |
review_url ($attemptid) | |
show_only_active_users () | |
Check is only active users in course should be shown. More... | |
start_attempt_url ($page=0) | |
Get the URL to start/continue an attempt. More... | |
summary_url ($attemptid) | |
view_url () | |
Static Public Member Functions | |
static | create ($quizid, $userid=null) |
Static function to create a new quiz object for a specific user. More... | |
Protected Member Functions | |
ensure_question_loaded ($id) | |
Check that the definition of a particular question is loaded, and if not throw an exception. More... | |
Protected Attributes | |
quiz_access_manager | $accessmanager = null |
the access manager for this quiz. | |
stdClass | $cm |
the course_module settings from the database. | |
context | $context |
the quiz context. | |
stdClass | $course |
the course settings from the database. | |
bool | $ispreviewuser = null |
whether the current user has capability mod/quiz:preview. | |
stdClass[] | $questions = null |
of questions augmented with slot information. | |
stdClass | $quiz |
the quiz settings from the database. | |
stdClass[] | $sections = null |
of quiz_section rows. | |
A class encapsulating a quiz and the questions it contains, and making the information available to scripts like view.php.
Initially, it only loads a minimal amout of information about each question - loading extra information only when necessary or when asked. The class tracks which questions are loaded.
quiz::__construct | ( | $quiz, | |
$cm, | |||
$course, | |||
$getcontext = true |
|||
) |
Constructor, assuming we already have the necessary data loaded.
object | $quiz | the row from the quiz table. |
object | $cm | the course_module object for this quiz. |
object | $course | the row from the course table for the course we belong to. |
bool | $getcontext | intended for testing - stops the constructor getting the context. |
quiz::attempt_url | ( | $attemptid, | |
$page = 0 |
|||
) |
int | $attemptid | the id of an attempt. |
int | $page | optional page number to go to in the attempt. |
string | the URL of that attempt. |
quiz::cannot_review_message | ( | $when, | |
$short = false |
|||
) |
If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.
int | $when | One of the mod_quiz_display_options::DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants. |
bool | $short | if true, return a shorter string. |
string | an appropraite message. |
quiz::confirm_start_attempt_message | ( | $notused | ) |
bool | $notused | not used. |
string | an empty string. |
|
static |
Static function to create a new quiz object for a specific user.
int | $quizid | the the quiz id. |
int | null | $userid | the the userid (optional). If passed, relevant overrides are applied. |
quiz | the new quiz object. |
quiz::create_attempt_object | ( | $attemptdata | ) |
Create a quiz_attempt for an attempt at this quiz.
object | $attemptdata | row from the quiz_attempts table. |
quiz_attempt | the new quiz_attempt object. |
quiz::edit_url | ( | ) |
string | the URL of this quiz's edit page. |
|
protected |
Check that the definition of a particular question is loaded, and if not throw an exception.
int | $id | a question id. |
quiz::get_access_manager | ( | $timenow | ) |
Return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time.
int | $timenow | the current time as a unix timestamp. |
quiz_access_manager | and instance of the quiz_access_manager class for this quiz at this time. |
quiz::get_all_question_types_used | ( | $includepotential = false | ) |
Return all the question types used in this quiz.
boolean | $includepotential | if the quiz include random questions, setting this flag to true will make the function to return all the possible question types in the random questions category. |
array | a sorted array including the different question types. |
quiz::get_cm | ( | ) |
Get the course-module object for this quiz.
object | the course_module object. |
quiz::get_cmid | ( | ) |
Get the course-module id for this quiz.
int | the course_module id. |
quiz::get_context | ( | ) |
Get the quiz context.
context | the module context for this quiz. |
quiz::get_course | ( | ) |
Get the course settings object that this quiz belongs to.
object | the row of the course table. |
quiz::get_courseid | ( | ) |
Get the id of the course this quiz belongs to.
int | the course id. |
quiz::get_navigation_method | ( | ) |
Get the navigation method in use.
int | QUIZ_NAVMETHOD_FREE or QUIZ_NAVMETHOD_SEQ. |
quiz::get_num_attempts_allowed | ( | ) |
int | the number of attempts allowed at this quiz (0 = infinite). |
quiz::get_question | ( | $id | ) |
int | $id | the question id. |
stdClass | the question object with that id. |
quiz::get_questions | ( | $questionids = null | ) |
array | null | $questionids | question ids of the questions to load. null for all. |
stdClass[] | the question data objects. |
quiz::get_quiz | ( | ) |
Get the quiz settings object.
stdClass | the row of the quiz table. |
quiz::get_quiz_name | ( | ) |
Get the quiz name.
string | the name of this quiz. |
quiz::get_quizid | ( | ) |
Get this quiz's id (in the quiz table).
int | the quiz id. |
quiz::get_sections | ( | ) |
Get all the sections in this quiz.
array | 0, 1, 2, ... => quiz_sections row from the database. |
quiz::get_structure | ( | ) |
Get an instance of the mod_quiz::structure class for this quiz.
mod_quiz::structure | describes the questions in the quiz. |
quiz::has_capability | ( | $capability, | |
$userid = null , |
|||
$doanything = true |
|||
) |
Wrapper round the has_capability funciton that automatically passes in the quiz context.
string | $capability | the name of the capability to check. For example mod/quiz:view. |
int | null | $userid | A user id. By default (null) checks the permissions of the current user. |
bool | $doanything | If false, ignore effect of admin role assignment. |
boolean | true if the user has this capability. Otherwise false. |
quiz::has_questions | ( | ) |
bool | whether any questions have been added to this quiz. |
quiz::is_participant | ( | $userid | ) |
Checks user enrollment in the current course.
int | $userid | the id of the user to check. |
bool | whether the user is enrolled. |
quiz::is_preview_user | ( | ) |
bool | wether the current user is someone who previews the quiz, rather than attempting it. |
quiz::load_questions | ( | $questionids = null | ) |
Fully load some or all of the questions for this quiz.
You must call preload_questions() first.
array | null | $questionids | question ids of the questions to load. null for all. |
quiz::navigation | ( | $title | ) |
Probably not used any more, but left for backwards compatibility.
string | $title | the name of this particular quiz page. |
string | always returns ''. |
quiz::require_capability | ( | $capability, | |
$userid = null , |
|||
$doanything = true |
|||
) |
Wrapper round the require_capability function that automatically passes in the quiz context.
string | $capability | the name of the capability to check. For example mod/quiz:view. |
int | null | $userid | A user id. By default (null) checks the permissions of the current user. |
bool | $doanything | If false, ignore effect of admin role assignment. |
quiz::review_url | ( | $attemptid | ) |
int | $attemptid | the id of an attempt. |
string | the URL of the review of that attempt. |
quiz::show_only_active_users | ( | ) |
Check is only active users in course should be shown.
bool | true if only active users should be shown. |
quiz::start_attempt_url | ( | $page = 0 | ) |
Get the URL to start/continue an attempt.
int | $page | page in the attempt to start on (optional). |
moodle_url | the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter. |
quiz::summary_url | ( | $attemptid | ) |
int | $attemptid | the id of an attempt. |
string | the URL of the review of that attempt. |
quiz::view_url | ( | ) |
string | the URL of this quiz's view page. |