Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,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
Expand All @@ -410,9 +410,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;
Expand Down
22 changes: 19 additions & 3 deletions inc/dropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}