Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

Profile field API library file.

Copyright: 2007 onwards Shane Elliot {@link http://pukunui.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 907 lines (30 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 2 classes


Class: profile_field_base  - X-Ref

Base class for the customisable profile fields.

__construct($fieldid=0, $userid=0, $fielddata=null)   X-Ref
Constructor method.

param: int $fieldid id of the profile from the user_info_field table
param: int $userid id of the user for whom we are displaying data
param: object $fielddata optional data for the field object plus additional fields 'hasuserdata', 'data' and 'dataformat'

profile_field_base($fieldid=0, $userid=0)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

edit_field_add($mform)   X-Ref
Abstract method: Adds the profile field to the moodle form class

param: moodleform $mform instance of the moodleform class

display_data()   X-Ref
Display the data for this field

return: string

edit_field($mform)   X-Ref
Print out the form field in the edit profile page

param: moodleform $mform instance of the moodleform class
return: bool

edit_after_data($mform)   X-Ref
Tweaks the edit form

param: moodleform $mform instance of the moodleform class
return: bool

edit_save_data($usernew)   X-Ref
Saves the data coming from form

param: stdClass $usernew data coming from the form
return: mixed returns data id if success of db insert/update, false on fail, 0 if not permitted

edit_validate_field($usernew)   X-Ref
Validate the form field from profile page

param: stdClass $usernew
return: string  contains error message otherwise null

edit_field_set_default($mform)   X-Ref
Sets the default data for the field in the form object

param: moodleform $mform instance of the moodleform class

edit_field_set_required($mform)   X-Ref
Sets the required flag for the field in the form object

param: moodleform $mform instance of the moodleform class

edit_field_set_locked($mform)   X-Ref
HardFreeze the field if locked.

param: moodleform $mform instance of the moodleform class

edit_save_data_preprocess($data, $datarecord)   X-Ref
Hook for child classess to process the data before it gets saved in database

param: stdClass $data
param: stdClass $datarecord The object that will be used to save the record
return: mixed

edit_load_user_data($user)   X-Ref
Loads a user object with data for this field ready for the edit profile
form

param: stdClass $user a user object

is_user_object_data()   X-Ref
Check if the field data should be loaded into the user object
By default it is, but for field types where the data may be potentially
large, the child class should override this and return false

return: bool

set_userid($userid)   X-Ref
Accessor method: set the userid for this instance

param: integer $userid id from the user table

set_fieldid($fieldid)   X-Ref
Accessor method: set the fieldid for this instance

param: integer $fieldid id from the user_info_field table

set_field($field)   X-Ref
Sets the field object and default data and format into $this->data and $this->dataformat

This method should be called before {@link self::set_user_data}

param: stdClass $field

set_user_data($data, $dataformat)   X-Ref
Sets user id and user data for the field

param: mixed $data
param: int $dataformat

set_category_name($categoryname)   X-Ref
Set the name for the profile category where this field is

param: string $categoryname

get_category_name()   X-Ref
Returns the name of the profile category where this field is

return: string

load_data()   X-Ref
Accessor method: Load the field record and user data associated with the
object's fieldid and userid


is_visible()   X-Ref
Check if the field data is visible to the current user

return: bool

is_editable()   X-Ref
Check if the field data is editable for the current user
This method should not generally be overwritten by child classes.

return: bool

is_empty()   X-Ref
Check if the field data is considered empty

return: boolean

is_required()   X-Ref
Check if the field is required on the edit profile page

return: bool

is_locked()   X-Ref
Check if the field is locked on the edit profile page

return: bool

is_unique()   X-Ref
Check if the field data should be unique

return: bool

is_signup_field()   X-Ref
Check if the field should appear on the signup page

return: bool

get_field_config_for_external()   X-Ref
Return the field settings suitable to be exported via an external function.
By default it return all the field settings.

return: array all the settings

get_field_properties()   X-Ref
Return the field type and null properties.
This will be used for validating the data submitted by a user.

return: array the param type and null property

profile_get_user_fields_with_data($userid)   X-Ref
Returns an array of all custom field records with any defined data (or empty data), for the specified user id.

param: int $userid
return: profile_field_base[]

profile_get_user_fields_with_data_by_category($userid)   X-Ref
Returns an array of all custom field records with any defined data (or empty data), for the specified user id, by category.

param: int $userid
return: profile_field_base[][]

profile_load_data($user)   X-Ref
Loads user profile field data into the user object.

param: stdClass $user

profile_definition($mform, $userid = 0)   X-Ref
Print out the customisable categories and fields for a users profile

param: moodleform $mform instance of the moodleform class
param: int $userid id of user whose profile is being edited.

profile_definition_after_data($mform, $userid)   X-Ref
Adds profile fields to user edit forms.

param: moodleform $mform
param: int $userid

profile_validation($usernew, $files)   X-Ref
Validates profile data.

param: stdClass $usernew
param: array $files
return: array

profile_save_data($usernew)   X-Ref
Saves profile data for a user.

param: stdClass $usernew

profile_display_fields($userid)   X-Ref
Display profile fields.

param: int $userid

profile_get_signup_fields()   X-Ref
Retrieves a list of profile fields that must be displayed in the sign-up form.

return: array list of profile fields info

profile_signup_fields($mform)   X-Ref
Adds code snippet to a moodle form object for custom profile fields that
should appear on the signup page

param: moodleform $mform moodle form object

profile_user_record($userid, $onlyinuserobject = true)   X-Ref
Returns an object with the custom profile fields set for the given user

param: integer $userid
param: bool $onlyinuserobject True if you only want the ones in $USER.
return: stdClass

profile_get_custom_fields($onlyinuserobject = false)   X-Ref
Obtains a list of all available custom profile fields, indexed by id.

Some profile fields are not included in the user object data (see
profile_user_record function above). Optionally, you can obtain only those
fields that are included in the user object.

To be clear, this function returns the available fields, and does not
return the field values for a particular user.

param: bool $onlyinuserobject True if you only want the ones in $USER
return: array Array of field objects from database (indexed by id)

profile_load_custom_fields($user)   X-Ref
Load custom profile fields into user object

param: stdClass $user user object

profile_save_custom_fields($userid, $profilefields)   X-Ref
Save custom profile fields for a user.

param: int $userid The user id
param: array $profilefields The fields to save

profile_view($user, $context, $course = null)   X-Ref
Trigger a user profile viewed event.

param: stdClass  $user user  object
param: stdClass  $context  context object (course or user)
param: stdClass  $course course  object

profile_has_required_custom_fields_set($userid)   X-Ref
Does the user have all required custom fields set?

Internal, to be exclusively used by {@link user_not_fully_set_up()} only.

Note that if users have no way to fill a required field via editing their
profiles (e.g. the field is not visible or it is locked), we still return true.
So this is actually checking if we should redirect the user to edit their
profile, rather than whether there is a value in the database.

param: int $userid
return: bool