Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
core_course\customfield\course_handler Class Reference

Course handler for custom fields. More...

Inheritance diagram for core_course\customfield\course_handler:
core_customfield\handler

Public Member Functions

 can_configure ()
 The current user can configure custom fields on this component. More...
 
 can_edit (field_controller $field, int $instanceid=0)
 The current user can edit custom fields on the given course. More...
 
 can_view (field_controller $field, int $instanceid)
 The current user can view custom fields on the given course. More...
 
 config_form_definition (\MoodleQuickForm $mform)
 Allows to add custom controls to the field configuration form that will be saved in configdata. More...
 
 create_category (string $name=null)
 Creates a new category and inserts it to the database. More...
 
 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. More...
 
 delete_field_configuration (field_controller $field)
 Permanently delete a custom field configuration and all associated data. More...
 
 delete_instance (int $instanceid)
 Deletes all data related to all fields of an instance. More...
 
 display_custom_fields_data (array $fieldsdata)
 Display visible custom fields. More...
 
 export_instance_data (int $instanceid, bool $returnall=false)
 Returns the custom field values for an individual instance ready to be displayed. More...
 
 export_instance_data_object (int $instanceid, bool $returnall=false)
 Returns the custom field values for an individual instance ready to be displayed. More...
 
 get_area ()
 Get area. More...
 
 get_available_field_types ()
 Get field types array. More...
 
 get_categories_with_fields ()
 Returns array of categories, each of them contains a list of fields definitions. More...
 
 get_component ()
 Get component. More...
 
 get_configuration_context ()
 Context that should be used for new categories created by this handler. More...
 
 get_configuration_url ()
 URL for configuration of the fields on this handler. More...
 
 get_description_text_options ()
 Options for processing embedded files in the field description. More...
 
 get_editable_fields (int $instanceid)
 Get editable fields. More...
 
 get_field_config_form (field_controller $field)
 The form to create or edit a field. More...
 
 get_fields ()
 Returns list of fields defined for this instance as an array (not groupped by categories) More...
 
 get_instance_context (int $instanceid=0)
 Returns the context for the data associated with the given instanceid. More...
 
 get_instance_data (int $instanceid, bool $returnall=false)
 Returns the custom field values for an individual instance. More...
 
 get_instance_data_for_backup (int $instanceid)
 Get raw data associated with all fields current user can view or edit. More...
 
 get_instances_data (array $instanceids, bool $returnall=false)
 Returns the custom fields values for multiple instances. More...
 
 get_itemid ()
 Get itemid. More...
 
 instance_form_before_set_data (stdClass $instance)
 Prepares the custom fields data related to the instance to pass to mform->set_data() More...
 
 instance_form_definition (\MoodleQuickForm $mform, int $instanceid=0, ?string $headerlangidentifier=null, ?string $headerlangcomponent=null)
 Adds custom fields to instance editing form. More...
 
 instance_form_definition_after_data (\MoodleQuickForm $mform, int $instanceid=0)
 Form data definition callback. More...
 
 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. More...
 
 instance_form_validation (array $data, array $files)
 Validates the given data for custom fields, used in moodleform validation() function. More...
 
 move_category (category_controller $category, int $beforeid=0)
 Change sort order of the categories. More...
 
 move_field (field_controller $field, int $categoryid, int $beforeid=0)
 Change fields sort order, move field to another category. More...
 
 rename_category (category_controller $category, string $name)
 Change name for a field category. More...
 
 restore_instance_data_from_backup (\restore_task $task, array $data)
 Creates or updates custom field data. More...
 
 save_field_configuration (field_controller $field, stdClass $data)
 Save the field configuration with the data from the form. More...
 
 set_parent_context (\context $context)
 Sets parent context for the course. More...
 
 setup_edit_page (field_controller $field)
 Set up page customfield/edit.php. More...
 
 uses_categories ()
 Uses categories. More...
 

Static Public Member Functions

static create (int $itemid=0)
 Returns a singleton. More...
 
static get_handler (string $component, string $area, int $itemid=0)
 Returns an instance of handler by component/area/itemid. More...
 
static reset_caches ()
 Run reset code after unit tests to reset the singleton usage.
 

Public Attributes

int const NOTVISIBLE = 0
 Field is not displayed in the course listing.
 
int const VISIBLETOALL = 2
 Field is displayed in the course listing, visible to everybody.
 
int const VISIBLETOTEACHERS = 1
 Field is displayed in the course listing but only for teachers.
 

Protected Member Functions

 can_backup (field_controller $field, int $instanceid)
 Checks if current user can backup a given field. More...
 
 clear_configuration_cache ()
 Clears a list of categories with corresponding fields definitions.
 
 generate_category_name ($suffix=0)
 Generates a name for the new category. More...
 
 get_parent_context ()
 Returns the parent context for the course. More...
 
 get_visible_fields (int $instanceid)
 Get visible fields. More...
 
 validate_category (category_controller $category)
 Validate that the given category belongs to this handler. More...
 
 validate_field (field_controller $field)
 Validate that the given field belongs to this handler. More...
 

Protected Attributes

category_controller[] $categories = null
 
context $parentcontext
 

Static Protected Attributes

static course_handler $singleton
 

Detailed Description

Course handler for custom fields.

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

Member Function Documentation

◆ can_backup()

core_customfield\handler::can_backup ( field_controller  $field,
int  $instanceid 
)
protectedinherited

Checks if current user can backup a given field.

Capability to backup the instance does not need to be checked here

Parameters
field_controller$field
int$instanceid
Return values
bool

◆ can_configure()

core_course\customfield\course_handler::can_configure ( )

The current user can configure custom fields on this component.

Return values
booltrue if the current can configure custom fields, false otherwise

Reimplemented from core_customfield\handler.

◆ can_edit()

core_course\customfield\course_handler::can_edit ( field_controller  $field,
int  $instanceid = 0 
)

The current user can edit custom fields on the given course.

Parameters
field_controller$field
int$instanceidid of the course to test edit permission
Return values
booltrue if the current can edit custom fields, false otherwise

Reimplemented from core_customfield\handler.

◆ can_view()

core_course\customfield\course_handler::can_view ( field_controller  $field,
int  $instanceid 
)

The current user can view custom fields on the given course.

Parameters
field_controller$field
int$instanceidid of the course to test edit permission
Return values
booltrue if the current can edit custom fields, false otherwise

Reimplemented from core_customfield\handler.

◆ config_form_definition()

core_course\customfield\course_handler::config_form_definition ( \MoodleQuickForm  $mform)

Allows to add custom controls to the field configuration form that will be saved in configdata.

Parameters
MoodleQuickForm$mform

Reimplemented from core_customfield\handler.

◆ create()

static core_course\customfield\course_handler::create ( int  $itemid = 0)
static

Returns a singleton.

Parameters
int$itemid
Return values
core_course::customfield::course_handler

Reimplemented from core_customfield\handler.

◆ create_category()

core_customfield\handler::create_category ( string  $name = null)
inherited

Creates a new category and inserts it to the database.

Parameters
string$namename of the category, null to generate automatically
Return values
intid of the new category

◆ delete_category()

core_customfield\handler::delete_category ( category_controller  $category)
inherited

Permanently delete category, all fields in it and all associated data.

Parameters
category_controller$category
Return values
bool

◆ delete_field_configuration()

core_customfield\handler::delete_field_configuration ( field_controller  $field)
inherited

Permanently delete a custom field configuration and all associated data.

Parameters
field_controller$field
Return values
bool

◆ delete_instance()

core_customfield\handler::delete_instance ( int  $instanceid)
inherited

Deletes all data related to all fields of an instance.

Parameters
int$instanceid

◆ display_custom_fields_data()

core_customfield\handler::display_custom_fields_data ( array  $fieldsdata)
inherited

Display visible custom fields.

This is a sample implementation that can be overridden in each handler.

Parameters
data_controller[]$fieldsdata
Return values
string

◆ export_instance_data()

core_customfield\handler::export_instance_data ( int  $instanceid,
bool  $returnall = false 
)
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

Parameters
int$instanceid
bool$returnall
Return values
core_customfield::output::field_data[]

◆ export_instance_data_object()

core_customfield\handler::export_instance_data_object ( int  $instanceid,
bool  $returnall = false 
)
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

Parameters
int$instanceid
bool$returnall
Return values
stdClass

◆ generate_category_name()

core_customfield\handler::generate_category_name (   $suffix = 0)
protectedinherited

Generates a name for the new category.

Parameters
int$suffix
Return values
string

◆ get_area()

core_customfield\handler::get_area ( )
inherited

Get area.

Return values
string

◆ get_available_field_types()

core_customfield\handler::get_available_field_types ( )
inherited

Get field types array.

Return values
array

◆ get_categories_with_fields()

core_customfield\handler::get_categories_with_fields ( )
inherited

Returns array of categories, each of them contains a list of fields definitions.

Return values
category_controller[]

◆ get_component()

core_customfield\handler::get_component ( )
inherited

Get component.

Return values
string

◆ get_configuration_context()

core_course\customfield\course_handler::get_configuration_context ( )

Context that should be used for new categories created by this handler.

Return values
contextthe context for configuration

Reimplemented from core_customfield\handler.

◆ get_configuration_url()

core_course\customfield\course_handler::get_configuration_url ( )

URL for configuration of the fields on this handler.

Return values
moodle_urlThe URL to configure custom fields for this component

Reimplemented from core_customfield\handler.

◆ get_description_text_options()

core_customfield\handler::get_description_text_options ( )
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

Return values
array

◆ get_editable_fields()

core_customfield\handler::get_editable_fields ( int  $instanceid)
inherited

Get editable fields.

Parameters
int$instanceid
Return values
field_controller[]

◆ get_field_config_form()

core_customfield\handler::get_field_config_form ( field_controller  $field)
inherited

The form to create or edit a field.

Parameters
field_controller$field
Return values
field_config_form

◆ get_fields()

core_customfield\handler::get_fields ( )
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

Return values
field_controller[]

◆ get_handler()

static core_customfield\handler::get_handler ( string  $component,
string  $area,
int  $itemid = 0 
)
staticinherited

Returns an instance of handler by component/area/itemid.

Parameters
string$componentcomponent name of full frankenstyle plugin name
string$areaname of the area (each component/plugin may define handlers for multiple areas)
int$itemiditem id if the area uses them (usually not used)
Return values
handler

◆ get_instance_context()

core_course\customfield\course_handler::get_instance_context ( int  $instanceid = 0)

Returns the context for the data associated with the given instanceid.

Parameters
int$instanceidid of the record to get the context for
Return values
contextthe context for the given record

Reimplemented from core_customfield\handler.

◆ get_instance_data()

core_customfield\handler::get_instance_data ( int  $instanceid,
bool  $returnall = false 
)
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

Parameters
int$instanceid
bool$returnallreturn data for all fields (by default only visible fields)
Return values
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.

◆ get_instance_data_for_backup()

core_customfield\handler::get_instance_data_for_backup ( int  $instanceid)
inherited

Get raw data associated with all fields current user can view or edit.

Parameters
int$instanceid
Return values
array

◆ get_instances_data()

core_customfield\handler::get_instances_data ( array  $instanceids,
bool  $returnall = false 
)
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

Parameters
int[]$instanceids
bool$returnallreturn data for all fields (by default only visible fields)
Return values
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.

◆ get_itemid()

core_customfield\handler::get_itemid ( )
inherited

Get itemid.

Return values
int|null

◆ get_parent_context()

core_course\customfield\course_handler::get_parent_context ( )
protected

Returns the parent context for the course.

Return values
context

◆ get_visible_fields()

core_customfield\handler::get_visible_fields ( int  $instanceid)
protectedinherited

Get visible fields.

Parameters
int$instanceid
Return values
field_controller[]

◆ instance_form_before_set_data()

core_customfield\handler::instance_form_before_set_data ( stdClass  $instance)
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);

Parameters
stdClass$instancethe 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.

◆ instance_form_definition()

core_customfield\handler::instance_form_definition ( \MoodleQuickForm  $mform,
int  $instanceid = 0,
?string  $headerlangidentifier = null,
?string  $headerlangcomponent = null 
)
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(); }

Parameters
MoodleQuickForm$mform
int$instanceidid of the instance, can be null when instance is being created
string$headerlangidentifierIf specified, a lang string will be used for field category headings
string$headerlangcomponent

◆ instance_form_definition_after_data()

core_customfield\handler::instance_form_definition_after_data ( \MoodleQuickForm  $mform,
int  $instanceid = 0 
)
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.

Parameters
MoodleQuickForm$mform
int$instanceid

◆ instance_form_save()

core_customfield\handler::instance_form_save ( stdClass  $instance,
bool  $isnewinstance = false 
)
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(...); }

Parameters
stdClass$instancedata received from a form
bool$isnewinstanceif this is call is made during instance creation

◆ instance_form_validation()

core_customfield\handler::instance_form_validation ( array  $data,
array  $files 
)
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; }

Parameters
array$data
array$files
Return values
arrayvalidation errors

◆ move_category()

core_customfield\handler::move_category ( category_controller  $category,
int  $beforeid = 0 
)
inherited

Change sort order of the categories.

Parameters
category_controller$categorycategory that needs to be moved
int$beforeidid of the category this category needs to be moved before, 0 to move to the end

◆ move_field()

core_customfield\handler::move_field ( field_controller  $field,
int  $categoryid,
int  $beforeid = 0 
)
inherited

Change fields sort order, move field to another category.

Parameters
field_controller$fieldfield that needs to be moved
int$categoryidcategory that needs to be moved
int$beforeidid of the category this category needs to be moved before, 0 to move to the end

◆ rename_category()

core_customfield\handler::rename_category ( category_controller  $category,
string  $name 
)
inherited

Change name for a field category.

Parameters
category_controller$category
string$name

◆ restore_instance_data_from_backup()

core_course\customfield\course_handler::restore_instance_data_from_backup ( \restore_task  $task,
array  $data 
)

Creates or updates custom field data.

Parameters
restore_task$task
array$data

Reimplemented from core_customfield\handler.

◆ save_field_configuration()

core_customfield\handler::save_field_configuration ( field_controller  $field,
stdClass  $data 
)
inherited

Save the field configuration with the data from the form.

Parameters
field_controller$field
stdClass$datadata from the form

◆ set_parent_context()

core_course\customfield\course_handler::set_parent_context ( \context  $context)

Sets parent context for the course.

This may be needed when course is being created, there is no course context but we need to check capabilities

Parameters
context$context

◆ setup_edit_page()

core_course\customfield\course_handler::setup_edit_page ( field_controller  $field)

Set up page customfield/edit.php.

Parameters
field_controller$field
Return values
stringpage heading

Reimplemented from core_customfield\handler.

◆ uses_categories()

core_customfield\handler::uses_categories ( )
inherited

Uses categories.

Return values
bool

◆ validate_category()

core_customfield\handler::validate_category ( category_controller  $category)
protectedinherited

Validate that the given category belongs to this handler.

Parameters
category_controller$category
Return values
category_controller
Exceptions
moodle_exception

◆ validate_field()

core_customfield\handler::validate_field ( field_controller  $field)
protectedinherited

Validate that the given field belongs to this handler.

Parameters
field_controller$field
Return values
field_controller
Exceptions
moodle_exception

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