Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Public Member Functions | |
backup_define_structure (int $instanceid, backup_nested_element $customfieldselement) | |
Run the custom field backup callback for each controller. | |
can_configure () | |
The current user can configure custom fields on this component. | |
can_edit (field_controller $field, int $instanceid=0) | |
The current user can edit custom fields for the given question. | |
can_view (field_controller $field, int $instanceid) | |
The current user can view custom fields for the given question. | |
can_view_type (field_controller $field, context $context) | |
Determine if the current user can view custom field in their given context. | |
config_form_definition (\MoodleQuickForm $mform) | |
Add custom controls to the field configuration form that will be saved. | |
create_category (string $name=null) | |
Creates a new category and inserts it to the database. | |
delete_all () | |
Deletes all data and all fields and categories defined in this handler. | |
delete_category (category_controller $category) | |
Permanently delete category, all fields in it and all associated data. | |
delete_field_configuration (field_controller $field) | |
Permanently delete a custom field configuration and all associated data. | |
delete_instance (int $instanceid) | |
Deletes all data related to all fields of an instance. | |
display_custom_categories_fields (array $catfielddata) | |
Render the custom field category and filed data as HTML ready for display. | |
display_custom_field_table (object $fielddata) | |
Get the custom data for the given field and render HTML ready for display in question table. | |
display_custom_fields_data (array $fieldsdata) | |
Display visible custom fields. | |
export_instance_data (int $instanceid, bool $returnall=false) | |
Returns the custom field values for an individual instance ready to be displayed. | |
export_instance_data_object (int $instanceid, bool $returnall=false) | |
Returns the custom field values for an individual instance ready to be displayed. | |
get_area () | |
Get area. | |
get_available_field_types () | |
Get field types array. | |
get_categories_fields_data (int $instanceid) | |
For a given instance id (question id) get the categories and the fields with any data. | |
get_categories_with_fields () | |
Returns array of categories, each of them contains a list of fields definitions. | |
get_component () | |
Get component. | |
get_configuration_context () | |
Context that should be used for new categories created by this handler. | |
get_configuration_url () | |
URL for configuration page for the fields for the question custom fields. | |
get_description_text_options () | |
Options for processing embedded files in the field description. | |
get_editable_fields (int $instanceid) | |
Get editable fields. | |
get_field_data (\core_customfield\field_controller $field, int $instanceid) | |
Given a field and instance id get all the filed data. | |
get_fields () | |
Returns list of fields defined for this instance as an array (not groupped by categories) | |
get_instance_context (int $instanceid=0) | |
Returns the context for the data associated with the given instanceid. | |
get_instance_data (int $instanceid, bool $returnall=false) | |
Returns the custom field values for an individual instance. | |
get_instance_data_for_backup (int $instanceid) | |
Get raw data associated with all fields current user can view or edit. | |
get_instances_data (array $instanceids, bool $returnall=false) | |
Returns the custom fields values for multiple instances. | |
get_itemid () | |
Get itemid. | |
instance_form_before_set_data (stdClass $instance) | |
Prepares the custom fields data related to the instance to pass to mform->set_data() | |
instance_form_definition (\MoodleQuickForm $mform, int $instanceid=0, ?string $headerlangidentifier=null, ?string $headerlangcomponent=null) | |
Adds custom fields to instance editing form. | |
instance_form_definition_after_data (\MoodleQuickForm $mform, int $instanceid=0) | |
Form data definition callback. | |
instance_form_save (stdClass $instance, bool $isnewinstance=false) | |
Saves the given data for custom fields, must be called after the instance is saved and id is present. | |
instance_form_validation (array $data, array $files) | |
Validates the given data for custom fields, used in moodleform validation() function. | |
move_category (category_controller $category, int $beforeid=0) | |
Change sort order of the categories. | |
move_field (field_controller $field, int $categoryid, int $beforeid=0) | |
Change fields sort order, move field to another category. | |
rename_category (category_controller $category, string $name) | |
Change name for a field category. | |
restore_define_structure (\restore_structure_step $step, int $newid, int $oldid) | |
Run the custom field restore callback for each controller. | |
restore_instance_data_from_backup (\restore_task $task, array $data) | |
Creates or updates the question custom field data when restoring from a backup. | |
save_field_configuration (field_controller $field, stdClass $data) | |
Save the field configuration with the data from the form. | |
set_parent_context (\context $context) | |
Sets parent context for the question. | |
uses_categories () | |
Uses categories. | |
Static Public Member Functions | |
static | create (int $itemid=0) |
Creates the custom field handler and returns a singleton. | |
static | get_handler (string $component, string $area, int $itemid=0) |
Returns an instance of handler by component/area/itemid. | |
static | reset_caches () |
Run reset code after unit tests to reset the singleton usage. | |
Protected Member Functions | |
can_backup (field_controller $field, int $instanceid) | |
Checks if current user can backup a given field. | |
clear_configuration_cache () | |
Clears a list of categories with corresponding fields definitions. | |
generate_category_name ($suffix=0) | |
Generates a name for the new category. | |
get_parent_context () | |
Returns the parent context for the question. | |
get_visible_fields (int $instanceid) | |
Get visible fields. | |
validate_category (category_controller $category) | |
Validate that the given category belongs to this handler. | |
validate_field (field_controller $field) | |
Validate that the given field belongs to this handler. | |
Protected Attributes | |
category_controller[] | $categories = null |
context | $parentcontext |
Static Protected Attributes | |
static question_handler | $singleton |
|
inherited |
Run the custom field backup callback for each controller.
int | $instanceid | The instance ID. |
backup_nested_element | $customfieldselement | The custom field element to be backed up. |
|
protectedinherited |
Checks if current user can backup a given field.
Capability to backup the instance does not need to be checked here
field_controller | $field | |
int | $instanceid |
bool |
qbank_customfields\customfield\question_handler::can_configure | ( | ) |
The current user can configure custom fields on this component.
bool | true if the current can configure custom fields, false otherwise |
Reimplemented from core_customfield\handler.
qbank_customfields\customfield\question_handler::can_edit | ( | field_controller | $field, |
int | $instanceid = 0 ) |
The current user can edit custom fields for the given question.
field_controller | $field | |
int | $instanceid | id of the question to test edit permission |
bool | true if the current can edit custom fields, false otherwise |
Reimplemented from core_customfield\handler.
qbank_customfields\customfield\question_handler::can_view | ( | field_controller | $field, |
int | $instanceid ) |
The current user can view custom fields for the given question.
field_controller | $field | |
int | $instanceid | id of the question to test edit permission |
bool | true if the current can edit custom fields, false otherwise |
Reimplemented from core_customfield\handler.
qbank_customfields\customfield\question_handler::can_view_type | ( | field_controller | $field, |
context | $context ) |
Determine if the current user can view custom field in their given context.
This determines if the user can see the field at all not just the field for a particular instance. Used primarily in showing or not the field in the question bank table.
field_controller | $field | The field trying to be viewed. |
context | $context | The context the field is being displayed in. |
bool | true if the current can edit custom fields, false otherwise. |
qbank_customfields\customfield\question_handler::config_form_definition | ( | \MoodleQuickForm | $mform | ) |
Add custom controls to the field configuration form that will be saved.
MoodleQuickForm | $mform | The form to add the custom fields to. |
Reimplemented from core_customfield\handler.
|
static |
Creates the custom field handler and returns a singleton.
Itemid is always zero as the custom fields are the same for every question across the system.
int | $itemid | Always zero. |
qbank_customfields\customfield\question_handler |
Reimplemented from core_customfield\handler.
|
inherited |
Creates a new category and inserts it to the database.
string | $name | name of the category, null to generate automatically |
int | id of the new category |
|
inherited |
Permanently delete category, all fields in it and all associated data.
category_controller | $category |
bool |
|
inherited |
Permanently delete a custom field configuration and all associated data.
field_controller | $field |
bool |
|
inherited |
Deletes all data related to all fields of an instance.
int | $instanceid |
qbank_customfields\customfield\question_handler::display_custom_categories_fields | ( | array | $catfielddata | ) |
Render the custom field category and filed data as HTML ready for display.
array | $catfielddata | Array of categories and field names and values. |
string | The HTML to display. |
qbank_customfields\customfield\question_handler::display_custom_field_table | ( | object | $fielddata | ) |
Get the custom data for the given field and render HTML ready for display in question table.
object | $fielddata | The field data used for display. |
string | The HTML to display in the table column. |
|
inherited |
Display visible custom fields.
This is a sample implementation that can be overridden in each handler.
data_controller[] | $fieldsdata |
string |
|
inherited |
Returns the custom field values for an individual instance ready to be displayed.
The caller must check access to the instance itself before invoking this method
The result is an array of core_customfield\output\field_data objects
int | $instanceid | |
bool | $returnall |
core_customfield\output\field_data[] |
|
inherited |
Returns the custom field values for an individual instance ready to be displayed.
The caller must check access to the instance itself before invoking this method
The result is a class where properties are fields short names and the values their export values for this instance
int | $instanceid | |
bool | $returnall |
stdClass |
|
protectedinherited |
Generates a name for the new category.
int | $suffix |
string |
|
inherited |
Get area.
string |
|
inherited |
Get field types array.
array |
qbank_customfields\customfield\question_handler::get_categories_fields_data | ( | int | $instanceid | ) |
For a given instance id (question id) get the categories and the fields with any data.
Return an array of categories containing an array of field names and values that is ready to be passed to a renderer.
int | $instanceid | The instance id to get the data for. |
array\$cfdata | The fetched data |
|
inherited |
Returns array of categories, each of them contains a list of fields definitions.
category_controller[] |
|
inherited |
Get component.
string |
qbank_customfields\customfield\question_handler::get_configuration_context | ( | ) |
Context that should be used for new categories created by this handler.
context | the context for configuration |
Reimplemented from core_customfield\handler.
qbank_customfields\customfield\question_handler::get_configuration_url | ( | ) |
URL for configuration page for the fields for the question custom fields.
moodle_url | The URL to configure custom fields for this component |
Reimplemented from core_customfield\handler.
|
inherited |
Options for processing embedded files in the field description.
Handlers may want to extend it to disable files support and/or specify 'noclean'=>true Context is not necessary here
array |
|
inherited |
Get editable fields.
int | $instanceid |
field_controller[] |
qbank_customfields\customfield\question_handler::get_field_data | ( | \core_customfield\field_controller | $field, |
int | $instanceid ) |
Given a field and instance id get all the filed data.
field_controller | $field | The field to get the data for. |
int | $instanceid | The instance id to get the data for. |
core_customfield\data_controller | The fetched data. |
|
inherited |
Returns list of fields defined for this instance as an array (not groupped by categories)
Fields are sorted in the same order they would appear on the instance edit form
Note that this function returns all fields in all categories regardless of whether the current user can view or edit data associated with them
field_controller[] |
|
staticinherited |
Returns an instance of handler by component/area/itemid.
string | $component | component name of full frankenstyle plugin name |
string | $area | name of the area (each component/plugin may define handlers for multiple areas) |
int | $itemid | item id if the area uses them (usually not used) |
handler |
qbank_customfields\customfield\question_handler::get_instance_context | ( | int | $instanceid = 0 | ) |
Returns the context for the data associated with the given instanceid.
int | $instanceid | id of the record to get the context for |
context | the context for the given record |
coding_exception |
Reimplemented from core_customfield\handler.
|
inherited |
Returns the custom field values for an individual instance.
The caller must check access to the instance itself before invoking this method
The result is an array of data_controller objects
int | $instanceid | |
bool | $returnall | return data for all fields (by default only visible fields) |
data_controller[] | array of data_controller objects indexed by fieldid. All fields are present, some data_controller objects may have 'id', some not In the last case data_controller\get_value() and export_value() functions will return default values. |
|
inherited |
Get raw data associated with all fields current user can view or edit.
int | $instanceid |
array |
Reimplemented in core_group\customfield\group_handler, and core_group\customfield\grouping_handler.
|
inherited |
Returns the custom fields values for multiple instances.
The caller must check access to the instance itself before invoking this method
The result is an array of data_controller objects
int[] | $instanceids | |
bool | $returnall | return data for all fields (by default only visible fields) |
data_controller[][] | 2-dimension array, first index is instanceid, second index is fieldid. All instanceids and all fieldids are present, some data_controller objects may have 'id', some not. In the last case data_controller\get_value() and export_value() functions will return default values. |
|
inherited |
Get itemid.
int|null |
|
protected |
Returns the parent context for the question.
context |
|
protectedinherited |
Get visible fields.
int | $instanceid |
field_controller[] |
|
inherited |
Prepares the custom fields data related to the instance to pass to mform->set_data()
Example: $instance = $DB->get_record(...); // .... prepare editor, filemanager, add tags, etc. $handler->instance_form_before_set_data($instance); $form->set_data($instance);
stdClass | $instance | the instance that has custom fields, if 'id' attribute is present the custom fields for this instance will be added, otherwise the default values will be added. |
|
inherited |
Adds custom fields to instance editing form.
Example: public function definition() { // ... normal instance definition, including hidden 'id' field. $handler->instance_form_definition($this->_form, $instanceid); $this->add_action_buttons(); }
MoodleQuickForm | $mform | |
int | $instanceid | id of the instance, can be null when instance is being created |
string | $headerlangidentifier | If specified, a lang string will be used for field category headings |
string | $headerlangcomponent |
|
inherited |
Form data definition callback.
This method is called from moodleform\definition_after_data and allows to tweak mform with some data coming directly from the field plugin data controller.
MoodleQuickForm | $mform | |
int | $instanceid |
|
inherited |
Saves the given data for custom fields, must be called after the instance is saved and id is present.
Example: if ($data = $form->get_data()) { // ... save main instance, set $data->id if instance was created. $handler->instance_form_save($data); redirect(...); }
stdClass | $instance | data received from a form |
bool | $isnewinstance | if this is call is made during instance creation |
|
inherited |
Validates the given data for custom fields, used in moodleform validation() function.
Example: public function validation($data, $files) { $errors = []; // .... check other fields. $errors = array_merge($errors, $handler->instance_form_validation($data, $files)); return $errors; }
array | $data | |
array | $files |
array | validation errors |
|
inherited |
Change sort order of the categories.
category_controller | $category | category that needs to be moved |
int | $beforeid | id of the category this category needs to be moved before, 0 to move to the end |
|
inherited |
Change fields sort order, move field to another category.
field_controller | $field | field that needs to be moved |
int | $categoryid | category that needs to be moved |
int | $beforeid | id of the category this category needs to be moved before, 0 to move to the end |
|
inherited |
Change name for a field category.
category_controller | $category | |
string | $name |
|
inherited |
Run the custom field restore callback for each controller.
restore_structure_step | $step | The restore step instance. |
int | $newid | The new ID for the custom field data after restore. |
int | $oldid | The original ID of the custom field data before backup. |
qbank_customfields\customfield\question_handler::restore_instance_data_from_backup | ( | \restore_task | $task, |
array | $data ) |
Creates or updates the question custom field data when restoring from a backup.
restore_task | $task | |
array | $data |
int|void | Conditionally returns the ID of the created or updated record. |
Reimplemented from core_customfield\handler.
|
inherited |
Save the field configuration with the data from the form.
field_controller | $field | |
stdClass | $data | data from the form |
qbank_customfields\customfield\question_handler::set_parent_context | ( | \context | $context | ) |
Sets parent context for the question.
This may be needed when question is being created, there is no question context but we need to check capabilities
context | $context |
|
inherited |
Uses categories.
bool |
|
protectedinherited |
Validate that the given category belongs to this handler.
category_controller | $category |
category_controller |
moodle_exception |
|
protectedinherited |
Validate that the given field belongs to this handler.
field_controller | $field |
field_controller |
moodle_exception |