MDL-56595 tool_usertours: set page params when configuring tours/steps.
[moodle.git] / admin / tool / dataprivacy / datarequests.php
CommitLineData
5efc1f9e
DM
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 * Prints the contact form to the site's Data Protection Officer
19 *
20 * @copyright 2018 onwards Jun Pataleta
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package tool_dataprivacy
23 */
24
25require_once("../../../config.php");
26require_once('lib.php');
27
dd26f1be
JP
28require_login(null, false);
29
19bad13a
MG
30$perpage = optional_param('perpage', 0, PARAM_INT);
31
5efc1f9e
DM
32$url = new moodle_url('/admin/tool/dataprivacy/datarequests.php');
33
34$title = get_string('datarequests', 'tool_dataprivacy');
35
36\tool_dataprivacy\page_helper::setup($url, $title, '', 'tool/dataprivacy:managedatarequests');
37
38echo $OUTPUT->header();
39echo $OUTPUT->heading($title);
40
26ce2c0a
AN
41if (!\tool_dataprivacy\data_registry::defaults_set()) {
42 \core\notification::error(get_string('systemconfignotsetwarning', 'tool_dataprivacy'));
43}
44
161a5c8a
MH
45if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
46 $filtersapplied = optional_param_array('request-filters', [-1], PARAM_NOTAGS);
47 $filterscleared = optional_param('filters-cleared', 0, PARAM_INT);
48 if ($filtersapplied === [-1]) {
49 // If there are no filters submitted, check if there is a saved filters from the user preferences.
50 $filterprefs = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, null);
51 if ($filterprefs && empty($filterscleared)) {
52 $filtersapplied = json_decode($filterprefs);
53 } else {
54 $filtersapplied = [];
55 }
4c72ffa5 56 }
161a5c8a
MH
57 // Save the current applied filters to the user preferences.
58 set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, json_encode($filtersapplied));
4c72ffa5 59
161a5c8a
MH
60 $types = [];
61 $statuses = [];
b4ecfa38 62 $creationmethods = [];
161a5c8a
MH
63 foreach ($filtersapplied as $filter) {
64 list($category, $value) = explode(':', $filter);
65 switch($category) {
66 case \tool_dataprivacy\local\helper::FILTER_TYPE:
67 $types[] = $value;
68 break;
69 case \tool_dataprivacy\local\helper::FILTER_STATUS:
70 $statuses[] = $value;
71 break;
b4ecfa38
MG
72 case \tool_dataprivacy\local\helper::FILTER_CREATION:
73 $creationmethods[] = $value;
74 break;
161a5c8a 75 }
4c72ffa5 76 }
4c72ffa5 77
b4ecfa38 78 $table = new \tool_dataprivacy\output\data_requests_table(0, $statuses, $types, $creationmethods, true);
19bad13a
MG
79 if (!empty($perpage)) {
80 set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_PERPAGE, $perpage);
81 } else {
82 $prefperpage = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_PERPAGE);
83 $perpage = ($prefperpage) ? $prefperpage : $table->get_requests_per_page_options()[0];
84 }
85 $table->set_requests_per_page($perpage);
161a5c8a 86 $table->baseurl = $url;
4c72ffa5 87
161a5c8a
MH
88 $requestlist = new tool_dataprivacy\output\data_requests_page($table, $filtersapplied);
89 $requestlistoutput = $PAGE->get_renderer('tool_dataprivacy');
90 echo $requestlistoutput->render($requestlist);
91} else {
92 $dponamestring = implode (', ', tool_dataprivacy\api::get_dpo_role_names());
93 $message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
94 echo $OUTPUT->notification($message, 'error');
95}
5efc1f9e
DM
96
97echo $OUTPUT->footer();