Skip to content

Commit

Permalink
MDL-63926 block_recentlyaccesseditems: Support user removal by context
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mickhawkins committed Nov 14, 2018
1 parent 13bd038 commit 8adf5d9
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions blocks/recentlyaccesseditems/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
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;

/**
Expand All @@ -39,7 +41,10 @@
* @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.
Expand Down Expand Up @@ -80,6 +85,25 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
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.
*
Expand Down Expand Up @@ -151,4 +175,19 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
}
}
}
}

/**
* 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]);
}
}
}

0 comments on commit 8adf5d9

Please sign in to comment.