1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-26 07:44:02 +01:00

Fix ricerca per id

This commit is contained in:
Thomas Zilio 2019-02-02 08:23:12 +01:00
parent 60a356809e
commit 19b1b8957b

View File

@ -104,28 +104,38 @@ class Query
$search_filters = []; $search_filters = [];
foreach ($search as $field => $value) { foreach ($search as $field => $value) {
$pos = array_search($field, $total['fields']); $pos = array_search($field, $total['fields']);
$value = trim($value);
if (isset($value) && $pos !== false) { if (isset($value) && $pos !== false) {
$search_query = $total['search_inside'][$pos]; $search_query = $total['search_inside'][$pos];
// Campo con ricerca personalizzata
if (str_contains($search_query, '|search|')) { if (str_contains($search_query, '|search|')) {
$pieces = explode(',', $value); $pieces = explode(',', $value);
foreach ($pieces as $piece) { foreach ($pieces as $piece) {
$piece = trim($piece); $piece = trim($piece);
$search_filters[] = str_replace('|search|', prepare('%'.$piece.'%'), $search_query); $search_filters[] = str_replace('|search|', prepare('%'.$piece.'%'), $search_query);
} }
} else { }
// Per le icone cerco nel campo icon_title
// Campo id: ricerca tramite comparazione
elseif ($field == 'id') {
$search_filters[] = $search_query.' = '.prepare($value);
}
// Campi tradizionali: ricerca tramite like
else {
// Ricerca nei titoli icon_title_* per le icone icon_*
if (preg_match('/^icon_(.+?)$/', $field, $m)) { if (preg_match('/^icon_(.+?)$/', $field, $m)) {
$search_query = '`icon_title_'.$m[1].'`'; $search_query = '`icon_title_'.$m[1].'`';
} }
// Per i colori cerco nel campo color_title // Ricerca nei titoli color_title_* per i colori color_*
elseif (preg_match('/^color_(.+?)$/', $field, $m)) { elseif (preg_match('/^color_(.+?)$/', $field, $m)) {
$search_query = '`color_title_'.$m[1].'`'; $search_query = '`color_title_'.$m[1].'`';
} }
$search_filters[] = $search_query.' LIKE '.prepare('%'.trim($value.'%')); $search_filters[] = $search_query.' LIKE '.prepare('%'.$value.'%');
} }
} }