Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * Privacy Subsystem implementation for core_my.
  18   *
  19   * @package    core_my
  20   * @copyright  2018 Zig Tan <zig@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  namespace core_my\privacy;
  24  
  25  use core_privacy\local\metadata\collection;
  26  use core_privacy\local\request\approved_contextlist;
  27  use core_privacy\local\request\context;
  28  use core_privacy\local\request\contextlist;
  29  use core_privacy\local\request\writer;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  /**
  34   * Privacy Subsystem for core_my implementing metadata, plugin, and user_preference providers.
  35   *
  36   * @copyright  2018 Zig Tan <zig@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class provider implements
  40      \core_privacy\local\metadata\provider,
  41      \core_privacy\local\request\user_preference_provider {
  42  
  43      /**
  44       * Returns meta data about this system.
  45       *
  46       * @param   collection $collection The initialised collection to add items to.
  47       * @return  collection     A listing of user data stored through this system.
  48       */
  49      public static function get_metadata(collection $collection) : collection {
  50          $collection->add_user_preference(
  51              'user_home_page_preference',
  52              'privacy:metadata:core_my:preference:user_home_page_preference'
  53          );
  54  
  55          return $collection;
  56      }
  57  
  58      /**
  59       * Export all user preferences for the plugin.
  60       *
  61       * @param   int $userid The userid of the user whose data is to be exported.
  62       */
  63      public static function export_user_preferences(int $userid) {
  64          $userhomepagepreference = get_user_preferences('user_home_page_preference', null, $userid);
  65  
  66          if (null !== $userhomepagepreference) {
  67              writer::export_user_preference(
  68                  'core_my',
  69                  'user_home_page_preference',
  70                  $userhomepagepreference,
  71                  get_string('privacy:metadata:core_my:preference:user_home_page_preference', 'core_my')
  72              );
  73          }
  74      }
  75  
  76  }