2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Class for exporting user evidence with all competencies.
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\external
;
25 defined('MOODLE_INTERNAL') ||
die();
28 use core\external\persistent_exporter
;
30 use core_user\external\user_summary_exporter
;
34 use tool_dataprivacy\api
;
35 use tool_dataprivacy\data_request
;
36 use tool_dataprivacy\local\helper
;
39 * Class for exporting user evidence with all competencies.
41 * @copyright 2018 Jun Pataleta
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class data_request_exporter
extends persistent_exporter
{
51 protected static function define_class() {
52 return data_request
::class;
56 * Related objects definition.
60 protected static function define_related() {
62 'context' => 'context',
67 * Other properties definition.
71 protected static function define_other_properties() {
74 'type' => user_summary_exporter
::read_properties_definition(),
76 'requestedbyuser' => [
77 'type' => user_summary_exporter
::read_properties_definition(),
81 'type' => user_summary_exporter
::read_properties_definition(),
97 'statuslabelclass' => [
101 'type' => PARAM_BOOL
,
106 'type' => PARAM_BOOL
,
110 'canmarkcomplete' => [
111 'type' => PARAM_BOOL
,
119 * Assign values to the defined other properties.
121 * @param renderer_base $output The output renderer object.
123 * @throws coding_exception
124 * @throws dml_exception
125 * @throws moodle_exception
127 protected function get_other_values(renderer_base
$output) {
130 $foruserid = $this->persistent
->get('userid');
131 $user = core_user
::get_user($foruserid, '*', MUST_EXIST
);
132 $userexporter = new user_summary_exporter($user);
133 $values['foruser'] = $userexporter->export($output);
135 $requestedbyid = $this->persistent
->get('requestedby');
136 if ($requestedbyid != $foruserid) {
137 $user = core_user
::get_user($requestedbyid, '*', MUST_EXIST
);
138 $userexporter = new user_summary_exporter($user);
139 $values['requestedbyuser'] = $userexporter->export($output);
141 $values['requestedbyuser'] = $values['foruser'];
144 if (!empty($this->persistent
->get('dpo'))) {
145 $dpoid = $this->persistent
->get('dpo');
146 $user = core_user
::get_user($dpoid, '*', MUST_EXIST
);
147 $userexporter = new user_summary_exporter($user);
148 $values['dpouser'] = $userexporter->export($output);
151 $values['messagehtml'] = text_to_html($this->persistent
->get('comments'));
153 $requesttype = $this->persistent
->get('type');
154 $values['typename'] = helper
::get_request_type_string($requesttype);
155 $values['typenameshort'] = helper
::get_shortened_request_type_string($requesttype);
157 $values['canreview'] = false;
158 $values['approvedeny'] = false;
159 $values['statuslabel'] = helper
::get_request_status_string($this->persistent
->get('status'));
161 switch ($this->persistent
->get('status')) {
162 case api
::DATAREQUEST_STATUS_PENDING
:
163 $values['statuslabelclass'] = 'label-info';
164 // Request can be manually completed for general enquiry requests.
165 $values['canmarkcomplete'] = $requesttype == api
::DATAREQUEST_TYPE_OTHERS
;
167 case api
::DATAREQUEST_STATUS_AWAITING_APPROVAL
:
168 $values['statuslabelclass'] = 'label-info';
169 // DPO can review the request once it's ready.
170 $values['canreview'] = true;
171 // Whether the DPO can approve or deny the request.
172 $values['approvedeny'] = in_array($requesttype, [api
::DATAREQUEST_TYPE_EXPORT
, api
::DATAREQUEST_TYPE_DELETE
]);
174 case api
::DATAREQUEST_STATUS_APPROVED
:
175 $values['statuslabelclass'] = 'label-info';
177 case api
::DATAREQUEST_STATUS_PROCESSING
:
178 $values['statuslabelclass'] = 'label-info';
180 case api
::DATAREQUEST_STATUS_COMPLETE
:
181 case api
::DATAREQUEST_STATUS_DOWNLOAD_READY
:
182 case api
::DATAREQUEST_STATUS_DELETED
:
183 $values['statuslabelclass'] = 'label-success';
185 case api
::DATAREQUEST_STATUS_CANCELLED
:
186 $values['statuslabelclass'] = 'label-warning';
188 case api
::DATAREQUEST_STATUS_REJECTED
:
189 $values['statuslabelclass'] = 'label-important';
191 case api
::DATAREQUEST_STATUS_EXPIRED
:
192 $values['statuslabelclass'] = 'label-default';