Skip to content

Commit

Permalink
MBS-9448: Trying(!) to implement autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Nov 20, 2024
1 parent 7599afa commit d40757e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
13 changes: 8 additions & 5 deletions classes/form/rights_config_filter_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ public function definition() {
$mform->addElement('hidden', 'tenant', $tenant->get_identifier());
$mform->setType('tenant', PARAM_ALPHANUM);

$options = [
'multiple' => true,
'noselectionstring' => get_string('allareas', 'search'),
];

$elementarray = [];
if (!empty($filteroptions)) {
$filteroptionsmultiselect =
$mform->createElement('select', 'filterids', '', $filteroptions,
['size' => 2, 'class' => 'local_ai_manager-filter_select pr-1']);
$mform->createElement('autocomplete', 'filterids', '', $filteroptions, $options);
$filteroptionsmultiselect->setMultiple(true);
$filteroptionsmultiselect->setSelected(0);
$elementarray[] = $filteroptionsmultiselect;
Expand All @@ -65,13 +69,12 @@ public function definition() {
'local_ai_manager'),
];
$rolefilteroptionsmultiselect =
$mform->createElement('select', 'rolefilterids', '', $rolefilteroptions,
['size' => 2, 'class' => 'local_ai_manager-filter_select pr-1']);
$mform->createElement('autocomplete', 'rolefilterids', '', $rolefilteroptions, $options);
$rolefilteroptionsmultiselect->setMultiple(true);
$elementarray[] = $rolefilteroptionsmultiselect;

$elementarray[] = $mform->createElement('submit', 'applyfilter', get_string('applyfilter', 'local_ai_manager'));
$elementarray[] = $mform->createElement('cancel', 'resetfilter', get_string('resetfilter', 'local_ai_manager'));
$elementarray[] = $mform->createElement('submit', 'resetfilter', get_string('resetfilter', 'local_ai_manager'));
$mform->addGroup($elementarray, 'elementarray', get_string('filterheading', 'local_ai_manager'), [' '], false);
}
}
20 changes: 13 additions & 7 deletions rights_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,26 @@
$filterform =
new \local_ai_manager\form\rights_config_filter_form(null,
['filteroptions' => $usertablefilter->get_filter_options()]);
if ($filterform->is_cancelled()) {
$filterids = [];
$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 : [];
$filterform->set_data(['rolefilterids' => [1,2,3]]);
if (!empty($filterform->get_data())) {
if (!empty($filterform->get_data()->resetfilter)) {
$filterids = [];
$rolefilterids = [];
} else {
$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 {
// Filter form has not submitted, so use the filter ids stored in the session.
$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]);
}
$filterform->set_data(['filterids' => $filterids, 'rolefilterids' => $rolefilterids]);

// Update session if necessary.
if ($SESSION->local_ai_manager_filterids !== $filterids) {
$SESSION->local_ai_manager_filterids = $filterids;
}
Expand Down

0 comments on commit d40757e

Please sign in to comment.