Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Base class for drag-and-drop onto images editing form definition. More...
Public Member Functions | |
_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. | |
add_sticky_action_buttons (bool $cancel=true, ?string $submitlabel=null) | |
Use this method to make a sticky submit/cancel button at the end of your form. | |
definition_after_data () | |
Tweak the form with values provided by custom fields in use. | |
display () | |
Print html form. | |
filter_shown_headers (array $shownonly) | |
Use this method to indicate that the fieldsets should be shown as expanded and all other fieldsets should be hidden. | |
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_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. | |
js_call () | |
Performce the needed JS setup for this question type. | |
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 ($fromform, $files) | |
Dummy stub method - override if you needed to perform some extra validation. | |
Static Public Member Functions | |
static | file_picker_options () |
Options shared by all file pickers in the form. | |
static | file_uploaded ($draftitemid) |
Checks to see if a file has been uploaded. | |
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. | |
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. | |
after_definition () | |
After definition hook. | |
can_preview () | |
Is the question being edited in a state where it can be previewed? | |
data_preprocessing ($question) | |
Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form. | |
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. | |
definition () | |
Build the form definition. | |
definition_draggable_items ($mform, $itemrepeatsatstart) | |
Builds and adds the needed form items for draggable items. | |
definition_drop_zones ($mform, $imagerepeats) | |
Make and add drop zones to the form. | |
definition_inner ($mform) | |
definition_inner adds all specific fields to the form. | |
draggable_item ($mform) | |
Creates and returns a set of form elements to make a draggable item. | |
draggable_items_repeated_options () | |
Returns an array of default repeat options. | |
drop_zone ($mform, $imagerepeats) | |
Returns an array with a drop zone form element. | |
drop_zones_repeated_options () | |
Returns an array of default drop zone repeat options. | |
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_drag_item_repeats () | |
Returns an array of starting number of repeats, and the total number of repeats. | |
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. | |
get_per_answer_fields ($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) | |
Get the list of form elements to repeat, one for each answer. | |
validate_draft_files () | |
Internal method. | |
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 | |
$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. | |
Static Protected Attributes | |
static int | $uniqueid = 0 |
Unique identifier to be used for action buttons. | |
Base class for drag-and-drop onto images editing form definition.
|
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.
object | $mform | the form being built. |
$label | the label to use for each option. | |
$gradeoptions | the possible grades for each answer. | |
$minoptions | the minimum number of answer blanks to display. Default QUESTION_NUMANS_START. | |
$addoptions | the number of answer blanks to add. Default QUESTION_NUMANS_ADD. |
|
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.
object | $mform | The form being built |
|
protectedinherited |
Is the question being edited in a state where it can be previewed?
bool | whether to show the preview link. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_calculatedsimple_edit_form.
|
protectedinherited |
Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.
object | $question | the data being passed to the form. |
object\$question | the modified data. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_calculatedsimple_edit_form, qtype_ddimageortext_edit_form, qtype_ddmarker_edit_form, qtype_essay_edit_form, qtype_gapselect_edit_form_base, qtype_match_edit_form, qtype_multichoice_edit_form, qtype_numerical_edit_form, qtype_ordering_edit_form, qtype_randomsamatch_edit_form, qtype_shortanswer_edit_form, and qtype_truefalse_edit_form.
|
protectedinherited |
Perform the necessary preprocessing for the fields added by add_per_answer_fields().
object | $question | the data being passed to the form. |
object\$question | the modified data. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_numerical_edit_form.
|
protectedinherited |
Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().
object | $question | the data being passed to the form. |
object\$question | the modified data. |
|
protectedinherited |
Perfmorm preprocessing for particular extra answer field.
Questions with non-trivial DB - form element relationship will want to override this.
object | $answer | an answer object to get extra field from. |
string | $field | extra answer field name. |
field | value to be set to the form. |
|
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.
object | $question | the data being passed to the form. |
array | $extraanswerfields | extra answer fields (without table name). |
object\$question | the modified data. |
|
protectedinherited |
Perform the necessary preprocessing for the hint fields.
object | $question | The data being passed to the form. |
bool | $withclearwrong | Clear wrong hints. |
bool | $withshownumpartscorrect | Show number correct. |
stdClass | The modified data. |
Reimplemented in qtype_ddmarker_edit_form, and qtype_ordering_edit_form.
|
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.
|
inherited |
Tweak the form with values provided by custom fields in use.
Reimplemented from moodleform.
|
abstractprotected |
Builds and adds the needed form items for draggable items.
object | $mform | The Moodle form object. |
int | $itemrepeatsatstart | The initial number of repeat elements. |
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
protected |
Make and add drop zones to the form.
object | $mform | The Moodle form object. |
int | $imagerepeats | The initial number of repeat elements. |
|
protected |
definition_inner adds all specific fields to the form.
MoodleQuickForm | $mform | (the form being built). |
Reimplemented from question_edit_form.
Reimplemented in qtype_ddmarker_edit_form.
|
abstractprotected |
Creates and returns a set of form elements to make a draggable item.
object | $mform | The Moodle form object. |
array | An array of form elements. |
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
abstractprotected |
Returns an array of default repeat options.
array |
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
abstractprotected |
Returns an array with a drop zone form element.
object | $mform | The Moodle form object. |
int | $imagerepeats | The number of repeat images. |
array | Array with the dropzone element. |
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
abstractprotected |
Returns an array of default drop zone repeat options.
array |
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
static |
Options shared by all file pickers in the form.
array | Array of filepicker options. |
|
static |
Checks to see if a file has been uploaded.
string | $draftitemid | The draft id |
bool | True if files exist, false if not. |
|
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}));
string | $name | the name of the form field. |
mixed | $default | default value. |
string|null | default value for a given form element. |
|
protected |
Returns an array of starting number of repeats, and the total number of repeats.
array |
|
protectedinherited |
Create the form elements required by one hint.
string | $withclearwrong | whether this quesiton type uses the 'Clear wrong' option on hints. |
string | $withshownumpartscorrect | whether this quesiton type uses the 'Show num parts correct' option on hints. |
array | form field elements for one hint. |
Reimplemented in qtype_ddmarker_edit_form, qtype_multichoice_edit_form, and qtype_ordering_edit_form.
|
protectedinherited |
Language string to use for 'Add {no} more {whatever we call answers}'.
Reimplemented in qtype_match_edit_form, qtype_numerical_edit_form, and qtype_shortanswer_edit_form.
|
protectedinherited |
Returns an array of editor options with collapsed options turned off.
array |
|
protectedinherited |
Get the list of form elements to repeat, one for each answer.
object | $mform | the form being built. |
$label | the label to use for each option. | |
$gradeoptions | the possible grades for each answer. | |
$repeatedoptions | reference to array of repeated options to fill | |
$answersoption | reference to return the name of $question->options field holding an array of answers |
array | of form fields. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_match_edit_form, qtype_multichoice_edit_form, and qtype_numerical_edit_form.
|
abstract |
Performce the needed JS setup for this question type.
Reimplemented in qtype_ddimageortext_edit_form, and qtype_ddmarker_edit_form.
|
abstractinherited |
Override this in the subclass to question type name.
the | question type name, should be the same as the name() method in the question type class. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_calculatedsimple_edit_form, qtype_ddimageortext_edit_form, qtype_ddmarker_edit_form, qtype_ddwtos_edit_form, qtype_description_edit_form, qtype_essay_edit_form, qtype_gapselect_edit_form, qtype_gapselect_edit_form_base, qtype_match_edit_form, qtype_missingtype_edit_form, qtype_multianswer_edit_form, qtype_multichoice_edit_form, qtype_numerical_edit_form, qtype_ordering_edit_form, qtype_random_edit_form, qtype_randomsamatch_edit_form, qtype_shortanswer_edit_form, and qtype_truefalse_edit_form.
|
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
stdClass | array | $default_values | object or array of default values |
Reimplemented from moodleform.
Reimplemented in qtype_missingtype_edit_form, qtype_multianswer_edit_form, and qtype_random_edit_form.
|
inherited |
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.
array | $data | array of ("fieldname"=>value) of submitted data |
array | $files | array of uploaded files "element_name"=>tmp_file_path |
array | of "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too). |
Reimplemented from moodleform.
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_calculatedsimple_edit_form, qtype_ddimageortext_edit_form, qtype_ddmarker_edit_form, qtype_essay_edit_form, qtype_gapselect_edit_form_base, qtype_match_edit_form, qtype_missingtype_edit_form, qtype_multianswer_edit_form, qtype_multichoice_edit_form, qtype_numerical_edit_form, qtype_ordering_edit_form, qtype_random_edit_form, qtype_randomsamatch_edit_form, and qtype_shortanswer_edit_form.