Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 ]; 118 } 119 120 /** 121 * Assign values to the defined other properties. 122 * 123 * @param renderer_base $output The output renderer object. 124 * @return array 125 * @throws coding_exception 126 * @throws dml_exception 127 * @throws moodle_exception 128 */ 129 protected function get_other_values(renderer_base $output) { 130 $values = []; 131 132 $foruserid = $this->persistent->get('userid'); 133 $user = core_user::get_user($foruserid, '*', MUST_EXIST); 134 $userexporter = new user_summary_exporter($user); 135 $values['foruser'] = $userexporter->export($output); 136 137 $requestedbyid = $this->persistent->get('requestedby'); 138 if ($requestedbyid != $foruserid) { 139 $user = core_user::get_user($requestedbyid, '*', MUST_EXIST); 140 $userexporter = new user_summary_exporter($user); 141 $values['requestedbyuser'] = $userexporter->export($output); 142 } else { 143 $values['requestedbyuser'] = $values['foruser']; 144 } 145 146 if (!empty($this->persistent->get('dpo'))) { 147 $dpoid = $this->persistent->get('dpo'); 148 $user = core_user::get_user($dpoid, '*', MUST_EXIST); 149 $userexporter = new user_summary_exporter($user); 150 $values['dpouser'] = $userexporter->export($output); 151 } 152 153 $values['messagehtml'] = text_to_html($this->persistent->get('comments')); 154 155 $requesttype = $this->persistent->get('type'); 156 $values['typename'] = helper::get_request_type_string($requesttype); 157 $values['typenameshort'] = helper::get_shortened_request_type_string($requesttype); 158 159 $values['canreview'] = false; 160 $values['approvedeny'] = false; 161 $values['allowfiltering'] = get_config('tool_dataprivacy', 'allowfiltering'); 162 $values['statuslabel'] = helper::get_request_status_string($this->persistent->get('status')); 163 164 switch ($this->persistent->get('status')) { 165 case api::DATAREQUEST_STATUS_PENDING: 166 case api::DATAREQUEST_STATUS_PREPROCESSING: 167 $values['statuslabelclass'] = 'badge-info'; 168 // Request can be manually completed for general enquiry requests. 169 $values['canmarkcomplete'] = $requesttype == api::DATAREQUEST_TYPE_OTHERS; 170 break; 171 case api::DATAREQUEST_STATUS_AWAITING_APPROVAL: 172 $values['statuslabelclass'] = 'badge-info'; 173 // DPO can review the request once it's ready. 174 $values['canreview'] = true; 175 // Whether the DPO can approve or deny the request. 176 $values['approvedeny'] = in_array($requesttype, [api::DATAREQUEST_TYPE_EXPORT, api::DATAREQUEST_TYPE_DELETE]); 177 // If the request's type is delete, check if user have permission to approve/deny it. 178 if ($requesttype == api::DATAREQUEST_TYPE_DELETE) { 179 $values['approvedeny'] = api::can_create_data_deletion_request_for_other(); 180 } 181 break; 182 case api::DATAREQUEST_STATUS_APPROVED: 183 $values['statuslabelclass'] = 'badge-info'; 184 break; 185 case api::DATAREQUEST_STATUS_PROCESSING: 186 $values['statuslabelclass'] = 'badge-info'; 187 break; 188 case api::DATAREQUEST_STATUS_COMPLETE: 189 case api::DATAREQUEST_STATUS_DOWNLOAD_READY: 190 case api::DATAREQUEST_STATUS_DELETED: 191 $values['statuslabelclass'] = 'badge-success'; 192 break; 193 case api::DATAREQUEST_STATUS_CANCELLED: 194 $values['statuslabelclass'] = 'badge-warning'; 195 break; 196 case api::DATAREQUEST_STATUS_REJECTED: 197 $values['statuslabelclass'] = 'badge-danger'; 198 break; 199 case api::DATAREQUEST_STATUS_EXPIRED: 200 $values['statuslabelclass'] = 'badge-secondary'; 201 break; 202 } 203 204 return $values; 205 } 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body