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.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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 enrol_meta.
  19   *
  20   * @package    enrol_meta
  21   * @category   privacy
  22   * @copyright  2018 Carlos Escobedo <carlos@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace enrol_meta\privacy;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  use core_privacy\local\metadata\collection;
  31  use core_privacy\local\request\approved_userlist;
  32  use core_privacy\local\request\contextlist;
  33  use core_privacy\local\request\approved_contextlist;
  34  use core_privacy\local\request\userlist;
  35  
  36  /**
  37   * Privacy provider for enrol_meta.
  38   *
  39   * @copyright  2018 Carlos Escobedo <carlos@moodle.com>
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class provider implements
  43          // This plugin stores user data.
  44          \core_privacy\local\metadata\provider,
  45  
  46          // This plugin contains user's enrolments.
  47          \core_privacy\local\request\plugin\provider,
  48  
  49          // This plugin is capable of determining which users have data within it.
  50          \core_privacy\local\request\core_userlist_provider {
  51  
  52      /**
  53       * Returns meta data about this system.
  54       *
  55       * @param   collection     $collection The initialised item collection to add items to.
  56       * @return  collection     A listing of user data stored through this system.
  57       */
  58      public static function get_metadata(collection $collection) : collection {
  59  
  60          $collection->add_subsystem_link('core_group', [], 'privacy:metadata:core_group');
  61          return $collection;
  62      }
  63  
  64      /**
  65       * Get the list of contexts that contain user information for the specified user.
  66       *
  67       * @param int $userid The user to search.
  68       * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
  69       */
  70      public static function get_contexts_for_userid(int $userid) : contextlist {
  71          return \core_group\privacy\provider::get_contexts_for_group_member($userid, 'enrol_meta');
  72      }
  73  
  74      /**
  75       * Get the list of users who have data within a context.
  76       *
  77       * @param   userlist    $userlist   The userlist containing the list of users who have data in this context/plugin combination.
  78       */
  79      public static function get_users_in_context(userlist $userlist) {
  80          $context = $userlist->get_context();
  81  
  82          if (!$context instanceof \context_course) {
  83              return;
  84          }
  85  
  86          \core_group\privacy\provider::get_group_members_in_context($userlist, 'enrol_meta');
  87      }
  88  
  89      /**
  90       * Export all user data for the specified user, in the specified contexts.
  91       *
  92       * @param approved_contextlist $contextlist The approved contexts to export information for.
  93       */
  94      public static function export_user_data(approved_contextlist $contextlist) {
  95          if (empty($contextlist)) {
  96              return;
  97          }
  98          foreach ($contextlist as $context) {
  99              if ($context->contextlevel == CONTEXT_COURSE) {
 100                  \core_group\privacy\provider::export_groups(
 101                      $context,
 102                      'enrol_meta',
 103                      [get_string('pluginname', 'enrol_meta')]
 104                  );
 105              }
 106          }
 107      }
 108  
 109      /**
 110       * Delete all use data which matches the specified deletion_criteria.
 111       *
 112       * @param \context $context A user context.
 113       */
 114      public static function delete_data_for_all_users_in_context(\context $context) {
 115          if (empty($context)) {
 116              return;
 117          }
 118          if ($context->contextlevel == CONTEXT_COURSE) {
 119              // Delete all the associated groups.
 120              \core_group\privacy\provider::delete_groups_for_all_users($context, 'enrol_meta');
 121          }
 122      }
 123  
 124      /**
 125       * Delete all user data for the specified user, in the specified contexts.
 126       *
 127       * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
 128       */
 129      public static function delete_data_for_user(approved_contextlist $contextlist) {
 130          if (empty($contextlist->count())) {
 131              return;
 132          }
 133          \core_group\privacy\provider::delete_groups_for_user($contextlist, 'enrol_meta');
 134      }
 135  
 136      /**
 137       * Delete multiple users within a single context.
 138       *
 139       * @param   approved_userlist   $userlist   The approved context and user information to delete information for.
 140       */
 141      public static function delete_data_for_users(approved_userlist $userlist) {
 142          \core_group\privacy\provider::delete_groups_for_users($userlist, 'enrol_meta');
 143      }
 144  }