MDL-63688 core_tag: Add method that returns users in context

This issue is part of the MDL-62560 Epic.
This commit is contained in:
Mihail Geshoski 2018-10-24 09:26:11 +08:00
parent cc486e6125
commit 1d3d4c66df
2 changed files with 114 additions and 0 deletions

View file

@ -31,6 +31,8 @@ use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
use core_privacy\local\request\userlist;
use core_privacy\local\request\approved_userlist;
/**
* Privacy Subsystem implementation for core_tag.
@ -45,6 +47,9 @@ class provider implements
// The tag subsystem provides data to other components.
\core_privacy\local\request\subsystem\plugin_provider,
// This plugin is capable of determining which users have data within it.
\core_privacy\local\request\core_userlist_provider,
// The tag subsystem may have data that belongs to this user.
\core_privacy\local\request\plugin\provider {
@ -210,6 +215,24 @@ class provider implements
return $contextlist;
}
/**
* Get the list of users within a specific 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_system) {
return;
}
$sql = "SELECT userid
FROM {tag}";
$userlist->add_from_sql('userid', $sql, []);
}
/**
* Export all user data for the specified user, in the specified contexts.
*
@ -264,6 +287,25 @@ 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_system) {
// Do not delete tags themselves in case they are used by somebody else.
// If the user is the only one using the tag, it will be automatically deleted anyway during the
// next cron cleanup.
list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
$DB->set_field_select('tag', 'userid', 0, "userid {$usersql}", $userparams);
}
}
/**
* Delete all user data for the specified user, in the specified contexts.
*