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 39 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 qtype_essay.
  19   *
  20   * @package    qtype_essay
  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 qtype_essay\privacy;
  26  
  27  use \core_privacy\local\metadata\collection;
  28  use \core_privacy\local\request\user_preference_provider;
  29  use \core_privacy\local\request\writer;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  /**
  34   * Privacy Subsystem for qtype_essay implementing user_preference_provider.
  35   *
  36   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class provider implements
  40          // This component has data.
  41          // We need to return default options that have been set a user preferences.
  42          \core_privacy\local\metadata\provider,
  43          \core_privacy\local\request\user_preference_provider
  44  {
  45  
  46      /**
  47       * Returns meta data about this system.
  48       *
  49       * @param   collection     $collection The initialised collection to add items to.
  50       * @return  collection     A listing of user data stored through this system.
  51       */
  52      public static function get_metadata(collection $collection) : collection {
  53          $collection->add_user_preference('qtype_essay_defaultmark', 'privacy:preference:defaultmark');
  54          $collection->add_user_preference('qtype_essay_responseformat', 'privacy:preference:responseformat');
  55          $collection->add_user_preference('qtype_essay_responserequired', 'privacy:preference:responserequired');
  56          $collection->add_user_preference('qtype_essay_responsefieldlines', 'privacy:preference:responsefieldlines');
  57          $collection->add_user_preference('qtype_essay_attachments', 'privacy:preference:attachments');
  58          $collection->add_user_preference('qtype_essay_attachmentsrequired', 'privacy:preference:attachmentsrequired');
  59          $collection->add_user_preference('qtype_essay_maxbytes', 'privacy:preference:maxbytes');
  60          return $collection;
  61      }
  62  
  63      /**
  64       * Export all user preferences for the plugin.
  65       *
  66       * @param int $userid The userid of the user whose data is to be exported.
  67       */
  68      public static function export_user_preferences(int $userid) {
  69          $preference = get_user_preferences('qtype_essay_defaultmark', null, $userid);
  70          if (null !== $preference) {
  71              $desc = get_string('privacy:preference:defaultmark', 'qtype_essay');
  72              writer::export_user_preference('qtype_essay', 'defaultmark', $preference, $desc);
  73          }
  74  
  75          $preference = get_user_preferences('qtype_essay_responseformat', null, $userid);
  76          if (null !== $preference) {
  77              switch($preference) {
  78                  case 'editor':
  79                      $stringvalue = get_string('formateditor', 'qtype_essay');
  80                      break;
  81                  case 'editorfilepicker':
  82                      $stringvalue = get_string('formateditorfilepicker', 'qtype_essay');
  83                      break;
  84                  case 'plain':
  85                      $stringvalue = get_string('formatplain', 'qtype_essay');
  86                      break;
  87                  case 'monospaced':
  88                      $stringvalue = get_string('formatmonospaced', 'qtype_essay');
  89                      break;
  90                  case 'noinline':
  91                      $stringvalue = get_string('formatnoinline', 'qtype_essay');
  92                      break;
  93                  default:
  94                      $stringvalue = get_string('formateditor', 'qtype_essay');
  95                      break;
  96              }
  97              $desc = get_string('privacy:preference:responseformat', 'qtype_essay');
  98              writer::export_user_preference('qtype_essay', 'responseformat', $stringvalue, $desc);
  99          }
 100  
 101          $preference = get_user_preferences('qtype_essay_responserequired', null, $userid);
 102          if (null !== $preference) {
 103              if ($preference) {
 104                  $stringvalue = get_string('responseisrequired', 'qtype_essay');
 105              } else {
 106                  $stringvalue = get_string('responsenotrequired', 'qtype_essay');
 107              }
 108              $desc = get_string('privacy:preference:responserequired', 'qtype_essay');
 109              writer::export_user_preference('qtype_essay', 'responserequired', $stringvalue, $desc);
 110          }
 111  
 112          $preference = get_user_preferences('qtype_essay_responsefieldlines', null, $userid);
 113          if (null !== $preference) {
 114              $desc = get_string('privacy:preference:responsefieldlines', 'qtype_essay');
 115              writer::export_user_preference('qtype_essay', 'responsefieldlines',
 116                      get_string('nlines', 'qtype_essay', $preference), $desc);
 117          }
 118          $preference = get_user_preferences('qtype_essay_attachments', null, $userid);
 119          if (null !== $preference) {
 120              if ($preference == 0) {
 121                  $stringvalue = get_string('no');
 122              } else if ($preference == -1) {
 123                      $stringvalue = get_string('unlimited');
 124              } else {
 125                  $stringvalue = $preference;
 126              }
 127              $desc = get_string('privacy:preference:attachments', 'qtype_essay');
 128              writer::export_user_preference('qtype_essay', 'attachments', $stringvalue, $desc);
 129          }
 130  
 131          $preference = get_user_preferences('qtype_essay_attachmentsrequired', null, $userid);
 132          if (null !== $preference) {
 133              if ($preference == 0) {
 134                  $stringvalue = get_string('attachmentsoptional', 'qtype_essay');
 135              } else {
 136                  $stringvalue = $preference;
 137              }
 138              $desc = get_string('privacy:preference:attachmentsrequired', 'qtype_essay');
 139              writer::export_user_preference('qtype_essay', 'attachmentsrequired', $stringvalue, $desc);
 140          }
 141  
 142          $preference = get_user_preferences('qtype_essay_maxbytes', null, $userid);
 143          if (null !== $preference) {
 144              switch ($preference) {
 145                  case 52428800:
 146                      $stringvalue = '50MB';
 147                      break;
 148                  case 20971520:
 149                      $stringvalue = '20MB';
 150                      break;
 151                  case 10485760:
 152                      $stringvalue = '10MB';
 153                      break;
 154                  case 5242880:
 155                      $stringvalue = '5MB';
 156                      break;
 157                  case 2097152:
 158                      $stringvalue = '2MB';
 159                      break;
 160                  case 1048576:
 161                      $stringvalue = '1MB';
 162                      break;
 163                  case 512000:
 164                      $stringvalue = '500KB';
 165                      break;
 166                  case 102400:
 167                      $stringvalue = '100KB';
 168                      break;
 169                  case 51200:
 170                      $stringvalue = '50KB';
 171                      break;
 172                  case 10240:
 173                      $stringvalue = '10KB';
 174                      break;
 175                  default:
 176                      $stringvalue = '50MB';
 177                      break;
 178              }
 179              $desc = get_string('privacy:preference:maxbytes', 'qtype_essay');
 180              writer::export_user_preference('qtype_essay', 'maxbytes', $stringvalue, $desc);
 181          }
 182      }
 183  }