Skip to content

Commit 5af8b09

Browse files
MyvTsvstonebuzz
andauthored
fix(searchOption): notequals operator returns equals values for multiple dropdown (#928)
* fix(searchOption): notequals operator returns equals values for multiple dropdown * fix notequals * Update hook.php Co-authored-by: Stanislas <[email protected]> * verif not condition * lint * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Stanislas <[email protected]> --------- Co-authored-by: Stanislas <[email protected]>
1 parent 204c9b0 commit 5af8b09

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Fixed
1111

1212
- Fix container update from other context (like plugins)
13+
- Fix "not equals" search operator for dropdown `multiple`
1314

1415
## [1.21.19] - 2025-02-03
1516

hook.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ function plugin_datainjection_populate_fields()
338338

339339
function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
340340
{
341-
/** @var \DBmysql $DB */
342-
global $DB;
343-
344341
$searchopt = &Search::getOptions($itemtype);
345342
$table = $searchopt[$ID]['table'];
346343
$field = $searchopt[$ID]['field'];
@@ -357,12 +354,19 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
357354
],
358355
)
359356
) {
360-
return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ;
357+
$tablefield = "$table" . '_' . "$field";
358+
switch ($searchtype) {
359+
case 'equals':
360+
return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals');
361+
case 'notequals':
362+
return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals');
363+
}
361364
} else {
362365
// if 'multiple' field with cleaned name is found -> 'dropdown' case
363366
// update WHERE clause with LIKE statement
364367
$cleanfield = str_replace('plugin_fields_', '', $field);
365368
$cleanfield = str_replace('dropdowns_id', '', $cleanfield);
369+
$tablefield = "$table" . '_' . "$cleanfield";
366370
if (
367371
$field_field->getFromDBByCrit(
368372
[
@@ -371,7 +375,12 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
371375
],
372376
)
373377
) {
374-
return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ;
378+
switch ($searchtype) {
379+
case 'equals':
380+
return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals');
381+
case 'notequals':
382+
return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals');
383+
}
375384
} else {
376385
return false;
377386
}

inc/dropdown.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,17 @@ public static function getClassname($system_name)
254254
{
255255
return 'PluginFields' . ucfirst($system_name) . 'Dropdown';
256256
}
257+
258+
public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype)
259+
{
260+
/** @var \DBmysql $DB */
261+
global $DB;
262+
263+
switch ($searchtype) {
264+
case 'equals':
265+
return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ;
266+
case 'notequals':
267+
return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'IS NULL ';
268+
}
269+
}
257270
}

0 commit comments

Comments
 (0)