diff --git a/classes/form/rights_config_filter_form.php b/classes/form/rights_config_filter_form.php index c23ebc0..40cbb07 100644 --- a/classes/form/rights_config_filter_form.php +++ b/classes/form/rights_config_filter_form.php @@ -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; @@ -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); } } diff --git a/rights_config.php b/rights_config.php index fc22dd1..d3ad2e1 100644 --- a/rights_config.php +++ b/rights_config.php @@ -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; }