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] [Versions 39 and 401] [Versions 401 and 403]

Class containing helper methods for processing data requests.

Copyright: 2018 Jun Pataleta
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1345 lines (52 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

api:: (49 methods):
  can_contact_dpo()
  can_manage_data_requests()
  check_can_manage_data_registry()
  get_assigned_privacy_officer_roles()
  get_dpo_role_names()
  get_site_dpos()
  is_site_dpo()
  create_data_request()
  get_data_requests()
  get_data_requests_count()
  has_ongoing_request()
  find_ongoing_request_types_for_users()
  is_active()
  update_request_status()
  get_request()
  approve_data_request()
  deny_data_request()
  notify_dpo()
  can_create_data_request_for_user()
  require_can_create_data_request_for_user()
  can_create_data_download_request_for_self()
  can_create_data_deletion_request_for_self()
  can_create_data_deletion_request_for_other()
  can_create_data_deletion_request_for_children()
  can_download_data_request_for_user()
  get_download_link()
  create_purpose()
  update_purpose()
  delete_purpose()
  get_purposes()
  create_category()
  update_category()
  delete_category()
  get_categories()
  set_context_instance()
  unset_context_instance()
  set_contextlevel()
  get_effective_context_category()
  get_effective_context_purpose()
  get_effective_contextlevel_category()
  get_effective_contextlevel_purpose()
  create_expired_context()
  delete_expired_context()
  set_expired_context_status()
  get_approved_contextlist_collection_for_collection()
  set_context_defaults()
  format_retention_period()
  is_automatic_request_approval_on()
  queue_data_request_task()


Class: api  - X-Ref

Class containing helper methods for processing data requests.

can_contact_dpo()   X-Ref
Determines whether the user can contact the site's Data Protection Officer via Moodle.

return: boolean True when tool_dataprivacy|contactdataprotectionofficer is enabled.

can_manage_data_requests($userid)   X-Ref
Checks whether the current user has the capability to manage data requests.

param: int $userid The user ID.
return: bool

check_can_manage_data_registry($contextid = false)   X-Ref
Checks if the current user can manage the data registry at the provided id.

param: int $contextid Fallback to system context id.
return: null

get_assigned_privacy_officer_roles()   X-Ref
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: int[]

get_dpo_role_names()   X-Ref
Fetches the role shortnames of Data Protection Officer roles.

return: array An array of the DPO role shortnames

get_site_dpos()   X-Ref
Fetches the list of users with the Privacy Officer role.


is_site_dpo($userid)   X-Ref
Checks whether a given user is a site Privacy Officer.

param: int $userid The user ID.
return: bool

create_data_request($foruser, $type, $comments = '',$creationmethod = data_request::DATAREQUEST_CREATION_MANUAL,$notify = null)   X-Ref
Lodges a data request and sends the request details to the site Data Protection Officer(s).

param: int $foruser The user whom the request is being made for.
param: int $type The request type.
param: string $comments Request comments.
param: int $creationmethod The creation method of the data request.
param: bool $notify Notify DPOs of this pending request.
return: data_request

get_data_requests($userid = 0, $statuses = [], $types = [], $creationmethods = [],$sort = '', $offset = 0, $limit = 0)   X-Ref
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)

param: int $userid The User ID.
param: int[] $statuses The status filters.
param: int[] $types The request type filters.
param: int[] $creationmethods The request creation method filters.
param: string $sort The order by clause.
param: int $offset Amount of records to skip.
param: int $limit Amount of records to fetch.
return: data_request[]

get_data_requests_count($userid = 0, $statuses = [], $types = [], $creationmethods = [])   X-Ref
Fetches the count of data request records based on the given parameters.

param: int $userid The User ID.
param: int[] $statuses The status filters.
param: int[] $types The request type filters.
param: int[] $creationmethods The request creation method filters.
return: int

has_ongoing_request($userid, $type)   X-Ref
Checks whether there is already an existing pending/in-progress data request for a user for a given request type.

param: int $userid The user ID.
param: int $type The request type.
return: bool

find_ongoing_request_types_for_users(array $userids)   X-Ref
Find whether any ongoing requests exist for a set of users.

param: array   $userids
return: array

is_active($status)   X-Ref
Determines whether a request is active or not based on its status.

param: int $status The request status.
return: bool

update_request_status($requestid, $status, $dpoid = 0, $comment = '')   X-Ref
Cancels the data request for a given request ID.

param: int $requestid The request identifier.
param: int $status The request status.
param: int $dpoid The user ID of the Data Protection Officer
param: string $comment The comment about the status update.
return: bool

get_request($requestid)   X-Ref
Fetches a request based on the request ID.

param: int $requestid The request identifier
return: data_request

approve_data_request($requestid)   X-Ref
Approves a data request based on the request ID.

param: int $requestid The request identifier
return: bool

deny_data_request($requestid)   X-Ref
Rejects a data request based on the request ID.

param: int $requestid The request identifier
return: bool

notify_dpo($dpo, data_request $request)   X-Ref
Sends a message to the site's Data Protection Officer about a request.

param: stdClass $dpo The DPO user record
param: data_request $request The data request
return: int|false

can_create_data_request_for_user($user, $requester = null)   X-Ref
Checks whether a non-DPO user can make a data request for another user.

param: int     $user The user ID of the target user.
param: int     $requester The user ID of the user making the request.
return: bool

require_can_create_data_request_for_user($user, $requester = null)   X-Ref
Require that the current user can make a data request for the specified other user.

param: int     $user The user ID of the target user.
param: int     $requester The user ID of the user making the request.
return: bool

can_create_data_download_request_for_self(int $userid = null)   X-Ref
Check if user has permission to create data download request for themselves

param: int|null $userid
return: bool

can_create_data_deletion_request_for_self(int $userid = null)   X-Ref
Check if user has permisson to create data deletion request for themselves.

param: int|null $userid ID of the user.
return: bool

can_create_data_deletion_request_for_other(int $userid = null)   X-Ref
Check if user has permission to create data deletion request for another user.

param: int|null $userid ID of the user.
return: bool

can_create_data_deletion_request_for_children(int $userid, int $requesterid = null)   X-Ref
Check if parent can create data deletion request for their children.

param: int $userid ID of a user being requested.
param: int|null $requesterid ID of a user making request.
return: bool

can_download_data_request_for_user($userid, $requesterid, $downloaderid = null)   X-Ref
Checks whether a user can download a data request.

param: int $userid Target user id (subject of data request)
param: int $requesterid Requester user id (person who requsted it)
param: int|null $downloaderid Person who wants to download user id (default current)
return: bool

get_download_link(\context_user $usercontext, $requestid)   X-Ref
Gets an action menu link to download a data request.

param: \context_user $usercontext User context (of user who the data is for)
param: int $requestid Request id
return: \action_menu_link_secondary Action menu link

create_purpose(stdClass $record)   X-Ref
Creates a new data purpose.

param: stdClass $record
return: \tool_dataprivacy\purpose.

update_purpose(stdClass $record)   X-Ref
Updates an existing data purpose.

param: stdClass $record
return: \tool_dataprivacy\purpose.

delete_purpose($id)   X-Ref
Deletes a data purpose.

param: int $id
return: bool

get_purposes()   X-Ref
Get all system data purposes.

return: \tool_dataprivacy\purpose[]

create_category(stdClass $record)   X-Ref
Creates a new data category.

param: stdClass $record
return: \tool_dataprivacy\category.

update_category(stdClass $record)   X-Ref
Updates an existing data category.

param: stdClass $record
return: \tool_dataprivacy\category.

delete_category($id)   X-Ref
Deletes a data category.

param: int $id
return: bool

get_categories()   X-Ref
Get all system data categories.

return: \tool_dataprivacy\category[]

set_context_instance($record)   X-Ref
Sets the context instance purpose and category.

param: \stdClass $record
return: \tool_dataprivacy\context_instance

unset_context_instance(context_instance $instance)   X-Ref
Unsets the context instance record.

param: \tool_dataprivacy\context_instance $instance
return: null

set_contextlevel($record)   X-Ref
Sets the context level purpose and category.

param: \stdClass $record
return: contextlevel

get_effective_context_category(\context $context, $forcedvalue = false)   X-Ref
Returns the effective category given a context instance.

param: \context $context
param: int $forcedvalue Use this categoryid value as if this was this context instance category.
return: category|false

get_effective_context_purpose(\context $context, $forcedvalue = false)   X-Ref
Returns the effective purpose given a context instance.

param: \context $context
param: int $forcedvalue Use this purposeid value as if this was this context instance purpose.
return: purpose|false

get_effective_contextlevel_category($contextlevel)   X-Ref
Returns the effective category given a context level.

param: int $contextlevel
return: category|false

get_effective_contextlevel_purpose($contextlevel, $forcedvalue=false)   X-Ref
Returns the effective purpose given a context level.

param: int $contextlevel
param: int $forcedvalue Use this purposeid value as if this was this context level purpose.
return: purpose|false

create_expired_context($contextid)   X-Ref
Creates an expired context record for the provided context id.

param: int $contextid
return: \tool_dataprivacy\expired_context

delete_expired_context($id)   X-Ref
Deletes an expired context record.

param: int $id The tool_dataprivacy_ctxexpire id.
return: bool True on success.

set_expired_context_status(expired_context $expiredctx, $status)   X-Ref
Updates the status of an expired context.

param: \tool_dataprivacy\expired_context $expiredctx
param: int $status
return: null

get_approved_contextlist_collection_for_collection(contextlist_collection $collection,\stdClass $foruser, int $type)   X-Ref
Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.

param: contextlist_collection  $collection The collection of unapproved contextlist objects.
param: \stdClass               $foruser The target user
param: int                     $type The purpose of the collection
return: contextlist_collection  The collection of approved_contextlist objects.

set_context_defaults($contextlevel, $categoryid, $purposeid, $activity = null, $override = false)   X-Ref
Updates the default category and purpose for a given context level (and optionally, a plugin).

param: int $contextlevel The context level.
param: int $categoryid The ID matching the category.
param: int $purposeid The ID matching the purpose record.
param: int $activity The name of the activity that we're making a defaults configuration for.
param: bool $override Whether to override the purpose/categories of existing instances to these defaults.
return: boolean True if set/unset config succeeds. Otherwise, it throws an exception.

format_retention_period(\DateInterval $interval)   X-Ref
Format the supplied date interval as a retention period.

param: \DateInterval   $interval
return: string

is_automatic_request_approval_on(int $type)   X-Ref
Whether automatic data request approval is turned on or not for the given request type.

param: int $type The request type.
return: bool

queue_data_request_task(int $requestid, int $userid = null)   X-Ref
Creates an ad-hoc task for the data request.

param: int $requestid The data request ID.
param: int $userid Optional. The user ID to run the task as, if necessary.