Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
data_field_base Class Reference
Inheritance diagram for data_field_base:
data_field_checkbox data_field_date data_field_file data_field_latlong data_field_menu data_field_multimenu data_field_number data_field_picture data_field_radiobutton data_field_text data_field_textarea data_field_url

Public Member Functions

object __construct ($field=0, $data=0, $cm=0)
 Constructor function.
 
 define_default_field ()
 This field just sets up a default field object.
 
 define_field ($data)
 Set up the field object according to data in an object.
 
object delete_content ($recordid=0)
 Delete all content associated with the field.
 
object delete_field ()
 Delete a field completely.
 
object display_add_field ($recordid=0, $formdata=null)
 Print the relevant form element in the ADD template for this field.
 
object display_browse_field ($recordid, $template)
 Display the content of the field in browse mode.
 
object display_edit_field ()
 Print the relevant form element to define the attributes for this field viewable by teachers only.
 
 export_file_value (stdClass $record)
 Per default, does not return a file (just null).
 
 export_text_value (stdClass $record)
 Per default, return the record's text value only from the "content" field.
 
 file_export_supported ()
 Per default, it is assumed that fields do not support file exporting.
 
 file_import_supported ()
 Per default, a field does not support the import of files.
 
 file_ok ($relativepath)
 
 get_config_for_external ()
 Return the plugin configs for external functions, in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
 
 get_data_content_preview (int $recordid)
 Generate a fake data_content for this field to be used in preset previews.
 
 get_name ()
 Return the field type name.
 
 get_preview ()
 Get the field preview value.
 
 get_sort_field ()
 Returns the sortable field for the content.
 
 get_sort_sql ($fieldname)
 Returns the SQL needed to refer to the column.
 
object image ()
 Prints the respective type icon.
 
 import_file_value (int $contentid, string $filecontent, string $filename)
 Returns a stored_file object for exporting a file of a given record.
 
object insert_field ()
 Insert a new field in the database We assume the field object is already defined as $this->field.
 
 name ()
 Returns the name/type of the field.
 
 notemptyfield ($value, $name)
 Check if a field from an add form is empty.
 
 print_after_form ()
 Just in case a field needs to print something after the whole form.
 
 print_before_form ()
 Just in case a field needs to print something before the whole form.
 
 set_preview (bool $preview)
 Set the field to preview mode.
 
 supports_preview ()
 Return if the field type supports preview.
 
 text_export_supported ()
 Per default, it is assumed that fields support text exporting.
 
object update_content ($recordid, $value, $name='')
 Update the content of one data field in the data_content table.
 
object update_field ()
 Update a field in the database.
 
 validate (stdClass $fieldinput)
 Validates params of fieldinput data.
 

Static Public Member Functions

static get_content_value ($content)
 Returns the presentable string value for a field content.
 
static get_priority ()
 Returns the priority for being indexed by globalsearch.
 

Public Attributes

object $cm
 course module or cmifno
 
object $context
 activity context
 
object $data = NULL
 The database object that this field belongs to.
 
object $field = NULL
 The field object itself, if we know it.
 
int $iconheight = 16
 Width of the icon for this fieldtype.
 
int $iconwidth = 16
 Width of the icon for this fieldtype.
 
string $type = 'unknown'
 Subclasses must override the type with their name.
 
const HIGH_PRIORITY = 3
 priority value for high priority
 
const LOW_PRIORITY = 2
 priority value for low priority
 
const MAX_PRIORITY = 4
 priority value for maximum priority
 
const MIN_PRIORITY = 1
 priority value for minimum priority
 
const NO_PRIORITY = 0
 priority value for invalid fields regarding indexing
 

Protected Member Functions

 get_data_content (int $recordid)
 Return the data_content of the field, or generate it if it is in preview mode.
 
 get_field_params ()
 Function to let field define their parameters.
 

Protected Attributes

bool $preview = false
 whether the field is used in preview mode.
 

Static Protected Attributes

static priority $priority = self::NO_PRIORITY
 for globalsearch indexing
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

object data_field_base::__construct ( $field = 0,
$data = 0,
$cm = 0 )

Constructor function.

@uses CONTEXT_MODULE

Parameters
int$field
int$data
int$cm

Member Function Documentation

◆ define_default_field()

data_field_base::define_default_field ( )

This field just sets up a default field object.

Return values
bool

◆ define_field()

data_field_base::define_field ( $data)

Set up the field object according to data in an object.

Now is the time to clean it!

Return values
bool

◆ delete_content()

object data_field_base::delete_content ( $recordid = 0)

Delete all content associated with the field.

Parameters
int$recordid
Return values
bool

◆ delete_field()

object data_field_base::delete_field ( )

Delete a field completely.

Return values
bool

◆ display_add_field()

object data_field_base::display_add_field ( $recordid = 0,
$formdata = null )

Print the relevant form element in the ADD template for this field.

Parameters
int$recordid
Return values
string

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_menu, data_field_multimenu, data_field_picture, data_field_radiobutton, data_field_textarea, and data_field_url.

◆ display_browse_field()

object data_field_base::display_browse_field ( $recordid,
$template )

Display the content of the field in browse mode.

Parameters
int$recordid
object$template
Return values
bool|string

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_multimenu, data_field_number, data_field_picture, data_field_textarea, and data_field_url.

◆ display_edit_field()

object data_field_base::display_edit_field ( )

Print the relevant form element to define the attributes for this field viewable by teachers only.

@global object

Return values
voidOutput is echo'd

◆ export_file_value()

data_field_base::export_file_value ( stdClass $record)

Per default, does not return a file (just null).

Override this in fields class, if you want your field to export a file content. In case you are exporting a file value, export_text_value() should return the corresponding file name.

Parameters
stdClass$record
Return values
null|stringthe file content as string or null, if no file content is being provided

Reimplemented in data_field_file, and data_field_picture.

◆ export_text_value()

data_field_base::export_text_value ( stdClass $record)

Per default, return the record's text value only from the "content" field.

Override this in fields class if necessary.

Parameters
stdClass$record
Return values
string

Reimplemented in data_field_file, and data_field_picture.

◆ file_export_supported()

data_field_base::file_export_supported ( )

Per default, it is assumed that fields do not support file exporting.

Override this (return true) on fields supporting file export. You will also have to implement export_file_value().

Return values
booltrue if field will export a file, false otherwise

Reimplemented in data_field_file, and data_field_picture.

◆ file_import_supported()

data_field_base::file_import_supported ( )

Per default, a field does not support the import of files.

A field type can overwrite this function and return true. In this case it also has to implement the function import_file_value().

Return values
falsemeans file imports are not supported

Reimplemented in data_field_file, and data_field_picture.

◆ file_ok()

data_field_base::file_ok ( $relativepath)
Parameters
string$relativepath
Return values
boolfalse

Reimplemented in data_field_file, data_field_picture, and data_field_textarea.

◆ get_config_for_external()

data_field_base::get_config_for_external ( )

Return the plugin configs for external functions, in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.

Return values
arraythe list of config parameters
Since
Moodle 3.3

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_menu, data_field_multimenu, data_field_number, data_field_picture, data_field_radiobutton, data_field_text, data_field_textarea, and data_field_url.

◆ get_content_value()

static data_field_base::get_content_value ( $content)
static

Returns the presentable string value for a field content.

The returned string should be plain text.

Parameters
stdClass$content
Return values
string

Reimplemented in data_field_checkbox, data_field_multimenu, and data_field_textarea.

◆ get_data_content()

data_field_base::get_data_content ( int $recordid)
protected

Return the data_content of the field, or generate it if it is in preview mode.

Parameters
int$recordidthe record id
Return values
stdClass|boolthe record data or false if none

◆ get_data_content_preview()

data_field_base::get_data_content_preview ( int $recordid)

Generate a fake data_content for this field to be used in preset previews.

Data plugins must override this method and support_preview in order to enable preset preview for this field.

Parameters
int$recordidthe fake record id
Return values
stdClassthe fake record

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_menu, data_field_multimenu, data_field_number, data_field_picture, data_field_radiobutton, data_field_text, data_field_textarea, and data_field_url.

◆ get_field_params()

data_field_base::get_field_params ( )
protected

Function to let field define their parameters.

This method that should be overridden by the datafield plugins when they need to define their data.

Return values
array

Reimplemented in data_field_file, data_field_latlong, and data_field_picture.

◆ get_name()

data_field_base::get_name ( )

Return the field type name.

Return values
stringthe filed type.

◆ get_preview()

data_field_base::get_preview ( )

Get the field preview value.

Return values
bool

◆ get_priority()

static data_field_base::get_priority ( )
static

Returns the priority for being indexed by globalsearch.

Return values
int

◆ get_sort_field()

data_field_base::get_sort_field ( )

Returns the sortable field for the content.

By default, it's just content but for some plugins, it could be content 1 - content4

Return values
string

◆ get_sort_sql()

data_field_base::get_sort_sql ( $fieldname)

Returns the SQL needed to refer to the column.

Some fields may need to CAST() etc.

Parameters
string$fieldname
Return values
string\$fieldname

Reimplemented in data_field_date, data_field_latlong, and data_field_number.

◆ image()

object data_field_base::image ( )

Prints the respective type icon.

Return values
string

◆ import_file_value()

data_field_base::import_file_value ( int $contentid,
string $filecontent,
string $filename )

Returns a stored_file object for exporting a file of a given record.

Parameters
int$contentidcontent id
string$filecontentthe content of the file as string
string$filenamethe filename the file should have

Reimplemented in data_field_file, and data_field_picture.

◆ insert_field()

object data_field_base::insert_field ( )

Insert a new field in the database We assume the field object is already defined as $this->field.

Return values
bool

◆ name()

data_field_base::name ( )

Returns the name/type of the field.

Return values
string

◆ notemptyfield()

data_field_base::notemptyfield ( $value,
$name )

Check if a field from an add form is empty.

Parameters
mixed$value
mixed$name
Return values
bool

Reimplemented in data_field_checkbox, data_field_file, data_field_latlong, data_field_menu, data_field_multimenu, data_field_number, data_field_picture, data_field_radiobutton, data_field_text, data_field_textarea, and data_field_url.

◆ print_after_form()

data_field_base::print_after_form ( )

Just in case a field needs to print something after the whole form.

Reimplemented in data_field_textarea.

◆ set_preview()

data_field_base::set_preview ( bool $preview)

Set the field to preview mode.

Parameters
bool$previewthe new preview value

◆ supports_preview()

data_field_base::supports_preview ( )

Return if the field type supports preview.

Fields without a preview cannot be displayed in the preset preview.

Return values
boolif the plugin supports preview.

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_menu, data_field_multimenu, data_field_number, data_field_picture, data_field_radiobutton, data_field_text, data_field_textarea, and data_field_url.

◆ text_export_supported()

data_field_base::text_export_supported ( )

Per default, it is assumed that fields support text exporting.

Override this (return false) on fields not supporting text exporting.

Return values
booltrue

◆ update_content()

object data_field_base::update_content ( $recordid,
$value,
$name = '' )

Update the content of one data field in the data_content table.

Parameters
int$recordid
mixed$value
string$name
Return values
bool

Reimplemented in data_field_checkbox, data_field_date, data_field_file, data_field_latlong, data_field_multimenu, data_field_number, data_field_picture, data_field_textarea, and data_field_url.

◆ update_field()

object data_field_base::update_field ( )

Update a field in the database.

Return values
bool

Reimplemented in data_field_picture.

◆ validate()

data_field_base::validate ( stdClass $fieldinput)

Validates params of fieldinput data.

Overwrite to validate fieldtype specific data.

You are expected to return an array like ['paramname' => 'Error message for paramname param'] if there is an error, return an empty array if everything is fine.

Parameters
stdClass$fieldinputThe field input data to check
Return values
array\$errorsif empty validation was fine, otherwise contains one or more error messages

Reimplemented in data_field_picture.


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