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

Calculated question type editing form definition. More...

Inheritance diagram for qtype_calculated_edit_form:
qtype_numerical_edit_form question_edit_form question_wizard_form moodleform qtype_calculatedsimple_edit_form

Public Member Functions

 __construct ($submiturl, $question, $category, $contexts, $formeditable=true)
 
 _process_submission ($method)
 Internal method.
 
 _validate_files (&$files)
 Internal method.
 
 add_action_buttons ($cancel=true, $submitlabel=null)
 Use this method to a cancel and submit button to the end of your form.
 
 add_checkbox_controller ($groupid, $text=null, $attributes=null, $originalValue=0)
 Adds a link/button that controls the checked state of a group of checkboxes.
 
 data_preprocessing ($question)
 Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.
 
 definition_after_data ()
 Tweak the form with values provided by custom fields in use.
 
 display ()
 Print html form.
 
 focus ($name=NULL)
 To autofocus on first form element or first element with error.
 
 get_data ()
 Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data.
 
 get_file_content ($elname)
 Get content of uploaded file.
 
 get_new_filename ($elname=null)
 Returns name of uploaded file.
 
 get_per_answer_fields ($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption)
 Get the list of form elements to repeat, one for each answer.
 
 get_submitted_data ()
 Return submitted data without validation or NULL if there is no submitted data.
 
 init_javascript_enhancement ($element, $enhancement, array $options=array(), array $strings=null)
 Adds an initialisation call for a standard JavaScript enhancement.
 
 is_cancelled ()
 Return true if a cancel button has been pressed resulting in the form being submitted.
 
 is_submitted ()
 Check that form was submitted.
 
 is_validated ()
 Check that form data is valid.
 
 moodleform ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true)
 Old syntax of class constructor.
 
 no_submit_button_pressed ()
 Checks if button pressed is not for submitting the form.
 
 optional_param ($name, $default, $type)
 Checks if a parameter was passed in the previous form submission.
 
 qtype ()
 Override this in the subclass to question type name.
 
 render ()
 Renders the html form (same as display, but returns the result).
 
 repeat_elements ($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false, $deletebuttonname='')
 Method to add a repeating group of elements to a form.
 
 repeat_elements_fix_clone ($i, $elementclone, &$namecloned)
 Helper used by repeat_elements().
 
 save_file ($elname, $pathname, $override=false)
 Save file to standard filesystem.
 
 save_files ($destination)
 Save verified uploaded files into directory.
 
 save_stored_file ($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null)
 Save file to local filesystem pool.
 
 save_temp_file ($elname)
 Returns a temporary file, do not forget to delete after not needed any more.
 
 set_data ($question)
 Load in existing data as form defaults.
 
 set_display_vertical ()
 Set display mode for the form when labels take full width of the form and above the elements even on big screens.
 
 set_initial_dirty_state ($state=false)
 Set the initial 'dirty' state of the form.
 
 validate_defined_fields ($validateonnosubmit=false)
 Validate the form.
 
 validation ($data, $files)
 Dummy stub method - override if you needed to perform some extra validation.
 

Static Public Member Functions

static get_js_module ()
 Returns a JS module definition for the mforms JS.
 
static mock_ajax_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null)
 Used by tests to simulate submitted form data submission via AJAX.
 
static mock_generate_submit_keys ($data=[])
 Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data.
 
static mock_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null)
 Used by tests to simulate submitted form data submission from the user.
 

Public Attributes

 $activecategory
 
 $categorychanged = false
 
object $context
 current context
 
array $editoroptions
 html editor options
 
array $fileoptions
 options to preapre draft area
 
 $initialname = ''
 
object $instance
 instance of question type
 
qtype_calculated $qtypeobj
 Handle to the question type for this question.
 
 $questiondisplay
 
 $reload = false
 
const DEFAULT_NUM_HINTS = 2
 
int const UNITS_MIN_REPEATS = 1
 we always show at least this many sets of unit fields.
 
const UNITS_TO_ADD = 2
 

Protected Member Functions

 _get_post_params ()
 Internal method - should not be used anywhere.
 
 add_combined_feedback_fields ($withshownumpartscorrect=false)
 
 add_hidden_fields ()
 Add all the hidden form fields used by question/question.php.
 
 add_interactive_settings ($withclearwrong=false, $withshownumpartscorrect=false)
 
 add_per_answer_fields (&$mform, $label, $gradeoptions, $minoptions=QUESTION_NUMANS_START, $addoptions=QUESTION_NUMANS_ADD)
 Add a set of form fields, obtained from get_per_answer_fields, to the form, one for each existing answer, with some blanks for some new ones.
 
 add_tag_fields ($mform)
 Add the tag and course tag fields to the mform.
 
 add_unit_fields ($mform)
 Add the input areas for each unit.
 
 add_unit_options ($mform)
 Add the unit handling options to the form.
 
 after_definition ()
 After definition hook.
 
 can_preview ()
 Is the question being edited in a state where it can be previewed?
 
 data_preprocessing_answers ($question, $withanswerfiles=false)
 Perform the necessary preprocessing for the fields added by add_per_answer_fields().
 
 data_preprocessing_combined_feedback ($question, $withshownumcorrect=false)
 Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().
 
 data_preprocessing_extra_answer_field ($answer, $field)
 Perfmorm preprocessing for particular extra answer field.
 
 data_preprocessing_extra_answer_fields ($question, $extraanswerfields)
 Perform the necessary preprocessing for the extra answer fields.
 
 data_preprocessing_hints ($question, $withclearwrong=false, $withshownumpartscorrect=false)
 Perform the necessary preprocessing for the hint fields.
 
 data_preprocessing_unit_options ($question)
 Perform the necessary preprocessing for the fields added by add_unit_options().
 
 data_preprocessing_units ($question)
 Perform the necessary preprocessing for the fields added by add_unit_fields().
 
 definition ()
 Build the form definition.
 
 definition_inner ($mform)
 Add question-type specific form fields.
 
 get_array_value_by_keys (array $array, array $keys)
 Returns an element of multi-dimensional array given the list of keys.
 
 get_default_value (string $name, $default)
 Return default value for a given form element either from user_preferences table or $default.
 
 get_draft_files ($elname)
 Get draft files of a form element This is a protected method which will be used only inside moodleforms.
 
 get_form_identifier ()
 It should returns unique identifier for the form.
 
 get_hint_fields ($withclearwrong=false, $withshownumpartscorrect=false)
 Create the form elements required by one hint.
 
 get_more_choices_string ()
 Language string to use for 'Add {no} more {whatever we call answers}'.
 
 get_non_collabsible_editor_options ()
 Returns an array of editor options with collapsed options turned off.
 
 is_valid_answer ($answer, $data)
 Validate a particular answer.
 
 unit_group ($mform)
 Get the form fields needed to edit one unit.
 
 valid_answer_message ($answer)
 
 validate_answers ($data, $errors)
 Validate the answers.
 
 validate_draft_files ()
 Internal method.
 
 validate_numerical_options ($data, $errors)
 Validate the answers.
 
 validate_text ($errors, $field, $text)
 Validate the equations in the some question content.
 

Protected Attributes

array $_ajaxformdata
 submitted form data when using mforms with ajax
 
mixed $_customdata
 globals workaround
 
object $_definition_finalized = false
 definition_after_data executed flag
 
MoodleQuickForm $_form
 quickform object definition
 
string $_formname
 name of the form
 
bool null $_validated = null
 stores the validation result of this form or null if not yet validated
 
 $ap = null
 
 $category
 
 $categorycontext
 
 $contexts
 
object $customfieldhandler
 instance of custom field
 
bool $customfieldpluginenabled = true
 custom field plugin enabled or disabled
 
object $question
 Question object with options and answers already loaded by get_question_options Be careful how you use this it is needed sometimes to set up the structure of the form in definition_inner but data is always loaded into the form with set_data.
 

Detailed Description

Calculated question type editing form definition.

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

Constructor & Destructor Documentation

◆ __construct()

qtype_calculated_edit_form::__construct ( $submiturl,
$question,
$category,
$contexts,
$formeditable = true )

Reimplemented from question_edit_form.

Member Function Documentation

◆ add_per_answer_fields()

question_edit_form::add_per_answer_fields ( & $mform,
$label,
$gradeoptions,
$minoptions = QUESTION_NUMANS_START,
$addoptions = QUESTION_NUMANS_ADD )
protectedinherited

Add a set of form fields, obtained from get_per_answer_fields, to the form, one for each existing answer, with some blanks for some new ones.

Parameters
object$mformthe form being built.
$labelthe label to use for each option.
$gradeoptionsthe possible grades for each answer.
$minoptionsthe minimum number of answer blanks to display. Default QUESTION_NUMANS_START.
$addoptionsthe number of answer blanks to add. Default QUESTION_NUMANS_ADD.

◆ add_tag_fields()

question_edit_form::add_tag_fields ( $mform)
protectedinherited

Add the tag and course tag fields to the mform.

If the form is being built in a course context then add the field for course tags.

If the question category doesn't belong to a course context or we aren't editing in a course context then add the tags element to allow tags to be added to the question category context.

Parameters
object$mformThe form being built

◆ add_unit_fields()

qtype_numerical_edit_form::add_unit_fields ( $mform)
protectedinherited

Add the input areas for each unit.

Parameters
object$mformthe form being built.

◆ add_unit_options()

qtype_numerical_edit_form::add_unit_options ( $mform)
protectedinherited

Add the unit handling options to the form.

Parameters
object$mformthe form being built.

◆ can_preview()

qtype_calculated_edit_form::can_preview ( )
protected

Is the question being edited in a state where it can be previewed?

Return values
boolwhether to show the preview link.

Reimplemented from question_edit_form.

Reimplemented in qtype_calculatedsimple_edit_form.

◆ data_preprocessing()

qtype_calculated_edit_form::data_preprocessing ( $question)

Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

Reimplemented from qtype_numerical_edit_form.

Reimplemented in qtype_calculatedsimple_edit_form.

◆ data_preprocessing_answers()

qtype_calculated_edit_form::data_preprocessing_answers ( $question,
$withanswerfiles = false )
protected

Perform the necessary preprocessing for the fields added by add_per_answer_fields().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

Reimplemented from qtype_numerical_edit_form.

◆ data_preprocessing_combined_feedback()

question_edit_form::data_preprocessing_combined_feedback ( $question,
$withshownumcorrect = false )
protectedinherited

Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

◆ data_preprocessing_extra_answer_field()

question_edit_form::data_preprocessing_extra_answer_field ( $answer,
$field )
protectedinherited

Perfmorm preprocessing for particular extra answer field.

Questions with non-trivial DB - form element relationship will want to override this.

Parameters
object$answeran answer object to get extra field from.
string$fieldextra answer field name.
Return values
fieldvalue to be set to the form.

◆ data_preprocessing_extra_answer_fields()

question_edit_form::data_preprocessing_extra_answer_fields ( $question,
$extraanswerfields )
protectedinherited

Perform the necessary preprocessing for the extra answer fields.

Questions that do something not trivial when editing extra answer fields will want to override this.

Parameters
object$questionthe data being passed to the form.
array$extraanswerfieldsextra answer fields (without table name).
Return values
object\$questionthe modified data.

◆ data_preprocessing_hints()

question_edit_form::data_preprocessing_hints ( $question,
$withclearwrong = false,
$withshownumpartscorrect = false )
protectedinherited

Perform the necessary preprocessing for the hint fields.

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

Reimplemented in qtype_ddmarker_edit_form.

◆ data_preprocessing_unit_options()

qtype_numerical_edit_form::data_preprocessing_unit_options ( $question)
protectedinherited

Perform the necessary preprocessing for the fields added by add_unit_options().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

◆ data_preprocessing_units()

qtype_numerical_edit_form::data_preprocessing_units ( $question)
protectedinherited

Perform the necessary preprocessing for the fields added by add_unit_fields().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

◆ definition()

question_edit_form::definition ( )
protectedinherited

Build the form definition.

This adds all the form fields that the default question type supports. If your question type does not support all these fields, then you can override this method and remove the ones you don't want with $mform->removeElement().

Reimplemented from moodleform.

Reimplemented in qtype_random_edit_form.

◆ definition_after_data()

question_edit_form::definition_after_data ( )
inherited

Tweak the form with values provided by custom fields in use.

Reimplemented from moodleform.

◆ definition_inner()

qtype_calculated_edit_form::definition_inner ( $mform)
protected

Add question-type specific form fields.

Parameters
MoodleQuickForm$mformthe form being built.

Reimplemented from qtype_numerical_edit_form.

Reimplemented in qtype_calculatedsimple_edit_form.

◆ get_default_value()

question_edit_form::get_default_value ( string $name,
$default )
protectedinherited

Return default value for a given form element either from user_preferences table or $default.

To make use of user_preferences in your qtype default settings, you need to replace $mform->setDefault({elementname}, {defaultvalue}); in edit_{qtypename}_form.php with $mform->setDefault({elementname}, $this->get_default_value({elementname}, {defaultvalue}));

Parameters
string$namethe name of the form field.
mixed$defaultdefault value.
Return values
string|nulldefault value for a given form element.

◆ get_hint_fields()

question_edit_form::get_hint_fields ( $withclearwrong = false,
$withshownumpartscorrect = false )
protectedinherited

Create the form elements required by one hint.

Parameters
string$withclearwrongwhether this quesiton type uses the 'Clear wrong' option on hints.
string$withshownumpartscorrectwhether this quesiton type uses the 'Show num parts correct' option on hints.
Return values
arrayform field elements for one hint.

Reimplemented in qtype_ddmarker_edit_form, and qtype_multichoice_edit_form.

◆ get_more_choices_string()

qtype_numerical_edit_form::get_more_choices_string ( )
protectedinherited

Language string to use for 'Add {no} more {whatever we call answers}'.

Reimplemented from question_edit_form.

◆ get_non_collabsible_editor_options()

question_edit_form::get_non_collabsible_editor_options ( )
protectedinherited

Returns an array of editor options with collapsed options turned off.

Deprecated
since 2.6
Return values
array

◆ get_per_answer_fields()

qtype_calculated_edit_form::get_per_answer_fields ( $mform,
$label,
$gradeoptions,
& $repeatedoptions,
& $answersoption )

Get the list of form elements to repeat, one for each answer.

Parameters
object$mformthe form being built.
$labelthe label to use for each option.
$gradeoptionsthe possible grades for each answer.
$repeatedoptionsreference to array of repeated options to fill
$answersoptionreference to return the name of $question->options field holding an array of answers
Return values
arrayof form fields.

Reimplemented from qtype_numerical_edit_form.

◆ is_valid_answer()

qtype_calculated_edit_form::is_valid_answer ( $answer,
$data )
protected

Validate a particular answer.

Parameters
string$answeran answer to validate. Known to be non-blank and already trimmed.
array$datathe submitted data.
Return values
boolwhether this is a valid answer.

Reimplemented from qtype_numerical_edit_form.

◆ qtype()

qtype_calculated_edit_form::qtype ( )

Override this in the subclass to question type name.

Return values
thequestion type name, should be the same as the name() method in the question type class.

Reimplemented from qtype_numerical_edit_form.

Reimplemented in qtype_calculatedsimple_edit_form.

◆ set_data()

question_edit_form::set_data ( $default_values)
inherited

Load in existing data as form defaults.

Usually new entry defaults are stored directly in form definition (new entry form); this function is used to load in data where values already exist and data is being edited (edit entry form).

note: $slashed param removed

Parameters
stdClass | array$default_valuesobject or array of default values

Reimplemented from moodleform.

Reimplemented in qtype_missingtype_edit_form, qtype_multianswer_edit_form, and qtype_random_edit_form.

◆ unit_group()

qtype_numerical_edit_form::unit_group ( $mform)
protectedinherited

Get the form fields needed to edit one unit.

Parameters
MoodleQuickForm$mformthe form being built.
Return values
arrayof form fields.

◆ valid_answer_message()

qtype_calculated_edit_form::valid_answer_message ( $answer)
protected
Return values
stringerre describing what an answer should be.

Reimplemented from qtype_numerical_edit_form.

◆ validate_answers()

qtype_numerical_edit_form::validate_answers ( $data,
$errors )
protectedinherited

Validate the answers.

Parameters
array$datathe submitted data.
array$errorsthe errors array to add to.
Return values
arraythe updated errors array.

◆ validate_numerical_options()

qtype_numerical_edit_form::validate_numerical_options ( $data,
$errors )
protectedinherited

Validate the answers.

Parameters
array$datathe submitted data.
array$errorsthe errors array to add to.
Return values
arraythe updated errors array.

◆ validate_text()

qtype_calculated_edit_form::validate_text ( $errors,
$field,
$text )
protected

Validate the equations in the some question content.

Parameters
array$errorswhere errors are being accumulated.
string$fieldthe field being validated.
string$textthe content of that field.
Return values
arraythe updated $errors array.

◆ validation()

qtype_calculated_edit_form::validation ( $data,
$files )

Dummy stub method - override if you needed to perform some extra validation.

If there are errors return array of errors ("fieldname"=>"error message"), otherwise true if ok.

Server side rules do not work for uploaded files, implement serverside rules here if needed.

Parameters
array$dataarray of ("fieldname"=>value) of submitted data
array$filesarray of uploaded files "element_name"=>tmp_file_path
Return values
arrayof "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too).

Reimplemented from qtype_numerical_edit_form.

Reimplemented in qtype_calculatedsimple_edit_form.


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