2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
21 * @copyright 2018 Frédéric Massart
22 * @author Frédéric Massart <fred@branchup.tech>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace tool_log\privacy;
27 defined('MOODLE_INTERNAL') || die();
30 use core_privacy\local\metadata\collection;
31 use core_privacy\local\request\approved_contextlist;
32 use core_privacy\local\request\transform;
33 use core_privacy\local\request\writer;
34 use tool_log\log\manager;
37 * Data provider class.
40 * @copyright 2018 Frédéric Massart
41 * @author Frédéric Massart <fred@branchup.tech>
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class provider implements
45 \core_privacy\local\metadata\provider,
46 \core_privacy\local\request\subsystem\provider,
47 \core_privacy\local\request\core_userlist_provider {
52 * @param collection $collection The initialised collection to add items to.
53 * @return collection A listing of user data stored through this system.
55 public static function get_metadata(collection $collection) : collection {
56 $collection->add_plugintype_link('logstore', [], 'privacy:metadata:logstore');
61 * Get the list of contexts that contain user information for the specified user.
63 * @param int $userid The user to search.
64 * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
66 public static function get_contexts_for_userid(int $userid) : \core_privacy\local\request\contextlist {
67 $contextlist = new \core_privacy\local\request\contextlist();
68 static::call_subplugins_method_with_args('add_contexts_for_userid', [$contextlist, $userid]);
73 * Get the list of contexts that contain user information for the specified user.
75 * @param \core_privacy\local\request\userlist $userlist The userlist containing the list of users who have data in
76 * this context/plugin combination.
78 public static function get_users_in_context(\core_privacy\local\request\userlist $userlist) {
79 $interface = \tool_log\local\privacy\logstore_userlist_provider::class;
80 static::call_subplugins_method_with_args('add_userids_for_context', [$userlist], $interface);
84 * Export all user data for the specified user, in the specified contexts.
86 * @param approved_contextlist $contextlist The approved contexts to export information for.
88 public static function export_user_data(approved_contextlist $contextlist) {
89 if (get_config('tool_log', 'exportlog')) {
90 static::call_subplugins_method_with_args('export_user_data', [$contextlist]);
95 * Delete all data for all users in the specified context.
97 * @param context $context The specific context to delete data for.
99 public static function delete_data_for_all_users_in_context(context $context) {
100 static::call_subplugins_method_with_args('delete_data_for_all_users_in_context', [$context]);
104 * Delete all user data for the specified user, in the specified contexts.
106 * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
108 public static function delete_data_for_user(approved_contextlist $contextlist) {
109 static::call_subplugins_method_with_args('delete_data_for_user', [$contextlist]);
113 * Delete multiple users within a single context.
115 * @param \core_privacy\local\request\approved_userlist $userlist The approved context and user information to delete
118 public static function delete_data_for_users(\core_privacy\local\request\approved_userlist $userlist) {
119 $interface = \tool_log\local\privacy\logstore_userlist_provider::class;
120 static::call_subplugins_method_with_args('delete_data_for_userlist', [$userlist], $interface);
124 * Invoke the subplugins method with arguments.
126 * @param string $method The method name.
127 * @param array $args The arguments.
128 * @param string $interface The interface to use. By default uses the logstore_provider.
131 protected static function call_subplugins_method_with_args($method, array $args = [], string $interface = null) {
132 if (!isset($interface)) {
133 $interface = \tool_log\local\privacy\logstore_provider::class;
135 \core_privacy\manager::plugintype_class_callback('logstore', $interface, $method, $args);