Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * Data privacy tool data generator.
  19   *
  20   * @package    tool_dataprivacy
  21   * @category   test
  22   * @copyright  2018 Jun Pataleta
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  use tool_dataprivacy\api;
  27  use tool_dataprivacy\category;
  28  use tool_dataprivacy\purpose;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  /**
  33   * Data privacy tool data generator class.
  34   *
  35   * @package    tool_dataprivacy
  36   * @category   test
  37   * @copyright  2018 Jun Pataleta
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class tool_dataprivacy_generator extends component_generator_base {
  41  
  42      /** @var int Number of created categories. */
  43      protected $categorycount = 0;
  44  
  45      /** @var int Number of created purposes. */
  46      protected $purposecount = 0;
  47  
  48      /**
  49       * Reset process.
  50       *
  51       * Do not call directly.
  52       *
  53       * @return void
  54       */
  55      public function reset() {
  56          $this->categorycount = 0;
  57          $this->purposecount = 0;
  58      }
  59  
  60      /**
  61       * Create a new category.
  62       *
  63       * @param array|stdClass $record
  64       * @return category
  65       */
  66      public function create_category($record = null) {
  67          $this->categorycount++;
  68          $i = $this->categorycount;
  69          $record = (object)$record;
  70  
  71          if (!isset($record->name)) {
  72              $record->name = "Test purpose $i";
  73          }
  74  
  75          if (!isset($record->description)) {
  76              $record->description = "{$record->name} description";
  77          }
  78  
  79          $category = api::create_category($record);
  80  
  81          return $category;
  82      }
  83  
  84      /**
  85       * Create a new purpose.
  86       *
  87       * @param array|stdClass $record
  88       * @return purpose
  89       */
  90      public function create_purpose($record = null) {
  91          $this->purposecount++;
  92          $i = $this->purposecount;
  93          $record = (object)$record;
  94  
  95          if (!isset($record->name)) {
  96              $record->name = "Test purpose $i";
  97          }
  98  
  99          if (!isset($record->description)) {
 100              $record->description = "{$record->name} $i description";
 101          }
 102  
 103          if (!isset($record->retentionperiod)) {
 104              $record->retentionperiod = 'PT1M';
 105          }
 106  
 107          if (!isset($record->lawfulbases)) {
 108              $record->lawfulbases = 'gdpr_art_6_1_a';
 109          }
 110  
 111          $purpose = api::create_purpose($record);
 112  
 113          return $purpose;
 114      }
 115  }