Skip to content
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/).

### Fixed

- Fix `numeric` field search
- Fix containers migration while adding `is_recursive` field
- Fix container update from other context (like plugins)
- Fix "not equals" search operator for dropdown `multiple`
Expand Down
39 changes: 36 additions & 3 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,45 @@ function plugin_datainjection_populate_fields()

function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
{
$searchopt = &Search::getOptions($itemtype);
$table = $searchopt[$ID]['table'];
$field = $searchopt[$ID]['field'];
/** @var \DBmysql $DB */
global $DB;

$searchopt = &Search::getOptions($itemtype);
$table = $searchopt[$ID]['table'];
$field = $searchopt[$ID]['field'];
$pfields_type = $searchopt[$ID]['pfields_type'] ?? '';

$field_field = new PluginFieldsField();

if (
$field_field->getFromDBByCrit(
[
'name' => $field,
'type' => 'number',
],
)
&& $pfields_type == 'number'
) {
// if 'number' field with name is found with searchtype 'equals' or 'notequals'
// update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used
if ($searchtype == 'equals' || $searchtype == 'notequals') {
$operator = ($searchtype == 'equals') ? '=' : '!=';
if ($nott) {
$link = $link . ' NOT ';
}
return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,7))' . $operator . ' ' . $DB->quoteValue($val) ;
} else {
// if 'number' field with name is found with <= or >= or < or > search
// update WHERE clause with the correct operator
$val = html_entity_decode($val);
if (preg_match('/(<=|>=|>|<)/', $val, $matches)) {
$operator = $matches[1];
$val = trim(str_replace($operator, '', $val));
return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val);
}
}
}

// if 'multiple' field with name is found -> 'Dropdown-XXXX' case
// update WHERE clause with LIKE statement
if (
Expand Down
4 changes: 3 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,9 @@ public static function getAddSearchOptions($itemtype, $containers_id = false)
$opt[$i]['datatype'] = 'text';
break;
case 'number':
$opt[$i]['datatype'] = 'decimal';
// change datatype to string to get `is` / `is not` operator
$opt[$i]['datatype'] = 'string';
$opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals'];
break;
case 'date':
case 'datetime':
Expand Down