Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
qtype_ordering_question Class Reference
Inheritance diagram for qtype_ordering_question:
question_graded_automatically question_with_responses question_automatically_gradable question_definition question_manually_gradable question_manually_gradable

Public Member Functions

 __get ($name)
 When a pending definition tries to read its latest version, fill in the latest version for all pending definitions.
 
 apply_attempt_state (question_attempt_step $step)
 When an in-progress question_attempt is re-loaded from the database, this method is called so that the question can re-initialise its internal state as needed by this attempt.
 
 check_file_access ($qa, $options, $component, $filearea, $args, $forcedownload)
 Checks whether the users is allow to be served a particular file.
 
 classify_response (array $response)
 Categorise the student's response according to the categories defined by get_possible_responses.
 
 clear_wrong_from_response (array $response)
 Given a response, rest the parts that are wrong.
 
 format_generalfeedback ($qa)
 
 format_hint (question_hint $hint, question_attempt $qa)
 
 format_questiontext ($qa)
 
 format_text ($text, $format, $qa, $component, $filearea, $itemid, $clean=false)
 Apply format_text() to some content with appropriate settings for this question.
 
 get_correct_response ()
 What data would need to be submitted to get this question correct.
 
 get_expected_data ()
 What data may be included in the form submission when a student submits this question in its current state?
 
 get_hint ($hintnumber, question_attempt $qa)
 Get one of the question hints.
 
 get_max_fraction ()
 Some questions can return a mark greater than the maximum.
 
 get_min_fraction ()
 Some questions can return a negative mark if the student gets it wrong.
 
 get_next_answerids (array $answerids, bool $lastitem=false)
 Returns array of next answers.
 
 get_num_parts_right (array $response)
 Return the number of subparts of this response that are correct|partial|incorrect.
 
 get_num_variants ()
 
 get_ordered_positions (array $correctresponse, array $currentresponse)
 Get array of right answer positions for current response.
 
 get_ordered_subset (bool $contiguous)
 Search for best ordered subset.
 
 get_ordered_subsets (array $positions, bool $contiguous)
 Get all ordered subsets in the positions array.
 
 get_ordering_item_score (question_definition $question, int $position, int $answerid)
 Returns score for one item depending on correctness and question settings.
 
 get_ordering_layoutclass ()
 Returns layoutclass.
 
 get_previous_and_next_answerids (array $answerids, bool $all=false)
 Returns prev and next answers array.
 
 get_question_definition_for_external_rendering (question_attempt $qa, question_display_options $options)
 Return the question settings that define this question as structured data.
 
 get_question_summary ()
 Generate a brief, plain-text, summary of this question.
 
 get_renderer (moodle_page $page)
 
 get_response_fieldname ()
 Returns response mform field name.
 
 get_right_answer_summary ()
 Generate a brief, plain-text, summary of the correct answer to this question.
 
 get_student_response_values_for_simulation ($realresponse)
 Does the opposite of prepare_simulated_post_data.
 
 get_type_name ()
 
 get_validation_error (array $response)
 In situations where is_gradable_response() returns false, this method should generate a description of what the problem is.
 
 get_variants_selection_seed ()
 
 grade_response (array $response)
 Grade a response to the question, returning a fraction between get_min_fraction() and get_max_fraction(), and the corresponding question_state right, partial or wrong.
 
 html_to_text ($text, $format)
 Convert some part of the question text to plain text.
 
 is_complete_response (array $response)
 Used by many of the behaviours, to work out whether the student's response to the question is complete.
 
 is_gradable_response (array $response)
 Use by many of the behaviours to determine whether the student has provided enough of an answer for the question to be graded automatically, or whether it must be considered aborted.
 
 is_same_response (array $old, array $new)
 Use by many of the behaviours to determine whether the student's response has changed.
 
 make_behaviour (question_attempt $qa, $preferredbehaviour)
 Creat the appropriate behaviour for an attempt at this quetsion, given the desired (archetypal) behaviour.
 
 make_html_inline ($html)
 Take some HTML that should probably already be a single line, like a multiple choice choice, or the corresponding feedback, and make it so that it is suitable to go in a place where the HTML must be inline, like inside a.
 
 prepare_simulated_post_data ($simulatedresponse)
 Takes an array of values representing a student response represented in a way that is understandable by a human and transforms that to the response as the POST values returned from the HTML form that takes the student response during a student attempt.
 
 set_latest_version (int $latestversion)
 Set the latest version.
 
 start_attempt (question_attempt_step $step, $variant)
 Start a new attempt at this question, storing any information that will be needed later in the step.
 
 summarise_response (array $response)
 Produce a plain text summary of a response.
 
 un_summarise_response (string $summary)
 If possible, construct a response that could have lead to the given response summary.
 
 update_attempt_state_data_for_new_version (question_attempt_step $oldstep, question_definition $oldquestion)
 Update the data representing the initial state of an attempt another version of this question, to allow for the changes.
 
 update_current_response (array $response)
 Unpack the students' response into an array which updates the question currentresponse.
 
 validate_can_regrade_with_other_version (question_definition $otherversion)
 Verify if an attempt at this question can be re-graded using the other question version.
 

Static Public Member Functions

static get_grading_types (int $type=null)
 Returns available values and descriptions for field "gradingtype".
 
static get_layout_types (int $type=null)
 Returns available values and descriptions for field "layouttype".
 
static get_numbering_styles (string $style=null)
 Get the numbering styles supported.
 
static get_select_types (int $type=null)
 Returns available values and descriptions for field "selecttype".
 
static get_types (array $types, $type)
 Helper function for get_select_types, get_layout_types, get_grading_types.
 

Public Attributes

array $answers
 Records from "question_answers" table.
 
integer $category
 question category id.
 
integer $contextid
 question context id.
 
string $correctfeedback
 
int $correctfeedbackformat
 
array $correctresponse
 of answerids in correct order
 
integer $createdby
 userid of the use who created this question.
 
array $currentresponse
 contatining current order of answerids
 
array $customfields = array()
 of array of core_customfield\data_controller objects indexed by fieldid for the questions custom fields.
 
float $defaultmark = 1
 what this quetsion is marked out of, by default.
 
string $generalfeedback
 question general feedback.
 
integer $generalfeedbackformat
 question test format.
 
int $gradingtype
 Which grading strategy to use.
 
array $hints = array()
 of question_hints.
 
integer $id
 id of the question in the datase, or null if this question is not in the database.
 
string $idnumber
 question idnumber.
 
string $incorrectfeedback
 
int $incorrectfeedbackformat
 
int $layouttype
 {
 
integer $length = 1
 How many question numbers this question consumes.
 
integer $modifiedby
 userid of the use who modified this question.
 
string $name
 question name.
 
string $numberingstyle
 How to number the items.
 
integer $parent = 0
 parent question id.
 
string $partiallycorrectfeedback
 
int $partiallycorrectfeedbackformat
 
number $penalty = 0
 penalty factor of this question.
 
question_type $qtype
 the question type this question is.
 
int $questionbankentryid
 Bank entry id for the question.
 
string $questiontext
 question text.
 
integer $questiontextformat
 question test format.
 
int $selectcount
 if {
 
int $selecttype
 {
 
bool $showgrading
 Should details of the grading calculation be shown to students.
 
Some $shownumcorrect = false
 question types have the option to show the number of sub-parts correct.
 
string $stamp
 unique identifier of this question.
 
boolean $status = core_question\local\bank\question_version_status::QUESTION_STATUS_READY
 question status hidden/ready/draft in the question bank.
 
integer $timecreated
 timestamp when this question was created.
 
integer $timemodified
 timestamp when this question was modified.
 
int $version
 Version number of the question in a question bank.
 
int $versionid
 Version id of the question in a question bank.
 
int const GRADING_ABSOLUTE_POSITION = 0
 Counts items, placed into right absolute place.
 
int const GRADING_ALL_OR_NOTHING = -1
 Zero grade on any error.
 
int const GRADING_LONGEST_CONTIGUOUS_SUBSET = 6
 Only longest ordered and contiguous subset is graded.
 
int const GRADING_LONGEST_ORDERED_SUBSET = 5
 Only longest ordered subset is graded.
 
int const GRADING_RELATIVE_ALL_PREVIOUS_AND_NEXT = 4
 All answers that are placed before and after each answer is graded if in right order.
 
int const GRADING_RELATIVE_NEXT_EXCLUDE_LAST = 1
 Every sequential pair in right order is graded (last pair is excluded)
 
int const GRADING_RELATIVE_NEXT_INCLUDE_LAST = 2
 Every sequential pair in right order is graded (last pair is included)
 
int const GRADING_RELATIVE_ONE_PREVIOUS_AND_NEXT = 3
 Single answers that are placed before and after each answer is graded if in right order.
 
int const GRADING_RELATIVE_TO_CORRECT = 7
 Items are graded relative to their position in the correct answer.
 
const LAYOUT_HORIZONTAL = 1
 Show answers in one horizontal line.
 
const LAYOUT_VERTICAL = 0
 Show answers in vertical list.
 
const MIN_SUBSET_ITEMS = 2
 The minimum number of items to create a subset.
 
const NUMBERING_STYLE_DEFAULT = 'none'
 Default value for numberingstyle.
 
const SELECT_ALL = 0
 Select all answers.
 
const SELECT_CONTIGUOUS = 2
 Select contiguous subset of answers.
 
const SELECT_RANDOM = 1
 Select random set of answers.
 

Protected Member Functions

 check_combined_feedback_file_access ($qa, $options, $filearea, $args=null)
 Check a request for access to a file belonging to a combined feedback field.
 
 check_hint_file_access ($qa, $options, $args)
 Check a request for access to a file belonging to a hint.
 
 get_fraction_maxscore_score_of_item (int $position, int $answerid, array $correctresponse, array $currentresponse)
 Returns the grade for one item, base on the fraction scale.
 
 get_response_depend_on_grading_type (string $gradingtype)
 Get correcresponse and currentinfo depending on grading type.
 

Protected Attributes

array $itemscores = []
 of scored for every item
 
int $latestversion = null
 The latest version of the question.
 

Member Function Documentation

◆ __get()

question_definition::__get ( $name)
inherited

When a pending definition tries to read its latest version, fill in the latest version for all pending definitions.

Parameters
string$name
Return values
mixed

◆ apply_attempt_state()

qtype_ordering_question::apply_attempt_state ( question_attempt_step $step)

When an in-progress question_attempt is re-loaded from the database, this method is called so that the question can re-initialise its internal state as needed by this attempt.

For example, the multiple choice question type needs to set the order of the choices to the order that was set up when start_attempt was called originally. All the information required to do this should be in the $step object, which is the first step of the question_attempt being loaded.

Parameters
question_attempt_stepThe first step of the question_attempt being loaded.

Reimplemented from question_definition.

◆ check_combined_feedback_file_access()

qtype_ordering_question::check_combined_feedback_file_access ( $qa,
$options,
$filearea,
$args = null )
protected

Check a request for access to a file belonging to a combined feedback field.

Parameters
question_attempt$qathe question attempt being displayed.
question_display_options$optionsthe options that control display of the question.
string$fileareathe name of the file area.
array$argsthe remaining bits of the file path.
Return values
boolwhether access to the file should be allowed.

Reimplemented from question_graded_automatically.

◆ check_file_access()

qtype_ordering_question::check_file_access ( $qa,
$options,
$component,
$filearea,
$args,
$forcedownload )

Checks whether the users is allow to be served a particular file.

Parameters
question_attempt$qathe question attempt being displayed.
question_display_options$optionsthe options that control display of the question.
string$componentthe name of the component we are serving files for.
string$fileareathe name of the file area.
array$argsthe remaining bits of the file path.
bool$forcedownloadwhether the user must be forced to download the file.
Return values
booltrue if the user can access this file.

Reimplemented from question_definition.

◆ check_hint_file_access()

question_graded_automatically::check_hint_file_access ( $qa,
$options,
$args )
protectedinherited

Check a request for access to a file belonging to a hint.

Parameters
question_attempt$qathe question attempt being displayed.
question_display_options$optionsthe options that control display of the question.
array$argsthe remaining bits of the file path.
Return values
boolwhether access to the file should be allowed.

◆ classify_response()

qtype_ordering_question::classify_response ( array $response)

Categorise the student's response according to the categories defined by get_possible_responses.

Parameters
$responsea response, as might be passed to grade_response().
Return values
arraysubpartid => question_classified_response objects. returns an empty array if no analysis is possible.

Reimplemented from question_with_responses.

◆ clear_wrong_from_response()

question_definition::clear_wrong_from_response ( array $response)
inherited

Given a response, rest the parts that are wrong.

Parameters
array$responsea response
Return values
arraya cleaned up response with the wrong bits reset.

Reimplemented in qtype_ddmarker_question, qtype_ddtoimage_question_base, qtype_gapselect_question_base, qtype_match_question, qtype_multianswer_question, and qtype_multichoice_multi_question.

◆ format_generalfeedback()

question_definition::format_generalfeedback ( $qa)
inherited
Return values
theresult of applying format_text() to the general feedback.

◆ format_questiontext()

question_definition::format_questiontext ( $qa)
inherited
Return values
theresult of applying format_text() to the question text.

◆ format_text()

question_definition::format_text ( $text,
$format,
$qa,
$component,
$filearea,
$itemid,
$clean = false )
inherited

Apply format_text() to some content with appropriate settings for this question.

Parameters
string$textsome content that needs to be output.
int$formatthe FORMAT_... constant.
question_attempt$qathe question attempt.
string$componentused for rewriting file area URLs.
string$fileareaused for rewriting file area URLs.
bool$cleanWhether the HTML needs to be cleaned. Generally, parts of the question do not need to be cleaned, and student input does.
Return values
stringthe text formatted for output by format_text.

◆ get_correct_response()

qtype_ordering_question::get_correct_response ( )

What data would need to be submitted to get this question correct.

If there is more than one correct answer, this method should just return one possibility. If it is not possible to compute a correct response, this method should return null.

Return values
array|nullparameter name => value.

Reimplemented from question_definition.

◆ get_expected_data()

qtype_ordering_question::get_expected_data ( )

What data may be included in the form submission when a student submits this question in its current state?

This information is used in calls to optional_param. The parameter name has question_attempt::get_field_prefix() automatically prepended.

Return values
array|stringvariable name => PARAM_... constant, or, as a special case that should only be used in unavoidable, the constant question_attempt\USE_RAW_DATA meaning take all the raw submitted data belonging to this question.

Reimplemented from question_definition.

◆ get_fraction_maxscore_score_of_item()

qtype_ordering_question::get_fraction_maxscore_score_of_item ( int $position,
int $answerid,
array $correctresponse,
array $currentresponse )
protected

Returns the grade for one item, base on the fraction scale.

Parameters
int$positionThe position of the current response.
int$answeridThe answerid of the current response.
array$correctresponseThe correct response list base on grading type.
array$currentresponseThe current response list base on grading type.
Return values
array.

◆ get_grading_types()

static qtype_ordering_question::get_grading_types ( int $type = null)
static

Returns available values and descriptions for field "gradingtype".

Parameters
int | null$type
Return values
array|stringarray if $type is not specified and single string if $type is specified @codeCoverageIgnore

◆ get_hint()

question_graded_automatically::get_hint ( $hintnumber,
question_attempt $qa )
inherited

Get one of the question hints.

The question_attempt is passed in case the question type wants to do something complex. For example, the multiple choice with multiple responses question type will turn off most of the hint options if the student has selected too many opitions.

Parameters
int$hintnumberWhich hint to display. Indexed starting from 0
question_attempt$qaThe question_attempt.

Implements question_automatically_gradable.

Reimplemented in qtype_multichoice_multi_question.

◆ get_layout_types()

static qtype_ordering_question::get_layout_types ( int $type = null)
static

Returns available values and descriptions for field "layouttype".

Parameters
int | null$type
Return values
array|stringarray if $type is not specified and single string if $type is specified @codeCoverageIgnore

◆ get_max_fraction()

question_definition::get_max_fraction ( )
inherited

Some questions can return a mark greater than the maximum.

This method returns the lowest highest the question can return, on the fraction scale. that is, where the nominal maximum mark is 1.0.

Return values
floatmaximum fraction this question will ever return.

Reimplemented in qtype_multianswer_question.

◆ get_min_fraction()

question_definition::get_min_fraction ( )
inherited

Some questions can return a negative mark if the student gets it wrong.

This method returns the lowest mark the question can return, on the fraction scale. that is, where the maximum possible mark is 1.0.

Return values
floatminimum fraction this question will ever return.

Reimplemented in qtype_multianswer_question, qtype_multichoice_multi_question, and qtype_multichoice_single_question.

◆ get_next_answerids()

qtype_ordering_question::get_next_answerids ( array $answerids,
bool $lastitem = false )

Returns array of next answers.

Parameters
array$answeridsarray of answers id
bool$lastitemInclude last item?
Return values
arrayof id of next answer

◆ get_num_parts_right()

qtype_ordering_question::get_num_parts_right ( array $response)

Return the number of subparts of this response that are correct|partial|incorrect.

Parameters
array$responseA response.
Return values
arrayArray of three elements: the number of correct subparts, the number of partial correct subparts and the number of incorrect subparts.

Reimplemented from question_definition.

◆ get_num_variants()

question_definition::get_num_variants ( )
inherited
Return values
intthe number of vaiants that this question has.

Reimplemented in qtype_calculated_question, qtype_calculatedmulti_multi_question, and qtype_calculatedmulti_single_question.

◆ get_numbering_styles()

static qtype_ordering_question::get_numbering_styles ( string $style = null)
static

Get the numbering styles supported.

For each style, there should be a corresponding lang string 'numberingstylexxx' in the qtype_ordering language file, a case in the switch statement in number_in_style, and it should be listed in the definition of this column in install.xml.

Parameters
string | null$styleThe specific numbering style to retrieve.
Return values
array|stringNumbering style(s). The keys are style identifiers, and the values are the corresponding language strings. @codeCoverageIgnore

◆ get_ordered_positions()

qtype_ordering_question::get_ordered_positions ( array $correctresponse,
array $currentresponse )

Get array of right answer positions for current response.

Parameters
array$correctresponse
array$currentresponse
Return values
array

◆ get_ordered_subset()

qtype_ordering_question::get_ordered_subset ( bool $contiguous)

Search for best ordered subset.

Parameters
bool$contiguousA flag indicating whether only contiguous values should be considered for inclusion in the subset.
Return values
array

◆ get_ordered_subsets()

qtype_ordering_question::get_ordered_subsets ( array $positions,
bool $contiguous )

Get all ordered subsets in the positions array.

Parameters
array$positionsmaps an item's current position to its correct position
bool$contiguousTRUE if searching only for contiguous subsets; otherwise FALSE
Return values
arrayof ordered subsets from within the $positions array

◆ get_ordering_item_score()

qtype_ordering_question::get_ordering_item_score ( question_definition $question,
int $position,
int $answerid )

Returns score for one item depending on correctness and question settings.

Parameters
question_definition$questionquestion definition object
int$positionThe position of the current response.
int$answeridThe answerid of the current response.
Return values
array(score, maxscore, fraction, percent, class)

◆ get_ordering_layoutclass()

qtype_ordering_question::get_ordering_layoutclass ( )

Returns layoutclass.

Return values
string

◆ get_previous_and_next_answerids()

qtype_ordering_question::get_previous_and_next_answerids ( array $answerids,
bool $all = false )

Returns prev and next answers array.

Parameters
array$answeridsarray of answers id
bool$allinclude all answers
Return values
arrayof array('prev' => previd, 'next' => nextid)

◆ get_question_definition_for_external_rendering()

question_definition::get_question_definition_for_external_rendering ( question_attempt $qa,
question_display_options $options )
inherited

Return the question settings that define this question as structured data.

This is used by external systems such as the Moodle mobile app, which want to display the question themselves, rather than using the renderer provided.

This method should only return the data that the student is allowed to see or know, given the current state of the question. For example, do not include the 'General feedback' until the student has completed the question, and even then, only include it if the question_display_options say it should be visible.

But, within those rules, it is recommended that you return all the settings for the question, to give maximum flexibility to the external system providing its own rendering of the question.

Parameters
question_attempt$qathe current attempt for which we are exporting the settings.
question_display_options$optionsthe question display options which say which aspects of the question should be visible.
Return values
mixedstructure representing the question settings. In web services, this will be JSON-encoded.

Reimplemented in qtype_essay_question, qtype_gapselect_question_base, qtype_match_question, qtype_multianswer_question, qtype_multichoice_base, qtype_numerical_question, qtype_shortanswer_question, and qtype_truefalse_question.

◆ get_question_summary()

question_definition::get_question_summary ( )
inherited

Generate a brief, plain-text, summary of this question.

This is used by various reports. This should show the particular variant of the question as presented to students. For example, the calculated quetsion type would fill in the particular numbers that were presented to the student. This method will return null if such a summary is not possible, or inappropriate.

Return values
string|nulla plain text summary of this question.

Reimplemented in qtype_ddtoimage_question_base, qtype_gapselect_question_base, qtype_match_question, qtype_multianswer_question, qtype_multichoice_base, and question_information_item.

◆ get_renderer()

question_definition::get_renderer ( moodle_page $page)
inherited
Parameters
moodle_pagethe page we are outputting to.
Return values
qtype_rendererthe renderer to use for outputting this question.

Reimplemented in qtype_multichoice_multi_question, and qtype_multichoice_single_question.

◆ get_response_depend_on_grading_type()

qtype_ordering_question::get_response_depend_on_grading_type ( string $gradingtype)
protected

Get correcresponse and currentinfo depending on grading type.

Parameters
string$gradingtypeThe kind of grading.
Return values
arrayCorrectresponse and currentresponsescore in one array.

◆ get_response_fieldname()

qtype_ordering_question::get_response_fieldname ( )

Returns response mform field name.

Return values
string

◆ get_right_answer_summary()

question_graded_automatically::get_right_answer_summary ( )
inherited

Generate a brief, plain-text, summary of the correct answer to this question.

This is used by various reports, and can also be useful when testing. This method will return null if such a summary is not possible, or inappropriate.

Return values
string|nulla plain text summary of the right answer to this question.

Implements question_automatically_gradable.

Reimplemented in qtype_ddmarker_question.

◆ get_select_types()

static qtype_ordering_question::get_select_types ( int $type = null)
static

Returns available values and descriptions for field "selecttype".

Parameters
int | null$type
Return values
array|stringarray if $type is not specified and single string if $type is specified @codeCoverageIgnore

◆ get_student_response_values_for_simulation()

question_definition::get_student_response_values_for_simulation ( $realresponse)
inherited

Does the opposite of prepare_simulated_post_data.

This takes a student response (the POST values returned from the HTML form that takes the student response during a student attempt) it then represents it in a way that is understandable by a human.

Primarily this is used when creating a file of csv from real student responses in order later to be able to simulate the same student interaction with a quiz later.

Parameters
string[]$realresponsethe response array as was returned from the form during a student attempt (without prefixes).
Return values
string[]an array of data representing a student response.

Reimplemented in qtype_match_question, qtype_multianswer_question, qtype_multichoice_multi_question, and qtype_multichoice_single_question.

◆ get_type_name()

question_definition::get_type_name ( )
inherited
Return values
stringthe name of the question type (for example multichoice) that this question is.

◆ get_types()

static qtype_ordering_question::get_types ( array $types,
$type )
static

Helper function for get_select_types, get_layout_types, get_grading_types.

Parameters
array$types
int$type
Return values
array|stringarray if $type is not specified and single string if $type is specified
Exceptions
coding_exception@codeCoverageIgnore

◆ get_validation_error()

qtype_ordering_question::get_validation_error ( array $response)

In situations where is_gradable_response() returns false, this method should generate a description of what the problem is.

Return values
stringthe message.

Implements question_automatically_gradable.

◆ get_variants_selection_seed()

question_definition::get_variants_selection_seed ( )
inherited
Return values
stringthat can be used to seed the pseudo-random selection of a variant.

Reimplemented in qtype_calculated_question, qtype_calculatedmulti_multi_question, and qtype_calculatedmulti_single_question.

◆ grade_response()

qtype_ordering_question::grade_response ( array $response)

Grade a response to the question, returning a fraction between get_min_fraction() and get_max_fraction(), and the corresponding question_state right, partial or wrong.

Parameters
array$responseresponses, as returned by question_attempt_step::get_qt_data().
Return values
array(float, integer) the fraction, and the state.

Implements question_automatically_gradable.

◆ html_to_text()

question_definition::html_to_text ( $text,
$format )
inherited

Convert some part of the question text to plain text.

This might be used, for example, by get_response_summary().

Parameters
string$textThe HTML to reduce to plain text.
int$formatthe FORMAT_... constant.
Return values
stringthe equivalent plain text.

◆ is_complete_response()

qtype_ordering_question::is_complete_response ( array $response)

Used by many of the behaviours, to work out whether the student's response to the question is complete.

That is, whether the question attempt should move to the COMPLETE or INCOMPLETE state.

Parameters
array$responseresponses, as returned by question_attempt_step::get_qt_data().
Return values
boolwhether this response is a complete answer to this question.

Implements question_manually_gradable.

◆ is_gradable_response()

qtype_ordering_question::is_gradable_response ( array $response)

Use by many of the behaviours to determine whether the student has provided enough of an answer for the question to be graded automatically, or whether it must be considered aborted.

Parameters
array$responseresponses, as returned by question_attempt_step::get_qt_data().
Return values
boolwhether this response can be graded.

Reimplemented from question_with_responses.

◆ is_same_response()

qtype_ordering_question::is_same_response ( array $prevresponse,
array $newresponse )

Use by many of the behaviours to determine whether the student's response has changed.

This is normally used to determine that a new set of responses can safely be discarded.

Parameters
array$prevresponsethe responses previously recorded for this question, as returned by question_attempt_step::get_qt_data()
array$newresponsethe new responses, in the same format.
Return values
boolwhether the two sets of responses are the same - that is whether the new set of responses can safely be discarded.

Implements question_manually_gradable.

◆ make_behaviour()

question_definition::make_behaviour ( question_attempt $qa,
$preferredbehaviour )
inherited

Creat the appropriate behaviour for an attempt at this quetsion, given the desired (archetypal) behaviour.

This default implementation will suit most normal graded questions.

If your question is of a patricular type, then it may need to do something different. For example, if your question can only be graded manually, then it should probably return a manualgraded behaviour, irrespective of what is asked for.

If your question wants to do somthing especially complicated is some situations, then you may wish to return a particular behaviour related to the one asked for. For example, you migth want to return a qbehaviour_interactive_adapted_for_myqtype.

Parameters
question_attempt$qathe attempt we are creating a behaviour for.
string$preferredbehaviourthe requested type of behaviour.
Return values
question_behaviourthe new behaviour object.

Reimplemented in qtype_essay_question, question_graded_automatically_with_countback, and question_information_item.

◆ make_html_inline()

question_definition::make_html_inline ( $html)
inherited

Take some HTML that should probably already be a single line, like a multiple choice choice, or the corresponding feedback, and make it so that it is suitable to go in a place where the HTML must be inline, like inside a.

tag.

Parameters
string$htmlto HTML to fix up.
Return values
stringthe fixed HTML.

◆ prepare_simulated_post_data()

question_definition::prepare_simulated_post_data ( $simulatedresponse)
inherited

Takes an array of values representing a student response represented in a way that is understandable by a human and transforms that to the response as the POST values returned from the HTML form that takes the student response during a student attempt.

Primarily this is used when reading csv values from a file of student responses in order to be able to simulate the student interaction with a quiz.

In most cases the array will just be returned as is. Some question types will need to transform the keys of the array, as the meaning of the keys in the html form is deliberately obfuscated so that someone looking at the html does not get an advantage. The values that represent the response might also be changed in order to more meaningful to a human.

See the examples of question types that have overridden this in core and also see the csv files of simulated student responses used in unit tests in :

  • mod/quiz/tests/fixtures/stepsXX.csv
  • mod/quiz/report/responses/tests/fixtures/steps00.csv
  • mod/quiz/report/statistics/tests/fixtures/stepsXX.csv

Also see , a quiz report plug in for uploading and downloading student responses as csv files.

Parameters
array$simulatedresponsean array of data representing a student response
Return values
arraya response array as would be returned from the html form (but without prefixes)

Reimplemented in qtype_match_question, qtype_multianswer_question, qtype_multichoice_multi_question, and qtype_multichoice_single_question.

◆ set_latest_version()

question_definition::set_latest_version ( int $latestversion)
inherited

Set the latest version.

Making $this->latestversion public would break the magic __get() behaviour above, so allow it to be set externally.

Parameters
int$latestversion
Return values
void

◆ start_attempt()

qtype_ordering_question::start_attempt ( question_attempt_step $step,
$variant )

Start a new attempt at this question, storing any information that will be needed later in the step.

This is where the question can do any initialisation required on a per-attempt basis. For example, this is where the multiple choice question type randomly shuffles the choices (if that option is set).

Any information about how the question has been set up for this attempt should be stored in the $step, by calling $step->set_qt_var(...).

Parameters
question_attempt_stepThe first step of the question_attempt being started. Can be used to store state.
int$varantwhich variant of this question to start. Will be between 1 and get_num_variants() inclusive.

Reimplemented from question_definition.

◆ summarise_response()

qtype_ordering_question::summarise_response ( array $response)

Produce a plain text summary of a response.

Parameters
array$responsea response, as might be passed to grade_response().
Return values
stringa plain text summary of that response, that could be used in reports.

Implements question_manually_gradable.

◆ un_summarise_response()

question_with_responses::un_summarise_response ( string $summary)
inherited

If possible, construct a response that could have lead to the given response summary.

This is basically the opposite of summarise_response() but it is intended only to be used for testing.

Parameters
string$summarya string, which might have come from summarise_response
Return values
arraya response that could have lead to that.

Implements question_manually_gradable.

Reimplemented in qtype_essay_question, qtype_multichoice_multi_question, qtype_multichoice_single_question, qtype_numerical_question, qtype_shortanswer_question, and qtype_truefalse_question.

◆ update_attempt_state_data_for_new_version()

qtype_ordering_question::update_attempt_state_data_for_new_version ( question_attempt_step $oldstep,
question_definition $oldquestion )

Update the data representing the initial state of an attempt another version of this question, to allow for the changes.

What is required is probably most easily understood using an example. Think about multiple choice questions. The first step has a variable '_order' which is a comma-separated list of question_answer ids. A different version of the question will have different question_answers with different ids. However, the list of choices should be similar, and so we need to shuffle the new list of ids in the same way that the old one was.

Note: be sure to return all the data that was originally in $oldstep, while updating the fields that require it. Otherwise you might break features like 'Each attempt builds on last' in the quiz.

This method should only be called if {

See also
validate_can_regrade_with_other_version()} did not flag up a potential problem. So, this method will throw a {
coding_exception} if it is not possible to work out a return value.
Parameters
question_attempt_step$oldstepthe first step of a {
See also
question_attempt} at $oldquestion.
Parameters
question_definition$oldquestionthe previous version of the question, which $oldstate comes from.
Return values
arraythe submit data which can be passed to {
See also
apply_attempt_state} to start an attempt at this version of this question, corresponding to the attempt at the old question.
Exceptions
coding_exceptionif this can't be done.

Reimplemented from question_definition.

◆ update_current_response()

qtype_ordering_question::update_current_response ( array $response)

Unpack the students' response into an array which updates the question currentresponse.

Parameters
array$responseForm data

◆ validate_can_regrade_with_other_version()

qtype_ordering_question::validate_can_regrade_with_other_version ( question_definition $otherversion)

Verify if an attempt at this question can be re-graded using the other question version.

To put it another way, will {

See also
update_attempt_state_date_from_old_version()} be able to work?

It is expected that this relationship is symmetrical, so if you can regrade from V1 to V3, then you can change back from V3 to V1.

Parameters
question_definition$otherversiona different version of the question to use in the regrade.
Return values
string|nullnull if the regrade can proceed, else a reason why not.

Reimplemented from question_definition.

Member Data Documentation

◆ $gradingtype

int qtype_ordering_question::$gradingtype

Which grading strategy to use.

One of the GRADING_... constants.

◆ $latestversion

int question_definition::$latestversion = null
protectedinherited

The latest version of the question.

null if we haven't checked yet.

◆ $layouttype

int qtype_ordering_question::$layouttype

{

See also
LAYOUT_VERTICAL} or {
LAYOUT_HORIZONTAL}.

◆ $numberingstyle

string qtype_ordering_question::$numberingstyle

How to number the items.

A key from the array returned by {

See also
get_numbering_styles()}.

◆ $selectcount

int qtype_ordering_question::$selectcount

if {

See also
$selecttype} is not SELECT_ALL, then the number to select.

◆ $selecttype

int qtype_ordering_question::$selecttype

{

See also
SELECT_ALL}, {
SELECT_RANDOM} or {
SELECT_CONTIGUOUS}.

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