openstamanager/modules/automezzi/ajax/search.php

43 lines
1.0 KiB
PHP
Raw Normal View History

2023-11-30 12:57:03 +01:00
<?php
include_once __DIR__.'/../../../core.php';
2024-03-05 16:01:45 +01:00
use Models\Module;
2023-11-30 12:57:03 +01:00
2024-06-11 16:58:27 +02:00
$link_id = Module::where('name', 'Automezzi')->first()->id;
2023-11-30 12:57:03 +01:00
$fields = [
'Nome' => 'nome',
'Descrizione' => 'descrizione',
'Targa' => 'targa',
];
2024-05-14 17:16:30 +02:00
$query = 'SELECT * FROM an_sedi WHERE 1=0 ';
2023-11-30 12:57:03 +01:00
foreach ($fields as $name => $value) {
2024-05-14 17:16:30 +02:00
$query .= ' OR '.$value.' LIKE '.prepare('%'.$term.'%');
2023-11-30 12:57:03 +01:00
}
$query .= Modules::getAdditionalsQuery('Automezzi');
$rs = $dbo->fetchArray($query);
foreach ($rs as $r) {
$result = [];
$result['link'] = ROOTDIR.'/editor.php?id_module='.$link_id.'&id_record='.$r['id'];
$result['title'] = $r['nome'];
2024-05-14 17:16:30 +02:00
$result['category'] = tr('Automezzi');
2023-11-30 12:57:03 +01:00
// Campi da evidenziare
$result['labels'] = [];
foreach ($fields as $name => $value) {
2024-05-23 11:36:25 +02:00
if (str_contains((string) $r[$name], (string) $term)) {
2023-11-30 12:57:03 +01:00
$text = str_replace($term, "<span class='highlight'>".$term.'</span>', $r[$name]);
$result['labels'][] = $name.': '.$text.'<br/>';
}
}
$results[] = $result;
}