Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.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   * Privacy Subsystem implementation for repository_wikimedia.
  19   *
  20   * @package    repository_wikimedia
  21   * @copyright  2018 Zig Tan <zig@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace repository_wikimedia\privacy;
  26  
  27  use core_privacy\local\metadata\collection;
  28  use core_privacy\local\request\approved_contextlist;
  29  use core_privacy\local\request\approved_userlist;
  30  use core_privacy\local\request\context;
  31  use core_privacy\local\request\contextlist;
  32  use core_privacy\local\request\userlist;
  33  use core_privacy\local\request\writer;
  34  
  35  defined('MOODLE_INTERNAL') || die();
  36  
  37  /**
  38   * Privacy Subsystem for repository_wikimedia implementing metadata and plugin providers.
  39   *
  40   * @copyright  2018 Zig Tan <zig@moodle.com>
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class provider implements
  44      \core_privacy\local\metadata\provider,
  45      \core_privacy\local\request\core_userlist_provider,
  46      \core_privacy\local\request\plugin\provider,
  47      \core_privacy\local\request\user_preference_provider
  48  {
  49  
  50      /**
  51       * Returns meta data about this system.
  52       *
  53       * @param   collection $collection The initialised collection to add items to.
  54       * @return  collection     A listing of user data stored through this system.
  55       */
  56      public static function get_metadata(collection $collection) : collection {
  57          $collection->add_external_location_link(
  58              'wikimedia.org',
  59              [
  60                  'search_text' => 'privacy:metadata:repository_wikimedia:search_text'
  61              ],
  62              'privacy:metadata:repository_wikimedia'
  63          );
  64  
  65          $collection->add_user_preference(
  66              'repository_wikimedia_maxwidth',
  67              'privacy:metadata:repository_wikimedia:preference:maxwidth'
  68          );
  69  
  70          $collection->add_user_preference(
  71              'repository_wikimedia_maxheight',
  72              'privacy:metadata:repository_wikimedia:preference:maxheight'
  73          );
  74  
  75          return $collection;
  76      }
  77  
  78      /**
  79       * Get the list of contexts that contain user information for the specified user.
  80       *
  81       * @param   int $userid The user to search.
  82       * @return  contextlist   $contextlist  The contextlist containing the list of contexts used in this plugin.
  83       */
  84      public static function get_contexts_for_userid(int $userid) : contextlist {
  85          return new contextlist();
  86      }
  87  
  88      /**
  89       * Get the list of users who have data within a context.
  90       *
  91       * @param   userlist    $userlist   The userlist containing the list of users who have data in this context/plugin combination.
  92       */
  93      public static function get_users_in_context(userlist $userlist) {
  94      }
  95  
  96      /**
  97       * Export all user data for the specified user, in the specified contexts.
  98       *
  99       * @param   approved_contextlist $contextlist The approved contexts to export information for.
 100       */
 101      public static function export_user_data(approved_contextlist $contextlist) {
 102      }
 103  
 104      /**
 105       * Delete all data for all users in the specified context.
 106       *
 107       * @param   context $context The specific context to delete data for.
 108       */
 109      public static function delete_data_for_all_users_in_context(\context $context) {
 110      }
 111  
 112      /**
 113       * Delete all user data for the specified user, in the specified contexts.
 114       *
 115       * @param   approved_contextlist $contextlist The approved contexts and user information to delete information for.
 116       */
 117      public static function delete_data_for_user(approved_contextlist $contextlist) {
 118      }
 119  
 120      /**
 121       * Delete multiple users within a single context.
 122       *
 123       * @param   approved_userlist       $userlist The approved context and user information to delete information for.
 124       */
 125      public static function delete_data_for_users(approved_userlist $userlist) {
 126      }
 127  
 128      /**
 129       * Export all user preferences for the plugin.
 130       *
 131       * @param   int $userid The userid of the user whose data is to be exported.
 132       */
 133      public static function export_user_preferences(int $userid) {
 134          $maxwidth = get_user_preferences('repository_wikimedia_maxwidth', null, $userid);
 135          if ($maxwidth !== null) {
 136              writer::export_user_preference(
 137                  'repository_wikimedia',
 138                  'repository_wikimedia_maxwidth',
 139                  $maxwidth,
 140                  get_string('privacy:metadata:repository_wikimedia:preference:maxwidth', 'repository_wikimedia')
 141              );
 142          }
 143  
 144          $maxheight = get_user_preferences('repository_wikimedia_maxheight', null, $userid);
 145          if ($maxheight !== null) {
 146              writer::export_user_preference(
 147                  'repository_wikimedia',
 148                  'repository_wikimedia_maxheight',
 149                  $maxheight,
 150                  get_string('privacy:metadata:repository_wikimedia:preference:maxheight', 'repository_wikimedia')
 151              );
 152          }
 153      }
 154  }