diff --git a/CHANGELOG.md b/CHANGELOG.md index e8fcfed9..f5682350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/hook.php b/hook.php index 15f48a43..f6fadaa9 100644 --- a/hook.php +++ b/hook.php @@ -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 ( diff --git a/inc/container.class.php b/inc/container.class.php index c3b6d856..f4d0db07 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -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':