[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Source view] [Print] [Project Stats]
Back-end code for handling data about quizzes and the current user's attempt. There are classes for loading all the information about a quiz and attempts, and for displaying the navigation panel.
Copyright: | 2008 onwards Tim Hunt |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 1862 lines (68 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
moodle_quiz_exception:: (1 method):
__construct()
quiz:: (33 methods):
__construct()
create()
create_attempt_object()
preload_questions()
load_questions()
get_structure()
get_courseid()
get_course()
get_quizid()
get_quiz()
get_quiz_name()
get_navigation_method()
get_num_attempts_allowed()
get_cmid()
get_cm()
get_context()
is_preview_user()
has_questions()
get_question()
get_questions()
get_access_manager()
has_capability()
require_capability()
view_url()
edit_url()
attempt_url()
start_attempt_url()
review_url()
summary_url()
confirm_start_attempt_message()
cannot_review_message()
navigation()
ensure_question_loaded()
quiz_attempt:: (87 methods):
__construct()
create_helper()
create()
create_from_usage_id()
state_name()
determine_layout()
number_questions()
force_page_number_into_range()
get_quiz()
get_quizobj()
get_courseid()
get_course()
get_quizid()
get_quiz_name()
get_navigation_method()
get_cm()
get_cmid()
is_preview_user()
get_num_attempts_allowed()
get_num_pages()
get_access_manager()
get_attemptid()
get_uniqueid()
get_attempt()
get_attempt_number()
get_state()
get_userid()
get_currentpage()
get_sum_marks()
is_finished()
is_preview()
is_own_attempt()
is_own_preview()
is_review_allowed()
has_response_to_at_least_one_graded_question()
get_additional_summary_data()
get_overall_feedback()
has_capability()
require_capability()
check_review_capability()
can_navigate_to()
get_attempt_state()
get_display_options()
get_display_options_with_edit_link()
is_last_page()
get_slots()
get_question_attempt()
is_real_question()
is_question_flagged()
get_question_number()
get_question_page()
get_question_name()
get_question_status()
get_question_state_class()
get_question_mark()
get_question_action_time()
get_time_left_display()
get_submitted_date()
get_due_date()
view_url()
start_attempt_url()
attempt_url()
summary_url()
processattempt_url()
review_url()
get_default_show_all()
cannot_review_message()
get_html_head_contributions()
get_question_html_head_contributions()
restart_preview_button()
render_question()
render_question_at_step()
render_question_for_commenting()
check_file_access()
get_navigation_panel()
links_to_other_attempts()
handle_if_time_expired()
process_submitted_actions()
process_auto_save()
save_question_flags()
process_finish()
update_timecheckstate()
process_going_overdue()
process_abandon()
fire_state_transition_event()
question_print_comment_fields()
page_and_question_url()
quiz_nav_question_button:: (7 methods):
__construct()
get_question_buttons()
get_state_string()
render_before_button_bits()
render_restart_preview_link()
user_picture()
get_button_container_class()
quiz_attempt_nav_panel:: (3 methods):
get_question_url()
render_before_button_bits()
render_end_bits()
quiz_review_nav_panel:: (2 methods):
get_question_url()
render_end_bits()
Class: moodle_quiz_exception - X-Ref
Class for quiz exceptions. Just saves a couple of arguments on the__construct($quizobj, $errorcode, $a = null, $link = '', $debuginfo = null) X-Ref |
No description |
__construct($quiz, $cm, $course, $getcontext = true) X-Ref |
Constructor, assuming we already have the necessary data loaded. param: object $quiz the row from the quiz table. param: object $cm the course_module object for this quiz. param: object $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($quizid, $userid = null) X-Ref |
Static function to create a new quiz object for a specific user. param: int $quizid the the quiz id. param: int $userid the the userid. return: quiz the new quiz object |
create_attempt_object($attemptdata) X-Ref |
Create a {@link quiz_attempt} for an attempt at this quiz. param: object $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($questionids = null) X-Ref |
Fully load some or all of the questions for this quiz. You must call {@link preload_questions()} first. param: array $questionids question ids of the questions to load. null for all. |
get_structure() X-Ref |
Get an instance of the {@link \mod_quiz\structure} class for this quiz. return: \mod_quiz\structure describes the questions in the quiz. |
get_courseid() X-Ref |
No description |
get_course() X-Ref |
No description |
get_quizid() X-Ref |
No description |
get_quiz() X-Ref |
No description |
get_quiz_name() X-Ref |
No description |
get_navigation_method() X-Ref |
No description |
get_num_attempts_allowed() X-Ref |
No description |
get_cmid() X-Ref |
No description |
get_cm() X-Ref |
No description |
get_context() X-Ref |
No description |
is_preview_user() X-Ref |
return: bool wether the current user is someone who previews the quiz, |
has_questions() X-Ref |
return: whether any questions have been added to this quiz. |
get_question($id) X-Ref |
param: int $id the question id. return: object the question object with that id. |
get_questions($questionids = null) X-Ref |
param: array $questionids question ids of the questions to load. null for all. |
get_access_manager($timenow) X-Ref |
param: int $timenow the current time as a unix timestamp. return: quiz_access_manager and instance of the quiz_access_manager class |
has_capability($capability, $userid = null, $doanything = true) X-Ref |
Wrapper round the has_capability funciton that automatically passes in the quiz context. |
require_capability($capability, $userid = null, $doanything = true) X-Ref |
Wrapper round the require_capability funciton that automatically passes in the quiz context. |
view_url() X-Ref |
return: string the URL of this quiz's view page. |
edit_url() X-Ref |
return: string the URL of this quiz's edit page. |
attempt_url($attemptid, $page = 0) X-Ref |
param: int $attemptid the id of an attempt. param: int $page optional page number to go to in the attempt. return: string the URL of that attempt. |
start_attempt_url($page = 0) X-Ref |
return: string the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter. |
review_url($attemptid) X-Ref |
param: int $attemptid the id of an attempt. return: string the URL of the review of that attempt. |
summary_url($attemptid) X-Ref |
param: int $attemptid the id of an attempt. return: string the URL of the review of that attempt. |
confirm_start_attempt_message($unfinished) X-Ref |
param: bool $unfinished whether there is currently an unfinished attempt active. return: string if the quiz policies merit it, return a warning string to |
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 mod_quiz_display_options::DURING, param: bool $short if true, return a shorter string. return: string an appropraite message. |
navigation($title) X-Ref |
param: string $title the name of this particular quiz page. return: array the data that needs to be sent to print_header_simple as the $navigation |
ensure_question_loaded($id) X-Ref |
Check that the definition of a particular question is loaded, and if not throw an exception. param: $id a questionid. |
Class: quiz_attempt - X-Ref
This class extends the quiz class to hold data about the state of a particular attempt,__construct($attempt, $quiz, $cm, $course, $loadquestions = true) X-Ref |
Constructor assuming we already have the necessary data loaded. param: object $attempt the row of the quiz_attempts table. param: object $quiz the quiz object for this attempt and user. param: object $cm the course_module object for this quiz. param: object $course the row from the course table for the course we belong to. param: bool $loadquestions (optional) if true, the default, load all the details |
create_helper($conditions) X-Ref |
Used by {create()} and {create_from_usage_id()}. param: array $conditions passed to $DB->get_record('quiz_attempts', $conditions). |
create($attemptid) X-Ref |
Static function to create a new quiz_attempt object given an attemptid. param: int $attemptid the attempt id. return: quiz_attempt the new quiz_attempt object |
create_from_usage_id($usageid) X-Ref |
Static function to create a new quiz_attempt object given a usage id. param: int $usageid the attempt usage id. return: quiz_attempt the new quiz_attempt object |
state_name($state) X-Ref |
param: string $state one of the state constants like IN_PROGRESS. return: string the human-readable state name. |
determine_layout() X-Ref |
Parse attempt->layout to populate the other arrays the represent the layout. |
number_questions() X-Ref |
Work out the number to display for each question/slot. |
force_page_number_into_range($page) X-Ref |
If the given page number is out of range (before the first page, or after the last page, chnage it to be within range). param: int $page the requested page number. return: int a safe page number to use. |
get_quiz() X-Ref |
No description |
get_quizobj() X-Ref |
No description |
get_courseid() X-Ref |
No description |
get_course() X-Ref |
No description |
get_quizid() X-Ref |
No description |
get_quiz_name() X-Ref |
No description |
get_navigation_method() X-Ref |
No description |
get_cm() X-Ref |
No description |
get_cmid() X-Ref |
No description |
is_preview_user() X-Ref |
return: bool wether the current user is someone who previews the quiz, |
get_num_attempts_allowed() X-Ref |
No description |
get_num_pages() X-Ref |
No description |
get_access_manager($timenow) X-Ref |
param: int $timenow the current time as a unix timestamp. return: quiz_access_manager and instance of the quiz_access_manager class |
get_attemptid() X-Ref |
No description |
get_uniqueid() X-Ref |
No description |
get_attempt() X-Ref |
No description |
get_attempt_number() X-Ref |
No description |
get_state() X-Ref |
No description |
get_userid() X-Ref |
No description |
get_currentpage() X-Ref |
No description |
get_sum_marks() X-Ref |
No description |
is_finished() X-Ref |
return: bool whether this attempt has been finished (true) or is still |
is_preview() X-Ref |
No description |
is_own_attempt() X-Ref |
Is this a student dealing with their own attempt/teacher previewing, or someone with 'mod/quiz:viewreports' reviewing someone elses attempt. return: bool whether this situation should be treated as someone looking at their own |
is_own_preview() X-Ref |
return: bool whether this attempt is a preview belonging to the current user. |
is_review_allowed() X-Ref |
Is the current user allowed to review this attempt. This applies when {@link is_own_attempt()} returns false. return: bool whether the review should be allowed. |
has_response_to_at_least_one_graded_question() X-Ref |
Has the student, in this attempt, engaged with the quiz in a non-trivial way? That is, is there any question worth a non-zero number of marks, where the student has made some response that we have saved? return: bool true if we have saved a response for at least one graded question. |
get_additional_summary_data(question_display_options $options) X-Ref |
Get extra summary information about this attempt. Some behaviours may be able to provide interesting summary information about the attempt as a whole, and this method provides access to that data. To see how this works, try setting a quiz to one of the CBM behaviours, and then look at the extra information displayed at the top of the quiz review page once you have sumitted an attempt. In the return value, the array keys are identifiers of the form qbehaviour_behaviourname_meaningfullkey. For qbehaviour_deferredcbm_highsummary. The values are arrays with two items, title and content. Each of these will be either a string, or a renderable. param: question_display_options $options the display options for this quiz attempt at this time. return: array as described above. |
get_overall_feedback($grade) X-Ref |
Get the overall feedback corresponding to a particular mark. param: $grade a particular grade. |
has_capability($capability, $userid = null, $doanything = true) X-Ref |
Wrapper round the has_capability funciton that automatically passes in the quiz context. |
require_capability($capability, $userid = null, $doanything = true) X-Ref |
Wrapper round the require_capability funciton that automatically passes in the quiz context. |
check_review_capability() X-Ref |
Check the appropriate capability to see whether this user may review their own attempt. If not, prints an error. |
can_navigate_to($slot) X-Ref |
Checks whether a user may navigate to a particular slot |
get_attempt_state() X-Ref |
return: int one of the mod_quiz_display_options::DURING, |
get_display_options($reviewing) X-Ref |
Wrapper that the correct mod_quiz_display_options for this quiz at the moment. return: question_display_options the render options for this user on this attempt. |
get_display_options_with_edit_link($reviewing, $slot, $thispageurl) X-Ref |
Wrapper that the correct mod_quiz_display_options for this quiz at the moment. param: bool $reviewing true for review page, else attempt page. param: int $slot which question is being displayed. param: moodle_url $thispageurl to return to after the editing form is return: question_display_options the render options for this user on this |
is_last_page($page) X-Ref |
param: int $page page number return: bool true if this is the last page of the quiz. |
get_slots($page = 'all') X-Ref |
Return the list of question ids for either a given page of the quiz, or for the whole quiz. param: mixed $page string 'all' or integer page number. return: array the reqested list of question ids. |
get_question_attempt($slot) X-Ref |
Get the question_attempt object for a particular question in this attempt. param: int $slot the number used to identify this question within this attempt. return: question_attempt |
is_real_question($slot) X-Ref |
Is a particular question in this attempt a real question, or something like a description. param: int $slot the number used to identify this question within this attempt. return: int whether that question is a real question. Actually returns the |
is_question_flagged($slot) X-Ref |
Is a particular question in this attempt a real question, or something like a description. param: int $slot the number used to identify this question within this attempt. return: bool whether that question is a real question. |
get_question_number($slot) X-Ref |
param: int $slot the number used to identify this question within this attempt. return: string the displayed question number for the question in this slot. |
get_question_page($slot) X-Ref |
param: int $slot the number used to identify this question within this attempt. return: int the page of the quiz this question appears on. |
get_question_name($slot) X-Ref |
Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question. param: int $slot the number used to identify this question within this attempt. return: string the formatted grade, to the number of decimal places specified |
get_question_status($slot, $showcorrectness) X-Ref |
Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question. param: int $slot the number used to identify this question within this attempt. param: bool $showcorrectness Whether right/partial/wrong states should return: string the formatted grade, to the number of decimal places specified |
get_question_state_class($slot, $showcorrectness) X-Ref |
Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question. param: int $slot the number used to identify this question within this attempt. param: bool $showcorrectness Whether right/partial/wrong states should return: string class name for this state. |
get_question_mark($slot) X-Ref |
Return the grade obtained on a particular question. You must previously have called load_question_states to load the state data about this question. param: int $slot the number used to identify this question within this attempt. return: string the formatted grade, to the number of decimal places specified by the quiz. |
get_question_action_time($slot) X-Ref |
Get the time of the most recent action performed on a question. param: int $slot the number used to identify this question within this usage. return: int timestamp. |
get_time_left_display($timenow) X-Ref |
Get the time remaining for an in-progress attempt, if the time is short enought that it would be worth showing a timer. param: int $timenow the time to consider as 'now'. return: int|false the number of seconds remaining for this attempt. |
get_submitted_date() X-Ref |
return: int the time when this attempt was submitted. 0 if it has not been |
get_due_date() X-Ref |
If the attempt is in an applicable state, work out the time by which the student should next do something. return: int timestamp by which the student needs to do something. |
view_url() X-Ref |
return: string quiz view url. |
start_attempt_url($slot = null, $page = -1) X-Ref |
return: string the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter. |
attempt_url($slot = null, $page = -1, $thispage = -1) X-Ref |
param: int $slot if speified, the slot number of a specific question to link to. param: int $page if specified, a particular page to link to. If not givem deduced param: int $questionid a question id. If set, will add a fragment to the URL param: int $thispage if not -1, the current page. Will cause links to other things on return: string the URL to continue this attempt. |
summary_url() X-Ref |
return: string the URL of this quiz's summary page. |
processattempt_url() X-Ref |
return: string the URL of this quiz's summary page. |
review_url($slot = null, $page = -1, $showall = null, $thispage = -1) X-Ref |
param: int $slot indicates which question to link to. param: int $page if specified, the URL of this particular page of the attempt, otherwise param: bool|null $showall if true, the URL will be to review the entire attempt on one page, param: int $thispage if not -1, the current page. Will cause links to other things on return: string the URL to review this attempt. |
get_default_show_all($script) X-Ref |
By default, should this script show all questions on one page for this attempt? param: string $script the script name, e.g. 'attempt', 'summary', 'review'. return: whether show all on one page should be on by default. |
cannot_review_message($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: bool $short if true, return a shorter string. return: string an appropraite message. |
get_html_head_contributions($page = 'all', $showall = false) X-Ref |
Initialise the JS etc. required all the questions on a page. param: mixed $page a page number, or 'all'. |
get_question_html_head_contributions($slot) X-Ref |
Initialise the JS etc. required by one question. param: int $questionid the question id. |
restart_preview_button() X-Ref |
Print the HTML for the start new preview button, if the current user is allowed to see one. |
render_question($slot, $reviewing, $thispageurl = null) X-Ref |
Generate the HTML that displayes the question in its current state, with the appropriate display options. param: int $id the id of a question in this quiz attempt. param: bool $reviewing is the being printed on an attempt or a review page. param: moodle_url $thispageurl the URL of the page this question is being printed on. return: string HTML for the question in its current state. |
render_question_at_step($slot, $seq, $reviewing, $thispageurl = '') X-Ref |
Like {@link render_question()} but displays the question at the past step indicated by $seq, rather than showing the latest step. param: int $id the id of a question in this quiz attempt. param: int $seq the seq number of the past state to display. param: bool $reviewing is the being printed on an attempt or a review page. param: string $thispageurl the URL of the page this question is being printed on. return: string HTML for the question in its current state. |
render_question_for_commenting($slot) X-Ref |
Wrapper round print_question from lib/questionlib.php. param: int $id the id of a question in this quiz attempt. |
check_file_access($slot, $reviewing, $contextid, $component,$filearea, $args, $forcedownload) X-Ref |
Check wheter access should be allowed to a particular file. param: int $id the id of a question in this quiz attempt. param: bool $reviewing is the being printed on an attempt or a review page. param: string $thispageurl the URL of the page this question is being printed on. return: string HTML for the question in its current state. |
get_navigation_panel(mod_quiz_renderer $output,$panelclass, $page, $showall = false) X-Ref |
Get the navigation panel object for this attempt. param: $panelclass The type of panel, quiz_attempt_nav_panel or quiz_review_nav_panel param: $page the current page number. param: $showall whether we are showing the whole quiz on one page. (Used by review.php) return: quiz_nav_panel_base the requested object. |
links_to_other_attempts(moodle_url $url) X-Ref |
Given a URL containing attempt={this attempt id}, return an array of variant URLs param: moodle_url $url a URL. return: string HTML fragment. Comma-separated list of links to the other |
handle_if_time_expired($timestamp, $studentisonline) X-Ref |
Check this attempt, to see if there are any state transitions that should happen automatically. This function will update the attempt checkstatetime. param: int $timestamp the timestamp that should be stored as the modifed param: bool $studentisonline is the student currently interacting with Moodle? |
process_submitted_actions($timestamp, $becomingoverdue = false, $simulatedresponses = null) X-Ref |
Process all the actions that were submitted as part of the current request. param: int $timestamp the timestamp that should be stored as the modifed param: bool $becomingoverdue param: array|null $simulatedresponses If not null, then we are testing, and this is an array of simulated data, keys are slot |
process_auto_save($timestamp) X-Ref |
Process all the autosaved data that was part of the current request. param: int $timestamp the timestamp that should be stored as the modifed |
save_question_flags() X-Ref |
Update the flagged state for all question_attempts in this usage, if their flagged state was changed in the request. |
process_finish($timestamp, $processsubmitted) X-Ref |
No description |
update_timecheckstate($time) X-Ref |
Update this attempt timecheckstate if necessary. param: int|null the timecheckstate |
process_going_overdue($timestamp, $studentisonline) X-Ref |
Mark this attempt as now overdue. param: int $timestamp the time to deem as now. param: bool $studentisonline is the student currently interacting with Moodle? |
process_abandon($timestamp, $studentisonline) X-Ref |
Mark this attempt as abandoned. param: int $timestamp the time to deem as now. param: bool $studentisonline is the student currently interacting with Moodle? |
fire_state_transition_event($eventclass, $timestamp) X-Ref |
Fire a state transition event. the same event information. param: string $eventclass the event class name. param: int $timestamp the timestamp to include in the event. return: void |
question_print_comment_fields($slot, $prefix) X-Ref |
Print the fields of the comment form for questions in this attempt. param: $slot which question to output the fields for. param: $prefix Prefix to add to all field names. |
page_and_question_url($script, $slot, $page, $showall, $thispage) X-Ref |
Get a URL for a particular question on a particular page of the quiz. Used by {@link attempt_url()} and {@link review_url()}. param: string $script. Used in the URL like /mod/quiz/$script.php param: int $slot identifies the specific question on the page to jump to. param: int $page -1 to look up the page number from the slot, otherwise param: bool|null $showall if true, return a URL with showall=1, and not page number. param: int $thispage the page we are currently on. Links to questions on this return: The requested URL. |
Class: quiz_nav_question_button - X-Ref
Represents a single link in the navigation panel.__construct(quiz_attempt $attemptobj,question_display_options $options, $page, $showall) X-Ref |
No description |
get_question_buttons() X-Ref |
No description |
get_state_string(question_attempt $qa, $showcorrectness) X-Ref |
No description |
render_before_button_bits(mod_quiz_renderer $output) X-Ref |
No description |
render_restart_preview_link($output) X-Ref |
No description |
user_picture() X-Ref |
No description |
get_button_container_class() X-Ref |
Return 'allquestionsononepage' as CSS class name when $showall is set, otherwise, return 'multipages' as CSS class name. return: string, CSS class name |
Class: quiz_attempt_nav_panel - X-Ref
Specialisation of {@link quiz_nav_panel_base} for the attempt quiz page.get_question_url($slot) X-Ref |
No description |
render_before_button_bits(mod_quiz_renderer $output) X-Ref |
No description |
render_end_bits(mod_quiz_renderer $output) X-Ref |
No description |
Class: quiz_review_nav_panel - X-Ref
Specialisation of {@link quiz_nav_panel_base} for the review quiz page.get_question_url($slot) X-Ref |
No description |
render_end_bits(mod_quiz_renderer $output) X-Ref |
No description |
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |