Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
tool_dataprivacy\api Class Reference

Class containing helper methods for processing data requests. More...

Static Public Member Functions

static add_request_contexts_with_status (contextlist_collection $clcollection, int $requestid, int $status)
 Adds the contexts from the contextlist_collection to the request with the status provided.
 
static approve_contexts_belonging_to_request (int $requestid, array $coursecontextids=[])
 Only approve the contexts which are children of the provided course contexts.
 
static approve_data_request ($requestid, $filtercoursecontexts=[])
 Approves a data request based on the request ID.
 
static can_contact_dpo ()
 Determines whether the user can contact the site's Data Protection Officer via Moodle.
 
static can_create_data_deletion_request_for_children (int $userid, int $requesterid=null)
 Check if parent can create data deletion request for their children.
 
static can_create_data_deletion_request_for_other (int $userid=null)
 Check if user has permission to create data deletion request for another user.
 
static can_create_data_deletion_request_for_self (int $userid=null)
 Check if user has permisson to create data deletion request for themselves.
 
static can_create_data_download_request_for_self (int $userid=null)
 Check if user has permission to create data download request for themselves.
 
static can_create_data_request_for_user ($user, $requester=null)
 Checks whether a non-DPO user can make a data request for another user.
 
static can_download_data_request_for_user ($userid, $requesterid, $downloaderid=null)
 Checks whether a user can download a data request.
 
static can_manage_data_requests ($userid)
 Checks whether the current user has the capability to manage data requests.
 
static check_can_manage_data_registry ($contextid=false)
 Checks if the current user can manage the data registry at the provided id.
 
static create_category (stdClass $record)
 Creates a new data category.
 
static create_data_request ($foruser, $type, $comments='', $creationmethod=data_request::DATAREQUEST_CREATION_MANUAL, $notify=null)
 Lodges a data request and sends the request details to the site Data Protection Officer(s).
 
static create_expired_context ($contextid)
 Creates an expired context record for the provided context id.
 
static create_purpose (stdClass $record)
 Creates a new data purpose.
 
static delete_category ($id)
 Deletes a data category.
 
static delete_expired_context ($id)
 Deletes an expired context record.
 
static delete_purpose ($id)
 Deletes a data purpose.
 
static deny_data_request ($requestid)
 Rejects a data request based on the request ID.
 
static find_ongoing_request_types_for_users (array $userids)
 Find whether any ongoing requests exist for a set of users.
 
static format_retention_period (\DateInterval $interval)
 Format the supplied date interval as a retention period.
 
static get_approved_contextlist_collection_for_collection (contextlist_collection $collection, stdClass $foruser, int $type)
 Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.
 
static get_approved_contextlist_collection_for_request (data_request $request)
 Finds all request contextlists having at least on approved context, and returns them as in a contextlist_collection.
 
static get_assigned_privacy_officer_roles ()
 Fetches the list of configured privacy officer roles.
 
static get_categories ()
 Get all system data categories.
 
static get_course_contexts_for_view_filter (int $requestid)
 Get list of course context for user to filter.
 
static get_data_requests ($userid=0, $statuses=[], $types=[], $creationmethods=[], $sort='', $offset=0, $limit=0)
 Fetches the list of the data requests.
 
static get_data_requests_count ($userid=0, $statuses=[], $types=[], $creationmethods=[])
 Fetches the count of data request records based on the given parameters.
 
static get_download_link (\context_user $usercontext, $requestid)
 Gets an action menu link to download a data request.
 
static get_dpo_role_names ()
 Fetches the role shortnames of Data Protection Officer roles.
 
static get_effective_context_category (\context $context, $forcedvalue=false)
 Returns the effective category given a context instance.
 
static get_effective_context_purpose (\context $context, $forcedvalue=false)
 Returns the effective purpose given a context instance.
 
static get_effective_contextlevel_category ($contextlevel)
 Returns the effective category given a context level.
 
static get_effective_contextlevel_purpose ($contextlevel, $forcedvalue=false)
 Returns the effective purpose given a context level.
 
static get_purposes ()
 Get all system data purposes.
 
static get_request ($requestid)
 Fetches a request based on the request ID.
 
static get_site_dpos ()
 Fetches the list of users with the Privacy Officer role.
 
static has_ongoing_request ($userid, $type)
 Checks whether there is already an existing pending/in-progress data request for a user for a given request type.
 
static is_active ($status)
 Determines whether a request is active or not based on its status.
 
static is_automatic_request_approval_on (int $type)
 Whether automatic data request approval is turned on or not for the given request type.
 
static is_site_dpo ($userid)
 Checks whether a given user is a site Privacy Officer.
 
static notify_dpo ($dpo, data_request $request)
 Sends a message to the site's Data Protection Officer about a request.
 
static queue_data_request_task (int $requestid, int $userid=null)
 Creates an ad-hoc task for the data request.
 
static require_can_create_data_request_for_user ($user, $requester=null)
 Require that the current user can make a data request for the specified other user.
 
static set_context_defaults ($contextlevel, $categoryid, $purposeid, $activity=null, $override=false)
 Updates the default category and purpose for a given context level (and optionally, a plugin).
 
static set_context_instance ($record)
 Sets the context instance purpose and category.
 
static set_contextlevel ($record)
 Sets the context level purpose and category.
 
static set_expired_context_status (expired_context $expiredctx, $status)
 Updates the status of an expired context.
 
static unset_context_instance (context_instance $instance)
 Unsets the context instance record.
 
static update_category (stdClass $record)
 Updates an existing data category.
 
static update_purpose (stdClass $record)
 Updates an existing data purpose.
 
static update_request_contexts_with_status (int $requestid, int $status)
 Sets the status of all contexts associated with the request.
 
static update_request_status ($requestid, $status, $dpoid=0, $comment='')
 Cancels the data request for a given request ID.
 

Public Attributes

const DATAREQUEST_ACTION_APPROVE = 1
 Approve data request.
 
const DATAREQUEST_ACTION_REJECT = 2
 Reject data request.
 
const DATAREQUEST_STATUS_APPROVED = 3
 Request approved and will be processed soon.
 
const DATAREQUEST_STATUS_AWAITING_APPROVAL = 2
 Metadata ready and awaiting review and approval by the Data Protection officer.
 
const DATAREQUEST_STATUS_CANCELLED = 6
 Data request cancelled by the user.
 
const DATAREQUEST_STATUS_COMPLETE = 5
 Information/other request completed.
 
const DATAREQUEST_STATUS_DELETED = 10
 Data delete request completed, account is removed.
 
const DATAREQUEST_STATUS_DOWNLOAD_READY = 8
 Data request download ready.
 
const DATAREQUEST_STATUS_EXPIRED = 9
 Data request expired.
 
const DATAREQUEST_STATUS_PENDING = 0
 Newly submitted and we haven't yet started finding out where they have data.
 
const DATAREQUEST_STATUS_PREPROCESSING = 1
 Newly submitted and we have started to find the location of data.
 
const DATAREQUEST_STATUS_PROCESSING = 4
 The request is now being processed.
 
const DATAREQUEST_STATUS_REJECTED = 7
 Data request rejected by the DPO.
 
const DATAREQUEST_TYPE_DELETE = 2
 Data deletion request type.
 
const DATAREQUEST_TYPE_EXPORT = 1
 Data export request type.
 
const DATAREQUEST_TYPE_OTHERS = 3
 Other request type.
 

Detailed Description

Class containing helper methods for processing data requests.

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

Member Function Documentation

◆ add_request_contexts_with_status()

static tool_dataprivacy\api::add_request_contexts_with_status ( contextlist_collection $clcollection,
int $requestid,
int $status )
static

Adds the contexts from the contextlist_collection to the request with the status provided.

Since
Moodle 4.3
Parameters
contextlist_collection$clcollectiona collection of contextlists for all components.
int$requestidthe id of the request.
int$statusthe status to set the contexts to.

◆ approve_contexts_belonging_to_request()

static tool_dataprivacy\api::approve_contexts_belonging_to_request ( int $requestid,
array $coursecontextids = [] )
static

Only approve the contexts which are children of the provided course contexts.

Since
Moodle 4.3
Parameters
int$requestidRequest identifier
array$coursecontextidsList of course context identifier.
Exceptions
dml_transaction_exception
coding_exception
dml_exception

◆ approve_data_request()

static tool_dataprivacy\api::approve_data_request ( $requestid,
$filtercoursecontexts = [] )
static

Approves a data request based on the request ID.

Parameters
int$requestidThe request identifier
array$filtercoursecontextsApply to export request, only approve contexts belong to these courses.
Return values
bool
Exceptions
coding_exception
dml_exception
invalid_persistent_exception
required_capability_exception
moodle_exception

◆ can_contact_dpo()

static tool_dataprivacy\api::can_contact_dpo ( )
static

Determines whether the user can contact the site's Data Protection Officer via Moodle.

Return values
booleanTrue when tool_dataprivacy|contactdataprotectionofficer is enabled.
Exceptions
dml_exception

◆ can_create_data_deletion_request_for_children()

static tool_dataprivacy\api::can_create_data_deletion_request_for_children ( int $userid,
int $requesterid = null )
static

Check if parent can create data deletion request for their children.

Parameters
int$useridID of a user being requested.
int | null$requesteridID of a user making request.
Return values
bool
Exceptions
coding_exception

◆ can_create_data_deletion_request_for_other()

static tool_dataprivacy\api::can_create_data_deletion_request_for_other ( int $userid = null)
static

Check if user has permission to create data deletion request for another user.

Parameters
int | null$useridID of the user.
Return values
bool
Exceptions
coding_exception
dml_exception

◆ can_create_data_deletion_request_for_self()

static tool_dataprivacy\api::can_create_data_deletion_request_for_self ( int $userid = null)
static

Check if user has permisson to create data deletion request for themselves.

Parameters
int | null$useridID of the user.
Return values
bool
Exceptions
coding_exception

◆ can_create_data_download_request_for_self()

static tool_dataprivacy\api::can_create_data_download_request_for_self ( int $userid = null)
static

Check if user has permission to create data download request for themselves.

Parameters
int | null$userid
Return values
bool

◆ can_create_data_request_for_user()

static tool_dataprivacy\api::can_create_data_request_for_user ( $user,
$requester = null )
static

Checks whether a non-DPO user can make a data request for another user.

Parameters
int$userThe user ID of the target user.
int$requesterThe user ID of the user making the request.
Return values
bool

◆ can_download_data_request_for_user()

static tool_dataprivacy\api::can_download_data_request_for_user ( $userid,
$requesterid,
$downloaderid = null )
static

Checks whether a user can download a data request.

Parameters
int$useridTarget user id (subject of data request)
int$requesteridRequester user id (person who requsted it)
int | null$downloaderidPerson who wants to download user id (default current)
Return values
bool
Exceptions
coding_exception

◆ can_manage_data_requests()

static tool_dataprivacy\api::can_manage_data_requests ( $userid)
static

Checks whether the current user has the capability to manage data requests.

Parameters
int$useridThe user ID.
Return values
bool

◆ check_can_manage_data_registry()

static tool_dataprivacy\api::check_can_manage_data_registry ( $contextid = false)
static

Checks if the current user can manage the data registry at the provided id.

Parameters
int$contextidFallback to system context id.
Exceptions
required_capability_exception
Return values
null

◆ create_category()

static tool_dataprivacy\api::create_category ( stdClass $record)
static

Creates a new data category.

Parameters
stdClass$record
Return values
tool_dataprivacy\category.

◆ create_data_request()

static tool_dataprivacy\api::create_data_request ( $foruser,
$type,
$comments = '',
$creationmethod = data_request::DATAREQUEST_CREATION_MANUAL,
$notify = null )
static

Lodges a data request and sends the request details to the site Data Protection Officer(s).

Parameters
int$foruserThe user whom the request is being made for.
int$typeThe request type.
string$commentsRequest comments.
int$creationmethodThe creation method of the data request.
bool$notifyNotify DPOs of this pending request.
Return values
data_request
Exceptions
invalid_persistent_exception
coding_exception

◆ create_expired_context()

static tool_dataprivacy\api::create_expired_context ( $contextid)
static

Creates an expired context record for the provided context id.

Parameters
int$contextid
Return values
tool_dataprivacy\expired_context

◆ create_purpose()

static tool_dataprivacy\api::create_purpose ( stdClass $record)
static

Creates a new data purpose.

Parameters
stdClass$record
Return values
tool_dataprivacy\purpose.

◆ delete_category()

static tool_dataprivacy\api::delete_category ( $id)
static

Deletes a data category.

Parameters
int$id
Return values
bool

◆ delete_expired_context()

static tool_dataprivacy\api::delete_expired_context ( $id)
static

Deletes an expired context record.

Parameters
int$idThe tool_dataprivacy_ctxexpire id.
Return values
boolTrue on success.

◆ delete_purpose()

static tool_dataprivacy\api::delete_purpose ( $id)
static

Deletes a data purpose.

Parameters
int$id
Return values
bool

◆ deny_data_request()

static tool_dataprivacy\api::deny_data_request ( $requestid)
static

Rejects a data request based on the request ID.

Parameters
int$requestidThe request identifier
Return values
bool
Exceptions
coding_exception
dml_exception
invalid_persistent_exception
required_capability_exception
moodle_exception

◆ find_ongoing_request_types_for_users()

static tool_dataprivacy\api::find_ongoing_request_types_for_users ( array $userids)
static

Find whether any ongoing requests exist for a set of users.

Parameters
array$userids
Return values
array

◆ format_retention_period()

static tool_dataprivacy\api::format_retention_period ( \DateInterval $interval)
static

Format the supplied date interval as a retention period.

Parameters
DateInterval$interval
Return values
string

◆ get_approved_contextlist_collection_for_collection()

static tool_dataprivacy\api::get_approved_contextlist_collection_for_collection ( contextlist_collection $collection,
stdClass $foruser,
int $type )
static

Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.

Parameters
contextlist_collection$collectionThe collection of unapproved contextlist objects.
stdClass$foruserThe target user
int$typeThe purpose of the collection
Return values
contextlist_collectionThe collection of approved_contextlist objects.

◆ get_approved_contextlist_collection_for_request()

static tool_dataprivacy\api::get_approved_contextlist_collection_for_request ( data_request $request)
static

Finds all request contextlists having at least on approved context, and returns them as in a contextlist_collection.

Since
Moodle 4.3
Parameters
data_request$requestthe data request with which the contextlists are associated.
Return values
contextlist_collectionthe collection of approved_contextlist objects.
Exceptions
coding_exception
dml_exception
moodle_exception

◆ get_assigned_privacy_officer_roles()

static tool_dataprivacy\api::get_assigned_privacy_officer_roles ( )
static

Fetches the list of configured privacy officer roles.

Every time this function is called, it checks each role if they have the 'managedatarequests' capability and removes any role that doesn't have the required capability anymore.

Return values
int[]
Exceptions
dml_exception

◆ get_categories()

static tool_dataprivacy\api::get_categories ( )
static

Get all system data categories.

Return values
tool_dataprivacy\category[]

◆ get_course_contexts_for_view_filter()

static tool_dataprivacy\api::get_course_contexts_for_view_filter ( int $requestid)
static

Get list of course context for user to filter.

Since
Moodle 4.3
Parameters
int$requestidRequest identifier.
Return values
array
Exceptions
dml_exception
coding_exception

◆ get_data_requests()

static tool_dataprivacy\api::get_data_requests ( $userid = 0,
$statuses = [],
$types = [],
$creationmethods = [],
$sort = '',
$offset = 0,
$limit = 0 )
static

Fetches the list of the data requests.

If user ID is provided, it fetches the data requests for the user. Otherwise, it fetches all of the data requests, provided that the user has the capability to manage data requests. (e.g. Users with the Data Protection Officer roles)

Parameters
int$useridThe User ID.
int[]$statusesThe status filters.
int[]$typesThe request type filters.
int[]$creationmethodsThe request creation method filters.
string$sortThe order by clause.
int$offsetAmount of records to skip.
int$limitAmount of records to fetch.
Return values
data_request[]
Exceptions
coding_exception
dml_exception

◆ get_data_requests_count()

static tool_dataprivacy\api::get_data_requests_count ( $userid = 0,
$statuses = [],
$types = [],
$creationmethods = [] )
static

Fetches the count of data request records based on the given parameters.

Parameters
int$useridThe User ID.
int[]$statusesThe status filters.
int[]$typesThe request type filters.
int[]$creationmethodsThe request creation method filters.
Return values
int
Exceptions
coding_exception
dml_exception

◆ get_download_link()

static tool_dataprivacy\api::get_download_link ( \context_user $usercontext,
$requestid )
static

Gets an action menu link to download a data request.

Parameters
context_user$usercontextUser context (of user who the data is for)
int$requestidRequest id
Return values
action_menu_link_secondaryAction menu link
Exceptions
coding_exception

◆ get_dpo_role_names()

static tool_dataprivacy\api::get_dpo_role_names ( )
static

Fetches the role shortnames of Data Protection Officer roles.

Return values
arrayAn array of the DPO role shortnames

◆ get_effective_context_category()

static tool_dataprivacy\api::get_effective_context_category ( \context $context,
$forcedvalue = false )
static

Returns the effective category given a context instance.

Parameters
context$context
int$forcedvalueUse this categoryid value as if this was this context instance category.
Return values
category|false

◆ get_effective_context_purpose()

static tool_dataprivacy\api::get_effective_context_purpose ( \context $context,
$forcedvalue = false )
static

Returns the effective purpose given a context instance.

Parameters
context$context
int$forcedvalueUse this purposeid value as if this was this context instance purpose.
Return values
purpose|false

◆ get_effective_contextlevel_category()

static tool_dataprivacy\api::get_effective_contextlevel_category ( $contextlevel)
static

Returns the effective category given a context level.

Parameters
int$contextlevel
Return values
category|false

◆ get_effective_contextlevel_purpose()

static tool_dataprivacy\api::get_effective_contextlevel_purpose ( $contextlevel,
$forcedvalue = false )
static

Returns the effective purpose given a context level.

Parameters
int$contextlevel
int$forcedvalueUse this purposeid value as if this was this context level purpose.
Return values
purpose|false

◆ get_purposes()

static tool_dataprivacy\api::get_purposes ( )
static

Get all system data purposes.

Return values
tool_dataprivacy\purpose[]

◆ get_request()

static tool_dataprivacy\api::get_request ( $requestid)
static

Fetches a request based on the request ID.

Parameters
int$requestidThe request identifier
Return values
data_request

◆ has_ongoing_request()

static tool_dataprivacy\api::has_ongoing_request ( $userid,
$type )
static

Checks whether there is already an existing pending/in-progress data request for a user for a given request type.

Parameters
int$useridThe user ID.
int$typeThe request type.
Return values
bool
Exceptions
coding_exception
dml_exception

◆ is_active()

static tool_dataprivacy\api::is_active ( $status)
static

Determines whether a request is active or not based on its status.

Parameters
int$statusThe request status.
Return values
bool

◆ is_automatic_request_approval_on()

static tool_dataprivacy\api::is_automatic_request_approval_on ( int $type)
static

Whether automatic data request approval is turned on or not for the given request type.

Parameters
int$typeThe request type.
Return values
bool

◆ is_site_dpo()

static tool_dataprivacy\api::is_site_dpo ( $userid)
static

Checks whether a given user is a site Privacy Officer.

Parameters
int$useridThe user ID.
Return values
bool

◆ notify_dpo()

static tool_dataprivacy\api::notify_dpo ( $dpo,
data_request $request )
static

Sends a message to the site's Data Protection Officer about a request.

Parameters
stdClass$dpoThe DPO user record
data_request$requestThe data request
Return values
int|false
Exceptions
coding_exception
moodle_exception

◆ queue_data_request_task()

static tool_dataprivacy\api::queue_data_request_task ( int $requestid,
int $userid = null )
static

Creates an ad-hoc task for the data request.

Parameters
int$requestidThe data request ID.
int$useridOptional. The user ID to run the task as, if necessary.

◆ require_can_create_data_request_for_user()

static tool_dataprivacy\api::require_can_create_data_request_for_user ( $user,
$requester = null )
static

Require that the current user can make a data request for the specified other user.

Parameters
int$userThe user ID of the target user.
int$requesterThe user ID of the user making the request.
Return values
bool

◆ set_context_defaults()

static tool_dataprivacy\api::set_context_defaults ( $contextlevel,
$categoryid,
$purposeid,
$activity = null,
$override = false )
static

Updates the default category and purpose for a given context level (and optionally, a plugin).

Parameters
int$contextlevelThe context level.
int$categoryidThe ID matching the category.
int$purposeidThe ID matching the purpose record.
int$activityThe name of the activity that we're making a defaults configuration for.
bool$overrideWhether to override the purpose/categories of existing instances to these defaults.
Return values
booleanTrue if set/unset config succeeds. Otherwise, it throws an exception.

◆ set_context_instance()

static tool_dataprivacy\api::set_context_instance ( $record)
static

Sets the context instance purpose and category.

Parameters
stdClass$record
Return values
tool_dataprivacy\context_instance

◆ set_contextlevel()

static tool_dataprivacy\api::set_contextlevel ( $record)
static

Sets the context level purpose and category.

Exceptions
coding_exception
Parameters
stdClass$record
Return values
contextlevel

◆ set_expired_context_status()

static tool_dataprivacy\api::set_expired_context_status ( expired_context $expiredctx,
$status )
static

Updates the status of an expired context.

Parameters
tool_dataprivacy\expired_context$expiredctx
int$status
Return values
null

◆ unset_context_instance()

static tool_dataprivacy\api::unset_context_instance ( context_instance $instance)
static

Unsets the context instance record.

Parameters
tool_dataprivacy\context_instance$instance
Return values
null

◆ update_category()

static tool_dataprivacy\api::update_category ( stdClass $record)
static

Updates an existing data category.

Parameters
stdClass$record
Return values
tool_dataprivacy\category.

◆ update_purpose()

static tool_dataprivacy\api::update_purpose ( stdClass $record)
static

Updates an existing data purpose.

Parameters
stdClass$record
Return values
tool_dataprivacy\purpose.

◆ update_request_contexts_with_status()

static tool_dataprivacy\api::update_request_contexts_with_status ( int $requestid,
int $status )
static

Sets the status of all contexts associated with the request.

Since
Moodle 4.3
Parameters
int$requestidthe requestid to which the contexts belong.
int$statusthe status to set to.
Exceptions
dml_exceptionif the requestid is invalid.
coding_exceptionif the status is invalid.

◆ update_request_status()

static tool_dataprivacy\api::update_request_status ( $requestid,
$status,
$dpoid = 0,
$comment = '' )
static

Cancels the data request for a given request ID.

Parameters
int$requestidThe request identifier.
int$statusThe request status.
int$dpoidThe user ID of the Data Protection Officer
string$commentThe comment about the status update.
Return values
bool
Exceptions
invalid_persistent_exception
coding_exception

Member Data Documentation

◆ DATAREQUEST_TYPE_OTHERS

const tool_dataprivacy\api::DATAREQUEST_TYPE_OTHERS = 3

Other request type.

Usually of enquiries to the DPO.


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