-
Notifications
You must be signed in to change notification settings - Fork 73
Fix number search option #926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 tasks
Contributor
|
seems a revert of Can you check whether the issue raised by this PR (857) is actually fixed with it? |
Contributor
Author
Yes, the problem has been solved |
stonebuzz
approved these changes
Mar 6, 2025
Contributor
|
Can you validate with customer ? |
stonebuzz
requested changes
Mar 13, 2025
stonebuzz
requested changes
Mar 13, 2025
Co-authored-by: Stanislas <skita@teclib.com>
Co-authored-by: Stanislas <skita@teclib.com>
Rom1-B
requested changes
Mar 13, 2025
Contributor
|
After some tests, can you reset all changes and just apply this diff --git a/hook.php b/hook.php
index 2ee27aa..91e041b 100644
--- a/hook.php
+++ b/hook.php
@@ -344,9 +344,32 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
$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'
+ // surround with with qote desired value
+ // database column is delcared as varchar while GLPI search use number
+ // prevent Truncated incorrect DECIMAL value: ''
+ // where some line are NULL or '' value in related column
+ if ($searchtype == 'equals' || $searchtype == 'notequals') {
+ $operator = ($searchtype == 'equals') ? '=' : '!=';
+ 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 eb6712e..e0710f6 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -1963,6 +1963,7 @@ HTML;
break;
case 'number':
$opt[$i]['datatype'] = 'decimal';
+ $opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals'];
break;
case 'date':
case 'datetime': |
stonebuzz
requested changes
Mar 19, 2025
Co-authored-by: Stanislas <skita@teclib.com>
stonebuzz
approved these changes
Mar 19, 2025
Rom1-B
approved these changes
Mar 19, 2025
Contributor
|
@Lainow can you rebase ? |
Contributor
Author
|
Ok for customer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Fix the ability to search on 'number' fields
Before :

After :

Screenshots (if appropriate):