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

Public Member Functions

 can_be_edited ()
 Quizzes can only be edited if they have not been attempted.
 
 can_be_repaginated ()
 Quizzes can only be repaginated if they have not been attempted, the questions are not shuffled, and there are two or more questions.
 
 can_display_number_be_customised (int $slotnumber)
 Check the question has a number that could be customised.
 
 can_finish_during_the_attempt ($slotnumber)
 Whether it is possible for another question to depend on this one finishing.
 
 can_question_depend_on_previous_slot ($slotnumber)
 Whether it would be possible, given the question types, etc.
 
 check_can_be_edited ()
 This quiz can only be edited if they have not been attempted.
 
 get_cmid ()
 Get the course module id of the quiz.
 
 get_context ()
 Get the quiz context.
 
 get_courseid ()
 Get the course id that the quiz belongs to.
 
 get_displayed_number_for_slot ($slotnumber)
 Get the displayed question number (or 'i') for a given slot.
 
 get_last_slot ()
 Get the final slot in the quiz.
 
 get_page_number_for_slot ($slotnumber)
 Get the page a given slot is on.
 
 get_question_by_id ($questionid)
 Get the information about the question with this id.
 
 get_question_count ()
 Get the number of questions in the quiz.
 
 get_question_in_slot ($slotnumber)
 Get the information about the question in a given slot.
 
 get_question_name_in_slot ($slotnumber)
 Get the name of the question in a given slot.
 
 get_question_type_for_slot ($slotnumber)
 Get the question type in a given slot.
 
 get_questions_per_page ()
 How many questions are allowed per page in the quiz.
 
 get_quiz ()
 Get the quiz object.
 
 get_quizid ()
 Get id of the quiz.
 
 get_slot_by_id ($slotid)
 Get a slot by its id.
 
 get_slot_by_number ($slotnumber)
 Get a slot by its slot number.
 
 get_slot_id_for_slot ($slotnumber)
 Get the slot id of a given slot slot.
 
 get_slots ()
 Get quiz slots.
 
 has_questions ()
 Whether there are any questions in the quiz.
 
 has_use_capability (int $slotnumber)
 Does the current user have '...use' capability over the question(s) in a given slot?
 
 is_display_number_customised (int $slotid)
 Check whether the question number is customised.
 
 is_first_section ($section)
 Is this the first section in the quiz?
 
 is_first_slot_on_page ($slotnumber)
 Is this slot the first one on its page?
 
 is_last_section ($section)
 Is this the last section in the quiz?
 
 is_last_slot_in_quiz ($slotnumber)
 Is this slot the last one in the quiz?
 
 is_last_slot_in_section ($slotnumber)
 Is this slot the last one in its section?
 
 is_last_slot_on_page ($slotnumber)
 Is this slot the last one on its page?
 
 is_only_one_slot_in_section ($section)
 Does this section only contain one slot?
 
 is_only_slot_in_section ($slotnumber)
 Is this slot the only one in its section?
 
 is_question_dependent_on_previous_slot ($slotnumber)
 Whether it would be possible, given the question types, etc.
 
 is_real_question ($slotnumber)
 Is a particular question in this attempt a real question, or something like a description.
 
 make_slot_display_number_in_place_editable (int $slotid, context $context)
 Make slot display number in place editable api call.
 

Static Public Member Functions

static create ()
 Create an instance of this class representing an empty quiz.
 
static create_for_quiz ($quizobj)
 Create an instance of this class representing the structure of a given quiz.
 

Protected Attributes

bool $canaddrandom = null
 caches the results of can_add_random_question.
 
bool $canbeedited = null
 caches the results of can_be_edited.
 
stdClass[] $questions = []
 the questions in this quiz.
 
quiz_settings $quizobj = null
 the quiz this is the structure of.
 
stdClass[] $sections = []
 currently a dummy.
 
stdClass[] $slotsinorder = []
 quiz_slots.slot => the quiz_slots rows for this quiz, augmented by sectionid.
 

Member Function Documentation

◆ can_be_edited()

mod_quiz\structure::can_be_edited ( )

Quizzes can only be edited if they have not been attempted.

Return values
boolwhether the quiz can be edited.

◆ can_be_repaginated()

mod_quiz\structure::can_be_repaginated ( )

Quizzes can only be repaginated if they have not been attempted, the questions are not shuffled, and there are two or more questions.

Return values
boolwhether this quiz can be repaginated.

◆ can_display_number_be_customised()

mod_quiz\structure::can_display_number_be_customised ( int $slotnumber)

Check the question has a number that could be customised.

Parameters
int$slotnumber
Return values
bool

◆ can_finish_during_the_attempt()

mod_quiz\structure::can_finish_during_the_attempt ( $slotnumber)

Whether it is possible for another question to depend on this one finishing.

Note that the answer is not exact, because of random questions, and sometimes questions cannot be depended upon because of quiz options.

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolcan this question finish naturally during the attempt?

◆ can_question_depend_on_previous_slot()

mod_quiz\structure::can_question_depend_on_previous_slot ( $slotnumber)

Whether it would be possible, given the question types, etc.

for the question in the given slot to require that the previous question had been answered before this one is displayed.

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolcan this question require the previous one.

◆ check_can_be_edited()

mod_quiz\structure::check_can_be_edited ( )

This quiz can only be edited if they have not been attempted.

Throw an exception if this is not the case.

◆ create()

static mod_quiz\structure::create ( )
static

Create an instance of this class representing an empty quiz.

Return values
structure

◆ create_for_quiz()

static mod_quiz\structure::create_for_quiz ( $quizobj)
static

Create an instance of this class representing the structure of a given quiz.

Parameters
quiz_settings$quizobjthe quiz.
Return values
structure

◆ get_cmid()

mod_quiz\structure::get_cmid ( )

Get the course module id of the quiz.

Return values
intthe course_modules.id for the quiz.

◆ get_context()

mod_quiz\structure::get_context ( )

Get the quiz context.

Return values
context_modulethe context of the quiz that this is the structure of.

◆ get_courseid()

mod_quiz\structure::get_courseid ( )

Get the course id that the quiz belongs to.

Return values
intthe course.id for the quiz.

◆ get_displayed_number_for_slot()

mod_quiz\structure::get_displayed_number_for_slot ( $slotnumber)

Get the displayed question number (or 'i') for a given slot.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stringthe question number ot display for this slot.

◆ get_last_slot()

mod_quiz\structure::get_last_slot ( )

Get the final slot in the quiz.

Return values
stdClassthe quiz_slots for the final slot in the quiz.

◆ get_page_number_for_slot()

mod_quiz\structure::get_page_number_for_slot ( $slotnumber)

Get the page a given slot is on.

Parameters
int$slotnumberthe index of the slot in question.
Return values
intthe page number of the page that slot is on.

◆ get_question_by_id()

mod_quiz\structure::get_question_by_id ( $questionid)

Get the information about the question with this id.

Parameters
int$questionidThe question id.
Return values
stdClassthe data from the questions table, augmented with question_category.contextid, and the quiz_slots data for the question in this quiz.

◆ get_question_count()

mod_quiz\structure::get_question_count ( )

Get the number of questions in the quiz.

Return values
intthe number of questions in the quiz.

◆ get_question_in_slot()

mod_quiz\structure::get_question_in_slot ( $slotnumber)

Get the information about the question in a given slot.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stdClassthe data from the questions table, augmented with question_category.contextid, and the quiz_slots data for the question in this quiz.

◆ get_question_name_in_slot()

mod_quiz\structure::get_question_name_in_slot ( $slotnumber)

Get the name of the question in a given slot.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stdClassthe data from the questions table, augmented with

◆ get_question_type_for_slot()

mod_quiz\structure::get_question_type_for_slot ( $slotnumber)

Get the question type in a given slot.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stringthe question type (e.g. multichoice).

◆ get_questions_per_page()

mod_quiz\structure::get_questions_per_page ( )

How many questions are allowed per page in the quiz.

This setting controls how frequently extra page-breaks should be inserted automatically when questions are added to the quiz.

Return values
intthe number of questions that should be on each page of the quiz by default.

◆ get_quiz()

mod_quiz\structure::get_quiz ( )

Get the quiz object.

Return values
stdClassthe quiz settings row from the database.

◆ get_quizid()

mod_quiz\structure::get_quizid ( )

Get id of the quiz.

Return values
intthe quiz.id for the quiz.

◆ get_slot_by_id()

mod_quiz\structure::get_slot_by_id ( $slotid)

Get a slot by its id.

Throws an exception if it is missing.

Parameters
int$slotidthe slot id.
Return values
stdClassthe requested quiz_slots row.

◆ get_slot_by_number()

mod_quiz\structure::get_slot_by_number ( $slotnumber)

Get a slot by its slot number.

Throws an exception if it is missing.

Parameters
int$slotnumberThe slot number
Return values
stdClass
Exceptions
coding_exception

◆ get_slot_id_for_slot()

mod_quiz\structure::get_slot_id_for_slot ( $slotnumber)

Get the slot id of a given slot slot.

Parameters
int$slotnumberthe index of the slot in question.
Return values
intthe page number of the page that slot is on.

◆ get_slots()

mod_quiz\structure::get_slots ( )

Get quiz slots.

Return values
stdClass[]the slots in this quiz.

◆ has_questions()

mod_quiz\structure::has_questions ( )

Whether there are any questions in the quiz.

Return values
booltrue if there is at least one question in the quiz.

◆ has_use_capability()

mod_quiz\structure::has_use_capability ( int $slotnumber)

Does the current user have '...use' capability over the question(s) in a given slot?

Parameters
int$slotnumberthe index of the slot in question.
Return values
booltrue if they have the required capability.

◆ is_display_number_customised()

mod_quiz\structure::is_display_number_customised ( int $slotid)

Check whether the question number is customised.

Parameters
int$slotid
Return values
bool
Todo
MDL-76612 Final deprecation in Moodle 4.6
Deprecated
since 4.2. $slot->displayednumber is no longer used. If you need this, use isset(...->displaynumber), but this method was not used.

◆ is_first_section()

mod_quiz\structure::is_first_section ( $section)

Is this the first section in the quiz?

Parameters
stdClass$sectionthe quiz_sections row.
Return values
boolwhether this is first section in the quiz.

◆ is_first_slot_on_page()

mod_quiz\structure::is_first_slot_on_page ( $slotnumber)

Is this slot the first one on its page?

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether this slot the first one on its page.

◆ is_last_section()

mod_quiz\structure::is_last_section ( $section)

Is this the last section in the quiz?

Parameters
stdClass$sectionthe quiz_sections row.
Return values
boolwhether this is first section in the quiz.

◆ is_last_slot_in_quiz()

mod_quiz\structure::is_last_slot_in_quiz ( $slotnumber)

Is this slot the last one in the quiz?

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether this slot the last one in the quiz.

◆ is_last_slot_in_section()

mod_quiz\structure::is_last_slot_in_section ( $slotnumber)

Is this slot the last one in its section?

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether this slot the last one on its section.

◆ is_last_slot_on_page()

mod_quiz\structure::is_last_slot_on_page ( $slotnumber)

Is this slot the last one on its page?

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether this slot the last one on its page.

◆ is_only_one_slot_in_section()

mod_quiz\structure::is_only_one_slot_in_section ( $section)

Does this section only contain one slot?

Parameters
stdClass$sectionthe quiz_sections row.
Return values
boolwhether this section contains only one slot.

◆ is_only_slot_in_section()

mod_quiz\structure::is_only_slot_in_section ( $slotnumber)

Is this slot the only one in its section?

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether this slot the only one on its section.

◆ is_question_dependent_on_previous_slot()

mod_quiz\structure::is_question_dependent_on_previous_slot ( $slotnumber)

Whether it would be possible, given the question types, etc.

for the question in the given slot to require that the previous question had been answered before this one is displayed.

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolcan this question require the previous one.

◆ is_real_question()

mod_quiz\structure::is_real_question ( $slotnumber)

Is a particular question in this attempt a real question, or something like a description.

Parameters
int$slotnumberthe index of the slot in question.
Return values
boolwhether that question is a real question.

◆ make_slot_display_number_in_place_editable()

mod_quiz\structure::make_slot_display_number_in_place_editable ( int $slotid,
context $context )

Make slot display number in place editable api call.

Parameters
int$slotid
context$context
Return values
core\output\inplace_editable

Member Data Documentation

◆ $questions

stdClass [] mod_quiz\structure::$questions = []
protected

the questions in this quiz.

Contains the row from the questions table, with the data from the quiz_slots table added, and also question_categories.contextid.

◆ $sections

stdClass [] mod_quiz\structure::$sections = []
protected

currently a dummy.

Holds data that will match the quiz_sections, once it exists.


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