Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
The calculated question type. More...
Public Member Functions | |
actual_number_of_questions ($question) | |
Returns the number of question numbers which are used by the question. | |
addnamecategory (&$question) | |
break_down_stats_and_response_analysis_by_variant ($questiondata) | |
Whether or not to break down question stats and response analysis, for a question defined by $questiondata. | |
can_analyse_responses () | |
Whether this question type can perform a frequency analysis of student responses. | |
clean_technical_prefix_from_question_name ($name) | |
Remove prefix #{..}# if exists. | |
comment_header ($question) | |
comment_on_datasetitems ($qtypeobj, $questionid, $questiontext, $answers, $data, $number) | |
construct_dataset_menus ($form, $mandatorydatasets, $optionaldatasets) | |
create_editing_form ($submiturl, $question, $category, $contexts, $formeditable) | |
Return an instance of the question editing form definition. | |
custom_generator_set_data ($datasetdefs, $formdata) | |
custom_generator_tools ($datasetdef) | |
custom_generator_tools_part ($mform, $idx, $j) | |
dataset_options ($form, $name, $mandatory=true, $renameabledatasets=false) | |
dataset_options_from_database ($form, $name, $prefix='', $langfile='qtype_calculated') | |
delete_question ($questionid, $contextid) | |
Deletes the question-type specific data when a question is deleted. | |
display_question_editing_page ($mform, $question, $wizardnow) | |
This method should be overriden if you want to include a special heading or some other html on a question editing page besides the question editing form. | |
evaluate_equations ($str, $dataset) | |
export_to_xml ($question, qformat_xml $format, $extra=null) | |
extra_answer_fields () | |
If your question type has a table that extends the question_answers table, make this method return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and answerid). | |
extra_question_fields () | |
If your question type has a table that extends the question table, and you want the base class to automatically save, backup and restore the extra fields, override this method to return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and questionid). | |
find_dataset_names ($text) | |
Find the names of all datasets mentioned in a piece of question content like the question text. | |
find_formulas ($text) | |
Find all the formulas in a bit of text. | |
find_standard_scripts () | |
Utility method used by qtype_renderer::head_code(). | |
finished_edit_wizard ($form) | |
Returns true if the editing wizard is finished, false otherwise. | |
generate_dataset_item ($options) | |
generate_test ($name, $courseid=null) | |
Abstract function implemented by each question type. | |
get_database_dataset_items ($definition) | |
This function get the dataset items using id as unique parameter and return an array with itemnumber as index sorted ascendant If the multiple records with the same itemnumber exist, only the newest one i.e with the greatest id is used, the others are ignored but not deleted. | |
get_dataset_definitions ($questionid, $newdatasets) | |
get_dataset_definitions_category ($form) | |
This function retrieve the item count of the available category shareable wild cards that is added as a comment displayed when a wild card with the same name is displayed in datasetdefinitions_form.php. | |
get_datasets_for_export ($question) | |
get_default_value (string $name, $default) | |
Return default value for a given form element either from user_preferences table or $default. | |
get_extra_question_bank_actions (stdClass $question) | |
Get extra actions for a question of this type to add to the question bank edit menu. | |
get_heading ($adding=false) | |
Method called by display_question_editing_page and by question.php to get heading for breadcrumbs. | |
get_possible_responses ($questiondata) | |
This method should return all the possible types of response that are recognised for this question. | |
get_question_options ($question) | |
Loads the question type specific options for the question. | |
get_random_guess_score ($questiondata) | |
Calculate the score a monkey would get on a question by clicking randomly. | |
get_short_question_name ($stringtoshorten, $characterlimit) | |
This function shortens a question name if it exceeds the character limit. | |
get_virtual_qtype () | |
has_html_answers () | |
import_datasets ($question) | |
import_file ($context, $component, $filearea, $itemid, $file) | |
import_from_xml ($data, $question, qformat_xml $format, $extra=null) | |
is_manual_graded () | |
is_question_manual_graded ($question, $otherquestionsinuse) | |
is_real_question_type () | |
is_usable_by_random () | |
local_name () | |
make_question ($questiondata) | |
Create an appropriate question_definition for the question of this type using data loaded from the database. | |
menu_name () | |
The name this question should appear as in the create new question dropdown. | |
move_files ($questionid, $oldcontextid, $newcontextid) | |
Move all the files belonging to this question from one context to another. | |
name () | |
& | next_wizard_form ($submiturl, $question, $wizardnow) |
pick_question_dataset ($question, $datasetitem) | |
plugin_baseurl () | |
plugin_dir () | |
plugin_name () | |
preparedatasets ($form, $questionfromid='0') | |
This method prepare the $datasets in a format similar to dadatesetdefinitions_form.php so that they can be saved using the function save_dataset_definitions($form) when creating a new calculated question or when editing an already existing calculated question or by function save_as_new_dataset_definitions($form, $initialid) when saving as new an already existing calculated question. | |
print_dataset_definitions_category ($form) | |
This function build a table showing the available category shareable wild cards, their name, their definition (Min, Max, Decimal) , the item count and the name of the question where they are used. | |
print_dataset_definitions_category_shared ($question, $datasetdefsq) | |
This function build a table showing the available category shareable wild cards, their name, their definition (Min, Max, Decimal) , the item count and the name of the question where they are used. | |
print_next_wizard_page ($question, $form, $course) | |
questionid_column_name () | |
If you use extra_question_fields, overload this function to return question id field name in case you table use another name for this column. | |
response_file_areas () | |
If the quetsion type uses files in responses, then this method should return an array of all the response variables that might have corresponding files. | |
save_as_new_dataset_definitions ($form, $initialid) | |
This function create a copy of the datasets (definition and dataitems) from the preceding question if they remain in the new question otherwise its create the datasets that have been added as in the save_dataset_definitions() | |
save_dataset_definitions ($form) | |
save_dataset_items ($question, $fromform) | |
save_defaults_for_new_questions (stdClass $fromform) | |
Save question defaults when creating new questions. | |
save_hints ($formdata, $withparts=false) | |
save_question ($question, $form) | |
this version save the available data at the different steps of the question editing process without using global $SESSION as storage between steps at the first step $wizardnow = 'question' when creating a new question when modifying a question when copying as a new question the general parameters and answers are saved using parent\save_question then the datasets are prepared and saved at the second step $wizardnow = 'datasetdefinitions' the datadefs final type are defined as private, category or not a datadef at the third step $wizardnow = 'datasetitems' the datadefs parameters and the data items are created or defined | |
save_question_answers ($question) | |
Save the answers, with any extra data. | |
save_question_calculated ($question, $fromform) | |
save_question_options ($question) | |
Saves question-type specific options. | |
set_default_options ($questiondata) | |
Set any missing settings for this question to the default values. | |
set_default_value (string $name, string $value) | |
Save the default value for a given form element in user_preferences table. | |
substitute_variables ($str, $dataset) | |
substitute_variables_and_eval ($str, $dataset) | |
supports_dataset_item_generation () | |
tolerance_types () | |
update_dataset_options ($datasetdefs, $form) | |
wizardpagesnumber () | |
Public Attributes | |
$wizardpagesnumber = 3 | |
string const | FORMULAS_IN_TEXT_REGEX = '~\{=([^{}]*(?:::{' . self::PLACEHOLDER_REGEX_PART . '\}[^{}]*)*)::}~' |
Regular expression that finds the formulas in content, with capturing brackets to get the forumlas. | |
const | MAX_DATASET_ITEMS = 100 |
string const | PLACEHODLER_REGEX = '~\{(' . self::PLACEHOLDER_REGEX_PART . ')\}~' |
REGEXP for a placeholder, wrapped in its {...} delimiters, with capturing brackets around the name. | |
string const | PLACEHOLDER_REGEX_PART = '[[:alpha:]][^>} <`{"\']*' |
a placeholder is a letter, followed by almost any characters. | |
Protected Member Functions | |
count_hints_on_form ($formdata, $withparts) | |
Count number of hints on the form. | |
decode_file ($file) | |
delete_files ($questionid, $contextid) | |
Delete all the files belonging to this question. | |
delete_files_in_answers ($questionid, $contextid, $answerstoo=false) | |
Delete all the files belonging to this question's answers. | |
delete_files_in_combined_feedback ($questionid, $contextid) | |
Delete all the files belonging to this question's answers. | |
delete_files_in_hints ($questionid, $contextid) | |
Delete all the files belonging to this question's hints. | |
fill_answer_fields ($answer, $questiondata, $key, $context) | |
Return $answer, filling necessary fields for the question_answers table. | |
fill_extra_answer_fields ($answerextra, $questiondata, $key, $context, $extraanswerfields) | |
Return $answerextra, filling necessary fields for the extra answer fields table. | |
get_context_by_category_id ($category) | |
Get question context by category id. | |
import_or_save_files ($field, $context, $component, $filearea, $itemid) | |
Save the file belonging to one text field. | |
initialise_calculated_answers (question_definition $question, stdClass $questiondata) | |
Initializes calculated answers for a given question. | |
initialise_combined_feedback (question_definition $question, $questiondata, $withparts=false) | |
Initialise the combined feedback fields. | |
initialise_core_question_metadata (question_definition $question, $questiondata) | |
Initialise the question metadata. | |
initialise_custom_fields (question_definition $question, $questiondata) | |
Initialise question custom fields. | |
initialise_question_answers (question_definition $question, $questiondata, $forceplaintextanswers=true) | |
Initialise question_definition\answers field. | |
initialise_question_hints (question_definition $question, $questiondata) | |
Initialise question_definition\hints field. | |
initialise_question_instance (question_definition $question, $questiondata) | |
Initialise the common question_definition fields. | |
is_answer_empty ($questiondata, $key) | |
Returns true is answer with the $key is empty in the question data and should not be saved in DB. | |
is_extra_answer_fields_empty ($questiondata, $key) | |
Returns true if extra answer fields for answer with the $key is empty in the question data and should not be saved in DB. | |
is_hint_empty_in_form_data ($formdata, $number, $withparts) | |
Determine if the hint with specified number is not empty and should be saved. | |
make_answer ($answer) | |
Create a question_answer, or an appropriate subclass for this question, from a row loaded from the database. | |
make_hint ($hint) | |
Create a question_hint, or an appropriate subclass for this question, from a row loaded from the database. | |
make_question_instance ($questiondata) | |
Create an appropriate question_definition for the question of this type using data loaded from the database. | |
move_files_in_answers ($questionid, $oldcontextid, $newcontextid, $answerstoo=false) | |
Move all the files belonging to this question's answers when the question is moved from one context to another. | |
move_files_in_combined_feedback ($questionid, $oldcontextid, $newcontextid) | |
Move all the files belonging to this question's answers when the question is moved from one context to another. | |
move_files_in_hints ($questionid, $oldcontextid, $newcontextid) | |
Move all the files belonging to this question's hints when the question is moved from one context to another. | |
save_combined_feedback_helper ($options, $formdata, $context, $withparts=false) | |
Can be used to save_question_options() to transfer the combined feedback fields from $formdata to $options. | |
save_hint_options ($formdata, $number, $withparts) | |
Save additional question type data into the hint optional field. | |
validate_answer ($answer) | |
Verify that an answer is OK. | |
validate_question_data ($question) | |
Validate data before save. | |
validate_text ($text) | |
Verify that the equations in part of the question are OK. | |
Protected Attributes | |
$fileoptions | |
The calculated question type.
|
inherited |
Returns the number of question numbers which are used by the question.
This function returns the number of question numbers to be assigned to the question. Most question types will have length one; they will be assigned one number. The 'description' type, however does not use up a number and so has a length of zero. Other question types may wish to handle a bundle of questions and hence return a number greater than one.
int | The number of question numbers which should be assigned to the question. |
object | $question | The question whose length is to be determined. Question type specific information is included. |
Reimplemented in qtype_description.
|
inherited |
Whether or not to break down question stats and response analysis, for a question defined by $questiondata.
object | $questiondata | The full question definition data. |
bool |
|
inherited |
Whether this question type can perform a frequency analysis of student responses.
If this method returns true, you must implement the get_possible_responses method, and the question_definition class must implement the classify_response method.
bool | whether this report can analyse all the student responses for things like the quiz statistics report. |
Reimplemented in qtype_description, qtype_missingtype, qtype_multianswer, and qtype_randomsamatch.
qtype_calculated::clean_technical_prefix_from_question_name | ( | $name | ) |
Remove prefix #{..}# if exists.
$name | a question name, |
string | the cleaned up question name. |
|
protectedinherited |
Count number of hints on the form.
Overload if you use custom hint controls.
object | $formdata | the data from the form. |
bool | $withparts | whether to take into account clearwrong and shownumcorrect options. |
int | count of hints on the form. |
|
inherited |
Return an instance of the question editing form definition.
This looks for a class called edit_{$this->name()}_question_form in the file question/type/{$this->name()}/edit_{$this->name()}_question_form.php and if it exists returns an instance of it.
string | $submiturl | passed on to the constructor call. |
object | an instance of the form definition, or null if one could not be found. |
|
protected |
Delete all the files belonging to this question.
int | $questionid | the question being deleted. |
int | $contextid | the context the question is in. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedmulti.
|
protectedinherited |
Delete all the files belonging to this question's answers.
int | $questionid | the question being deleted. |
int | $contextid | the context the question is in. |
bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
|
protectedinherited |
Delete all the files belonging to this question's answers.
int | $questionid | the question being deleted. |
int | $contextid | the context the question is in. |
bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
|
protectedinherited |
Delete all the files belonging to this question's hints.
int | $questionid | the question being deleted. |
int | $contextid | the context the question is in. |
qtype_calculated::delete_question | ( | $questionid, | |
$contextid ) |
Deletes the question-type specific data when a question is deleted.
int | $question | the question being deleted. |
int | $contextid | the context this quesiotn belongs to. |
Reimplemented from question_type.
qtype_calculated::display_question_editing_page | ( | $mform, | |
$question, | |||
$wizardnow ) |
This method should be overriden if you want to include a special heading or some other html on a question editing page besides the question editing form.
question_edit_form | $mform | a child of question_edit_form |
object | $question | |
string | $wizardnow | is '' for first page. |
Reimplemented from question_type.
|
inherited |
Reimplemented in qtype_randomsamatch.
|
inherited |
If your question type has a table that extends the question_answers table, make this method return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and answerid).
mixed | array as above, or null to tell the base class to do nothing. |
|
inherited |
If your question type has a table that extends the question table, and you want the base class to automatically save, backup and restore the extra fields, override this method to return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and questionid).
mixed | array as above, or null to tell the base class to do nothing. |
Reimplemented in qtype_randomsamatch, and qtype_shortanswer.
|
protectedinherited |
Return $answer, filling necessary fields for the question_answers table.
The questions using question_answers table may want to overload this. Default code will work for shortanswer and similar question types.
stdClass | $answer | Object to save data. |
object | $questiondata | This holds the information from the question editing form or import. |
int | $key | A key of the answer in question. |
object | $context | needed for working with files. |
$answer | answer with filled data. |
Reimplemented in qtype_shortanswer.
|
protectedinherited |
Return $answerextra, filling necessary fields for the extra answer fields table.
The questions may want to overload it to save files or do other data processing.
stdClass | $answerextra | Object to save data. |
object | $questiondata | This holds the information from the question editing form or import. |
int | $key | A key of the answer in question. |
object | $context | needed for working with files. |
array | $extraanswerfields | extra answer fields (without table name). |
$answer | answerextra with filled data. |
qtype_calculated::find_dataset_names | ( | $text | ) |
Find the names of all datasets mentioned in a piece of question content like the question text.
$text | the text to analyse. |
array | with dataset name for both key and value. |
qtype_calculated::find_formulas | ( | $text | ) |
Find all the formulas in a bit of text.
For example, called with "What is {a} plus {b}? (Hint, it is not {={a}*{b}}.)" this returns ['{a}*{b}'].
$text | text to analyse. |
array | where they keys an values are the formulas. |
|
inherited |
Utility method used by qtype_renderer::head_code().
It looks for any of the files script.js or script.php that exist in the plugin folder and ensures they get included.
qtype_calculated::finished_edit_wizard | ( | $form | ) |
Returns true if the editing wizard is finished, false otherwise.
The default implementation returns true, which is suitable for all question- types that only use one editing form. This function is used in question.php to decide whether we can regrade any states of the edited question and redirect to edit.php.
The dataset dependent question-type, which is extended by the calculated question-type, overwrites this method because it uses multiple pages (i.e. a wizard) to set up the question and associated datasets.
object | $form | The data submitted by the previous page. |
bool | Whether the wizard's last page was submitted or not. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedsimple.
|
inherited |
Abstract function implemented by each question type.
It runs all the code required to set up and save a question of any type for testing purposes. Alternate DB table prefix may be used to facilitate data deletion.
|
protectedinherited |
Get question context by category id.
int | $category |
object\$context |
qtype_calculated::get_database_dataset_items | ( | $definition | ) |
This function get the dataset items using id as unique parameter and return an array with itemnumber as index sorted ascendant If the multiple records with the same itemnumber exist, only the newest one i.e with the greatest id is used, the others are ignored but not deleted.
|
inherited |
Return default value for a given form element either from user_preferences table or $default.
string | $name | the name of the form element. |
mixed | $default | default value. |
string|null | default value for a given form element. |
|
inherited |
Get extra actions for a question of this type to add to the question bank edit menu.
This method is called if the edit_menu_column is being used in the question bank, which it is by default since Moodle 3.8. If applicable for your question type, you can return arn array of . These will be added at the end of the Edit menu for this question. The $question object passed in will have a hard-to-predict set of fields, because the fields present depend on which columns are included in the question bank view. However, you can rely on 'id', 'createdby', 'contextid', 'hidden' and 'category' (id) being present, and so you can call question_has_capability_on without causing performance problems. stdClass $question the available information about the particular question the action is for. action_menu_link[] any actions you want to add to the Edit menu for this question.
|
inherited |
Method called by display_question_editing_page and by question.php to get heading for breadcrumbs.
string | the heading |
qtype_calculated::get_possible_responses | ( | $questiondata | ) |
This method should return all the possible types of response that are recognised for this question.
The question is modelled as comprising one or more subparts. For each subpart, there are one or more classes that that students response might fall into, each of those classes earning a certain score.
For example, in a shortanswer question, there is only one subpart, the text entry field. The response the student gave will be classified according to which of the possible $question->options->answers it matches.
For the matching question type, there will be one subpart for each question stem, and for each stem, each of the possible choices is a class of student's response.
A response is an object with two fields, ->responseclass is a string presentation of that response, and ->fraction, the credit for a response in that class.
Array keys have no specific meaning, but must be unique, and must be the same if this function is called repeatedly.
object | $question | the question definition data. |
array | keys are subquestionid, values are arrays of possible responses to that subquestion. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedmulti.
qtype_calculated::get_question_options | ( | $question | ) |
Loads the question type specific options for the question.
This function loads any question type specific options for the question from the database into the question object. This information is placed in the $question->options field. A question type is free, however, to decide on a internal structure of the options field.
bool | Indicates success or failure. |
object | $question | The question object for the question. This object should be updated to include the question type specific information (it is passed by reference). |
Reimplemented from question_type.
qtype_calculated::get_random_guess_score | ( | $questiondata | ) |
Calculate the score a monkey would get on a question by clicking randomly.
Some question types have significant non-zero average expected score of the response is just selected randomly. For example 50% for a true-false question. It is useful to know what this is. For example it gets shown in the quiz statistics report.
For almost any open-ended question type (E.g. shortanswer or numerical) this should be 0.
For selective response question types (e.g. multiple choice), you can probably compute this.
For particularly complicated question types the may be impossible or very difficult to compute. In this case return null. (Or, if the expected score is very tiny even though the exact value is unknown, it may appropriate to return 0.)
stdClass | $questiondata | data defining a question, as returned by question_bank\load_question_data(). |
number|null | either a fraction estimating what the student would score by guessing, or null, if it is not possible to estimate. |
Reimplemented from question_type.
qtype_calculated::get_short_question_name | ( | $stringtoshorten, | |
$characterlimit ) |
This function shortens a question name if it exceeds the character limit.
string | $stringtoshorten | the string to be shortened. |
int | $characterlimit | the character limit. |
string |
|
inherited |
whether | the question_answers.answer field needs to have restore_decode_content_links_worker called on it. |
|
inherited |
Reimplemented in qtype_randomsamatch.
|
protectedinherited |
Save the file belonging to one text field.
array | $field | the data from the form (or from import). This will normally have come from the formslib editor element, so it will be an array with keys 'text', 'format' and 'itemid'. However, when we are importing, it will be an array with keys 'text', 'format' and 'files' |
object | $context | the context the question is in. |
string | $component | indentifies the file area question. |
string | $filearea | indentifies the file area questiontext, generalfeedback, answerfeedback, etc. |
int | $itemid | identifies the file area. |
string | the text for this field, after files have been processed. |
|
protected |
Initializes calculated answers for a given question.
question_definition | $question | The question definition object. |
stdClass | $questiondata | The question data object. |
|
protectedinherited |
Initialise the combined feedback fields.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
bool | $withparts | whether to set the shownumcorrect field. |
Reimplemented in qtype_ddmarker.
|
protectedinherited |
Initialise the question metadata.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
|
protectedinherited |
Initialise question custom fields.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
|
protectedinherited |
Initialise question_definition\answers field.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
bool | $forceplaintextanswers | most qtypes assume that answers are FORMAT_PLAIN, and dont use the answerformat DB column (it contains the default 0 = FORMAT_MOODLE). Therefore, by default this method ingores answerformat. Pass false here to use answerformat. For example multichoice does this. |
|
protectedinherited |
Initialise question_definition\hints field.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
|
protected |
Initialise the common question_definition fields.
question_definition | $question | the question_definition we are creating. |
object | $questiondata | the question data loaded from the database. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedmulti.
|
protectedinherited |
Returns true is answer with the $key is empty in the question data and should not be saved in DB.
The questions using question_answers table may want to overload this. Default code will work for shortanswer and similar question types.
object | $questiondata | This holds the information from the question editing form or import. |
int | $key | A key of the answer in question. |
bool | True if answer shouldn't be saved in DB. |
|
protectedinherited |
Returns true if extra answer fields for answer with the $key is empty in the question data and should not be saved in DB.
Questions where extra answer fields are optional will want to overload this.
object | $questiondata | This holds the information from the question editing form or import. |
int | $key | A key of the answer in question. |
bool | True if extra answer data shouldn't be saved in DB. |
|
protectedinherited |
Determine if the hint with specified number is not empty and should be saved.
Overload if you use custom hint controls.
object | $formdata | the data from the form. |
int | $number | number of hint under question. |
bool | $withparts | whether to take into account clearwrong and shownumcorrect options. |
bool | is this particular hint data empty. |
|
inherited |
bool | true if this question type sometimes requires manual grading. |
Reimplemented in qtype_essay, and qtype_random.
|
inherited |
object | $question | a question of this type. |
string | $otherquestionsinuse | comma-separate list of other question ids in this attempt. |
bool | true if a particular instance of this question requires manual grading. |
Reimplemented in qtype_random.
|
inherited |
bool | override this to return false if this is not really a question type, for example the description question type is not really a question type. |
Reimplemented in qtype_description.
|
inherited |
bool | true if this question type can be used by the random question type. |
Reimplemented in qtype_description, qtype_missingtype, qtype_random, and qtype_randomsamatch.
|
inherited |
string | the name of this question type in the user's language. You should not need to override this method, the default behaviour should be fine. |
|
protectedinherited |
Create a question_answer, or an appropriate subclass for this question, from a row loaded from the database.
object | $answer | the DB row from the question_answers table plus extra answer fields. |
question_answer |
Reimplemented in qtype_calculatedmulti, and qtype_multichoice.
|
protectedinherited |
Create a question_hint, or an appropriate subclass for this question, from a row loaded from the database.
object | $hint | the DB row from the question hints table. |
question_hint |
Reimplemented in qtype_calculatedmulti, qtype_ddimageortext, qtype_ddmarker, qtype_gapselect_base, qtype_match, qtype_multianswer, qtype_multichoice, and qtype_randomsamatch.
|
inherited |
Create an appropriate question_definition for the question of this type using data loaded from the database.
object | $questiondata | the question data loaded from the database. |
question_definition | the corresponding question_definition. |
Reimplemented in qtype_missingtype, and qtype_random.
|
protectedinherited |
Create an appropriate question_definition for the question of this type using data loaded from the database.
object | $questiondata | the question data loaded from the database. |
question_definition | an instance of the appropriate question_definition subclass. Still needs to be initialised. |
Reimplemented in qtype_calculatedmulti, and qtype_multichoice.
|
inherited |
The name this question should appear as in the create new question dropdown.
Override this method to return false if you don't want your question type to be createable, for example if it is an abstract base type, otherwise, you should not need to override this method.
mixed | the desired string, or false to hide this question type in the menu. |
Reimplemented in qtype_missingtype, and qtype_random.
qtype_calculated::move_files | ( | $questionid, | |
$oldcontextid, | |||
$newcontextid ) |
Move all the files belonging to this question from one context to another.
int | $questionid | the question being moved. |
int | $oldcontextid | the context it is moving from. |
int | $newcontextid | the context it is moving to. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedmulti.
|
protectedinherited |
Move all the files belonging to this question's answers when the question is moved from one context to another.
int | $questionid | the question being moved. |
int | $oldcontextid | the context it is moving from. |
int | $newcontextid | the context it is moving to. |
bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
|
protectedinherited |
Move all the files belonging to this question's answers when the question is moved from one context to another.
int | $questionid | the question being moved. |
int | $oldcontextid | the context it is moving from. |
int | $newcontextid | the context it is moving to. |
bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
|
protectedinherited |
Move all the files belonging to this question's hints when the question is moved from one context to another.
int | $questionid | the question being moved. |
int | $oldcontextid | the context it is moving from. |
int | $newcontextid | the context it is moving to. |
bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
|
inherited |
string | the name of this question type. |
|
inherited |
string | the URL of the folder this plugin's files live in. |
|
inherited |
string | the full path of the folder this plugin's files live in. |
|
inherited |
string | the full frankenstyle name for this plugin. |
qtype_calculated::preparedatasets | ( | $form, | |
$questionfromid = '0' ) |
This method prepare the $datasets in a format similar to dadatesetdefinitions_form.php so that they can be saved using the function save_dataset_definitions($form) when creating a new calculated question or when editing an already existing calculated question or by function save_as_new_dataset_definitions($form, $initialid) when saving as new an already existing calculated question.
object | $form | |
int | $questionfromid | default = '0' |
qtype_calculated::print_dataset_definitions_category | ( | $form | ) |
This function build a table showing the available category shareable wild cards, their name, their definition (Min, Max, Decimal) , the item count and the name of the question where they are used.
This table is intended to be add before the question text to help the user use these wild cards
qtype_calculated::print_dataset_definitions_category_shared | ( | $question, | |
$datasetdefsq ) |
This function build a table showing the available category shareable wild cards, their name, their definition (Min, Max, Decimal) , the item count and the name of the question where they are used.
This table is intended to be add before the question text to help the user use these wild cards
|
inherited |
If the quetsion type uses files in responses, then this method should return an array of all the response variables that might have corresponding files.
For example, the essay qtype returns array('attachments', 'answers').
array | response variable names that may have associated files. |
Reimplemented in qtype_essay.
|
protectedinherited |
Can be used to save_question_options() to transfer the combined feedback fields from $formdata to $options.
object | $options | the $question->options object being built. |
object | $formdata | the data from the form. |
object | $context | the context the quetsion is being saved into. |
bool | $withparts | whether $options->shownumcorrect should be set. |
|
inherited |
Save question defaults when creating new questions.
stdClass | $fromform | data from the form. |
Reimplemented in qtype_ddimageortext, qtype_ddmarker, qtype_essay, qtype_gapselect_base, qtype_match, qtype_multichoice, qtype_numerical, qtype_shortanswer, and qtype_truefalse.
|
protectedinherited |
Save additional question type data into the hint optional field.
Overload if you use custom hint information.
object | $formdata | the data from the form. |
int | $number | number of hint to get options from. |
bool | $withparts | whether question have parts. |
string | value to save into the options field of question_hints table. |
qtype_calculated::save_question | ( | $question, | |
$form ) |
this version save the available data at the different steps of the question editing process without using global $SESSION as storage between steps at the first step $wizardnow = 'question' when creating a new question when modifying a question when copying as a new question the general parameters and answers are saved using parent\save_question then the datasets are prepared and saved at the second step $wizardnow = 'datasetdefinitions' the datadefs final type are defined as private, category or not a datadef at the third step $wizardnow = 'datasetitems' the datadefs parameters and the data items are created or defined
object | question | |
object | $form | |
int | $course | |
PARAM_ALPHA | $wizardnow | should be added as we are coming from question2.php |
Reimplemented from question_type.
|
inherited |
Save the answers, with any extra data.
Questions that use answers will call it from save_question_options().
object | $question | This holds the information from the editing form, it is not a standard question object. |
object\$result-,>error | or $result->notice |
qtype_calculated::save_question_options | ( | $question | ) |
Saves question-type specific options.
This is called by save_question() to save the question-type specific data
object\$result-,>error | or $result->notice |
object | $question | This holds the information from the editing form, it is not a standard question object. |
Reimplemented from question_type.
Reimplemented in qtype_calculatedmulti, and qtype_calculatedsimple.
|
inherited |
Set any missing settings for this question to the default values.
This is called before displaying the question editing form.
object | $questiondata | the question data, loaded from the databsae, or more likely a newly created question object that is only partially initialised. |
|
inherited |
Save the default value for a given form element in user_preferences table.
string | $name | the name of the value to set. |
string | $value | the setting value. |
|
protected |
Verify that an answer is OK.
We throw an exception here because this should have already been validated by the form. This is just a last line of defence to prevent a question being stored in the database if it has bad formulas. This saves us from, for example, malicious imports.
string | $text | containing equations. |
Reimplemented in qtype_calculatedmulti.
|
protected |
Validate data before save.
stdClass | $question | data from the form / import file. |
Reimplemented in qtype_calculatedmulti.
|
protected |
Verify that the equations in part of the question are OK.
We throw an exception here because this should have already been validated by the form. This is just a last line of defence to prevent a question being stored in the database if it has bad formulas. This saves us from, for example, malicious imports.
string | $text | containing equations. |
|
protectedinherited |
string const qtype_calculated::PLACEHOLDER_REGEX_PART = '[[:alpha:]][^>} <`{"\']*' |
a placeholder is a letter, followed by almost any characters.
(This should probably be restricted more.)