c1a2202d7f9495c53070672ff4115efd2bc249ed
[moodle.git] / admin / tool / dataprivacy / classes / output / data_deletion_page.php
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/>.
17 /**
18  * Class containing data for a user's data requests.
19  *
20  * @package    tool_dataprivacy
21  * @copyright  2018 Jun Pataleta
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
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;
37 use tool_dataprivacy\output\expired_contexts_table;
39 /**
40  * Class containing data for a user's data requests.
41  *
42  * @copyright  2018 Jun Pataleta
43  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44  */
45 class data_deletion_page implements renderable, templatable {
47     /** The default number of results to be shown per page. */
48     const DEFAULT_PAGE_SIZE = 20;
50     /** @var data_request[] $requests List of data requests. */
51     protected $filter = null;
53     /** @var data_request[] $requests List of data requests. */
54     protected $expiredcontextstable = [];
56     /**
57      * Construct this renderable.
58      *
59      * @param \tool_dataprivacy\data_request[] $filter
60      * @param \tool_dataprivacy\expired_contexts_table $expiredcontextstable
61      */
62     public function __construct($filter, expired_contexts_table $expiredcontextstable) {
63         $this->filter = $filter;
64         $this->expiredcontextstable = $expiredcontextstable;
65     }
67     /**
68      * Export this data so it can be used as the context for a mustache template.
69      *
70      * @param renderer_base $output
71      * @return stdClass
72      * @throws coding_exception
73      * @throws dml_exception
74      * @throws moodle_exception
75      */
76     public function export_for_template(renderer_base $output) {
77         $data = new stdClass();
79         $url = new moodle_url('/admin/tool/dataprivacy/datadeletion.php');
80         $options = [
81             CONTEXT_USER => get_string('user'),
82             CONTEXT_COURSE => get_string('course'),
83             CONTEXT_MODULE => get_string('activitiesandresources', 'tool_dataprivacy'),
84             CONTEXT_BLOCK => get_string('blocks'),
85         ];
86         $filterselector = new single_select($url, 'filter', $options, $this->filter, null);
87         $data->filter = $filterselector->export_for_template($output);
89         ob_start();
90         $this->expiredcontextstable->out(self::DEFAULT_PAGE_SIZE, true);
91         $expiredcontexts = ob_get_contents();
92         ob_end_clean();
93         $data->expiredcontexts = $expiredcontexts;
95         $data->existingcontexts = $this->expiredcontextstable->rawdata ? true : false;
97         return $data;
98     }
99 }