$string['clearfilters'] = 'Clear filters';
$string['countparticipantsfound'] = '{$a} participants found';
$string['match'] = 'Match';
+$string['placeholdertypeorselect'] = 'Type or select...';
+$string['placeholdertype'] = 'Type...';
$string['privacy:courserequestpath'] = 'Requested courses';
$string['privacy:descriptionpath'] = 'Profile description';
$string['privacy:devicespath'] = 'User devices';
$string['privacy:profileimagespath'] = 'Profile images';
$string['privacy:privatefilespath'] = 'Private files';
$string['privacy:sessionpath'] = 'Session data';
+$string['filterbykeyword'] = 'Keyword';
$string['selectfiltertype'] = 'Select';
$string['target:upcomingactivitiesdue'] = 'Upcoming activities due';
$string['target:upcomingactivitiesdue_help'] = 'This target generates reminders for upcoming activities due.';
$string['target:upcomingactivitiesdueinfo'] = 'All upcoming activities due insights are listed here. These students have received these insights directly.';
-$string['typeorselect'] = 'Type or select...';
// eslint-disable-line no-empty-function
}
+ /**
+ * Get the placeholder to use when showing the value selector.
+ *
+ * @return {Promise} Resolving to a String
+ */
+ get placeholder() {
+ return getString('placeholdertypeorselect', 'core_user');
+ }
+
+ /**
+ * Whether to show suggestions in the autocomplete.
+ *
+ * @return {Boolean}
+ */
+ get showSuggestions() {
+ return true;
+ }
+
/**
* Add the value selector to the filter row.
*/
null,
// The string to use as a placeholder.
- await getString('typeorselect', 'core_user'),
+ await this.placeholder,
// Disable case sensitivity on searches.
false,
// Show suggestions.
- true,
+ this.showSuggestions,
// Do not override the 'no suggestions' string.
null,
--- /dev/null
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Keyword filter.
+ *
+ * @module core_user/local/participantsfilter/filtertypes/keyword
+ * @package core_user
+ * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+import Filter from '../filter';
+import {get_string as getString} from 'core/str';
+
+export default class extends Filter {
+ constructor(filterType, filterSet) {
+ super(filterType, filterSet);
+ }
+
+ /**
+ * For keywords the final value is an Array of strings.
+ *
+ * @returns {Object}
+ */
+ get values() {
+ return this.rawValues;
+ }
+
+ /**
+ * Get the placeholder to use when showing the value selector.
+ *
+ * @return {Promise} Resolving to a String
+ */
+ get placeholder() {
+ return getString('placeholdertype', 'core_user');
+ }
+
+ /**
+ * Whether to show suggestions in the autocomplete.
+ *
+ * @return {Boolean}
+ */
+ get showSuggestions() {
+ return false;
+ }
+}
protected function get_filtertypes(): array {
$filtertypes = [];
+ $filtertypes[] = $this->get_keyword_filter();
+
if ($filtertype = $this->get_enrolmentstatus_filter()) {
$filtertypes[] = $filtertype;
}
);
}
+ /**
+ * Get data for the keywords filter.
+ *
+ * @return stdClass|null
+ */
+ protected function get_keyword_filter(): ?stdClass {
+ return $this->get_filter_object(
+ 'keywords',
+ get_string('filterbykeyword', 'core_user'),
+ true,
+ true,
+ 'core_user/local/participantsfilter/filtertypes/keyword',
+ [],
+ true
+ );
+ }
+
/**
* Export the renderer data in a mustache template friendly format.
*
* @param bool $multiple
* @param string|null $filterclass
* @param array $values
+ * @param bool $allowempty
* @return stdClass|null
*/
protected function get_filter_object(
bool $custom,
bool $multiple,
?string $filterclass,
- array $values
+ array $values,
+ bool $allowempty = false
): ?stdClass {
- if (empty($values)) {
+
+ if (!$allowempty && empty($values)) {
// Do not show empty filters.
return null;
}