Skip to content

Commit

Permalink
MBS-9448: Fix fetching correct filter data
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Nov 21, 2024
1 parent 7897ee8 commit 321f83d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions rights_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()) {
Expand Down Expand Up @@ -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,
Expand All @@ -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, []);
Expand All @@ -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]);
Expand All @@ -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]);
Expand Down

0 comments on commit 321f83d

Please sign in to comment.