Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 402 and 403]

(no description)

File Size: 602 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: quiz_settings  - X-Ref

A class encapsulating the settings for a quiz.

When this class is initialised, it may have the settings adjusted to account
for the overrides for a particular user. See the create methods.

Initially, it only loads a minimal amount of information about each question - loading
extra information only when necessary or when asked. The class tracks which questions
are loaded.

__construct($quiz, $cm, $course, $getcontext = true)   X-Ref
Constructor, assuming we already have the necessary data loaded.

param: stdClass $quiz the row from the quiz table.
param: stdClass $cm the course_module object for this quiz.
param: stdClass $course the row from the course table for the course we belong to.
param: bool $getcontext intended for testing - stops the constructor getting the context.

create_helper(stdClass $quiz, cm_info|stdClass $cm, stdClass $course, ?int $userid)   X-Ref
Helper used by the other factory methods.

param: stdClass $quiz
param: cm_info|stdClass $cm
param: stdClass $course
param: int|null $userid the the userid (optional). If passed, relevant overrides are applied.
return: quiz_settings the new quiz settings object.

create(int $quizid, int $userid = null)   X-Ref
Static function to create a new quiz settings object from a quiz id, for a specific user.

param: int $quizid the quiz id.
param: int|null $userid the the userid (optional). If passed, relevant overrides are applied.
return: quiz_settings the new quiz settings object.

create_for_cmid(int $cmid, int $userid = null)   X-Ref
Static function to create a new quiz settings object from a cmid, for a specific user.

param: int $cmid the course-module id.
param: int|null $userid the the userid (optional). If passed, relevant overrides are applied.
return: quiz_settings the new quiz settings object.

create_attempt_object($attemptdata)   X-Ref
Create a {@see quiz_attempt} for an attempt at this quiz.

param: stdClass $attemptdata row from the quiz_attempts table.
return: quiz_attempt the new quiz_attempt object.

preload_questions()   X-Ref
Load just basic information about all the questions in this quiz.


load_questions($deprecated = null)   X-Ref
Fully load some or all of the questions for this quiz. You must call
{@see preload_questions()} first.

param: array|null $deprecated no longer supported (it was not used).

get_structure()   X-Ref
Get an instance of the {@see \mod_quiz\structure} class for this quiz.

return: structure describes the questions in the quiz.

get_courseid()   X-Ref
Get the id of the course this quiz belongs to.

return: int the course id.

get_course()   X-Ref
Get the course settings object that this quiz belongs to.

return: stdClass the row of the course table.

get_quizid()   X-Ref
Get this quiz's id (in the quiz table).

return: int the quiz id.

get_quiz()   X-Ref
Get the quiz settings object.

return: stdClass the row of the quiz table.

get_quiz_name()   X-Ref
Get the quiz name.

return: string the name of this quiz.

get_navigation_method()   X-Ref
Get the navigation method in use.

return: int QUIZ_NAVMETHOD_FREE or QUIZ_NAVMETHOD_SEQ.

get_num_attempts_allowed()   X-Ref
How many attepts is the user allowed at this quiz?

return: int the number of attempts allowed at this quiz (0 = infinite).

get_cmid()   X-Ref
Get the course-module id for this quiz.

return: int the course_module id.

get_cm()   X-Ref
Get the course-module object for this quiz.

return: stdClass the course_module object.

get_context()   X-Ref
Get the quiz context.

return: context_module the module context for this quiz.

is_preview_user()   X-Ref
Is the current user is someone who previews the quiz, rather than attempting it?

return: bool true user is a preview user. False, if they can do real attempts.

is_participant($userid)   X-Ref
Checks user enrollment in the current course.

param: int $userid the id of the user to check.
return: bool whether the user is enrolled.

show_only_active_users()   X-Ref
Check is only active users in course should be shown.

return: bool true if only active users should be shown.

has_questions()   X-Ref
Have any questions been added to this quiz yet?

return: bool whether any questions have been added to this quiz.

get_question($id)   X-Ref
Get a particular question in this quiz, by its id.

param: int $id the question id.
return: stdClass the question object with that id.

get_questions($questionids = null)   X-Ref
Get some of the question in this quiz.

param: array|null $questionids question ids of the questions to load. null for all.
return: stdClass[] the question data objects.

get_sections()   X-Ref
Get all the sections in this quiz.

return: array 0, 1, 2, ... => quiz_sections row from the database.

get_access_manager($timenow)   X-Ref
Return access_manager and instance of the access_manager class
for this quiz at this time.

param: int $timenow the current time as a unix timestamp.
return: access_manager an instance of the access_manager class

get_grade_calculator()   X-Ref
Return the grade_calculator object for this quiz.

return: grade_calculator

has_capability($capability, $userid = null, $doanything = true)   X-Ref
Wrapper round the has_capability funciton that automatically passes in the quiz context.

param: string $capability the name of the capability to check. For example mod/quiz:view.
param: int|null $userid A user id. By default (null) checks the permissions of the current user.
param: bool $doanything If false, ignore effect of admin role assignment.
return: boolean true if the user has this capability. Otherwise false.

require_capability($capability, $userid = null, $doanything = true)   X-Ref
Wrapper round the require_capability function that automatically passes in the quiz context.

param: string $capability the name of the capability to check. For example mod/quiz:view.
param: int|null $userid A user id. By default (null) checks the permissions of the current user.
param: bool $doanything If false, ignore effect of admin role assignment.

view_url()   X-Ref
Get the URL of this quiz's view.php page.

return: moodle_url the URL of this quiz's view page.

edit_url()   X-Ref
Get the URL of this quiz's edit questions page.

return: moodle_url the URL of this quiz's edit page.

attempt_url($attemptid, $page = 0)   X-Ref
Get the URL of a particular page within an attempt.

param: int $attemptid the id of an attempt.
param: int $page optional page number to go to in the attempt.
return: moodle_url the URL of that attempt.

start_attempt_url($page = 0)   X-Ref
Get the URL to start/continue an attempt.

param: int $page page in the attempt to start on (optional).
return: moodle_url the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.

review_url($attemptid)   X-Ref
Get the URL to review a particular quiz attempt.

param: int $attemptid the id of an attempt.
return: string the URL of the review of that attempt.

summary_url($attemptid)   X-Ref
Get the URL for the summary page for a particular attempt.

param: int $attemptid the id of an attempt.
return: string the URL of the review of that attempt.

cannot_review_message($when, $short = false)   X-Ref
If $reviewoptions->attempt is false, meaning that students can't review this
attempt at the moment, return an appropriate string explaining why.

param: int $when One of the display_options::DURING,
param: bool $short if true, return a shorter string.
return: string an appropraite message.

navigation($title)   X-Ref
Probably not used any more, but left for backwards compatibility.

param: string $title the name of this particular quiz page.
return: string always returns ''.

ensure_question_loaded($id)   X-Ref
Check that the definition of a particular question is loaded, and if not throw an exception.

param: int $id a question id.

get_all_question_types_used($includepotential = false)   X-Ref
Return all the question types used in this quiz.

param: boolean $includepotential if the quiz include random questions,
return: array a sorted array including the different question types.