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 data purpose.
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
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
;
31 use external_single_structure
;
34 use tool_dataprivacy\purpose
;
37 * Class for exporting field data.
39 * @copyright 2018 David Monllao
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class purpose_exporter
extends persistent_exporter
{
45 * Defines the persistent class.
49 protected static function define_class() {
50 return purpose
::class;
54 * Returns a list of objects that are related.
58 protected static function define_related() {
60 'context' => 'context',
65 * Return the list of additional properties.
69 protected static function define_other_properties() {
70 $namedescriptiontype = [
79 'formattedretentionperiod' => [
82 'formattedlawfulbases' => [
83 'type' => $namedescriptiontype,
86 'formattedsensitivedatareasons' => [
87 'type' => $namedescriptiontype,
95 * Return other properties.
97 * @param renderer_base $output
99 * @throws coding_exception
102 protected function get_other_values(renderer_base
$output) {
105 $formattedbases = [];
106 $lawfulbases = explode(',', $this->persistent
->get('lawfulbases'));
107 if (!empty($lawfulbases)) {
108 foreach ($lawfulbases as $basis) {
109 if (empty(trim($basis))) {
112 $formattedbases[] = (object)[
113 'name' => get_string($basis . '_name', 'tool_dataprivacy'),
114 'description' => get_string($basis . '_description', 'tool_dataprivacy')
118 $values['formattedlawfulbases'] = $formattedbases;
120 $formattedsensitivereasons = [];
121 $sensitivereasons = explode(',', $this->persistent
->get('sensitivedatareasons'));
122 if (!empty($sensitivereasons)) {
123 foreach ($sensitivereasons as $reason) {
124 if (empty(trim($reason))) {
127 $formattedsensitivereasons[] = (object)[
128 'name' => get_string($reason . '_name', 'tool_dataprivacy'),
129 'description' => get_string($reason . '_description', 'tool_dataprivacy')
133 $values['formattedsensitivedatareasons'] = $formattedsensitivereasons;
135 $retentionperiod = $this->persistent
->get('retentionperiod');
136 if ($retentionperiod) {
137 $interval = new DateInterval($retentionperiod);
139 // It is one or another.
141 $formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
142 } else if ($interval->m
) {
143 $formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
144 } else if ($interval->d
) {
145 $formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
147 $formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
150 $formattedtime = get_string('retentionperiodnotdefined', 'tool_dataprivacy');
152 $values['formattedretentionperiod'] = $formattedtime;