Skip to content

Commit

Permalink
Merge petervelosy:feature/filter_teammemberprofilefield
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Aug 16, 2024
2 parents cbea0da + 849d11c commit 6002866
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
10 changes: 9 additions & 1 deletion field/entryteammemberprofilefield/field_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
15 changes: 14 additions & 1 deletion field/entryteammemberprofilefield/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
8 changes: 8 additions & 0 deletions field/field_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions filter/filter_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6002866

Please sign in to comment.