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 contains the form add/update context level data. 19 * 20 * @package tool_dataprivacy 21 * @copyright 2018 David Monllao 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_dataprivacy\form; 26 defined('MOODLE_INTERNAL') || die(); 27 28 use core\form\persistent; 29 use tool_dataprivacy\api; 30 use tool_dataprivacy\data_registry; 31 32 /** 33 * Context level data form. 34 * 35 * @package tool_dataprivacy 36 * @copyright 2018 David Monllao 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class contextlevel extends context_instance { 40 41 /** 42 * @var The persistent class. 43 */ 44 protected static $persistentclass = 'tool_dataprivacy\\contextlevel'; 45 46 /** 47 * Define the form - called by parent constructor 48 */ 49 public function definition() { 50 $this->_form->setDisableShortforms(); 51 52 $this->_form->addElement('header', 'contextlevelname', $this->_customdata['contextlevelname']); 53 54 $this->add_purpose_category(); 55 56 $this->_form->addElement('hidden', 'contextlevel'); 57 $this->_form->setType('contextlevel', PARAM_INT); 58 59 parent::add_action_buttons(false, get_string('savechanges')); 60 } 61 62 /** 63 * Returns the customdata array for the provided context level. 64 * 65 * @param int $contextlevel 66 * @return array 67 */ 68 public static function get_contextlevel_customdata($contextlevel) { 69 70 $persistent = \tool_dataprivacy\contextlevel::get_record_by_contextlevel($contextlevel, false); 71 if (!$persistent) { 72 $persistent = new \tool_dataprivacy\contextlevel(); 73 $persistent->set('contextlevel', $contextlevel); 74 } 75 76 $includeinherit = true; 77 if ($contextlevel == CONTEXT_SYSTEM) { 78 // Nothing to inherit from Site level. 79 $includeinherit = false; 80 } 81 $includenotset = true; 82 if ($contextlevel == CONTEXT_SYSTEM || $contextlevel == CONTEXT_USER) { 83 // No 'not set' value for system and user because we do not have defaults for them. 84 $includenotset = false; 85 } 86 $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options( 87 api::get_purposes(), $includenotset, $includeinherit); 88 $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options( 89 api::get_categories(), $includenotset, $includeinherit); 90 91 $customdata = [ 92 'contextlevel' => $contextlevel, 93 'contextlevelname' => get_string('contextlevelname' . $contextlevel, 'tool_dataprivacy'), 94 'persistent' => $persistent, 95 'purposes' => $purposeoptions, 96 'categories' => $categoryoptions, 97 ]; 98 99 $effectivepurpose = api::get_effective_contextlevel_purpose($contextlevel); 100 if ($effectivepurpose) { 101 102 $customdata['currentretentionperiod'] = self::get_retention_display_text($effectivepurpose, $contextlevel, 103 \context_system::instance()); 104 105 $customdata['purposeretentionperiods'] = []; 106 foreach ($purposeoptions as $optionvalue => $unused) { 107 108 // Get the effective purpose if $optionvalue would be the selected value. 109 list($purposeid, $unused) = data_registry::get_effective_default_contextlevel_purpose_and_category($contextlevel, 110 $optionvalue); 111 $purpose = new \tool_dataprivacy\purpose($purposeid); 112 113 $retentionperiod = self::get_retention_display_text( 114 $purpose, 115 $contextlevel, 116 \context_system::instance() 117 ); 118 $customdata['purposeretentionperiods'][$optionvalue] = $retentionperiod; 119 } 120 } 121 122 return $customdata; 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body