diff --git a/field/entryteammemberprofilefield/field_class.php b/field/entryteammemberprofilefield/field_class.php index e70da235..40afb525 100644 --- a/field/entryteammemberprofilefield/field_class.php +++ b/field/entryteammemberprofilefield/field_class.php @@ -169,7 +169,7 @@ public function parse_search($formdata, $i) { $operator = !empty($formdata->{"searchoperator{$i}"}) ? $formdata->{"searchoperator{$i}"} : ''; $fieldvalue = !empty($formdata->{"f_{$i}_$field_id"}) ? $formdata->{"f_{$i}_$field_id"} : false; if ($operator == self::OPERATOR_MY_PROFILE_FIELD) { - return "-"; // FIXME: Find a way to save the filter without returning any value here. + return ""; } else { if ($operator == self::OPERATOR_LITERAL_VALUE) { return $fieldvalue; @@ -218,4 +218,12 @@ public function get_supported_search_operators() { self::OPERATOR_MY_PROFILE_FIELD => get_string('myprofilefield', 'datalynxfield_entryteammemberprofilefield') ); } + + public function get_argument_count(string $operator) { + if ($operator === self::OPERATOR_MY_PROFILE_FIELD) { + return 0; + } else { + return 1; + } + } } diff --git a/field/entryteammemberprofilefield/renderer.php b/field/entryteammemberprofilefield/renderer.php index 8f9d3cd5..7d7ab94d 100644 --- a/field/entryteammemberprofilefield/renderer.php +++ b/field/entryteammemberprofilefield/renderer.php @@ -33,5 +33,18 @@ /** */ class datalynxfield_entryteammemberprofilefield_renderer extends datalynxfield_renderer { - + + public function render_search_mode(MoodleQuickForm &$mform, int $i = 0, string $value = '') { + $fieldid = $this->_field->id(); + $fieldname = "f_{$i}_$fieldid"; + + $arr = array(); + $arr[] = &$mform->createElement('text', $fieldname, null, array('size' => '32')); + $mform->setType($fieldname, PARAM_NOTAGS); + $mform->setDefault($fieldname, $value); + $mform->disabledIf($fieldname, "searchoperator$i", 'eq', datalynxfield_entryteammemberprofilefield::OPERATOR_MY_PROFILE_FIELD); + + return array($arr, null); + } + } diff --git a/field/field_class.php b/field/field_class.php index c64c3e53..efa5c975 100644 --- a/field/field_class.php +++ b/field/field_class.php @@ -1251,6 +1251,14 @@ public function get_supported_search_operators() { 'ALL_OF' => get_string('allof', 'datalynx'), 'EXACTLY' => get_string('exactly', 'datalynx'), '' => get_string('empty', 'datalynx')); } + + public function get_argument_count(string $operator) { + if ($operator === "") { // "Empty" operator + return 0; + } else { + return 1; + } + } } /** diff --git a/filter/filter_class.php b/filter/filter_class.php index 568c1d2b..0d134d53 100644 --- a/filter/filter_class.php +++ b/filter/filter_class.php @@ -1069,9 +1069,9 @@ protected function get_search_options_from_form($formdata, $finalize = false) { $not = !empty($formdata->{"searchnot$i"}) ? $formdata->{"searchnot$i"} : ''; $operator = isset($formdata->{"searchoperator$i"}) ? $formdata->{"searchoperator$i"} : ''; $parsedvalue = $fields[$searchfieldid]->parse_search($formdata, $i); - // Don't add empty criteria on cleanup (unless operator is Empty and thus. - // Doesn't need search value). - if ($finalize && $operator && !$parsedvalue) { + // Don't add empty criteria on cleanup (unless operator + // doesn't need an argument/search value (e.g. the "Empty" operator)). + if ($finalize && ($fields[$searchfieldid]->get_argument_count($operator) > 0) && !$parsedvalue) { continue; }