diff --git a/rights_config.php b/rights_config.php index 1dc5e7c..259d425 100644 --- a/rights_config.php +++ b/rights_config.php @@ -24,6 +24,10 @@ */ use local_ai_manager\form\rights_config_filter_form; +use local_ai_manager\form\rights_config_form; +use local_ai_manager\local\rights_config_table; +use local_ai_manager\local\tenant; +use local_ai_manager\local\tenant_config_output_utils; use local_ai_manager\local\userinfo; use local_ai_manager\output\tenantnavbar; @@ -32,12 +36,12 @@ global $CFG, $DB, $OUTPUT, $PAGE, $SESSION, $USER; -\local_ai_manager\local\tenant_config_output_utils::setup_tenant_config_page(new moodle_url('/local/ai_manager/rights_config.php')); +tenant_config_output_utils::setup_tenant_config_page(new moodle_url('/local/ai_manager/rights_config.php')); -$tenant = \core\di::get(\local_ai_manager\local\tenant::class); +$tenant = \core\di::get(tenant::class); $returnurl = new moodle_url('/local/ai_manager/tenant_config.php', ['tenant' => $tenant->get_identifier()]); -$rightsconfigform = new \local_ai_manager\form\rights_config_form(null, ['tenant' => $tenant]); +$rightsconfigform = new rights_config_form(null, ['tenant' => $tenant]); // Standard form processing if statement. if ($rightsconfigform->is_cancelled()) { @@ -71,6 +75,9 @@ // Render and handle external filter provided through a hook. $usertablefilter = new \local_ai_manager\hook\usertable_filter($tenant); \core\di::get(\core\hook\manager::class)->dispatch($usertablefilter); + // phpcs:disable moodle.Commenting.TodoComment.MissingInfoInline + // TODO: Evtl. add validation possibility in usertable_filter. + // phpcs:enable moodle.Commenting.TodoComment.MissingInfoInline $filterform = new rights_config_filter_form(null, @@ -79,10 +86,11 @@ 'hookfilterlabel' => $usertablefilter->get_filter_label(), ] ); - $hookfilterids = []; - $rolefilterids = []; - if (!empty($filterform->get_data())) { + // Get currently stored filter ids from user session. + $hookfilterids = $filterform->get_stored_filterids(rights_config_filter_form::FILTER_IDENTIFIER_HOOK_FILTER); + $rolefilterids = $filterform->get_stored_filterids(rights_config_filter_form::FILTER_IDENTIFIER_ROLE_FILTER); + if (!empty($filterform->get_data())) { if (!empty($filterform->get_data()->resetfilter)) { $filterform->store_filterids(rights_config_filter_form::FILTER_IDENTIFIER_HOOK_FILTER, []); $filterform->store_filterids(rights_config_filter_form::FILTER_IDENTIFIER_ROLE_FILTER, []); @@ -91,18 +99,11 @@ $hookfilterids = !empty($filterform->get_data()->hookfilterids) ? $filterform->get_data()->hookfilterids : []; $rolefilterids = !empty($filterform->get_data()->rolefilterids) ? $filterform->get_data()->rolefilterids : []; } - // phpcs:disable moodle.Commenting.TodoComment.MissingInfoInline - // TODO: Evtl. add validation possibility in usertable_filter. - // phpcs:enable moodle.Commenting.TodoComment.MissingInfoInline - } else { - // Filter form has not submitted, so use the filter ids stored in the session. - $hookfilterids = $filterform->get_stored_filterids(rights_config_filter_form::FILTER_IDENTIFIER_HOOK_FILTER); - $hookfilterids = $filterform->get_stored_filterids(rights_config_filter_form::FILTER_IDENTIFIER_ROLE_FILTER); } // Store filterdata in session. - $filterform->store_filterids(\local_ai_manager\form\rights_config_filter_form::FILTER_IDENTIFIER_HOOK_FILTER, $hookfilterids); - $filterform->store_filterids(\local_ai_manager\form\rights_config_filter_form::FILTER_IDENTIFIER_ROLE_FILTER, $rolefilterids); + $filterform->store_filterids(rights_config_filter_form::FILTER_IDENTIFIER_HOOK_FILTER, $hookfilterids); + $filterform->store_filterids(rights_config_filter_form::FILTER_IDENTIFIER_ROLE_FILTER, $rolefilterids); // Set default data (if not set already by request). $filterform->set_data(['hookfilterids' => $hookfilterids, 'rolefilterids' => $rolefilterids]); @@ -119,7 +120,7 @@ // Render rights table. $uniqid = 'rights-config-table-' . uniqid(); $rightstable = - new \local_ai_manager\local\rights_config_table($uniqid, $tenant, $PAGE->url, $hookfilterids, $rolefilterids); + new rights_config_table($uniqid, $tenant, $PAGE->url, $hookfilterids, $rolefilterids); $rightstable->out(100, false); $rightsconfigform->display(); $PAGE->requires->js_call_amd('local_ai_manager/rights_config_table', 'init', ['id' => $uniqid]);