Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401]

Customfield component provider class

Copyright: 2018 David Matamoros <davidmc@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 491 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: provider  - X-Ref

Class provider

Customfields API does not directly store userid and does not perform any export or delete functionality by itself

However this class defines several functions that can be utilized by components that use customfields API to
export/delete user data.

get_metadata(collection $collection)   X-Ref
Return the fields which contain personal data.

param: collection $collection a reference to the collection to use to store the metadata.
return: collection the updated collection of metadata items.

get_customfields_data_contexts(string $component, string $area,string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = [])   X-Ref
Returns contexts that have customfields data

To be used in implementations of core_user_data_provider::get_contexts_for_userid
Caller needs to transfer the $userid to the select subqueries for
customfield_category->itemid and/or customfield_data->instanceid

param: string $component
param: string $area
param: string $itemidstest subquery for selecting customfield_category->itemid
param: string $instanceidstest subquery for selecting customfield_data->instanceid
param: array $params array of named parameters
return: contextlist

get_customfields_configuration_contexts(string $component, string $area,string $itemidstest = 'IS NOT NULL', array $params = [])   X-Ref
Returns contexts that have customfields configuration (categories and fields)

To be used in implementations of core_user_data_provider::get_contexts_for_userid in cases when user is
an owner of the fields configuration
Caller needs to transfer the $userid to the select subquery for customfield_category->itemid

param: string $component
param: string $area
param: string $itemidstest subquery for selecting customfield_category->itemid
param: array $params array of named parameters for itemidstest subquery
return: contextlist

export_customfields_data(approved_contextlist $contextlist, string $component, string $area,string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = [],array $subcontext = null)   X-Ref
Exports customfields data

To be used in implementations of core_user_data_provider::export_user_data
Caller needs to transfer the $userid to the select subqueries for
customfield_category->itemid and/or customfield_data->instanceid

param: approved_contextlist $contextlist
param: string $component
param: string $area
param: string $itemidstest subquery for selecting customfield_category->itemid
param: string $instanceidstest subquery for selecting customfield_data->instanceid
param: array $params array of named parameters for itemidstest and instanceidstest subqueries
param: array $subcontext subcontext to use in context_writer::export_data, if null (default) the

delete_customfields_data(approved_contextlist $contextlist, string $component, string $area,string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = [])   X-Ref
Deletes customfields data

To be used in implementations of core_user_data_provider::delete_data_for_user
Caller needs to transfer the $userid to the select subqueries for
customfield_category->itemid and/or customfield_data->instanceid

param: approved_contextlist $contextlist
param: string $component
param: string $area
param: string $itemidstest subquery for selecting customfield_category->itemid
param: string $instanceidstest subquery for selecting customfield_data->instanceid
param: array $params array of named parameters for itemidstest and instanceidstest subqueries

delete_customfields_configuration(approved_contextlist $contextlist, string $component, string $area,string $itemidstest = 'IS NOT NULL', array $params = [])   X-Ref
Deletes customfields configuration (categories and fields) and all relevant data

To be used in implementations of core_user_data_provider::delete_data_for_user in cases when user is
an owner of the fields configuration and it is considered user information (quite unlikely situtation but we never
know what customfields API can be used for)

Caller needs to transfer the $userid to the select subquery for customfield_category->itemid

param: approved_contextlist $contextlist
param: string $component
param: string $area
param: string $itemidstest subquery for selecting customfield_category->itemid
param: array $params array of named parameters for itemidstest subquery

delete_customfields_configuration_for_context(string $component, string $area, \context $context)   X-Ref
Deletes all customfields configuration (categories and fields) and all relevant data for the given category context

To be used in implementations of core_user_data_provider::delete_data_for_all_users_in_context

param: string $component
param: string $area
param: \context $context

delete_customfields_data_for_context(string $component, string $area, \context $context)   X-Ref
Deletes all customfields data for the given context

To be used in implementations of core_user_data_provider::delete_data_for_all_users_in_context

param: string $component
param: string $area
param: \context $context

get_params(string $component, string $area, array $params)   X-Ref
Checks that $params is an associative array and adds parameters for component and area

param: string $component
param: string $area
param: array $params
return: array

delete_categories(array $contextids, array $categoriesids)   X-Ref
Delete custom fields categories configurations, all their fields and data

param: array $contextids
param: array $categoriesids

before_delete_data(string $dataidstest, array $params)   X-Ref
Executes callbacks from the customfield plugins to delete anything related to the data records (usually files)

param: string $dataidstest
param: array $params

before_delete_fields(string $categoryidstest, array $params)   X-Ref
Executes callbacks from the plugins to delete anything related to the fields (usually files)

Also deletes description files

param: string $categoryidstest
param: array $params

export_customfield_data(data_controller $data, array $subcontext)   X-Ref
Exports one instance of custom field data

param: data_controller $data
param: array $subcontext subcontext to pass to content_writer::export_data

export_customfield_data_unknown(\stdClass $record, \stdClass $field, array $subcontext)   X-Ref
Export data record of unknown type when we were not able to create instance of data_controller

param: \stdClass $record record from db table {customfield_data}
param: \stdClass $field field record with at least fields type, shortname, name
param: array $subcontext