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);
$query = $builder->get();
$tplData['race']->n_laps = 0;
if ($query && $query->getNumRows() > 0)
{
$tplData['laps'] = json_encode($query->getResult());
$tplData['race']->n_laps = $query->getNumRows();
}
$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 view('race', $tplData);
echo get_footer(['chart.min.js']);

View File

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

View File

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