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
;
32 use tool_dataprivacy\purpose
;
35 * Class for exporting field data.
37 * @copyright 2018 David Monllao
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class purpose_exporter
extends persistent_exporter
{
43 * Defines the persistent class.
47 protected static function define_class() {
48 return purpose
::class;
52 * Returns a list of objects that are related.
56 protected static function define_related() {
58 'context' => 'context',
63 * Return the list of additional properties.
67 protected static function define_other_properties() {
69 'formattedretentionperiod' => [
72 'formattedlawfulbases' => [
73 'type' => name_description_exporter
::read_properties_definition(),
76 'formattedsensitivedatareasons' => [
77 'type' => name_description_exporter
::read_properties_definition(),
85 * Return other properties.
87 * @param renderer_base $output
89 * @throws coding_exception
92 protected function get_other_values(renderer_base
$output) {
96 $lawfulbases = explode(',', $this->persistent
->get('lawfulbases'));
97 if (!empty($lawfulbases)) {
98 foreach ($lawfulbases as $basis) {
99 if (empty(trim($basis))) {
102 $formattedbases[] = (object)[
103 'name' => get_string($basis . '_name', 'tool_dataprivacy'),
104 'description' => get_string($basis . '_description', 'tool_dataprivacy')
108 $values['formattedlawfulbases'] = $formattedbases;
110 $formattedsensitivereasons = [];
111 $sensitivereasons = explode(',', $this->persistent
->get('sensitivedatareasons'));
112 if (!empty($sensitivereasons)) {
113 foreach ($sensitivereasons as $reason) {
114 if (empty(trim($reason))) {
117 $formattedsensitivereasons[] = (object)[
118 'name' => get_string($reason . '_name', 'tool_dataprivacy'),
119 'description' => get_string($reason . '_description', 'tool_dataprivacy')
123 $values['formattedsensitivedatareasons'] = $formattedsensitivereasons;
125 $retentionperiod = $this->persistent
->get('retentionperiod');
126 if ($retentionperiod) {
127 $interval = new DateInterval($retentionperiod);
129 // It is one or another.
131 $formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
132 } else if ($interval->m
) {
133 $formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
134 } else if ($interval->d
) {
135 $formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
137 $formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
140 $formattedtime = get_string('retentionperiodnotdefined', 'tool_dataprivacy');
142 $values['formattedretentionperiod'] = $formattedtime;