Fix error if no laps

This commit is contained in:
Alfonso Saavedra "Son Link" 2022-11-27 09:20:37 +01:00
parent 4f4138e073
commit c3eff73ecc
No known key found for this signature in database
GPG Key ID: D3594BCF897F74D8
3 changed files with 19 additions and 7 deletions

View File

@ -30,14 +30,18 @@ class Races extends BaseController
$builder->where('race_id', $tplData['race']->id); $builder->where('race_id', $tplData['race']->id);
$query = $builder->get(); $query = $builder->get();
$tplData['race']->n_laps = 0;
if ($query && $query->getNumRows() > 0) if ($query && $query->getNumRows() > 0)
{ {
$tplData['laps'] = json_encode($query->getResult()); $tplData['laps'] = json_encode($query->getResult());
$tplData['user'] = new UsersModel($tplData['race']->user_id); $tplData['race']->n_laps = $query->getNumRows();
$tplData['car'] = new CarsModel(getCar($tplData['race']->car_id));
$tplData['track'] = new TracksModel(getTrack($tplData['race']->track_id));
} }
$tplData['user'] = new UsersModel($tplData['race']->user_id);
$tplData['car'] = new CarsModel(getCar($tplData['race']->car_id));
$tplData['track'] = new TracksModel(getTrack($tplData['race']->track_id));
} }
echo get_header('Races'); echo get_header('Races');
echo view('race', $tplData); echo view('race', $tplData);
echo get_footer(['chart.min.js']); echo get_footer(['chart.min.js']);

View File

@ -30,11 +30,18 @@
<?= $user->getLink() ?> <?= $user->getLink() ?>
</td> </td>
</tr> </tr>
<tr>
<th>Laps completed:</th>
<td>
<?= $race->n_laps ?>
</td>
</tr>
</table> </table>
<div> <div>
<canvas id="chart"></canvas> <canvas id="chart"></canvas>
</div> </div>
</div> </div>
<?php if (!empty($laps)): ?>
<script type="text/javascript"> <script type="text/javascript">
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
let lapsData = JSON.parse('<?= $laps ?>'); let lapsData = JSON.parse('<?= $laps ?>');
@ -129,3 +136,4 @@
}); });
</script> </script>
<?php endif ?>

View File

@ -582,11 +582,11 @@ sd-carcategoryselection {
} }
#open-menu { #open-menu {
background-image: url(/img/menu.svg); background-image: url('/img/menu.svg');
} }
#close-menu { #close-menu {
background-image: url(/img/backburger.svg); background-image: url('/img/backburger.svg');
} }
#menu { #menu {