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   * This file defines an item of metadata which encapsulates data which is exported to an external location.
  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  namespace core_privacy\local\metadata\types;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * The external_location type.
  30   *
  31   * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
  32   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class external_location implements type {
  35  
  36      /**
  37       * @var string The name to describe the type of information exported.
  38       */
  39      protected $name;
  40  
  41      /**
  42       * @var array The list of data names and descriptions exported.
  43       */
  44      protected $privacyfields;
  45  
  46      /**
  47       * @var string A description of what this table is used for.
  48       * This is a language string identifier.
  49       */
  50      protected $summary;
  51  
  52      /**
  53       * Constructor to create a new external_location type.
  54       *
  55       * @param   string  $name A name for the type of data exported.
  56       * @param   array   $privacyfields A list of fields with their description.
  57       * @param   string  $summary A description of what the table is used for. This is a language string identifier
  58       *                  within the component.
  59       */
  60      public function __construct($name, array $privacyfields = [], $summary = '') {
  61          if (debugging('', DEBUG_DEVELOPER)) {
  62              if (empty($privacyfields)) {
  63                  debugging("Location '{$name}' was supplied without any fields.", DEBUG_DEVELOPER);
  64              }
  65  
  66              foreach ($privacyfields as $key => $field) {
  67                  $teststring = clean_param($field, PARAM_STRINGID);
  68                  if ($teststring !== $field) {
  69                      debugging("Field '{$key}' passed for location '{$name}' has an invalid langstring identifier: '{$field}'",
  70                          DEBUG_DEVELOPER);
  71                  }
  72              }
  73  
  74              $teststring = clean_param($summary, PARAM_STRINGID);
  75              if ($teststring !== $summary) {
  76                  debugging("Summary information for the '{$name}' location has an invalid langstring identifier: '{$summary}'",
  77                      DEBUG_DEVELOPER);
  78              }
  79          }
  80  
  81          $this->name = $name;
  82          $this->privacyfields = $privacyfields;
  83          $this->summary = $summary;
  84      }
  85  
  86      /**
  87       * The name to describe the type of information exported.
  88       *
  89       * @return  string
  90       */
  91      public function get_name() {
  92          return $this->name;
  93      }
  94  
  95      /**
  96       * Get the list of fields which contain user data, with a description of each field.
  97       *
  98       * @return  array
  99       */
 100      public function get_privacy_fields() {
 101          return $this->privacyfields;
 102      }
 103  
 104      /**
 105       * A summary of what this type of exported data is used for.
 106       *
 107       * @return  string
 108       */
 109      public function get_summary() {
 110          return $this->summary;
 111      }
 112  }