Commit d95ad08f authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-63619 tool_dataprivacy: Cache purposes in form

parent 3b002c86
...@@ -145,12 +145,12 @@ class context_instance extends \core\form\persistent { ...@@ -145,12 +145,12 @@ class context_instance extends \core\form\persistent {
$persistent->set('contextid', $context->id); $persistent->set('contextid', $context->id);
} }
$purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options( $purposes = [];
api::get_purposes() foreach (api::get_purposes() as $purpose) {
); $purposes[$purpose->get('id')] = $purpose;
$categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options( }
api::get_categories() $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options($purposes);
); $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options(api::get_categories());
$customdata = [ $customdata = [
'context' => $context, 'context' => $context,
...@@ -168,9 +168,14 @@ class context_instance extends \core\form\persistent { ...@@ -168,9 +168,14 @@ class context_instance extends \core\form\persistent {
$context); $context);
$customdata['purposeretentionperiods'] = []; $customdata['purposeretentionperiods'] = [];
foreach ($purposeoptions as $optionvalue => $unused) { foreach (array_keys($purposeoptions) as $optionvalue) {
// Get the effective purpose if $optionvalue would be the selected value.
$purpose = api::get_effective_context_purpose($context, $optionvalue); if (isset($purposes[$optionvalue])) {
$purpose = $purposes[$optionvalue];
} else {
// Get the effective purpose if $optionvalue would be the selected value.
$purpose = api::get_effective_context_purpose($context, $optionvalue);
}
$retentionperiod = self::get_retention_display_text( $retentionperiod = self::get_retention_display_text(
$purpose, $purpose,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment