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 database table.
  19   *
  20   * @package core_privacy
  21   * @copyright 2018 Zig Tan <zig@moodle.com>
  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 database_table type.
  30   *
  31   * @copyright 2018 Zig Tan <zig@moodle.com>
  32   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class database_table implements type {
  35  
  36      /**
  37       * @var string  Database table name.
  38       */
  39      protected $name;
  40  
  41      /**
  42       * @var array Fields which contain user information within the table.
  43       */
  44      protected $privacyfields;
  45  
  46      /**
  47       * @var string  A description of what this table is used for.
  48       */
  49      protected $summary;
  50  
  51      /**
  52       * Constructor to create a new database_table type.
  53       *
  54       * @param   string  $name The name of the database table being described.
  55       * @param   array   $privacyfields A list of fields with their description.
  56       * @param   string  $summary A description of what the table is used for.
  57       */
  58      public function __construct($name, array $privacyfields = [], $summary = '') {
  59          if (debugging('', DEBUG_DEVELOPER)) {
  60              if (empty($privacyfields)) {
  61                  debugging("Table '{$name}' was supplied without any fields.", DEBUG_DEVELOPER);
  62              }
  63  
  64              foreach ($privacyfields as $key => $field) {
  65                  $teststring = clean_param($field, PARAM_STRINGID);
  66                  if ($teststring !== $field) {
  67                      debugging("Field '{$key}' passed for table '{$name}' has an invalid langstring identifier: '{$field}'",
  68                          DEBUG_DEVELOPER);
  69                  }
  70              }
  71  
  72              $teststring = clean_param($summary, PARAM_STRINGID);
  73              if ($teststring !== $summary) {
  74                  debugging("Summary information for the '{$name}' table has an invalid langstring identifier: '{$summary}'",
  75                      DEBUG_DEVELOPER);
  76              }
  77          }
  78  
  79          $this->name = $name;
  80          $this->privacyfields = $privacyfields;
  81          $this->summary = $summary;
  82      }
  83  
  84      /**
  85       * The name of the database table.
  86       *
  87       * @return  string
  88       */
  89      public function get_name() {
  90          return $this->name;
  91      }
  92  
  93      /**
  94       * The list of fields within the table which contain user data, with a description of each field.
  95       *
  96       * @return  array
  97       */
  98      public function get_privacy_fields() {
  99          return $this->privacyfields;
 100      }
 101  
 102      /**
 103       * A summary of what this table is used for.
 104       *
 105       * @return  string
 106       */
 107      public function get_summary() {
 108          return $this->summary;
 109      }
 110  }