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    logstore_standard
  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 logstore_standard\privacy;
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use context;
  30  use core_privacy\local\metadata\collection;
  31  use core_privacy\local\request\contextlist;
  32  
  33  /**
  34   * Data provider class.
  35   *
  36   * @package    logstore_standard
  37   * @copyright  2018 Frédéric Massart
  38   * @author     Frédéric Massart <fred@branchup.tech>
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class provider implements
  42      \core_privacy\local\metadata\provider,
  43      \tool_log\local\privacy\logstore_provider,
  44      \tool_log\local\privacy\logstore_userlist_provider {
  45  
  46      use \tool_log\local\privacy\moodle_database_export_and_delete;
  47  
  48      /**
  49       * Returns metadata.
  50       *
  51       * @param collection $collection The initialised collection to add items to.
  52       * @return collection A listing of user data stored through this system.
  53       */
  54      public static function get_metadata(collection $collection) : collection {
  55          $collection->add_database_table('logstore_standard_log', [
  56              'eventname' => 'privacy:metadata:log:eventname',
  57              'userid' => 'privacy:metadata:log:userid',
  58              'relateduserid' => 'privacy:metadata:log:relateduserid',
  59              'anonymous' => 'privacy:metadata:log:anonymous',
  60              'other' => 'privacy:metadata:log:other',
  61              'timecreated' => 'privacy:metadata:log:timecreated',
  62              'origin' => 'privacy:metadata:log:origin',
  63              'ip' => 'privacy:metadata:log:ip',
  64              'realuserid' => 'privacy:metadata:log:realuserid',
  65          ], 'privacy:metadata:log');
  66          return $collection;
  67      }
  68  
  69      /**
  70       * Add contexts that contain user information for the specified user.
  71       *
  72       * @param contextlist $contextlist The contextlist to add the contexts to.
  73       * @param int $userid The user to find the contexts for.
  74       * @return void
  75       */
  76      public static function add_contexts_for_userid(contextlist $contextlist, $userid) {
  77          $sql = "
  78              SELECT l.contextid
  79                FROM {logstore_standard_log} l
  80               WHERE l.userid = :userid1
  81                  OR l.relateduserid = :userid2
  82                  OR l.realuserid = :userid3";
  83          $contextlist->add_from_sql($sql, [
  84              'userid1' => $userid,
  85              'userid2' => $userid,
  86              'userid3' => $userid,
  87          ]);
  88      }
  89  
  90      /**
  91       * Add user IDs that contain user information for the specified context.
  92       *
  93       * @param \core_privacy\local\request\userlist $userlist The userlist to add the users to.
  94       * @return void
  95       */
  96      public static function add_userids_for_context(\core_privacy\local\request\userlist $userlist) {
  97          $params = ['contextid' => $userlist->get_context()->id];
  98          $sql = "SELECT userid, relateduserid, realuserid
  99                    FROM {logstore_standard_log}
 100                   WHERE contextid = :contextid";
 101          $userlist->add_from_sql('userid', $sql, $params);
 102          $userlist->add_from_sql('relateduserid', $sql, $params);
 103          $userlist->add_from_sql('realuserid', $sql, $params);
 104      }
 105  
 106      /**
 107       * Get the database object.
 108       *
 109       * @return array Containing moodle_database, string, or null values.
 110       */
 111      protected static function get_database_and_table() {
 112          global $DB;
 113          return [$DB, 'logstore_standard_log'];
 114      }
 115  
 116      /**
 117       * Get the path to export the logs to.
 118       *
 119       * @return array
 120       */
 121      protected static function get_export_subcontext() {
 122          return [get_string('privacy:path:logs', 'tool_log'), get_string('pluginname', 'logstore_standard')];
 123      }
 124  }