Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_customfield\data_controller Class Reference

Base class for custom fields data controllers. More...

Inheritance diagram for core_customfield\data_controller:
customfield_checkbox\data_controller customfield_date\data_controller customfield_select\data_controller customfield_text\data_controller customfield_textarea\data_controller

Public Member Functions

 __construct (int $id, stdClass $record)
 data_controller constructor.
 
 backup_define_structure (backup_nested_element $customfieldelement)
 Callback for backup, allowing custom fields to add additional data to the backup.
 
 datafield ()
 Return the name of the field in the db table {customfield_data} where the data is stored.
 
 delete ()
 Delete data.
 
 display ()
 Used by handlers to display data on various places.
 
 export_value ()
 Returns value in a human-readable format or default value if data record is not present.
 
 get ($property)
 Persistent getter parser.
 
 get_context ()
 Return the context of the field.
 
 get_default_value ()
 Returns the default value as it would be stored in the database (not in human-readable format).
 
 get_field ()
 Field associated with this data.
 
 get_form_element_name ()
 Returns the name of the field to be used on HTML forms.
 
 get_value ()
 Returns the value as it is stored in the database or default value if data record is not present.
 
 instance_form_before_set_data (\stdClass $instance)
 Prepares the custom field data related to the object to pass to mform->set_data() and adds them to it.
 
 instance_form_definition (\MoodleQuickForm $mform)
 Add a field to the instance edit form.
 
 instance_form_definition_after_data (\MoodleQuickForm $mform)
 Called from instance edit form in definition_after_data()
 
 instance_form_save (\stdClass $datanew)
 Saves the data coming from form.
 
 instance_form_validation (array $data, array $files)
 Called from instance edit form in validation()
 
 restore_define_structure (\restore_structure_step $step, int $newid, int $oldid)
 Callback for restore, allowing custom fields to restore additional data from the backup.
 
 save ()
 Persistent save parser.
 
 set ($property, $value)
 Persistent setter parser.
 
 to_record ()
 Persistent to_record parser.
 

Static Public Member Functions

static create (int $id, stdClass $record=null, field_controller $field=null)
 Creates an instance of data_controller.
 

Protected Member Functions

 is_empty ($value)
 Checks if the value is empty.
 
 is_unique ($value)
 Checks if the value is unique.
 

Protected Attributes

data $data
 Data persistent.
 
field_controller $field
 Field that this data belongs to.
 

Detailed Description

Base class for custom fields data controllers.

This class is a wrapper around the persistent data class that allows to define how the element behaves in the instance edit forms.

Custom field plugins must define a class {pluginname}data_controller extends core_customfield\data_controller

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

Constructor & Destructor Documentation

◆ __construct()

core_customfield\data_controller::__construct ( int $id,
stdClass $record )

data_controller constructor.

Parameters
int$id
stdClass | null$record

Member Function Documentation

◆ backup_define_structure()

core_customfield\data_controller::backup_define_structure ( backup_nested_element $customfieldelement)

Callback for backup, allowing custom fields to add additional data to the backup.

It is not an abstract method for backward compatibility reasons.

Parameters
backup_nested_element$customfieldelementThe custom field element to be backed up.

Reimplemented in customfield_textarea\data_controller.

◆ create()

static core_customfield\data_controller::create ( int $id,
stdClass $record = null,
field_controller $field = null )
static

Creates an instance of data_controller.

Parameters $id, $record and $field can complement each other but not conflict. If $id is not specified, fieldid must be present either in $record or in $field. If $id is not specified, instanceid must be present in $record

No DB queries are performed if both $record and $field are specified.

Parameters
int$id
stdClass | null$record
field_controller | null$field
Return values
data_controller
Exceptions
coding_exception
moodle_exception

◆ datafield()

core_customfield\data_controller::datafield ( )
abstract

Return the name of the field in the db table {customfield_data} where the data is stored.

Must be one of the following: intvalue - can store integer values, this field is indexed decvalue - can store decimal values shortcharvalue - can store character values up to 255 characters long, this field is indexed charvalue - can store character values up to 1333 characters long, this field is not indexed but full text search is faster than on field 'value' value - can store character values of unlimited length ("text" field in the db)

Return values
string

Reimplemented in customfield_checkbox\data_controller, customfield_date\data_controller, customfield_select\data_controller, customfield_text\data_controller, and customfield_textarea\data_controller.

◆ delete()

core_customfield\data_controller::delete ( )

Delete data.

Element can override it if related information needs to be deleted as well (such as files)

Return values
bool

Reimplemented in customfield_textarea\data_controller.

◆ display()

core_customfield\data_controller::display ( )

Used by handlers to display data on various places.

Return values
string

◆ export_value()

core_customfield\data_controller::export_value ( )

Returns value in a human-readable format or default value if data record is not present.

This is the default implementation that most likely needs to be overridden

Return values
mixed|nullvalue or null if empty

Reimplemented in customfield_checkbox\data_controller, customfield_date\data_controller, customfield_select\data_controller, customfield_text\data_controller, and customfield_textarea\data_controller.

◆ get()

core_customfield\data_controller::get ( $property)
final

Persistent getter parser.

Parameters
string$property
Return values
mixed

◆ get_context()

core_customfield\data_controller::get_context ( )

Return the context of the field.

Return values
context

◆ get_default_value()

core_customfield\data_controller::get_default_value ( )
abstract

Returns the default value as it would be stored in the database (not in human-readable format).

Return values
mixed

Reimplemented in customfield_checkbox\data_controller, customfield_date\data_controller, customfield_select\data_controller, customfield_text\data_controller, and customfield_textarea\data_controller.

◆ get_field()

core_customfield\data_controller::get_field ( )

Field associated with this data.

Return values
field_controller

◆ get_form_element_name()

core_customfield\data_controller::get_form_element_name ( )

Returns the name of the field to be used on HTML forms.

Return values
string

Reimplemented in customfield_textarea\data_controller.

◆ get_value()

core_customfield\data_controller::get_value ( )

Returns the value as it is stored in the database or default value if data record is not present.

Return values
mixed

◆ instance_form_before_set_data()

core_customfield\data_controller::instance_form_before_set_data ( \stdClass $instance)

Prepares the custom field data related to the object to pass to mform->set_data() and adds them to it.

This function must be called before calling $form->set_data($object);

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.

Reimplemented in customfield_textarea\data_controller.

◆ instance_form_definition()

core_customfield\data_controller::instance_form_definition ( \MoodleQuickForm $mform)
abstract

◆ instance_form_definition_after_data()

core_customfield\data_controller::instance_form_definition_after_data ( \MoodleQuickForm $mform)

Called from instance edit form in definition_after_data()

Parameters
MoodleQuickForm$mform

◆ instance_form_save()

core_customfield\data_controller::instance_form_save ( \stdClass $datanew)

Saves the data coming from form.

Parameters
stdClass$datanewdata coming from the form

Reimplemented in customfield_textarea\data_controller.

◆ instance_form_validation()

core_customfield\data_controller::instance_form_validation ( array $data,
array $files )

Called from instance edit form in validation()

Parameters
array$data
array$files
Return values
arrayarray of errors

Reimplemented in customfield_date\data_controller, customfield_select\data_controller, and customfield_text\data_controller.

◆ is_empty()

core_customfield\data_controller::is_empty ( $value)
protected

Checks if the value is empty.

Parameters
mixed$value
Return values
bool

Reimplemented in customfield_textarea\data_controller.

◆ is_unique()

core_customfield\data_controller::is_unique ( $value)
protected

Checks if the value is unique.

Parameters
mixed$value
Return values
bool

Reimplemented in customfield_textarea\data_controller.

◆ restore_define_structure()

core_customfield\data_controller::restore_define_structure ( \restore_structure_step $step,
int $newid,
int $oldid )

Callback for restore, allowing custom fields to restore additional data from the backup.

It is not an abstract method for backward compatibility reasons.

Parameters
restore_structure_step$stepThe restore step instance.
int$newidThe new ID for the custom field data after restore.
int$oldidThe original ID of the custom field data before backup.

Reimplemented in customfield_textarea\data_controller.

◆ save()

core_customfield\data_controller::save ( )

Persistent save parser.

Return values
void

◆ set()

core_customfield\data_controller::set ( $property,
$value )
final

Persistent setter parser.

Parameters
string$property
mixed$value
Return values
data

◆ to_record()

core_customfield\data_controller::to_record ( )
final

Persistent to_record parser.

Return values
stdClass

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