Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Defines the renderer for the quiz module.

Copyright: 2011 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1371 lines (55 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 3 classes


Class: mod_quiz_renderer  - X-Ref

The renderer for the quiz module.

review_page(quiz_attempt $attemptobj, $slots, $page, $showall,$lastpage, mod_quiz_display_options $displayoptions,$summarydata)   X-Ref
Builds the review page

param: quiz_attempt $attemptobj an instance of quiz_attempt.
param: array $slots an array of intgers relating to questions.
param: int $page the current page number
param: bool $showall whether to show entire attempt on one page.
param: bool $lastpage if true the current page is the last page.
param: mod_quiz_display_options $displayoptions instance of mod_quiz_display_options.
param: array $summarydata contains all table data
return: $output containing html data.

review_question_page(quiz_attempt $attemptobj, $slot, $seq,mod_quiz_display_options $displayoptions, $summarydata)   X-Ref
Renders the review question pop-up.

param: quiz_attempt $attemptobj an instance of quiz_attempt.
param: int $slot which question to display.
param: int $seq which step of the question attempt to show. null = latest.
param: mod_quiz_display_options $displayoptions instance of mod_quiz_display_options.
param: array $summarydata contains all table data
return: $output containing html data.

review_question_not_allowed(quiz_attempt $attemptobj, $message)   X-Ref
Renders the review question pop-up.

param: quiz_attempt $attemptobj an instance of quiz_attempt.
param: string $message Why the review is not allowed.
return: string html to output.

filter_review_summary_table($summarydata, $page)   X-Ref
Filters the summarydata array.

param: array $summarydata contains row data for table
param: int $page the current page number
return: $summarydata containing filtered row data

review_summary_table($summarydata, $page)   X-Ref
Outputs the table containing data from summary data array

param: array $summarydata contains row data for table
param: int $page contains the current page number

questions(quiz_attempt $attemptobj, $reviewing, $slots, $page, $showall,mod_quiz_display_options $displayoptions)   X-Ref
Renders each question

param: quiz_attempt $attemptobj instance of quiz_attempt
param: bool $reviewing
param: array $slots array of intgers relating to questions
param: int $page current page number
param: bool $showall if true shows attempt on single page
param: mod_quiz_display_options $displayoptions instance of mod_quiz_display_options

review_form($page, $showall, $displayoptions, $content, $attemptobj)   X-Ref
Renders the main bit of the review page.

param: array $summarydata contain row data for table
param: int $page current page number
param: mod_quiz_display_options $displayoptions instance of mod_quiz_display_options
param: $content contains each question
param: quiz_attempt $attemptobj instance of quiz_attempt
param: bool $showall if true display attempt on one page

finish_review_link(quiz_attempt $attemptobj)   X-Ref
Returns either a liink or button

param: quiz_attempt $attemptobj instance of quiz_attempt

review_next_navigation(quiz_attempt $attemptobj, $page, $lastpage, $showall = null)   X-Ref
Creates the navigation links/buttons at the bottom of the reivew attempt page.

Note, the name of this function is no longer accurate, but when the design
changed, it was decided to keep the old name for backwards compatibility.

param: quiz_attempt $attemptobj instance of quiz_attempt
param: int $page the current page
param: bool $lastpage if true current page is the last page
param: bool|null $showall if true, the URL will be to review the entire attempt on one page,
return: string HTML fragment.

countdown_timer(quiz_attempt $attemptobj, $timenow)   X-Ref
Return the HTML of the quiz timer.

return: string HTML content.

restart_preview_button($url)   X-Ref
Create a preview link

param: moodle_url $url contains a url to the given page

navigation_panel(quiz_nav_panel_base $panel)   X-Ref
Outputs the navigation block panel

param: quiz_nav_panel_base $panel instance of quiz_nav_panel_base

render_quiz_nav_question_button(quiz_nav_question_button $button)   X-Ref
Display a quiz navigation button.

param: quiz_nav_question_button $button
return: string HTML fragment.

render_quiz_nav_section_heading(quiz_nav_section_heading $heading)   X-Ref
Display a quiz navigation heading.

param: quiz_nav_section_heading $heading the heading.
return: string HTML fragment.

render_mod_quiz_links_to_other_attempts(mod_quiz_links_to_other_attempts $links)   X-Ref
outputs the link the other attempts.

param: mod_quiz_links_to_other_attempts $links

start_attempt_page(quiz $quizobj, mod_quiz_preflight_check_form $mform)   X-Ref
No description

attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id,$nextpage)   X-Ref
Attempt Page

param: quiz_attempt $attemptobj Instance of quiz_attempt
param: int $page Current page number
param: quiz_access_manager $accessmanager Instance of quiz_access_manager
param: array $messages An array of messages
param: array $slots Contains an array of integers that relate to questions
param: int $id The ID of an attempt
param: int $nextpage The number of the next page

quiz_notices($messages)   X-Ref
Returns any notices.

param: array $messages

attempt_form($attemptobj, $page, $slots, $id, $nextpage)   X-Ref
Ouputs the form for making an attempt

param: quiz_attempt $attemptobj
param: int $page Current page number
param: array $slots Array of integers relating to questions
param: int $id ID of the attempt
param: int $nextpage Next page number

attempt_navigation_buttons($page, $lastpage, $navmethod = 'free')   X-Ref
Display the prev/next buttons that go at the bottom of each page of the attempt.

param: int $page the page number. Starts at 0 for the first page.
param: bool $lastpage is this the last page in the quiz?
param: string $navmethod Optional quiz attribute, 'free' (default) or 'sequential'
return: string HTML fragment.

redo_question_button($slot, $disabled)   X-Ref
Render a button which allows students to redo a question in the attempt.

param: int $slot the number of the slot to generate the button for.
param: bool $disabled if true, output the button disabled.
return: string HTML fragment.

initialise_timer($timerstartvalue, $ispreview)   X-Ref
Output the JavaScript required to initialise the countdown timer.

param: int $timerstartvalue time remaining, in seconds.

close_attempt_popup($url, $message = '')   X-Ref
Output a page with an optional message, and JavaScript code to close the
current window and redirect the parent window to a new URL.

param: moodle_url $url the URL to redirect the parent window to.
param: string $message message to display before closing the window. (optional)
return: string HTML to output.

access_messages($messages)   X-Ref
Print each message in an array, surrounded by <p>, </p> tags.

param: array $messages the array of message strings.
param: bool $return if true, return a string, instead of outputting.
return: string HTML to output.

summary_page($attemptobj, $displayoptions)   X-Ref
Create the summary page

param: quiz_attempt $attemptobj
param: mod_quiz_display_options $displayoptions

summary_table($attemptobj, $displayoptions)   X-Ref
Generates the table of summarydata

param: quiz_attempt $attemptobj
param: mod_quiz_display_options $displayoptions

summary_page_controls($attemptobj)   X-Ref
Creates any controls a the page should have.

param: quiz_attempt $attemptobj

view_page($course, $quiz, $cm, $context, $viewobj)   X-Ref
Generates the view page

param: int $course The id of the course
param: array $quiz Array conting quiz data
param: int $cm Course Module ID
param: int $context The page context ID
param: array $infomessages information about this quiz
param: mod_quiz_view_object $viewobj
param: string $buttontext text for the start/continue attempt button, if
param: array $infomessages further information about why the student cannot

view_page_buttons(mod_quiz_view_object $viewobj)   X-Ref
Work out, and render, whatever buttons, and surrounding info, should appear
at the end of the review page.

param: mod_quiz_view_object $viewobj the information required to display
return: string HTML to output.

start_attempt_button($buttontext, moodle_url $url,mod_quiz_preflight_check_form $preflightcheckform = null,$popuprequired = false, $popupoptions = null)   X-Ref
Generates the view attempt button

param: string $buttontext the label to display on the button.
param: moodle_url $url The URL to POST to in order to start the attempt.
param: mod_quiz_preflight_check_form $preflightcheckform deprecated.
param: bool $popuprequired whether the attempt needs to be opened in a pop-up.
param: array $popupoptions the options to use if we are opening a popup.
return: string HTML fragment.

no_questions_message($canedit, $editurl)   X-Ref
Generate a message saying that this quiz has no questions, with a button to
go to the edit page, if the user has the right capability.

param: object $quiz the quiz settings.
param: object $cm the course_module object.
param: object $context the quiz context.
return: string HTML to output.

view_page_guest($course, $quiz, $cm, $context, $messages)   X-Ref
Outputs an error message for any guests accessing the quiz

param: int $course The course ID
param: array $quiz Array contingin quiz data
param: int $cm Course Module ID
param: int $context The page contect ID
param: array $messages Array containing any messages

view_page_notenrolled($course, $quiz, $cm, $context, $messages)   X-Ref
Outputs and error message for anyone who is not enrolle don the course

param: int $course The course ID
param: array $quiz Array contingin quiz data
param: int $cm Course Module ID
param: int $context The page contect ID
param: array $messages Array containing any messages

view_information($quiz, $cm, $context, $messages)   X-Ref
Output the page information

param: object $quiz the quiz settings.
param: object $cm the course_module object.
param: object $context the quiz context.
param: array $messages any access messages that should be described.
return: string HTML to output.

quiz_intro($quiz, $cm)   X-Ref
Output the quiz intro.

param: object $quiz the quiz settings.
param: object $cm the course_module object.
return: string HTML to output.

view_table_heading()   X-Ref
Generates the table heading.


view_table($quiz, $context, $viewobj)   X-Ref
Generates the table of data

param: array $quiz Array contining quiz data
param: int $context The page context ID
param: mod_quiz_view_object $viewobj

attempt_state($attemptobj)   X-Ref
Generate a brief textual desciption of the current state of an attempt.

param: quiz_attempt $attemptobj the attempt
param: int $timenow the time to use as 'now'.
return: string the appropriate lang string to describe the state.

view_result_info($quiz, $context, $cm, $viewobj)   X-Ref
Generates data pertaining to quiz results

param: array $quiz Array containing quiz data
param: int $context The page context ID
param: int $cm The Course Module Id
param: mod_quiz_view_object $viewobj

review_link($url, $reviewinpopup, $popupoptions)   X-Ref
Output either a link to the review page for an attempt, or a button to
open the review in a popup window.

param: moodle_url $url of the target page.
param: bool $reviewinpopup whether a pop-up is required.
param: array $popupoptions options to pass to the popup_action constructor.
return: string HTML to output.

no_review_message($message)   X-Ref
Displayed where there might normally be a review link, to explain why the
review is not available at this time.

param: string $message optional message explaining why the review is not possible.
return: string HTML to output.

quiz_attempt_summary_link_to_reports($quiz, $cm, $context,$returnzero = false, $currentgroup = 0)   X-Ref
Returns the same as {@link quiz_num_attempt_summary()} but wrapped in a link
to the quiz reports.

param: object $quiz the quiz object. Only $quiz->id is used at the moment.
param: object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid
param: object $context the quiz context.
param: bool $returnzero if false (default), when no attempts have been made '' is returned
param: int $currentgroup if there is a concept of current group where this method is being
return: string HTML fragment for the link.

chart(\core\chart_base $chart, $title, $attrs = [])   X-Ref
Outputs a chart.

param: \core\chart_base $chart The chart.
param: string $title The title to display above the graph.
param: array $attrs extra container html attributes.
return: string HTML fragment for the graph.

graph(moodle_url $url, $title)   X-Ref
Output a graph, or a message saying that GD is required.

param: moodle_url $url the URL of the graph.
param: string $title the title to display above the graph.
return: string HTML fragment for the graph.

connection_warning()   X-Ref
Output the connection warning messages, which are initially hidden, and
only revealed by JavaScript if necessary.


Class: mod_quiz_view_object  - X-Ref


__get($field)   X-Ref
No description