From 0194241c6b92c3ea57fd6ce8363eaeedfc316a6b Mon Sep 17 00:00:00 2001 From: Peter Schulze Date: Wed, 13 Nov 2024 12:59:42 +0100 Subject: [PATCH 1/2] adding possibility to search with comma separated list in integer and number fields (+ adding example in help notice) --- lang/de_de.lang | 4 ++-- lang/en_gb.lang | 4 ++-- lang/es_es.lang | 4 ++-- lang/sv_se.lang | 4 ++-- lib/yform/value/integer.php | 9 +++++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lang/de_de.lang b/lang/de_de.lang index 373a49f9..40650ce3 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -89,8 +89,8 @@ yform_values_number_precision = Anzahl der Ziffern inkl. Dezimalstellen insg., z yform_values_number_scale = Davon: Anzahl der Ziffern für Nachkommastellen, z. B. 2 eingeben für 4999,95 oder 0 für 100.000 (SCALE) yform_search_defaults_wildcard_notice = Beispiele: *name / !(empty) / (empty) -yform_search_integer_notice = Beispiele: >5 / !=5 / 3-5 / 2..5 / !(empty) / (empty) -yform_search_number_notice = Beispiele: >5 / !=5 / 3-5 / 2..5 / !(empty) / (empty) +yform_search_integer_notice = Beispiele: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) +yform_search_number_notice = Beispiele: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) yform_search_defaults_select_notice = Mit CTRL oder COMMAND mehrere auswählen yform_values_checkbox_values = Werte (0,1) (nicht angeklickt,angeklickt) diff --git a/lang/en_gb.lang b/lang/en_gb.lang index edde3f5b..e6fb0e8e 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -82,8 +82,8 @@ yform_values_number_precision = Number of digits (23335443.23 woud be 10 digits) yform_values_number_scale = Number of the digits decimal places (23335443.23 would be 2 decimal places) (SCALE) yform_search_defaults_wildcard_notice = Examples: *name / !(empty) / (empty) -yform_search_integer_notice = Examples: >5 / !=5 / 3-5 / 2..5 / !(empty) / (empty) -yform_search_number_notice = Examples: >5 / !=5 / 3-5 / 2..5 / !(empty) / (empty) +yform_search_integer_notice = Examples: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) +yform_search_number_notice = Examples: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) yform_search_defaults_select_notice = Please use CTRL or COMMAND to select more options yform_values_checkbox_values = Values (0,1 = unchecked, checked) diff --git a/lang/es_es.lang b/lang/es_es.lang index 3719db1c..29211d00 100644 --- a/lang/es_es.lang +++ b/lang/es_es.lang @@ -81,8 +81,8 @@ yform_values_number_precision = Número de dígitos (23335443.23 sería, por eje yform_values_number_scale = Número de dígitos después de los dígitos (23335443.23 serían 2 decimales, por ejemplo) (ESCALA) yform_search_defaults_wildcard_notice = Ejemplos: * nombre /! (Vacío) / (vacío) -yform_search_integer_notice = Ejemplos:> 5 /!= 5 / 3-5 / 2..5 /! (Vacío) / (vacío) -yform_search_number_notice = Ejemplos: >5 / !=5 / 3-5 / 2..5 / !(vacío ) / (vacío ) +yform_search_integer_notice = Ejemplos: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) +yform_search_number_notice = Ejemplos: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) yform_search_defaults_select_notice = Seleccione varios con CTRL o comando yform_values_checkbox_values = Valores (0,1) (sin hacer clic, hacer clic) diff --git a/lang/sv_se.lang b/lang/sv_se.lang index 3a594110..72fa2e22 100644 --- a/lang/sv_se.lang +++ b/lang/sv_se.lang @@ -83,8 +83,8 @@ yform_values_number_precision = Antal siffror (23335443.23 skulle till exempel v yform_values_number_scale = Antal decimaler (23335443.23 skulle exempelvis vara 2 decimaler) (SCALE) yform_search_defaults_wildcard_notice = Exempel: * namn /! (empty) / (empty) -yform_search_integer_notice = Exempel:> 5 /! = 5 / 3-5 / 2..5 /! (empty) / (empty) -yform_search_number_notice = Exempel: >5 / !=5 / 3-5 / 2..5 / !(empty) / (empty) +yform_search_integer_notice = Exempel: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) +yform_search_number_notice = Exempel: >5 / !=5 / 3-5 / 2..5 / 1,3,8 / !(empty) / (empty) yform_search_defaults_select_notice = Använd CTRL eller COMMAND för att välja fler alternativ yform_values_checkbox_values = Värden (0,1 = unchecked, checked) diff --git a/lib/yform/value/integer.php b/lib/yform/value/integer.php index eeb35d65..eaa8311b 100644 --- a/lib/yform/value/integer.php +++ b/lib/yform/value/integer.php @@ -93,11 +93,20 @@ public static function getSearchFilter($params) }, 'OR'); } + // check for range with 'x..y' or 'x-y' patterns if (preg_match('/^\s*(-?\d+)\s*\.\.\s*(-?\d+)\s*$/', $value, $match)) { $match[1] = (int) $match[1]; $match[2] = (int) $match[2]; return $query->whereBetween($field, $match[1], $match[2]); } + + // check for comma separated values + if( preg_match('/^(-?\d+)(?:\s*,\s*(-?\d+))*$/', $match[2]) ) { + $values = array_map('intval', explode(',', $match[2])); + return $query->whereListContains($field, $values); + } + + // default case including optional comparator preg_match('/^\s*(<|<=|>|>=|<>|!=)?\s*(.*)$/', $value, $match); $comparator = $match[1] ?: '='; $value = (int) $match[2]; From 187cb40a7ce5b56f6da30014d973f90d838709a1 Mon Sep 17 00:00:00 2001 From: Peter Schulze Date: Wed, 13 Nov 2024 13:03:53 +0100 Subject: [PATCH 2/2] coding style fix --- lib/yform/value/integer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/yform/value/integer.php b/lib/yform/value/integer.php index eaa8311b..4aaa27ef 100644 --- a/lib/yform/value/integer.php +++ b/lib/yform/value/integer.php @@ -101,7 +101,7 @@ public static function getSearchFilter($params) } // check for comma separated values - if( preg_match('/^(-?\d+)(?:\s*,\s*(-?\d+))*$/', $match[2]) ) { + if (preg_match('/^(-?\d+)(?:\s*,\s*(-?\d+))*$/', $match[2])) { $values = array_map('intval', explode(',', $match[2])); return $query->whereListContains($field, $values); }