From 0edb3dad5e4a82c30bc2e84a68daa8a5ae5cf9b9 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 17 Jul 2025 11:22:40 +0200 Subject: [PATCH 1/2] fix(SO): search options not working with default values in multi-select --- hook.php | 9 ++++----- inc/dropdown.class.php | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hook.php b/hook.php index f6fadaa9..9989d57f 100644 --- a/hook.php +++ b/hook.php @@ -376,7 +376,6 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) } } } - // if 'multiple' field with name is found -> 'Dropdown-XXXX' case // update WHERE clause with LIKE statement if ( @@ -390,9 +389,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $tablefield = "$table" . '_' . "$field"; switch ($searchtype) { case 'equals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals', $itemtype, $field_field); case 'notequals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals', $itemtype, $field_field); } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case @@ -410,9 +409,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ) { switch ($searchtype) { case 'equals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals', $itemtype, $field_field); case 'notequals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals', $itemtype, $field_field); } } else { return false; diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index 727c6d09..926b670a 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -255,16 +255,32 @@ public static function getClassname($system_name) return 'PluginFields' . ucfirst($system_name) . 'Dropdown'; } - public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype) + public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype, $itemtype, $field_field) { /** @var \DBmysql $DB */ global $DB; + $default_value_request = ""; + + if ($field_field->fields['default_value'] === '["' . $val . '"]') { + switch ($searchtype) { + case 'equals': + $default_value_request = ' OR (' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('itemtype') . ' IS NULL' . + ' AND ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('items_id') . ' IS NULL)'; + break; + case 'notequals': + $default_value_request = ' AND (' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('itemtype') . '=' . $DB->quoteValue($itemtype) . + ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('items_id') . '=' . $itemtype::getTable() . '.id)'; + break; + } + } + switch ($searchtype) { case 'equals': - return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' LIKE ' . $DB->quoteValue("%\"$val\"%") . $default_value_request; 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 '; + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . + ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' IS NULL' . $default_value_request; } } } From 9784d8edfaa39d7f64c1b178c6249c84df0eeab5 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 17 Jul 2025 11:40:32 +0200 Subject: [PATCH 2/2] CHANGELOG.md --- CHANGELOG.md | 1 + hook.php | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d4784c..bb7b07b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix incompatibility of `multiple` dropdowns with `massiveaction` - Fix default value properly applied in multiple dropdown search options +- Fix `search option` for default values in `multiple` dropdown ## [1.21.22] - 2025-05-28 diff --git a/hook.php b/hook.php index 9989d57f..2835d88a 100644 --- a/hook.php +++ b/hook.php @@ -376,6 +376,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) } } } + // if 'multiple' field with name is found -> 'Dropdown-XXXX' case // update WHERE clause with LIKE statement if (