MDL-61899 tool_dataprivacy: Add lawful bases fields
[moodle.git] / admin / tool / dataprivacy / defaults.php
blob06119084c6f9a61a89f81ec4e942e08929d8b13d
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.
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/>.
17 /**
18 * This page lets users manage default purposes and categories.
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../../../config.php');
26 require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');
28 $url = new \moodle_url('/admin/tool/dataprivacy/defaults.php');
29 $title = get_string('setdefaults', 'tool_dataprivacy');
31 \tool_dataprivacy\page_helper::setup($url, $title, 'dataregistry');
33 $levels = \context_helper::get_all_levels();
34 // They are set through the context level site and user.
35 unset($levels[CONTEXT_SYSTEM]);
36 unset($levels[CONTEXT_USER]);
38 $customdata = [
39 'levels' => $levels,
40 'purposes' => \tool_dataprivacy\api::get_purposes(),
41 'categories' => \tool_dataprivacy\api::get_categories(),
43 $form = new \tool_dataprivacy\form\defaults($PAGE->url->out(false), $customdata);
45 $toform = new stdClass();
46 foreach ($levels as $level => $classname) {
47 list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname);
48 $toform->{$purposevar} = get_config('tool_dataprivacy', $purposevar);
49 $toform->{$categoryvar} = get_config('tool_dataprivacy', $categoryvar);
51 $form->set_data($toform);
53 $returnurl = new \moodle_url('/admin/tool/dataprivacy/dataregistry.php');
54 if ($form->is_cancelled()) {
55 redirect($returnurl);
56 } else if ($data = $form->get_data()) {
58 foreach ($levels as $level => $classname) {
60 list($purposevar, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname);
62 if (isset($data->{$purposevar})) {
63 set_config($purposevar, $data->{$purposevar}, 'tool_dataprivacy');
65 if (isset($data->{$categoryvar})) {
66 set_config($categoryvar, $data->{$categoryvar}, 'tool_dataprivacy');
69 redirect($returnurl, get_string('defaultssaved', 'tool_dataprivacy'),
70 0, \core\output\notification::NOTIFY_SUCCESS);
73 $output = $PAGE->get_renderer('tool_dataprivacy');
74 echo $output->header();
75 $form->display();
76 echo $output->footer();