Skip to content

Commit

Permalink
MDL-63496 tool_dataprivacy: Add configuration for per-role retention
Browse files Browse the repository at this point in the history
This issue is a part of the MDL-62560 Epic.
  • Loading branch information
andrewnicols committed Oct 17, 2018
1 parent f30b061 commit e3ddf1e
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 82 deletions.
21 changes: 21 additions & 0 deletions admin/tool/dataprivacy/classes/api.php
Expand Up @@ -1210,4 +1210,25 @@ public static function set_context_defaults($contextlevel, $categoryid, $purpose

return true;
}

/**
* Format the supplied date interval as a retention period.
*
* @param \DateInterval $interval
* @return string
*/
public static function format_retention_period(\DateInterval $interval) : string {
// It is one or another.
if ($interval->y) {
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
} else if ($interval->m) {
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
} else if ($interval->d) {
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
} else {
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
}

return $formattedtime;
}
}
19 changes: 6 additions & 13 deletions admin/tool/dataprivacy/classes/external/purpose_exporter.php
Expand Up @@ -26,7 +26,6 @@

use coding_exception;
use core\external\persistent_exporter;
use DateInterval;
use Exception;
use renderer_base;
use tool_dataprivacy\context_instance;
Expand Down Expand Up @@ -79,6 +78,9 @@ protected static function define_other_properties() {
'multiple' => true,
'optional' => true
],
'roleoverrides' => [
'type' => PARAM_TEXT
],
];
}

Expand Down Expand Up @@ -125,23 +127,14 @@ protected function get_other_values(renderer_base $output) {

$retentionperiod = $this->persistent->get('retentionperiod');
if ($retentionperiod) {
$interval = new DateInterval($retentionperiod);

// It is one or another.
if ($interval->y) {
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
} else if ($interval->m) {
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
} else if ($interval->d) {
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
} else {
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
}
$formattedtime = \tool_dataprivacy\api::format_retention_period(new \DateInterval($retentionperiod));
} else {
$formattedtime = get_string('retentionperiodnotdefined', 'tool_dataprivacy');
}
$values['formattedretentionperiod'] = $formattedtime;

$values['roleoverrides'] = !empty($this->persistent->get_purpose_overrides());

return $values;
}

Expand Down

0 comments on commit e3ddf1e

Please sign in to comment.