Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * This file defines an item of metadata which encapsulates a user's preferences.
  19   *
  20   * @package    core_privacy
  21   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_privacy\local\metadata\types;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * The user_preference type.
  31   *
  32   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class user_preference implements type {
  36  
  37      /**
  38       * @var The name of this user preference.
  39       */
  40      protected $name;
  41  
  42      /**
  43       * @var A description of what this user preference means.
  44       */
  45      protected $summary;
  46  
  47      /**
  48       * Constructor to create a new user_preference types.
  49       *
  50       * @param   string  $name The name of the user preference.
  51       * @param   string  $summary A description of what the preference is used for.
  52       */
  53      public function __construct($name, $summary = '') {
  54          if (debugging('', DEBUG_DEVELOPER)) {
  55              $teststring = clean_param($summary, PARAM_STRINGID);
  56              if ($teststring !== $summary) {
  57                  debugging("Summary information for use of the '{$name}' subsystem " .
  58                      " has an invalid langstring identifier: '{$summary}'",
  59                      DEBUG_DEVELOPER);
  60              }
  61          }
  62  
  63          $this->name = $name;
  64          $this->summary = $summary;
  65      }
  66  
  67      /**
  68       * The name of the user preference.
  69       *
  70       * @return  string
  71       */
  72      public function get_name() {
  73          return $this->name;
  74      }
  75  
  76      /**
  77       * A user preference encapsulates a single field and has no sub-fields.
  78       *
  79       * @return  array
  80       */
  81      public function get_privacy_fields() {
  82          return null;
  83      }
  84  
  85      /**
  86       * A summary of what this user preference is used for.
  87       *
  88       * @return  string
  89       */
  90      public function get_summary() {
  91          return $this->summary;
  92      }
  93  }