Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   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.
   8  //
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Data provider.
  19   *
  20   * @package    tool_log
  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
  24   */
  25  
  26  namespace tool_log\privacy;
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use context;
  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;
  35  
  36  /**
  37   * Data provider class.
  38   *
  39   * @package    tool_log
  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
  43   */
  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 {
  48  
  49      /**
  50       * Returns metadata.
  51       *
  52       * @param collection $collection The initialised collection to add items to.
  53       * @return collection A listing of user data stored through this system.
  54       */
  55      public static function get_metadata(collection $collection) : collection {
  56          $collection->add_plugintype_link('logstore', [], 'privacy:metadata:logstore');
  57          return $collection;
  58      }
  59  
  60      /**
  61       * Get the list of contexts that contain user information for the specified user.
  62       *
  63       * @param int $userid The user to search.
  64       * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
  65       */
  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]);
  69          return $contextlist;
  70      }
  71  
  72      /**
  73       * Get the list of contexts that contain user information for the specified user.
  74       *
  75       * @param   \core_privacy\local\request\userlist    $userlist   The userlist containing the list of users who have data in
  76       * this context/plugin combination.
  77       */
  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);
  81      }
  82  
  83      /**
  84       * Export all user data for the specified user, in the specified contexts.
  85       *
  86       * @param approved_contextlist $contextlist The approved contexts to export information for.
  87       */
  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]);
  91          }
  92      }
  93  
  94      /**
  95       * Delete all data for all users in the specified context.
  96       *
  97       * @param context $context The specific context to delete data for.
  98       */
  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]);
 101      }
 102  
 103      /**
 104       * Delete all user data for the specified user, in the specified contexts.
 105       *
 106       * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
 107       */
 108      public static function delete_data_for_user(approved_contextlist $contextlist) {
 109          static::call_subplugins_method_with_args('delete_data_for_user', [$contextlist]);
 110      }
 111  
 112      /**
 113       * Delete multiple users within a single context.
 114       *
 115       * @param \core_privacy\local\request\approved_userlist $userlist The approved context and user information to delete
 116       * information for.
 117       */
 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);
 121      }
 122  
 123      /**
 124       * Invoke the subplugins method with arguments.
 125       *
 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.
 129       * @return void
 130       */
 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;
 134          }
 135          \core_privacy\manager::plugintype_class_callback('logstore', $interface, $method, $args);
 136      }
 137  }