Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_quiz\quiz_settings Class Reference

Public Member Functions

 __construct ($quiz, $cm, $course, $getcontext=true)
 Constructor, assuming we already have the necessary data loaded.
 
 attempt_url ($attemptid, $page=0)
 Get the URL of a particular page within an attempt.
 
 cannot_review_message ($when, $short=false, int $attemptsubmittime=null)
 If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.
 
 create_attempt_object ($attemptdata)
 Create a {.
 
 edit_url ()
 Get the URL of this quiz's edit questions page.
 
 get_access_manager ($timenow)
 Return access_manager and instance of the access_manager class for this quiz at this time.
 
 get_all_question_types_used ($includepotential=false)
 Return all the question types used in this quiz.
 
 get_cm ()
 Get the course-module object for this quiz.
 
 get_cmid ()
 Get the course-module id for this quiz.
 
 get_context ()
 Get the quiz context.
 
 get_course ()
 Get the course settings object that this quiz belongs to.
 
 get_courseid ()
 Get the id of the course this quiz belongs to.
 
 get_grade_calculator ()
 Return the grade_calculator object for this quiz.
 
 get_navigation_method ()
 Get the navigation method in use.
 
 get_num_attempts_allowed ()
 How many attepts is the user allowed at this quiz?
 
 get_question ($id)
 Get a particular question in this quiz, by its id.
 
 get_questions ($questionids=null)
 Get some of the question in this quiz.
 
 get_quiz ()
 Get the quiz settings object.
 
 get_quiz_name ()
 Get the quiz name.
 
 get_quizid ()
 Get this quiz's id (in the quiz table).
 
 get_sections ()
 Get all the sections in this quiz.
 
 get_structure ()
 Get an instance of the {.
 
 has_capability ($capability, $userid=null, $doanything=true)
 Wrapper round the has_capability funciton that automatically passes in the quiz context.
 
 has_questions ()
 Have any questions been added to this quiz yet?
 
 is_participant ($userid)
 Checks user enrollment in the current course.
 
 is_preview_user ()
 Is the current user is someone who previews the quiz, rather than attempting it?
 
 load_questions ($deprecated=null)
 Fully load some or all of the questions for this quiz.
 
 navigation ($title)
 Probably not used any more, but left for backwards compatibility.
 
 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.
 
 review_url ($attemptid)
 Get the URL to review a particular quiz attempt.
 
 show_only_active_users ()
 Check is only active users in course should be shown.
 
 start_attempt_url ($page=0)
 Get the URL to start/continue an attempt.
 
 summary_url ($attemptid)
 Get the URL for the summary page for a particular attempt.
 
 view_url ()
 Get the URL of this quiz's view.php page.
 

Static Public Member Functions

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

Protected Member Functions

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

Static Protected Member Functions

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

Protected Attributes

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.
 

Constructor & Destructor Documentation

◆ __construct()

mod_quiz\quiz_settings::__construct ( $quiz,
$cm,
$course,
$getcontext = true )

Constructor, assuming we already have the necessary data loaded.

Parameters
stdClass$quizthe row from the quiz table.
stdClass$cmthe course_module object for this quiz.
stdClass$coursethe row from the course table for the course we belong to.
bool$getcontextintended for testing - stops the constructor getting the context.

Member Function Documentation

◆ attempt_url()

mod_quiz\quiz_settings::attempt_url ( $attemptid,
$page = 0 )

Get the URL of a particular page within an attempt.

Parameters
int$attemptidthe id of an attempt.
int$pageoptional page number to go to in the attempt.
Return values
moodle_urlthe URL of that attempt.

◆ cannot_review_message()

mod_quiz\quiz_settings::cannot_review_message ( $when,
$short = false,
int $attemptsubmittime = null )

If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.

Parameters
int$whenOne of the display_options\DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.
bool$shortif true, return a shorter string.
int | null$attemptsubmittimetime this attempt was submitted. (Optional, but should be given.)
Return values
stringan appropraite message.

◆ create()

static mod_quiz\quiz_settings::create ( int $quizid,
int $userid = null )
static

Static function to create a new quiz settings object from a quiz id, for a specific user.

Parameters
int$quizidthe quiz id.
int | null$useridthe the userid (optional). If passed, relevant overrides are applied.
Return values
quiz_settingsthe new quiz settings object.

◆ create_attempt_object()

mod_quiz\quiz_settings::create_attempt_object ( $attemptdata)

Create a {.

See also
quiz_attempt} for an attempt at this quiz.
Parameters
stdClass$attemptdatarow from the quiz_attempts table.
Return values
quiz_attemptthe new quiz_attempt object.

◆ create_for_cmid()

static mod_quiz\quiz_settings::create_for_cmid ( int $cmid,
int $userid = null )
static

Static function to create a new quiz settings object from a cmid, for a specific user.

Parameters
int$cmidthe course-module id.
int | null$useridthe the userid (optional). If passed, relevant overrides are applied.
Return values
quiz_settingsthe new quiz settings object.

◆ create_helper()

static mod_quiz\quiz_settings::create_helper ( stdClass $quiz,
cm_info|stdClass $cm,
stdClass $course,
?int $userid )
staticprotected

Helper used by the other factory methods.

Parameters
stdClass$quiz
cm_info | stdClass$cm
stdClass$course
int | null$useridthe the userid (optional). If passed, relevant overrides are applied.
Return values
quiz_settingsthe new quiz settings object.

◆ edit_url()

mod_quiz\quiz_settings::edit_url ( )

Get the URL of this quiz's edit questions page.

Return values
moodle_urlthe URL of this quiz's edit page.

◆ ensure_question_loaded()

mod_quiz\quiz_settings::ensure_question_loaded ( $id)
protected

Check that the definition of a particular question is loaded, and if not throw an exception.

Parameters
int$ida question id.

◆ get_access_manager()

mod_quiz\quiz_settings::get_access_manager ( $timenow)

Return access_manager and instance of the access_manager class for this quiz at this time.

Parameters
int$timenowthe current time as a unix timestamp.
Return values
access_manageran instance of the access_manager class for this quiz at this time.

◆ get_all_question_types_used()

mod_quiz\quiz_settings::get_all_question_types_used ( $includepotential = false)

Return all the question types used in this quiz.

Parameters
boolean$includepotentialif 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.
Return values
arraya sorted array including the different question types.
Since
Moodle 3.1

◆ get_cm()

mod_quiz\quiz_settings::get_cm ( )

Get the course-module object for this quiz.

Return values
stdClassthe course_module object.

◆ get_cmid()

mod_quiz\quiz_settings::get_cmid ( )

Get the course-module id for this quiz.

Return values
intthe course_module id.

◆ get_context()

mod_quiz\quiz_settings::get_context ( )

Get the quiz context.

Return values
context_modulethe module context for this quiz.

◆ get_course()

mod_quiz\quiz_settings::get_course ( )

Get the course settings object that this quiz belongs to.

Return values
stdClassthe row of the course table.

◆ get_courseid()

mod_quiz\quiz_settings::get_courseid ( )

Get the id of the course this quiz belongs to.

Return values
intthe course id.

◆ get_grade_calculator()

mod_quiz\quiz_settings::get_grade_calculator ( )

Return the grade_calculator object for this quiz.

Return values
grade_calculator

◆ get_navigation_method()

mod_quiz\quiz_settings::get_navigation_method ( )

Get the navigation method in use.

Return values
intQUIZ_NAVMETHOD_FREE or QUIZ_NAVMETHOD_SEQ.

◆ get_num_attempts_allowed()

mod_quiz\quiz_settings::get_num_attempts_allowed ( )

How many attepts is the user allowed at this quiz?

Return values
intthe number of attempts allowed at this quiz (0 = infinite).

◆ get_question()

mod_quiz\quiz_settings::get_question ( $id)

Get a particular question in this quiz, by its id.

Parameters
int$idthe question id.
Return values
stdClassthe question object with that id.

◆ get_questions()

mod_quiz\quiz_settings::get_questions ( $questionids = null)

Get some of the question in this quiz.

Parameters
array | null$questionidsquestion ids of the questions to load. null for all.
Return values
stdClass[]the question data objects.

◆ get_quiz()

mod_quiz\quiz_settings::get_quiz ( )

Get the quiz settings object.

Return values
stdClassthe row of the quiz table.

◆ get_quiz_name()

mod_quiz\quiz_settings::get_quiz_name ( )

Get the quiz name.

Return values
stringthe name of this quiz.

◆ get_quizid()

mod_quiz\quiz_settings::get_quizid ( )

Get this quiz's id (in the quiz table).

Return values
intthe quiz id.

◆ get_sections()

mod_quiz\quiz_settings::get_sections ( )

Get all the sections in this quiz.

Return values
array0, 1, 2, ... => quiz_sections row from the database.

◆ get_structure()

mod_quiz\quiz_settings::get_structure ( )

Get an instance of the {.

See also
mod_quiz\structure} class for this quiz.
Return values
structuredescribes the questions in the quiz.

◆ has_capability()

mod_quiz\quiz_settings::has_capability ( $capability,
$userid = null,
$doanything = true )

Wrapper round the has_capability funciton that automatically passes in the quiz context.

Parameters
string$capabilitythe name of the capability to check. For example mod/quiz:view.
int | null$useridA user id. By default (null) checks the permissions of the current user.
bool$doanythingIf false, ignore effect of admin role assignment.
Return values
booleantrue if the user has this capability. Otherwise false.

◆ has_questions()

mod_quiz\quiz_settings::has_questions ( )

Have any questions been added to this quiz yet?

Return values
boolwhether any questions have been added to this quiz.

◆ is_participant()

mod_quiz\quiz_settings::is_participant ( $userid)

Checks user enrollment in the current course.

Parameters
int$useridthe id of the user to check.
Return values
boolwhether the user is enrolled.

◆ is_preview_user()

mod_quiz\quiz_settings::is_preview_user ( )

Is the current user is someone who previews the quiz, rather than attempting it?

Return values
booltrue user is a preview user. False, if they can do real attempts.

◆ load_questions()

mod_quiz\quiz_settings::load_questions ( $deprecated = null)

Fully load some or all of the questions for this quiz.

You must call {

See also
preload_questions()} first.
Parameters
array | null$deprecatedno longer supported (it was not used).

◆ navigation()

mod_quiz\quiz_settings::navigation ( $title)

Probably not used any more, but left for backwards compatibility.

Parameters
string$titlethe name of this particular quiz page.
Return values
stringalways returns ''.

◆ require_capability()

mod_quiz\quiz_settings::require_capability ( $capability,
$userid = null,
$doanything = true )

Wrapper round the require_capability function that automatically passes in the quiz context.

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

◆ review_url()

mod_quiz\quiz_settings::review_url ( $attemptid)

Get the URL to review a particular quiz attempt.

Parameters
int$attemptidthe id of an attempt.
Return values
stringthe URL of the review of that attempt.

◆ show_only_active_users()

mod_quiz\quiz_settings::show_only_active_users ( )

Check is only active users in course should be shown.

Return values
booltrue if only active users should be shown.

◆ start_attempt_url()

mod_quiz\quiz_settings::start_attempt_url ( $page = 0)

Get the URL to start/continue an attempt.

Parameters
int$pagepage in the attempt to start on (optional).
Return values
moodle_urlthe URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.

◆ summary_url()

mod_quiz\quiz_settings::summary_url ( $attemptid)

Get the URL for the summary page for a particular attempt.

Parameters
int$attemptidthe id of an attempt.
Return values
stringthe URL of the review of that attempt.

◆ view_url()

mod_quiz\quiz_settings::view_url ( )

Get the URL of this quiz's view.php page.

Return values
moodle_urlthe URL of this quiz's view page.

Member Data Documentation

◆ $questions

stdClass [] mod_quiz\quiz_settings::$questions = null
protected

of questions augmented with slot information.

For non-random questions, the array key is question id. For random quesions it is 's' . $slotid. probalby best to use ->questionid field of the object instead.


The documentation for this class was generated from the following file: