diff --git a/CHANGELOG.md b/CHANGELOG.md index acb543d6..de3ef73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix container update from other context (like plugins) +- Fix "not equals" search operator for dropdown `multiple` ## [1.21.19] - 2025-02-03 diff --git a/hook.php b/hook.php index 2ee27aa7..15f48a43 100644 --- a/hook.php +++ b/hook.php @@ -338,9 +338,6 @@ function plugin_datainjection_populate_fields() function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) { - /** @var \DBmysql $DB */ - global $DB; - $searchopt = &Search::getOptions($itemtype); $table = $searchopt[$ID]['table']; $field = $searchopt[$ID]['field']; @@ -357,12 +354,19 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ], ) ) { - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + $tablefield = "$table" . '_' . "$field"; + switch ($searchtype) { + case 'equals': + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + case 'notequals': + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case // update WHERE clause with LIKE statement $cleanfield = str_replace('plugin_fields_', '', $field); $cleanfield = str_replace('dropdowns_id', '', $cleanfield); + $tablefield = "$table" . '_' . "$cleanfield"; if ( $field_field->getFromDBByCrit( [ @@ -371,7 +375,12 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ], ) ) { - return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + switch ($searchtype) { + case 'equals': + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + case 'notequals': + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + } } else { return false; } diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index c3810aa7..727c6d09 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -254,4 +254,17 @@ public static function getClassname($system_name) { return 'PluginFields' . ucfirst($system_name) . 'Dropdown'; } + + public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype) + { + /** @var \DBmysql $DB */ + global $DB; + + switch ($searchtype) { + case 'equals': + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + case 'notequals': + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'IS NULL '; + } + } }