1 |
efrain |
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 |
* 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();
|
|
|
26 |
|
|
|
27 |
use action_menu;
|
|
|
28 |
use action_menu_link_secondary;
|
|
|
29 |
use coding_exception;
|
|
|
30 |
use context_user;
|
|
|
31 |
use moodle_exception;
|
|
|
32 |
use moodle_url;
|
|
|
33 |
use renderable;
|
|
|
34 |
use renderer_base;
|
|
|
35 |
use stdClass;
|
|
|
36 |
use templatable;
|
|
|
37 |
use tool_dataprivacy\api;
|
|
|
38 |
use tool_dataprivacy\data_request;
|
|
|
39 |
use tool_dataprivacy\external\data_request_exporter;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Class containing data for a user's data requests.
|
|
|
43 |
*
|
|
|
44 |
* @copyright 2018 Jun Pataleta
|
|
|
45 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
46 |
*/
|
|
|
47 |
class my_data_requests_page implements renderable, templatable {
|
|
|
48 |
|
|
|
49 |
/** @var array $requests List of data requests. */
|
|
|
50 |
protected $requests = [];
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Construct this renderable.
|
|
|
54 |
*
|
|
|
55 |
* @param data_request[] $requests
|
|
|
56 |
*/
|
|
|
57 |
public function __construct($requests) {
|
|
|
58 |
$this->requests = $requests;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
63 |
*
|
|
|
64 |
* @param renderer_base $output
|
|
|
65 |
* @return stdClass
|
|
|
66 |
* @throws coding_exception
|
|
|
67 |
* @throws moodle_exception
|
|
|
68 |
*/
|
|
|
69 |
public function export_for_template(renderer_base $output) {
|
|
|
70 |
global $USER;
|
|
|
71 |
|
|
|
72 |
$data = new stdClass();
|
|
|
73 |
$data->newdatarequesturl = new moodle_url('/admin/tool/dataprivacy/createdatarequest.php');
|
|
|
74 |
|
|
|
75 |
if (!is_https()) {
|
|
|
76 |
$httpwarningmessage = get_string('httpwarning', 'tool_dataprivacy');
|
|
|
77 |
$data->httpsite = array('message' => $httpwarningmessage, 'announce' => 1);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
$requests = [];
|
|
|
81 |
foreach ($this->requests as $request) {
|
|
|
82 |
$requestid = $request->get('id');
|
|
|
83 |
$status = $request->get('status');
|
|
|
84 |
$userid = $request->get('userid');
|
|
|
85 |
$type = $request->get('type');
|
|
|
86 |
|
|
|
87 |
$usercontext = context_user::instance($userid, IGNORE_MISSING);
|
|
|
88 |
if (!$usercontext) {
|
|
|
89 |
// Use the context system.
|
|
|
90 |
$outputcontext = \context_system::instance();
|
|
|
91 |
} else {
|
|
|
92 |
$outputcontext = $usercontext;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
$requestexporter = new data_request_exporter($request, ['context' => $outputcontext]);
|
|
|
96 |
$item = $requestexporter->export($output);
|
|
|
97 |
|
|
|
98 |
$self = $request->get('userid') == $USER->id;
|
|
|
99 |
if (!$self) {
|
|
|
100 |
// Append user name if it differs from $USER.
|
|
|
101 |
$a = (object)['typename' => $item->typename, 'user' => $item->foruser->fullname];
|
|
|
102 |
$item->typename = get_string('requesttypeuser', 'tool_dataprivacy', $a);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
$candownload = false;
|
|
|
106 |
$cancancel = true;
|
|
|
107 |
switch ($status) {
|
|
|
108 |
case api::DATAREQUEST_STATUS_COMPLETE:
|
|
|
109 |
$item->statuslabelclass = 'bg-success text-white';
|
|
|
110 |
$item->statuslabel = get_string('statuscomplete', 'tool_dataprivacy');
|
|
|
111 |
$cancancel = false;
|
|
|
112 |
break;
|
|
|
113 |
case api::DATAREQUEST_STATUS_DOWNLOAD_READY:
|
|
|
114 |
$item->statuslabelclass = 'bg-success text-white';
|
|
|
115 |
$item->statuslabel = get_string('statusready', 'tool_dataprivacy');
|
|
|
116 |
$cancancel = false;
|
|
|
117 |
$candownload = true;
|
|
|
118 |
|
|
|
119 |
if ($usercontext) {
|
|
|
120 |
$candownload = api::can_download_data_request_for_user(
|
|
|
121 |
$request->get('userid'), $request->get('requestedby'));
|
|
|
122 |
}
|
|
|
123 |
break;
|
|
|
124 |
case api::DATAREQUEST_STATUS_DELETED:
|
|
|
125 |
$item->statuslabelclass = 'bg-success text-white';
|
|
|
126 |
$item->statuslabel = get_string('statusdeleted', 'tool_dataprivacy');
|
|
|
127 |
$cancancel = false;
|
|
|
128 |
break;
|
|
|
129 |
case api::DATAREQUEST_STATUS_EXPIRED:
|
|
|
130 |
$item->statuslabelclass = 'bg-secondary text-dark';
|
|
|
131 |
$item->statuslabel = get_string('statusexpired', 'tool_dataprivacy');
|
|
|
132 |
$item->statuslabeltitle = get_string('downloadexpireduser', 'tool_dataprivacy');
|
|
|
133 |
$cancancel = false;
|
|
|
134 |
break;
|
|
|
135 |
case api::DATAREQUEST_STATUS_CANCELLED:
|
|
|
136 |
case api::DATAREQUEST_STATUS_REJECTED:
|
|
|
137 |
$cancancel = false;
|
|
|
138 |
break;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// Prepare actions.
|
|
|
142 |
$actions = [];
|
|
|
143 |
if ($cancancel) {
|
|
|
144 |
$cancelurl = new moodle_url('#');
|
|
|
145 |
$canceldata = ['data-action' => 'cancel', 'data-requestid' => $requestid];
|
|
|
146 |
$canceltext = get_string('cancelrequest', 'tool_dataprivacy');
|
|
|
147 |
$actions[] = new action_menu_link_secondary($cancelurl, null, $canceltext, $canceldata);
|
|
|
148 |
}
|
|
|
149 |
if ($candownload && $usercontext) {
|
|
|
150 |
$actions[] = api::get_download_link($usercontext, $requestid);
|
|
|
151 |
}
|
|
|
152 |
if (!empty($actions)) {
|
|
|
153 |
$actionsmenu = new action_menu($actions);
|
|
|
154 |
$actionsmenu->set_menu_trigger(get_string('actions'));
|
|
|
155 |
$actionsmenu->set_owner_selector('request-actions-' . $requestid);
|
|
|
156 |
$item->actions = $actionsmenu->export_for_template($output);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
$requests[] = $item;
|
|
|
160 |
}
|
|
|
161 |
$data->requests = $requests;
|
|
|
162 |
return $data;
|
|
|
163 |
}
|
|
|
164 |
}
|