Skip to content
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

adding possibility to search with comma separated list in integer and number fields #1536

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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. <code>2</code> eingeben für <code>4999,95</code> oder <code>0</code> für <code>100.000</code> (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)
Expand Down
4 changes: 2 additions & 2 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lang/es_es.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lang/sv_se.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/yform/value/integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading