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   * Provides {@link \core_form\privacy\provider} class.
  19   *
  20   * @package     core_form
  21   * @category    privacy
  22   * @copyright   2018 David Mudrák <david@moodle.com>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core_form\privacy;
  27  
  28  use core_privacy\local\metadata\collection;
  29  use core_privacy\local\request\writer;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  /**
  34   * Implements the privacy API for the core_form subsystem.
  35   *
  36   * @package   core_files
  37   * @copyright 2018 David Mudrák <david@moodle.com>
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class provider implements
  41          // The forms subsystem does not store any data itself, it has no database tables.
  42          \core_privacy\local\metadata\provider,
  43  
  44          // The forms subsystem has user preferences.
  45          \core_privacy\local\request\user_preference_provider {
  46  
  47      /**
  48       * Returns meta data about this system.
  49       *
  50       * @param collection $collection The initialised collection to add items to.
  51       * @return collection A listing of user data stored through this system.
  52       */
  53      public static function get_metadata(collection $collection) : collection {
  54  
  55          $collection->add_user_preference('filemanager_recentviewmode', 'privacy:metadata:preference:filemanager_recentviewmode');
  56  
  57          return $collection;
  58      }
  59  
  60      /**
  61       * Export all user preferences for the subsystem.
  62       *
  63       * @param int $userid The ID of the user whose data is to be exported.
  64       */
  65      public static function export_user_preferences(int $userid) {
  66          $preference = get_user_preferences('filemanager_recentviewmode', null, $userid);
  67          if ($preference !== null) {
  68              switch ($preference) {
  69                  case 1:
  70                      $value = get_string('displayasicons', 'core_repository');
  71                      break;
  72                  case 2:
  73                      $value = get_string('displayastree', 'core_repository');
  74                      break;
  75                  case 3:
  76                      $value = get_string('displaydetails', 'core_repository');
  77                      break;
  78                  default:
  79                      $value = $preference;
  80              }
  81  
  82              $desc = get_string('privacy:preference:filemanager_recentviewmode', 'core_form', $value);
  83              writer::export_user_preference('core_form', 'filemanager_recentviewmode', $preference, $desc);
  84          }
  85      }
  86  }