Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
qtype_multichoice_renderer_base Class Reference

Base class for generating the bits of output common to multiple choice single and multiple questions. More...

Inheritance diagram for qtype_multichoice_renderer_base:
qtype_with_combined_feedback_renderer qtype_renderer plugin_renderer_base renderer_base qtype_multichoice_multi_renderer qtype_multichoice_single_renderer

Public Member Functions

 __call ($method, $arguments)
 Magic method used to pass calls otherwise meant for the standard renderer to it to ensure we don't go causing unnecessary grief.
 
 add_action_handler (component_action $action, $id=null)
 Adds a JS action for the element with the provided id.
 
 clear_wrong (question_attempt $qa)
 Output hidden form fields to clear any wrong parts of the student's response.
 
 feedback (question_attempt $qa, question_display_options $options)
 Generate the display of the outcome part of the question.
 
 formulation_and_controls (question_attempt $qa, question_display_options $options)
 Generate the display of the formulation part of the question.
 
 formulation_heading ()
 In the question output there are some class="accesshide" headers to help screen-readers.
 
 get_compact_logo_url ($maxwidth=300, $maxheight=300)
 Return the site's compact logo URL, if any.
 
 get_logo_url ($maxwidth=null, $maxheight=200)
 Return the site's logo URL, if any.
 
 has_started ()
 Returns true is output has already started, and false if not.
 
 head_code (question_attempt $qa)
 Return any HTML that needs to be included in the page's <head> when this question is used.
 
 image_url ($imagename, $component='moodle')
 Return the moodle_url for an image.
 
 manual_comment (question_attempt $qa, question_display_options $options)
 Display any extra question-type specific content that should be visible when grading, if appropriate.
 
 pix_url ($imagename, $component='moodle')
 Return the direct URL for an image from the pix folder.
 
 render (renderable $widget)
 Renders the provided widget and returns the HTML to display it.
 
 render_from_template ($templatename, $context)
 Renders a template by name with the given context.
 
 should_display_main_logo ($headinglevel=1)
 Whether we should display the main logo.
 
 should_display_navbar_logo ()
 Whether we should display the logo in the navbar.
 
 specific_feedback (question_attempt $qa)
 Generate the specific feedback.
 

Static Public Member Functions

static prepare_classes ($classes)
 Given an array or space-separated list of classes, prepares and returns the HTML class attribute value.
 

Protected Member Functions

 after_choices (question_attempt $qa, question_display_options $options)
 Method to generating the bits of output after question choices.
 
 combined_feedback (question_attempt $qa)
 
 correct_choices (array $right)
 Function returns string based on number of correct answers.
 
 correct_response (question_attempt $qa)
 Gereate an automatic description of the correct response to this question.
 
 feedback_class ($fraction)
 
 feedback_image ($fraction, $selected=true)
 Return an appropriate icon (green tick, red cross, etc.) for a grade.
 
 general_feedback (question_attempt $qa)
 Gereate the general feedback.
 
 get_input_id (question_attempt $qa, $value)
 
 get_input_name (question_attempt $qa, $value)
 
 get_input_type ()
 
 get_input_value ($value)
 
 get_mustache ()
 Return an instance of the mustache class.
 
 hint (question_attempt $qa, question_hint $hint)
 Gereate the specific feedback.
 
 is_right (question_answer $ans)
 Whether a choice should be considered right, wrong or partially right.
 
 num_parts_correct (question_attempt $qa)
 Gereate a brief statement of how many sub-parts of this question the student got right.
 
 number_html ($qnum)
 
 number_in_style ($num, $style)
 
 prompt ()
 

Protected Attributes

xhtml_container_stack $opencontainers
 The xhtml_container_stack to use.
 
renderer_base core_renderer $output
 A reference to the current renderer.
 
moodle_page $page
 The Moodle page the renderer has been created to assist with.
 
string $target
 The requested rendering target.
 
array $templatecache = []
 $templatecache The mustache template cache.
 

Detailed Description

Base class for generating the bits of output common to multiple choice single and multiple questions.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ __call()

plugin_renderer_base::__call ( $method,
$arguments )
inherited

Magic method used to pass calls otherwise meant for the standard renderer to it to ensure we don't go causing unnecessary grief.

Parameters
string$method
array$arguments
Return values
mixed

◆ add_action_handler()

renderer_base::add_action_handler ( component_action $action,
$id = null )
inherited

Adds a JS action for the element with the provided id.

This method adds a JS event for the provided component action to the page and then returns the id that the event has been attached to. If no id has been provided then a new ID is generated by html_writer::random_id()

Parameters
component_action$action
string$id
Return values
stringid of element, either original submitted or random new if not supplied

◆ after_choices()

qtype_multichoice_renderer_base::after_choices ( question_attempt $qa,
question_display_options $options )
abstractprotected

Method to generating the bits of output after question choices.

Parameters
question_attempt$qaThe question attempt object.
question_display_options$optionscontrols what should and should not be displayed.
Return values
stringHTML output.

Reimplemented in qtype_multichoice_multi_renderer, and qtype_multichoice_single_renderer.

◆ clear_wrong()

qtype_renderer::clear_wrong ( question_attempt $qa)
inherited

Output hidden form fields to clear any wrong parts of the student's response.

This method will only be called if the question is in read-only mode.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

Reimplemented in qtype_ddtoimage_renderer_base.

◆ correct_choices()

qtype_multichoice_renderer_base::correct_choices ( array $right)
protected

Function returns string based on number of correct answers.

Parameters
array$rightAn Array of correct responses to the current question
Return values
stringbased on number of correct responses

◆ correct_response()

qtype_renderer::correct_response ( question_attempt $qa)
protectedinherited

Gereate an automatic description of the correct response to this question.

Not all question types can do this. If it is not possible, this method should just return an empty string.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

Reimplemented in qtype_calculated_renderer, qtype_ddtoimage_renderer_base, qtype_elements_embedded_in_question_text_renderer, qtype_match_renderer, qtype_multianswer_renderer, qtype_multichoice_multi_renderer, qtype_multichoice_single_renderer, qtype_numerical_renderer, qtype_shortanswer_renderer, and qtype_truefalse_renderer.

◆ feedback()

qtype_renderer::feedback ( question_attempt $qa,
question_display_options $options )
inherited

Generate the display of the outcome part of the question.

This is the area that contains the various forms of feedback. This function generates the content of this area belonging to the question type.

Subclasses will normally want to override the more specific methods {specific_feedback()}, {general_feedback()} and {correct_response()} that this method calls.

Parameters
question_attempt$qathe question attempt to display.
question_display_options$optionscontrols what should and should not be displayed.
Return values
stringHTML fragment.

◆ feedback_image()

qtype_renderer::feedback_image ( $fraction,
$selected = true )
protectedinherited

Return an appropriate icon (green tick, red cross, etc.) for a grade.

Parameters
float$fractiongrade on a scale 0..1.
bool$selectedwhether to show a big or small icon. (Deprecated)
Return values
stringhtml fragment.

◆ formulation_and_controls()

qtype_multichoice_renderer_base::formulation_and_controls ( question_attempt $qa,
question_display_options $options )

Generate the display of the formulation part of the question.

This is the area that contains the quetsion text, and the controls for students to input their answers. Some question types also embed bits of feedback, for example ticks and crosses, in this area.

Parameters
question_attempt$qathe question attempt to display.
question_display_options$optionscontrols what should and should not be displayed.
Return values
stringHTML fragment.

Reimplemented from qtype_renderer.

◆ formulation_heading()

qtype_renderer::formulation_heading ( )
inherited

In the question output there are some class="accesshide" headers to help screen-readers.

This method returns the text to use for the heading above the formulation_and_controls section.

Return values
stringto use as the heading.

Reimplemented in qtype_description_renderer.

◆ general_feedback()

qtype_renderer::general_feedback ( question_attempt $qa)
protectedinherited

Gereate the general feedback.

This is feedback is shown ot all students.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

◆ get_compact_logo_url()

renderer_base::get_compact_logo_url ( $maxwidth = 300,
$maxheight = 300 )
inherited

Return the site's compact logo URL, if any.

Parameters
int$maxwidthThe maximum width, or null when the maximum width does not matter.
int$maxheightThe maximum height, or null when the maximum height does not matter.
Return values
moodle_url|false

◆ get_logo_url()

renderer_base::get_logo_url ( $maxwidth = null,
$maxheight = 200 )
inherited

Return the site's logo URL, if any.

Parameters
int$maxwidthThe maximum width, or null when the maximum width does not matter.
int$maxheightThe maximum height, or null when the maximum height does not matter.
Return values
moodle_url|false

◆ get_mustache()

renderer_base::get_mustache ( )
protectedinherited

Return an instance of the mustache class.

Since
2.9
Return values
Mustache_Engine

◆ has_started()

renderer_base::has_started ( )
inherited

Returns true is output has already started, and false if not.

Return values
booleantrue if the header has been printed.

◆ head_code()

qtype_renderer::head_code ( question_attempt $qa)
inherited

Return any HTML that needs to be included in the page's <head> when this question is used.

Parameters
$qathe question attempt that will be displayed on the page.
Return values
stringHTML fragment.

◆ hint()

qtype_renderer::hint ( question_attempt $qa,
question_hint $hint )
protectedinherited

Gereate the specific feedback.

This is feedback that varies according to the response the student gave.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

Reimplemented in qtype_ddmarker_renderer.

◆ image_url()

renderer_base::image_url ( $imagename,
$component = 'moodle' )
inherited

Return the moodle_url for an image.

The exact image location and extension is determined automatically by searching for gif|png|jpg|jpeg, please note there can not be diferent images with the different extension. The imagename is for historical reasons a relative path name, it may be changed later for core images. It is recommended to not use subdirectories in plugin and theme pix directories.

There are three types of images: 1/ theme images - stored in theme/mytheme/pix/, use component 'theme' 2/ core images - stored in /pix/, overridden via theme/mytheme/pix_core/ 3/ plugin images - stored in mod/mymodule/pix, overridden via theme/mytheme/pix_plugins/mod/mymodule/, example: image_url('comment', 'mod_glossary')

Parameters
string$imagenamethe pathname of the image
string$componentfull plugin name (aka component) or 'theme'
Return values
moodle_url

◆ is_right()

qtype_multichoice_renderer_base::is_right ( question_answer $ans)
abstractprotected

Whether a choice should be considered right, wrong or partially right.

Parameters
question_answer$ansrepresenting one of the choices.
Return values
float1.0, 0.0 or something in between, respectively.

Reimplemented in qtype_multichoice_multi_renderer, and qtype_multichoice_single_renderer.

◆ manual_comment()

qtype_renderer::manual_comment ( question_attempt $qa,
question_display_options $options )
inherited

Display any extra question-type specific content that should be visible when grading, if appropriate.

Parameters
question_attempt$qaa question attempt.
question_display_options$optionscontrols what should and should not be displayed.
Return values
stringHTML fragment.

Reimplemented in qtype_essay_renderer.

◆ num_parts_correct()

qtype_renderer::num_parts_correct ( question_attempt $qa)
protectedinherited

Gereate a brief statement of how many sub-parts of this question the student got right.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

Reimplemented in qtype_multichoice_multi_renderer.

◆ number_in_style()

qtype_multichoice_renderer_base::number_in_style ( $num,
$style )
protected
Parameters
int$numThe number, starting at 0.
string$styleThe style to render the number in. One of the options returned by qtype_multichoice:;get_numbering_styles().
Return values
stringthe number $num in the requested style.

◆ pix_url()

renderer_base::pix_url ( $imagename,
$component = 'moodle' )
inherited

Return the direct URL for an image from the pix folder.

Use this function sparingly and never for icons. For icons use pix_icon or the pix helper in a mustache template.

Deprecated
since Moodle 3.3
Parameters
string$imagenamethe name of the icon.
string$componentspecification of one plugin like in get_string()
Return values
moodle_url

◆ prepare_classes()

static renderer_base::prepare_classes ( $classes)
staticinherited

Given an array or space-separated list of classes, prepares and returns the HTML class attribute value.

Parameters
mixed$classesSpace-separated string or array of classes
Return values
stringHTML class attribute value

◆ render()

plugin_renderer_base::render ( renderable $widget)
inherited

Renders the provided widget and returns the HTML to display it.

Parameters
renderable$widgetinstance with renderable interface
Return values
string

Reimplemented from renderer_base.

Reimplemented in core_courseformat\output\section_renderer, and tool_policy\output\renderer.

◆ render_from_template()

renderer_base::render_from_template ( $templatename,
$context )
inherited

Renders a template by name with the given context.

The provided data needs to be array/stdClass made up of only simple types. Simple types are array,stdClass,bool,int,float,string

Since
2.9
Parameters
array | stdClass$contextContext containing data for the template.
Return values
string|boolean

◆ should_display_main_logo()

renderer_base::should_display_main_logo ( $headinglevel = 1)
inherited

Whether we should display the main logo.

Deprecated
since Moodle 4.0
Todo
final deprecation. To be removed in Moodle 4.4 MDL-73165.
Parameters
int$headinglevelThe heading level we want to check against.
Return values
bool

◆ should_display_navbar_logo()

renderer_base::should_display_navbar_logo ( )
inherited

Whether we should display the logo in the navbar.

We will when there are no main logos, and we have compact logo.

Return values
bool

◆ specific_feedback()

qtype_multichoice_renderer_base::specific_feedback ( question_attempt $qa)

Generate the specific feedback.

This is feedback that varies according to the response the student gave.

Parameters
question_attempt$qathe question attempt to display.
Return values
stringHTML fragment.

Reimplemented from qtype_renderer.

Member Data Documentation

◆ $output

renderer_base core_renderer plugin_renderer_base::$output
protectedinherited

A reference to the current renderer.

The renderer provided here will be determined by the page but will in 90% of cases by the core_renderer


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