nice
All checks were successful
Build and push / Pulling repo on server (push) Successful in 2s

This commit is contained in:
Chris 2023-11-26 11:01:19 +01:00
parent 95837394a9
commit 26ec6de1e3
3 changed files with 36 additions and 3 deletions

View File

@ -322,4 +322,34 @@ function template($templatefile,$variables=[])
ob_end_clean(); ob_end_clean();
return $pagecontent; return $pagecontent;
} }
function printRelativeTime($timestamp1, $timestamp2)
{
$diff = abs($timestamp2 - $timestamp1);
$intervals = array(
'year' => 31536000,
'month' => 2592000,
'week' => 604800,
'day' => 86400,
'hour' => 3600,
'minute' => 60,
'second' => 1
);
$output = '';
foreach ($intervals as $interval => $seconds) {
$count = floor($diff / $seconds);
if ($count > 0) {
$output .= $count . ' ' . ($count === 1 ? $interval : $interval . 's') . ', ';
$diff -= $count * $seconds;
}
}
$output = rtrim($output, ', ');
return $output;
}

View File

@ -23,16 +23,17 @@ class Smart extends Page {
$results = []; $results = [];
while($row = $res->fetchArray()) while($row = $res->fetchArray())
{ {
$row['event'] = $db->querySingle("SELECT name FROM events WHERE id = ".$row['event']);
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']); $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['unixtimestamp'] = strtotime($row['date']);
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']); $row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
$results[] = $row; $results[] = $row;
} }
//sort results by date //sort results by date
usort($results, function($a, $b) { usort($results, function($a, $b) {
return $a['unixtimestamp'] <=> $b['unixtimestamp']; return $b['unixtimestamp'] <=> $a['unixtimestamp'];
}); });
$this->set('results', $results); $this->set('results', $results);

View File

@ -4,6 +4,7 @@
<tr> <tr>
<th>event</th> <th>event</th>
<th>Wann wars</th>
<th>run</th> <th>run</th>
<th>rang</th> <th>rang</th>
<th>stnr</th> <th>stnr</th>
@ -22,6 +23,7 @@
<?php foreach($results as $res): ?> <?php foreach($results as $res): ?>
<tr> <tr>
<td><?= $res['event'] ?></td> <td><?= $res['event'] ?></td>
<td><?= $res['ago'] ?></td>
<td><?= $res['run'] ?></td> <td><?= $res['run'] ?></td>
<td><?= $res['rang'] ?></td> <td><?= $res['rang'] ?></td>
<td><?= $res['stnr'] ?></td> <td><?= $res['stnr'] ?></td>