2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This file contains the defaults form.
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace tool_dataprivacy\form
;
26 defined('MOODLE_INTERNAL') ||
die();
28 use \tool_dataprivacy\output\data_registry_page
;
30 require_once($CFG->libdir
. '/formslib.php');
31 require_once($CFG->dirroot
. '/' . $CFG->admin
. '/tool/dataprivacy/lib.php');
34 * Context levels defaults form.
36 * @package tool_dataprivacy
37 * @copyright 2018 David Monllao
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class defaults
extends \moodleform
{
45 public function definition() {
48 $mform = $this->_form
;
49 $mform->setDisableShortforms();
51 $notification = $OUTPUT->notification(get_string('defaultsinfo', 'tool_dataprivacy'), \core\output\notification
::NOTIFY_INFO
);
52 $mform->addElement('html', $notification);
54 foreach ($this->_customdata
['levels'] as $level => $classname) {
56 $mform->addElement('header', $classname . '-header',
57 get_string('contextlevelname' . $level, 'tool_dataprivacy'));
59 list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry
::var_names_from_context($classname);
61 $includeinherit = true;
62 if ($level == CONTEXT_SYSTEM
) {
63 $includeinherit = false;
66 $categoryoptions = data_registry_page
::category_options($this->_customdata
['categories'], false, $includeinherit);
67 $purposeoptions = data_registry_page
::category_options($this->_customdata
['purposes'], false, $includeinherit);
69 $mform->addElement('select', $categoryvar, get_string('category', 'tool_dataprivacy'), $categoryoptions);
70 $mform->setType($categoryvar, PARAM_INT
);
72 $mform->addElement('select', $purposevar, get_string('purpose', 'tool_dataprivacy'), $purposeoptions);
73 $mform->setType($purposevar, PARAM_INT
);
76 $this->add_action_buttons(true, get_string('savechanges'));