#252 Privacy API update
Add support to get_users_in_context and delete_data_for_users methods added since 3.4.6 and 3.5.3 and 3.6.
This commit is contained in:
parent
2ebb734145
commit
7ae3101ea1
2 changed files with 157 additions and 0 deletions
|
@ -25,9 +25,11 @@ namespace mod_customcert\privacy;
|
|||
|
||||
use core_privacy\local\metadata\collection;
|
||||
use core_privacy\local\request\approved_contextlist;
|
||||
use core_privacy\local\request\approved_userlist;
|
||||
use core_privacy\local\request\contextlist;
|
||||
use core_privacy\local\request\helper;
|
||||
use core_privacy\local\request\transform;
|
||||
use core_privacy\local\request\userlist;
|
||||
use core_privacy\local\request\writer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
@ -96,6 +98,37 @@ class provider implements
|
|||
return $contextlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of users who have data within a context.
|
||||
*
|
||||
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
|
||||
*/
|
||||
public static function get_users_in_context(userlist $userlist) {
|
||||
$context = $userlist->get_context();
|
||||
|
||||
if (!$context instanceof \context_module) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch all users who have a custom certificate.
|
||||
$sql = "SELECT customcertissues.userid
|
||||
FROM {course_modules} cm
|
||||
JOIN {modules} m
|
||||
ON m.id = cm.module AND m.name = :modname
|
||||
JOIN {customcert} customcert
|
||||
ON customcert.id = cm.instance
|
||||
JOIN {customcert_issues} customcertissues
|
||||
ON customcertissues.customcertid = customcert.id
|
||||
WHERE cm.id = :cmid";
|
||||
|
||||
$params = [
|
||||
'cmid' => $context->instanceid,
|
||||
'modname' => 'customcert',
|
||||
];
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export personal data for the given approved_contextlist. User and context information is contained within the contextlist.
|
||||
*
|
||||
|
@ -182,6 +215,33 @@ class provider implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple users within a single context.
|
||||
*
|
||||
* @param approved_userlist $userlist The approved context and user information to delete information for.
|
||||
*/
|
||||
public static function delete_data_for_users(approved_userlist $userlist) {
|
||||
global $DB;
|
||||
|
||||
$context = $userlist->get_context();
|
||||
if (!$context instanceof \context_module) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_id('customcert', $context->instanceid);
|
||||
if (!$cm) {
|
||||
// Only customcert module will be handled.
|
||||
return;
|
||||
}
|
||||
|
||||
$userids = $userlist->get_userids();
|
||||
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
|
||||
|
||||
$select = "customcertid = :customcertid AND userid $usersql";
|
||||
$params = ['customcertid' => $cm->instance] + $userparams;
|
||||
$DB->delete_records_select('customcert_issues', $select, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of Customcert IDs mapped to their course module ID.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue