MDL-61899 tool_dataprivacy: Subject access requests tool
[moodle.git] / admin / tool / dataprivacy / classes / output / data_deletion_page.php
blobb2a5d58fad7ce8b8b5630f501e5bc9af70eb039b
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 * Class containing data for a user's data requests.
20 * @package tool_dataprivacy
21 * @copyright 2018 Jun Pataleta
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace tool_dataprivacy\output;
25 defined('MOODLE_INTERNAL') || die();
27 use coding_exception;
28 use dml_exception;
29 use moodle_exception;
30 use moodle_url;
31 use renderable;
32 use renderer_base;
33 use single_select;
34 use stdClass;
35 use templatable;
36 use tool_dataprivacy\data_request;
38 /**
39 * Class containing data for a user's data requests.
41 * @copyright 2018 Jun Pataleta
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class data_deletion_page implements renderable, templatable {
46 /** The default number of results to be shown per page. */
47 const DEFAULT_PAGE_SIZE = 20;
49 /** @var data_request[] $requests List of data requests. */
50 protected $filter = null;
52 /** @var data_request[] $requests List of data requests. */
53 protected $expiredcontextstable = [];
55 /**
56 * Construct this renderable.
58 * @param expired_contexts_table $expiredcontextstable
60 public function __construct($filter, $expiredcontextstable) {
61 $this->filter = $filter;
62 $this->expiredcontextstable = $expiredcontextstable;
65 /**
66 * Export this data so it can be used as the context for a mustache template.
68 * @param renderer_base $output
69 * @return stdClass
70 * @throws coding_exception
71 * @throws dml_exception
72 * @throws moodle_exception
74 public function export_for_template(renderer_base $output) {
75 $data = new stdClass();
77 $url = new moodle_url('/admin/tool/dataprivacy/datadeletion.php');
78 $options = [
79 CONTEXT_USER => get_string('user'),
80 CONTEXT_COURSE => get_string('course'),
81 CONTEXT_MODULE => get_string('activitiesandresources', 'tool_dataprivacy'),
82 CONTEXT_BLOCK => get_string('blocks'),
84 $filterselector = new single_select($url, 'filter', $options, $this->filter, null);
85 $data->filter = $filterselector->export_for_template($output);
87 ob_start();
88 $this->expiredcontextstable->out(self::DEFAULT_PAGE_SIZE, true);
89 $expiredcontexts = ob_get_contents();
90 ob_end_clean();
91 $data->expiredcontexts = $expiredcontexts;
93 $data->existingcontexts = $this->expiredcontextstable->rawdata ? true : false;
95 return $data;