Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Quiz structure class. More...
Public Member Functions | |
add_section_heading ($pagenumber, $heading=null) | |
Add a section heading on a given page and return the sectionid. More... | |
can_add_random_questions () | |
Whether the current user can add random questions to the quiz or not. More... | |
can_add_section_heading ($pagenumber) | |
Check whether adding a section heading is possible. More... | |
can_be_edited () | |
Quizzes can only be edited if they have not been attempted. More... | |
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. More... | |
can_finish_during_the_attempt ($slotnumber) | |
Whether it is possible for another question to depend on this one finishing. More... | |
can_question_depend_on_previous_slot ($slotnumber) | |
Whether it would be possible, given the question types, etc. More... | |
check_can_be_edited () | |
This quiz can only be edited if they have not been attempted. More... | |
formatted_question_grade ($slotnumber) | |
Get the maximum mark for a question, formatted for display. More... | |
formatted_quiz_grade () | |
Get the overall quiz grade formatted for display. More... | |
get_cmid () | |
Get the course module id of the quiz. More... | |
get_courseid () | |
Get the course id that the quiz belongs to. More... | |
get_dates_summary () | |
Get the date information about the current state of the quiz. More... | |
get_decimal_places_for_grades () | |
Get the number of decimal places for displyaing overall quiz grades or marks. More... | |
get_decimal_places_for_question_marks () | |
Get the number of decimal places for displyaing question marks. More... | |
get_displayed_number_for_slot ($slotnumber) | |
Get the displayed question number (or 'i') for a given slot. More... | |
get_edit_page_warnings () | |
Get any warnings to show at the top of the edit page. More... | |
get_last_slot () | |
Get the final slot in the quiz. More... | |
get_page_number_for_slot ($slotnumber) | |
Get the page a given slot is on. More... | |
get_question_by_id ($questionid) | |
Get the information about the question with this id. More... | |
get_question_count () | |
Get the number of questions in the quiz. More... | |
get_question_in_slot ($slotnumber) | |
Get the information about the question in a given slot. More... | |
get_question_type_for_slot ($slotnumber) | |
Get the question type in a given slot. More... | |
get_questions_per_page () | |
How many questions are allowed per page in the quiz. More... | |
get_quiz () | |
Get the quiz object. More... | |
get_quizid () | |
Get id of the quiz. More... | |
get_section_by_id ($sectionid) | |
Get a particular section by id. More... | |
get_section_count () | |
Get the number of questions in the quiz. More... | |
get_sections () | |
Get all the sections of the quiz. More... | |
get_slot_by_id ($slotid) | |
Get a slot by it's id. More... | |
get_slot_by_number ($slotnumber) | |
Get a slot by it's slot number. More... | |
get_slot_id_for_slot ($slotnumber) | |
Get the slot id of a given slot slot. More... | |
get_slot_tags_for_slot_id ($slotid) | |
Retrieve the list of slot tags for the given slot id. More... | |
get_slots () | |
Get quiz slots. More... | |
get_slots_in_section ($sectionid) | |
Get all the slots in a section of the quiz. More... | |
has_questions () | |
Whether there are any questions in the quiz. More... | |
is_first_section ($section) | |
Is this the first section in the quiz? More... | |
is_first_slot_on_page ($slotnumber) | |
Is this slot the first one on its page? More... | |
is_last_section ($section) | |
Is this the last section in the quiz? More... | |
is_last_slot_in_quiz ($slotnumber) | |
Is this slot the last one in the quiz? More... | |
is_last_slot_in_section ($slotnumber) | |
Is this slot the last one in its section? More... | |
is_last_slot_on_page ($slotnumber) | |
Is this slot the last one on its page? More... | |
is_only_one_slot_in_section ($section) | |
Does this section only contain one slot? More... | |
is_only_slot_in_section ($slotnumber) | |
Is this slot the only one in its section? More... | |
is_question_dependent_on_previous_slot ($slotnumber) | |
Whether it would be possible, given the question types, etc. More... | |
is_real_question ($slotnumber) | |
Is a particular question in this attempt a real question, or something like a description. More... | |
move_slot ($idmove, $idmoveafter, $page) | |
Move a slot from its current location to a new location. More... | |
populate_slots_with_sections () | |
Fill in the section ids for each slot. | |
populate_structure ($quiz) | |
Set up this class with the structure for a given quiz. More... | |
refresh_page_numbers ($slots=array()) | |
Refresh page numbering of quiz slots. More... | |
refresh_page_numbers_and_update_db () | |
Refresh page numbering of quiz slots and save to the database. More... | |
remove_section_heading ($sectionid) | |
Remove the section heading with the given id. More... | |
remove_slot ($slotnumber) | |
Remove a slot from a quiz. More... | |
set_section_heading ($id, $newheading) | |
Change the heading for a section. More... | |
set_section_shuffle ($id, $shuffle) | |
Change the shuffle setting for a section. More... | |
update_page_break ($slotid, $type) | |
Add/Remove a pagebreak. More... | |
update_question_dependency ($slotid, $requireprevious) | |
Set whether the question in a particular slot requires the previous one. More... | |
update_slot_maxmark ($slot, $maxmark) | |
Change the max mark for a slot. More... | |
Static Public Member Functions | |
static | create () |
Create an instance of this class representing an empty quiz. More... | |
static | create_for_quiz ($quizobj) |
Create an instance of this class representing the structure of a given quiz. More... | |
Protected Member Functions | |
populate_missing_questions ($slots) | |
Used by populate. More... | |
populate_question_numbers () | |
Number the questions. | |
populate_slot_tags () | |
Set up this class with the slot tags for each of the slots. | |
Protected Attributes | |
bool | $canaddrandom = null |
caches the results of can_add_random_question. | |
bool | $canbeedited = null |
caches the results of can_be_edited. | |
bool | $hasloadedtags = false |
tracks whether tags have been loaded | |
stdClass[] | $questions = array() |
the questions in this quiz. More... | |
quiz | $quizobj = null |
the quiz this is the structure of. | |
stdClass[] | $sections = array() |
currently a dummy. More... | |
stdClass[] | $slotsinorder = array() |
quiz_slots.slot => the quiz_slots rows for this quiz, agumented by sectionid. | |
stdClass[] | $slottags = array() |
the tags for slots. More... | |
Quiz structure class.
The structure of the quiz. That is, which questions it is built up from. This is used on the Edit quiz page (edit.php) and also when starting an attempt at the quiz (startattempt.php). Once an attempt has been started, then the attempt holds the specific set of questions that that student should answer, and we no longer use this class.
mod_quiz\structure::add_section_heading | ( | $pagenumber, | |
$heading = null |
|||
) |
Add a section heading on a given page and return the sectionid.
int | $pagenumber | the number of the page where the section heading begins. |
string | null | $heading | the heading to add. If not given, a default is used. |
mod_quiz\structure::can_add_random_questions | ( | ) |
Whether the current user can add random questions to the quiz or not.
It is only possible to add a random question if the user has the moodle/question:useall capability on at least one of the contexts related to the one where we are currently editing questions.
bool |
mod_quiz\structure::can_add_section_heading | ( | $pagenumber | ) |
Check whether adding a section heading is possible.
int | $pagenumber | the number of the page. |
boolean |
mod_quiz\structure::can_be_edited | ( | ) |
Quizzes can only be edited if they have not been attempted.
bool | whether the quiz can be edited. |
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.
bool | whether this quiz can be repaginated. |
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.
int | $slotnumber | the index of the slot in question. |
bool | can this question finish naturally during the attempt? |
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.
int | $slotnumber | the index of the slot in question. |
bool | can this question require the previous one. |
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.
|
static |
Create an instance of this class representing an empty quiz.
structure |
|
static |
Create an instance of this class representing the structure of a given quiz.
quiz | $quizobj | the quiz. |
structure |
mod_quiz\structure::formatted_question_grade | ( | $slotnumber | ) |
Get the maximum mark for a question, formatted for display.
int | $slotnumber | the index of the slot in question. |
string | the maximum mark for the question in this slot. |
mod_quiz\structure::formatted_quiz_grade | ( | ) |
Get the overall quiz grade formatted for display.
string | the maximum grade for this quiz. |
mod_quiz\structure::get_cmid | ( | ) |
Get the course module id of the quiz.
int | the course_modules.id for the quiz. |
mod_quiz\structure::get_courseid | ( | ) |
Get the course id that the quiz belongs to.
int | the course.id for the quiz. |
mod_quiz\structure::get_dates_summary | ( | ) |
Get the date information about the current state of the quiz.
string[] | array of two strings. First a short summary, then a longer explanation of the current state, e.g. for a tool-tip. |
mod_quiz\structure::get_decimal_places_for_grades | ( | ) |
Get the number of decimal places for displyaing overall quiz grades or marks.
int | the number of decimal places. |
mod_quiz\structure::get_decimal_places_for_question_marks | ( | ) |
Get the number of decimal places for displyaing question marks.
int | the number of decimal places. |
mod_quiz\structure::get_displayed_number_for_slot | ( | $slotnumber | ) |
Get the displayed question number (or 'i') for a given slot.
int | $slotnumber | the index of the slot in question. |
string | the question number ot display for this slot. |
mod_quiz\structure::get_edit_page_warnings | ( | ) |
Get any warnings to show at the top of the edit page.
string[] | array of strings. |
mod_quiz\structure::get_last_slot | ( | ) |
Get the final slot in the quiz.
stdClass | the quiz_slots for for the final slot in the quiz. |
mod_quiz\structure::get_page_number_for_slot | ( | $slotnumber | ) |
Get the page a given slot is on.
int | $slotnumber | the index of the slot in question. |
int | the page number of the page that slot is on. |
mod_quiz\structure::get_question_by_id | ( | $questionid | ) |
Get the information about the question with this id.
int | $questionid | The question id. |
stdClass | the data from the questions table, augmented with question_category.contextid, and the quiz_slots data for the question in this quiz. |
mod_quiz\structure::get_question_count | ( | ) |
Get the number of questions in the quiz.
int | the number of questions in the quiz. |
mod_quiz\structure::get_question_in_slot | ( | $slotnumber | ) |
Get the information about the question in a given slot.
int | $slotnumber | the index of the slot in question. |
stdClass | the data from the questions table, augmented with question_category.contextid, and the quiz_slots data for the question in this quiz. |
mod_quiz\structure::get_question_type_for_slot | ( | $slotnumber | ) |
Get the question type in a given slot.
int | $slotnumber | the index of the slot in question. |
string | the question type (e.g. multichoice). |
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.
int | the number of questions that should be on each page of the quiz by default. |
mod_quiz\structure::get_quiz | ( | ) |
Get the quiz object.
stdClass | the quiz settings row from the database. |
mod_quiz\structure::get_quizid | ( | ) |
Get id of the quiz.
int | the quiz.id for the quiz. |
mod_quiz\structure::get_section_by_id | ( | $sectionid | ) |
Get a particular section by id.
stdClass | the section. |
mod_quiz\structure::get_section_count | ( | ) |
Get the number of questions in the quiz.
int | the number of questions in the quiz. |
mod_quiz\structure::get_sections | ( | ) |
Get all the sections of the quiz.
stdClass[] | the sections in this quiz. |
mod_quiz\structure::get_slot_by_id | ( | $slotid | ) |
Get a slot by it's id.
Throws an exception if it is missing.
int | $slotid | the slot id. |
stdClass | the requested quiz_slots row. |
coding_exception |
mod_quiz\structure::get_slot_by_number | ( | $slotnumber | ) |
Get a slot by it's slot number.
Throws an exception if it is missing.
int | $slotnumber | The slot number |
stdClass |
coding_exception |
mod_quiz\structure::get_slot_id_for_slot | ( | $slotnumber | ) |
Get the slot id of a given slot slot.
int | $slotnumber | the index of the slot in question. |
int | the page number of the page that slot is on. |
mod_quiz\structure::get_slot_tags_for_slot_id | ( | $slotid | ) |
Retrieve the list of slot tags for the given slot id.
int | $slotid | The id for the slot |
stdClass[] | The list of slot tag records |
mod_quiz\structure::get_slots | ( | ) |
Get quiz slots.
stdClass[] | the slots in this quiz. |
mod_quiz\structure::get_slots_in_section | ( | $sectionid | ) |
Get all the slots in a section of the quiz.
int | $sectionid | the section id. |
int[] | slot numbers. |
mod_quiz\structure::has_questions | ( | ) |
Whether there are any questions in the quiz.
bool | true if there is at least one question in the quiz. |
mod_quiz\structure::is_first_section | ( | $section | ) |
Is this the first section in the quiz?
stdClass | $section | the quiz_sections row. |
bool | whether this is first section in the quiz. |
mod_quiz\structure::is_first_slot_on_page | ( | $slotnumber | ) |
Is this slot the first one on its page?
int | $slotnumber | the index of the slot in question. |
bool | whether this slot the first one on its page. |
mod_quiz\structure::is_last_section | ( | $section | ) |
Is this the last section in the quiz?
stdClass | $section | the quiz_sections row. |
bool | whether this is first section in the quiz. |
mod_quiz\structure::is_last_slot_in_quiz | ( | $slotnumber | ) |
Is this slot the last one in the quiz?
int | $slotnumber | the index of the slot in question. |
bool | whether this slot the last one in the quiz. |
mod_quiz\structure::is_last_slot_in_section | ( | $slotnumber | ) |
Is this slot the last one in its section?
int | $slotnumber | the index of the slot in question. |
bool | whether this slot the last one on its section. |
mod_quiz\structure::is_last_slot_on_page | ( | $slotnumber | ) |
Is this slot the last one on its page?
int | $slotnumber | the index of the slot in question. |
bool | whether this slot the last one on its page. |
mod_quiz\structure::is_only_one_slot_in_section | ( | $section | ) |
Does this section only contain one slot?
stdClass | $section | the quiz_sections row. |
bool | whether this section contains only one slot. |
mod_quiz\structure::is_only_slot_in_section | ( | $slotnumber | ) |
Is this slot the only one in its section?
int | $slotnumber | the index of the slot in question. |
bool | whether this slot the only one on its section. |
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.
int | $slotnumber | the index of the slot in question. |
bool | can this question require the previous one. |
mod_quiz\structure::is_real_question | ( | $slotnumber | ) |
Is a particular question in this attempt a real question, or something like a description.
int | $slotnumber | the index of the slot in question. |
bool | whether that question is a real question. |
mod_quiz\structure::move_slot | ( | $idmove, | |
$idmoveafter, | |||
$page | |||
) |
Move a slot from its current location to a new location.
After callig this method, this class will be in an invalid state, and should be discarded if you want to manipulate the structure further.
int | $idmove | id of slot to be moved |
int | $idmoveafter | id of slot to come before slot being moved |
int | $page | new page number of slot being moved |
bool | $insection | if the question is moving to a place where a new section starts, include it in that section. |
void |
|
protected |
Used by populate.
Make up fake data for any missing questions.
stdClass[] | $slots | the data about the slots and questions in the quiz. |
stdClass[] | updated $slots array. |
mod_quiz\structure::populate_structure | ( | $quiz | ) |
Set up this class with the structure for a given quiz.
stdClass | $quiz | the quiz settings. |
mod_quiz\structure::refresh_page_numbers | ( | $slots = array() | ) |
Refresh page numbering of quiz slots.
stdClass[] | $slots | (optional) array of slot objects. |
stdClass[] | array of slot objects. |
mod_quiz\structure::refresh_page_numbers_and_update_db | ( | ) |
Refresh page numbering of quiz slots and save to the database.
stdClass | $quiz | the quiz object. |
stdClass[] | array of slot objects. |
mod_quiz\structure::remove_section_heading | ( | $sectionid | ) |
Remove the section heading with the given id.
int | $sectionid | the section to remove. |
mod_quiz\structure::remove_slot | ( | $slotnumber | ) |
Remove a slot from a quiz.
int | $slotnumber | The number of the slot to be deleted. |
coding_exception |
mod_quiz\structure::set_section_heading | ( | $id, | |
$newheading | |||
) |
Change the heading for a section.
int | $id | the id of the section to change. |
string | $newheading | the new heading for this section. |
mod_quiz\structure::set_section_shuffle | ( | $id, | |
$shuffle | |||
) |
Change the shuffle setting for a section.
int | $id | the id of the section to change. |
bool | $shuffle | whether this section should be shuffled. |
mod_quiz\structure::update_page_break | ( | $slotid, | |
$type | |||
) |
Add/Remove a pagebreak.
Saves changes to the slot page relationship in the quiz_slots table and reorders the paging for subsequent slots.
int | $slotid | id of slot. |
int | $type | repaginate::LINK or repaginate::UNLINK. |
stdClass[] | array of slot objects. |
mod_quiz\structure::update_question_dependency | ( | $slotid, | |
$requireprevious | |||
) |
Set whether the question in a particular slot requires the previous one.
int | $slotid | id of slot. |
bool | $requireprevious | if true, set this question to require the previous one. |
mod_quiz\structure::update_slot_maxmark | ( | $slot, | |
$maxmark | |||
) |
Change the max mark for a slot.
Saves changes to the question grades in the quiz_slots table and any corresponding question_attempts. It does not update 'sumgrades' in the quiz table.
stdClass | $slot | row from the quiz_slots table. |
float | $maxmark | the new maxmark. |
bool | true if the new grade is different from the old one. |
|
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.
|
protected |
currently a dummy.
Holds data that will match the quiz_sections, once it exists.
|
protected |
the tags for slots.
Indexed by slot id.