use moodle_url;
use required_capability_exception;
use stdClass;
+use tool_dataprivacy\local\helper;
use tool_dataprivacy\task\initiate_data_request_task;
use tool_dataprivacy\task\process_data_request_task;
-use tool_dataprivacy\purpose;
-use tool_dataprivacy\category;
-use tool_dataprivacy\contextlevel;
-use tool_dataprivacy\context_instance;
-use tool_dataprivacy\data_registry;
-use tool_dataprivacy\expired_context;
defined('MOODLE_INTERNAL') || die();
// Create message to send to the Data Protection Officer(s).
$typetext = null;
- switch ($request->get('type')) {
- case self::DATAREQUEST_TYPE_EXPORT:
- $typetext = get_string('requesttypeexport', 'tool_dataprivacy');
- break;
- case self::DATAREQUEST_TYPE_DELETE:
- $typetext = get_string('requesttypedelete', 'tool_dataprivacy');
- break;
- case self::DATAREQUEST_TYPE_OTHERS:
- $typetext = get_string('requesttypeothers', 'tool_dataprivacy');
- break;
- default:
- throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
- }
+ $typetext = helper::get_request_type_string($request->get('type'));
$subject = get_string('datarequestemailsubject', 'tool_dataprivacy', $typetext);
$requestedby = core_user::get_user($request->get('requestedby'));
use core_user;
use core_user\external\user_summary_exporter;
use dml_exception;
+use moodle_exception;
use renderer_base;
use tool_dataprivacy\api;
use tool_dataprivacy\data_request;
+use tool_dataprivacy\local\helper;
/**
* Class for exporting user evidence with all competencies.
* @return array
* @throws coding_exception
* @throws dml_exception
+ * @throws moodle_exception
*/
protected function get_other_values(renderer_base $output) {
$values = [];
$values['messagehtml'] = text_to_html($this->persistent->get('comments'));
- if ($this->persistent->get('type') == api::DATAREQUEST_TYPE_EXPORT) {
- $values['typename'] = get_string('requesttypeexport', 'tool_dataprivacy');
- $values['typenameshort'] = get_string('requesttypeexportshort', 'tool_dataprivacy');
- } else if ($this->persistent->get('type') == api::DATAREQUEST_TYPE_DELETE) {
- $values['typename'] = get_string('requesttypedelete', 'tool_dataprivacy');
- $values['typenameshort'] = get_string('requesttypedeleteshort', 'tool_dataprivacy');
- } else {
- $values['typename'] = get_string('requesttypeothers', 'tool_dataprivacy');
- $values['typenameshort'] = get_string('requesttypeothersshort', 'tool_dataprivacy');
- }
+ $values['typename'] = helper::get_request_type_string($this->persistent->get('type'));
+ $values['typenameshort'] = helper::get_shortened_request_type_string($this->persistent->get('type'));
$values['canreview'] = false;
+ $values['statuslabel'] = helper::get_request_status_string($this->persistent->get('status'));
switch ($this->persistent->get('status')) {
case api::DATAREQUEST_STATUS_PENDING:
$values['statuslabelclass'] = 'label-default';
- $values['statuslabel'] = get_string('statuspending', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_PREPROCESSING:
$values['statuslabelclass'] = 'label-default';
- $values['statuslabel'] = get_string('statuspreprocessing', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_AWAITING_APPROVAL:
$values['statuslabelclass'] = 'label-info';
- $values['statuslabel'] = get_string('statusawaitingapproval', 'tool_dataprivacy');
// DPO can review the request once it's ready.
$values['canreview'] = true;
break;
case api::DATAREQUEST_STATUS_APPROVED:
$values['statuslabelclass'] = 'label-info';
- $values['statuslabel'] = get_string('statusapproved', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_PROCESSING:
$values['statuslabelclass'] = 'label-info';
- $values['statuslabel'] = get_string('statusprocessing', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_COMPLETE:
$values['statuslabelclass'] = 'label-success';
- $values['statuslabel'] = get_string('statuscomplete', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_CANCELLED:
$values['statuslabelclass'] = 'label-warning';
- $values['statuslabel'] = get_string('statuscancelled', 'tool_dataprivacy');
break;
case api::DATAREQUEST_STATUS_REJECTED:
$values['statuslabelclass'] = 'label-important';
- $values['statuslabel'] = get_string('statusrejected', 'tool_dataprivacy');
break;
}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Collection of helper functions for the data privacy tool.
+ *
+ * @package tool_dataprivacy
+ * @copyright 2018 Jun Pataleta
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace tool_dataprivacy\local;
+
+use coding_exception;
+use moodle_exception;
+use tool_dataprivacy\api;
+
+/**
+ * Class containing helper functions for the data privacy tool.
+ *
+ * @copyright 2018 Jun Pataleta
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class helper {
+
+ /**
+ * Retrieves the human-readable text value of a data request type.
+ *
+ * @param int $requesttype The request type.
+ * @return string
+ * @throws coding_exception
+ * @throws moodle_exception
+ */
+ public static function get_request_type_string($requesttype) {
+ switch ($requesttype) {
+ case api::DATAREQUEST_TYPE_EXPORT:
+ return get_string('requesttypeexport', 'tool_dataprivacy');
+ case api::DATAREQUEST_TYPE_DELETE:
+ return get_string('requesttypedelete', 'tool_dataprivacy');
+ case api::DATAREQUEST_TYPE_OTHERS:
+ return get_string('requesttypeothers', 'tool_dataprivacy');
+ default:
+ throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
+ }
+ }
+
+ /**
+ * Retrieves the human-readable shortened text value of a data request type.
+ *
+ * @param int $requesttype The request type.
+ * @return string
+ * @throws coding_exception
+ * @throws moodle_exception
+ */
+ public static function get_shortened_request_type_string($requesttype) {
+ switch ($requesttype) {
+ case api::DATAREQUEST_TYPE_EXPORT:
+ return get_string('requesttypeexportshort', 'tool_dataprivacy');
+ case api::DATAREQUEST_TYPE_DELETE:
+ return get_string('requesttypedeleteshort', 'tool_dataprivacy');
+ case api::DATAREQUEST_TYPE_OTHERS:
+ return get_string('requesttypeothersshort', 'tool_dataprivacy');
+ default:
+ throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
+ }
+ }
+
+ /**
+ * Retrieves the human-readable value of a data request status.
+ *
+ * @param int $status The request status.
+ * @return string
+ * @throws coding_exception
+ * @throws moodle_exception
+ */
+ public static function get_request_status_string($status) {
+ switch ($status) {
+ case api::DATAREQUEST_STATUS_PENDING:
+ return get_string('statuspending', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_PREPROCESSING:
+ return get_string('statuspreprocessing', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_AWAITING_APPROVAL:
+ return get_string('statusawaitingapproval', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_APPROVED:
+ return get_string('statusapproved', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_PROCESSING:
+ return get_string('statusprocessing', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_COMPLETE:
+ return get_string('statuscomplete', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_CANCELLED:
+ return get_string('statuscancelled', 'tool_dataprivacy');
+ case api::DATAREQUEST_STATUS_REJECTED:
+ return get_string('statusrejected', 'tool_dataprivacy');
+ default:
+ throw new moodle_exception('errorinvalidrequeststatus', 'tool_dataprivacy');
+ }
+ }
+}