Skip to content

Commit

Permalink
MBS-9448: Move current filter data to session
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Nov 18, 2024
1 parent 40db68b commit 68c33ef
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions rights_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_login();

global $CFG, $DB, $OUTPUT, $PAGE, $USER;
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'));

Expand Down Expand Up @@ -76,25 +76,35 @@
$usertablefilter = new \local_ai_manager\hook\usertable_filter($tenant);
\core\di::get(\core\hook\manager::class)->dispatch($usertablefilter);

$filterids = [];
$rolefilterids = [];
$filterform =
new \local_ai_manager\form\rights_config_filter_form(null,
['filteroptions' => $usertablefilter->get_filter_options()]);
if (!empty($filterform->get_data())) {
if ($filterform->is_cancelled()) {
$filterids = [];
if (!empty($filterform->get_data())) {
$filterids = $filterform->get_data()->filterids;
$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
}
$rolefilterids = [];
} else if (!empty($filterform->get_data())) {
$filterids = !empty($filterform->get_data()->filterids) ? $filterform->get_data()->filterids : [];
$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 {
$filterids = !empty($SESSION->local_ai_manager_filterids) ? $SESSION->local_ai_manager_filterids : [];
$rolefilterids = !empty($SESSION->local_ai_manager_rolefilterids) ? $SESSION->local_ai_manager_rolefilterids : [];
$filterform->set_data(['filterids' => $filterids, 'rolefilterids' => $rolefilterids]);
}
if ($SESSION->local_ai_manager_filterids !== $filterids) {
$SESSION->local_ai_manager_filterids = $filterids;
}
if ($SESSION->local_ai_manager_rolefilterids !== $rolefilterids) {
$SESSION->local_ai_manager_rolefilterids = $rolefilterids;
}
$filterform->display();

$uniqid = 'rights-config-table-' . uniqid();
$rightstable = new \local_ai_manager\local\rights_config_table($uniqid, $tenant, $PAGE->url, $filterids, $rolefilterids);
$rightstable =
new \local_ai_manager\local\rights_config_table($uniqid, $tenant, $PAGE->url, $SESSION->local_ai_manager_filterids,
$SESSION->local_ai_manager_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 68c33ef

Please sign in to comment.