graph it
All checks were successful
Build and push / Pulling repo on server (push) Successful in 5s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 5s
This commit is contained in:
@ -16,27 +16,44 @@ class Smart extends Page {
|
||||
|
||||
function search()
|
||||
{
|
||||
$db = new SQLite3(ROOT.DS.'../crawler/data.db');
|
||||
$db = new SQLite3(ROOT.DS.'../crawler/data.db', SQLITE3_OPEN_READONLY);
|
||||
$q = $_REQUEST['q'];
|
||||
$query = "SELECT * FROM results WHERE teilnehmer LIKE '$q'";
|
||||
if(!$q || strlen($q) < 3 || strpos($q, ' ') === false)
|
||||
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Error: Bitte Nachname und Vorname eingeben.']);
|
||||
$query = "SELECT DISTINCT(hund) FROM results WHERE teilnehmer LIKE '$q'";
|
||||
$res = $db->query($query);
|
||||
$results = [];
|
||||
$dogs = [];
|
||||
|
||||
while($row = $res->fetchArray())
|
||||
{
|
||||
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']);
|
||||
$row['event'] = $db->querySingle("SELECT name FROM events WHERE id = ".$row['event']);
|
||||
$row['unixtimestamp'] = strtotime($row['date']);
|
||||
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
|
||||
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
|
||||
$results[] = $row;
|
||||
$dogs[] = $row['hund'];
|
||||
}
|
||||
|
||||
//sort results by date
|
||||
usort($results, function($a, $b) {
|
||||
return $b['unixtimestamp'] <=> $a['unixtimestamp'];
|
||||
});
|
||||
if(count($dogs) == 0)
|
||||
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Error: Keine Ergebnisse gefunden. Bitte Nachname und Vorname prüfen.']);
|
||||
|
||||
$this->set('results', $results);
|
||||
foreach($dogs as $dog)
|
||||
{
|
||||
$res = $db->query("SELECT * FROM results WHERE teilnehmer LIKE '$q' AND hund LIKE '$dog'");
|
||||
while($row = $res->fetchArray())
|
||||
{
|
||||
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']);
|
||||
$row['event'] = $db->querySingle("SELECT name FROM events WHERE id = ".$row['event']);
|
||||
$row['unixtimestamp'] = strtotime($row['date']);
|
||||
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
|
||||
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
|
||||
$results[$dog][] = $row;
|
||||
}
|
||||
|
||||
//sort results by date
|
||||
usort($results[$dog], function($a, $b) {
|
||||
return $a['unixtimestamp'] <=> $b['unixtimestamp'];
|
||||
});
|
||||
}
|
||||
|
||||
$this->set('results_dogs', $results);
|
||||
$this->set('dogs', $dogs);
|
||||
$this->set('query', $query);
|
||||
$this->set('template', 'search.html.php');
|
||||
|
||||
|
Reference in New Issue
Block a user