MDL-63926 block_recentlyaccesseditems: Support user removal by context

Also fixed the provider interface type. This is self contained, so is
not a subsystem provider. It was also already set up as a plugin
provider, just not defined as such.
This commit is contained in:
Michael Hawkins 2018-11-12 12:19:51 +08:00
parent 13bd038912
commit 8adf5d94b2

View File

@ -29,7 +29,9 @@ defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\userlist;
use \core_privacy\local\request\approved_contextlist;
use \core_privacy\local\request\approved_userlist;
use \core_privacy\local\request\writer;
/**
@ -39,7 +41,10 @@ use \core_privacy\local\request\writer;
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\subsystem\provider {
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns information about the user data stored in this component.
@ -80,6 +85,25 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
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) {
global $DB;
$context = $userlist->get_context();
if (!$context instanceof \context_user) {
return;
}
if ($DB->record_exists('block_recentlyaccesseditems', ['userid' => $context->instanceid])) {
$userlist->add_user($context->instanceid);
}
}
/**
* Export all user data for the specified user, in the specified contexts.
*
@ -151,4 +175,19 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
}
}
}
}
/**
* 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_user && in_array($context->instanceid, $userlist->get_userids())) {
$DB->delete_records('block_recentlyaccesseditems', ['userid' => $context->instanceid]);
}
}
}