Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_quiz\structure Class Reference

Public Member Functions

 can_add_section_heading ($pagenumber)
 Check whether adding a section heading is possible.
 
 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.
 
 formatted_question_grade ($slotnumber)
 Get the maximum mark for a question, formatted for display.
 
 formatted_quiz_grade ()
 Get the overall quiz grade formatted for display.
 
 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_dates_summary ()
 Get the date information about the current state of the quiz.
 
 get_decimal_places_for_grades ()
 Get the number of decimal places for displaying overall quiz grades or marks.
 
 get_decimal_places_for_question_marks ()
 Get the number of decimal places for displaying question marks.
 
 get_displayed_number_for_slot ($slotnumber)
 Get the displayed question number (or 'i') for a given slot.
 
 get_edit_page_warnings ()
 Get any warnings to show at the top of the edit page.
 
 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_section_by_id ($sectionid)
 Get a particular section by id.
 
 get_section_count ()
 Get the number of questions in the quiz.
 
 get_sections ()
 Get all the sections 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.
 
 get_slots_in_section ($sectionid)
 Get all the slots in a section of the quiz.
 
 get_version_choices_for_slot (int $slotnumber)
 Get the version options to show on the 'Questions' page for a particular question.
 
 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.
 
 move_slot ($idmove, $idmoveafter, $page)
 Move a slot from its current location to a new location.
 
 populate_slots_with_sections ()
 Fill in the section ids for each slot.
 

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 Member Functions

 populate_grade_items ()
 Load the information about the grade items for this quiz.
 
 populate_question_numbers ()
 Number the questions.
 
 populate_structure ()
 Set up this class with the structure for 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[] array $gradeitems = []
 quiz_grade_items for this quiz indexed by id.
 
stdClass[] $questions = []
 the questions in this quiz.
 
quiz_settings $quizobj = null
 the quiz this is the structure of.
 
stdClass[] $sections = []
 this quiz's data from the quiz_sections table.
 
stdClass[] $slotsinorder = []
 quiz_slots.slot => the quiz_slots rows for this quiz, augmented by sectionid.
 

Member Function Documentation

◆ can_add_section_heading()

mod_quiz\structure::can_add_section_heading ( $pagenumber)

Check whether adding a section heading is possible.

Parameters
int$pagenumberthe number of the page.
Return values
boolean

◆ 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

◆ formatted_question_grade()

mod_quiz\structure::formatted_question_grade ( $slotnumber)

Get the maximum mark for a question, formatted for display.

Parameters
int$slotnumberthe index of the slot in question.
Return values
stringthe maximum mark for the question in this slot.

◆ formatted_quiz_grade()

mod_quiz\structure::formatted_quiz_grade ( )

Get the overall quiz grade formatted for display.

Return values
stringthe maximum grade for this quiz.

◆ 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_dates_summary()

mod_quiz\structure::get_dates_summary ( )

Get the date information about the current state of the quiz.

Return values
string[]array of two strings. First a short summary, then a longer explanation of the current state, e.g. for a tool-tip.

◆ get_decimal_places_for_grades()

mod_quiz\structure::get_decimal_places_for_grades ( )

Get the number of decimal places for displaying overall quiz grades or marks.

Return values
intthe number of decimal places.

◆ get_decimal_places_for_question_marks()

mod_quiz\structure::get_decimal_places_for_question_marks ( )

Get the number of decimal places for displaying question marks.

Return values
intthe number of decimal places.

◆ 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_edit_page_warnings()

mod_quiz\structure::get_edit_page_warnings ( )

Get any warnings to show at the top of the edit page.

Return values
string[]array of strings.

◆ 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_section_by_id()

mod_quiz\structure::get_section_by_id ( $sectionid)

Get a particular section by id.

Return values
stdClassthe section.

◆ get_section_count()

mod_quiz\structure::get_section_count ( )

Get the number of questions in the quiz.

Return values
intthe number of questions in the quiz.

◆ get_sections()

mod_quiz\structure::get_sections ( )

Get all the sections of the quiz.

Return values
stdClass[]the sections in this 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.

◆ get_slots_in_section()

mod_quiz\structure::get_slots_in_section ( $sectionid)

Get all the slots in a section of the quiz.

Parameters
int$sectionidthe section id.
Return values
int[]slot numbers.

◆ get_version_choices_for_slot()

mod_quiz\structure::get_version_choices_for_slot ( int $slotnumber)

Get the version options to show on the 'Questions' page for a particular question.

Parameters
int$slotnumberwhich slot to get the choices for.
Return values
stdClass[]other versions of this question. Each object has fields versionid, version and selected. Array is returned most recent version first.

◆ 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

◆ move_slot()

mod_quiz\structure::move_slot ( $idmove,
$idmoveafter,
$page )

Move a slot from its current location to a new location.

After calling this method, this class will be in an invalid state, and should be discarded if you want to manipulate the structure further.

Parameters
int$idmoveid of slot to be moved
int$idmoveafterid of slot to come before slot being moved
int$pagenew page number of slot being moved

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

this quiz's data from the quiz_sections table.

Each item has a ->lastslot field too.


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