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 for exporting user evidence with all competencies.
|
|
|
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\external;
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
use core\external\persistent_exporter;
|
|
|
28 |
use core_user;
|
|
|
29 |
use core_user\external\user_summary_exporter;
|
|
|
30 |
use renderer_base;
|
|
|
31 |
use tool_dataprivacy\api;
|
|
|
32 |
use tool_dataprivacy\data_request;
|
|
|
33 |
use tool_dataprivacy\local\helper;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Class for exporting user evidence with all competencies.
|
|
|
37 |
*
|
|
|
38 |
* @copyright 2018 Jun Pataleta
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
|
|
41 |
class data_request_exporter extends persistent_exporter {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Class definition.
|
|
|
45 |
*
|
|
|
46 |
* @return string
|
|
|
47 |
*/
|
|
|
48 |
protected static function define_class() {
|
|
|
49 |
return data_request::class;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Related objects definition.
|
|
|
54 |
*
|
|
|
55 |
* @return array
|
|
|
56 |
*/
|
|
|
57 |
protected static function define_related() {
|
|
|
58 |
return [
|
|
|
59 |
'context' => 'context',
|
|
|
60 |
];
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Other properties definition.
|
|
|
65 |
*
|
|
|
66 |
* @return array
|
|
|
67 |
*/
|
|
|
68 |
protected static function define_other_properties() {
|
|
|
69 |
return [
|
|
|
70 |
'foruser' => [
|
|
|
71 |
'type' => user_summary_exporter::read_properties_definition(),
|
|
|
72 |
],
|
|
|
73 |
'requestedbyuser' => [
|
|
|
74 |
'type' => user_summary_exporter::read_properties_definition(),
|
|
|
75 |
'optional' => true
|
|
|
76 |
],
|
|
|
77 |
'dpouser' => [
|
|
|
78 |
'type' => user_summary_exporter::read_properties_definition(),
|
|
|
79 |
'optional' => true
|
|
|
80 |
],
|
|
|
81 |
'messagehtml' => [
|
|
|
82 |
'type' => PARAM_RAW,
|
|
|
83 |
'optional' => true
|
|
|
84 |
],
|
|
|
85 |
'typename' => [
|
|
|
86 |
'type' => PARAM_TEXT,
|
|
|
87 |
],
|
|
|
88 |
'typenameshort' => [
|
|
|
89 |
'type' => PARAM_TEXT,
|
|
|
90 |
],
|
|
|
91 |
'statuslabel' => [
|
|
|
92 |
'type' => PARAM_TEXT,
|
|
|
93 |
],
|
|
|
94 |
'statuslabelclass' => [
|
|
|
95 |
'type' => PARAM_TEXT,
|
|
|
96 |
],
|
|
|
97 |
'canreview' => [
|
|
|
98 |
'type' => PARAM_BOOL,
|
|
|
99 |
'optional' => true,
|
|
|
100 |
'default' => false
|
|
|
101 |
],
|
|
|
102 |
'approvedeny' => [
|
|
|
103 |
'type' => PARAM_BOOL,
|
|
|
104 |
'optional' => true,
|
|
|
105 |
'default' => false
|
|
|
106 |
],
|
|
|
107 |
'allowfiltering' => [
|
|
|
108 |
'type' => PARAM_BOOL,
|
|
|
109 |
'optional' => true,
|
|
|
110 |
'default' => false,
|
|
|
111 |
],
|
|
|
112 |
'canmarkcomplete' => [
|
|
|
113 |
'type' => PARAM_BOOL,
|
|
|
114 |
'optional' => true,
|
|
|
115 |
'default' => false
|
|
|
116 |
],
|
|
|
117 |
'downloadlink' => [
|
|
|
118 |
'type' => PARAM_URL,
|
|
|
119 |
'optional' => true,
|
|
|
120 |
],
|
|
|
121 |
];
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* Assign values to the defined other properties.
|
|
|
126 |
*
|
|
|
127 |
* @param renderer_base $output The output renderer object.
|
|
|
128 |
* @return array
|
|
|
129 |
* @throws coding_exception
|
|
|
130 |
* @throws dml_exception
|
|
|
131 |
* @throws moodle_exception
|
|
|
132 |
*/
|
|
|
133 |
protected function get_other_values(renderer_base $output) {
|
|
|
134 |
$values = [];
|
|
|
135 |
|
|
|
136 |
$foruserid = $this->persistent->get('userid');
|
|
|
137 |
$user = core_user::get_user($foruserid, '*', MUST_EXIST);
|
|
|
138 |
$userexporter = new user_summary_exporter($user);
|
|
|
139 |
$values['foruser'] = $userexporter->export($output);
|
|
|
140 |
|
|
|
141 |
$requestedbyid = $this->persistent->get('requestedby');
|
|
|
142 |
if ($requestedbyid != $foruserid) {
|
|
|
143 |
$user = core_user::get_user($requestedbyid, '*', MUST_EXIST);
|
|
|
144 |
$userexporter = new user_summary_exporter($user);
|
|
|
145 |
$values['requestedbyuser'] = $userexporter->export($output);
|
|
|
146 |
} else {
|
|
|
147 |
$values['requestedbyuser'] = $values['foruser'];
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
if (!empty($this->persistent->get('dpo'))) {
|
|
|
151 |
$dpoid = $this->persistent->get('dpo');
|
|
|
152 |
$user = core_user::get_user($dpoid, '*', MUST_EXIST);
|
|
|
153 |
$userexporter = new user_summary_exporter($user);
|
|
|
154 |
$values['dpouser'] = $userexporter->export($output);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
$values['messagehtml'] = text_to_html($this->persistent->get('comments'));
|
|
|
158 |
|
|
|
159 |
$requesttype = $this->persistent->get('type');
|
|
|
160 |
$values['typename'] = helper::get_request_type_string($requesttype);
|
|
|
161 |
$values['typenameshort'] = helper::get_shortened_request_type_string($requesttype);
|
|
|
162 |
|
|
|
163 |
$values['canreview'] = false;
|
|
|
164 |
$values['approvedeny'] = false;
|
|
|
165 |
$values['allowfiltering'] = get_config('tool_dataprivacy', 'allowfiltering');
|
|
|
166 |
$values['statuslabel'] = helper::get_request_status_string($this->persistent->get('status'));
|
|
|
167 |
|
|
|
168 |
switch ($this->persistent->get('status')) {
|
|
|
169 |
case api::DATAREQUEST_STATUS_PENDING:
|
|
|
170 |
case api::DATAREQUEST_STATUS_PREPROCESSING:
|
|
|
171 |
$values['statuslabelclass'] = 'bg-info text-white';
|
|
|
172 |
// Request can be manually completed for general enquiry requests.
|
|
|
173 |
$values['canmarkcomplete'] = $requesttype == api::DATAREQUEST_TYPE_OTHERS;
|
|
|
174 |
break;
|
|
|
175 |
case api::DATAREQUEST_STATUS_AWAITING_APPROVAL:
|
|
|
176 |
$values['statuslabelclass'] = 'bg-info text-white';
|
|
|
177 |
// DPO can review the request once it's ready.
|
|
|
178 |
$values['canreview'] = true;
|
|
|
179 |
// Whether the DPO can approve or deny the request.
|
|
|
180 |
$values['approvedeny'] = in_array($requesttype, [api::DATAREQUEST_TYPE_EXPORT, api::DATAREQUEST_TYPE_DELETE]);
|
|
|
181 |
// If the request's type is delete, check if user have permission to approve/deny it.
|
|
|
182 |
if ($requesttype == api::DATAREQUEST_TYPE_DELETE) {
|
|
|
183 |
$values['approvedeny'] = api::can_create_data_deletion_request_for_other();
|
|
|
184 |
}
|
|
|
185 |
break;
|
|
|
186 |
case api::DATAREQUEST_STATUS_APPROVED:
|
|
|
187 |
$values['statuslabelclass'] = 'bg-info text-white';
|
|
|
188 |
break;
|
|
|
189 |
case api::DATAREQUEST_STATUS_PROCESSING:
|
|
|
190 |
$values['statuslabelclass'] = 'bg-info text-white';
|
|
|
191 |
break;
|
|
|
192 |
case api::DATAREQUEST_STATUS_COMPLETE:
|
|
|
193 |
case api::DATAREQUEST_STATUS_DOWNLOAD_READY:
|
|
|
194 |
case api::DATAREQUEST_STATUS_DELETED:
|
|
|
195 |
$values['statuslabelclass'] = 'bg-success text-white';
|
|
|
196 |
break;
|
|
|
197 |
case api::DATAREQUEST_STATUS_CANCELLED:
|
|
|
198 |
$values['statuslabelclass'] = 'bg-warning text-dark';
|
|
|
199 |
break;
|
|
|
200 |
case api::DATAREQUEST_STATUS_REJECTED:
|
|
|
201 |
$values['statuslabelclass'] = 'bg-danger text-white';
|
|
|
202 |
break;
|
|
|
203 |
case api::DATAREQUEST_STATUS_EXPIRED:
|
|
|
204 |
$values['statuslabelclass'] = 'bg-secondary text-dark';
|
|
|
205 |
break;
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
if ($this->persistent->get('status') == api::DATAREQUEST_STATUS_DOWNLOAD_READY) {
|
|
|
209 |
$usercontext = \context_user::instance($foruserid, IGNORE_MISSING);
|
|
|
210 |
// If user has permission to view download link, show relevant action item.
|
|
|
211 |
if ($usercontext && api::can_download_data_request_for_user($foruserid, $requestedbyid)) {
|
|
|
212 |
$downloadlink = api::get_download_link($usercontext, $this->persistent->get('id'))->url;
|
|
|
213 |
$values['downloadlink'] = $downloadlink->out(false);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
return $values;
|
|
|
218 |
}
|
|
|
219 |
}
|