Added new tables with the lists of the most used tracks and cars in the category

This commit is contained in:
Alfonso Saavedra "Son Link" 2024-12-31 11:51:25 +01:00
parent 053259f186
commit f1bd63c7ea
No known key found for this signature in database
GPG key ID: D3594BCF897F74D8
3 changed files with 62 additions and 49 deletions

View file

@ -130,7 +130,7 @@ class Home extends BaseController
################################
*/
//list($tplData['mylaps'], $_) = $bestLapsModel->getBests($period, $carCatId, 0, 0);
/*
$tplData['tracks'] = [];
$builder = $this->db->table('races');
$builder->select('track_id, COUNT(*) AS count');
@ -160,8 +160,9 @@ class Home extends BaseController
$tplData['tracks'] = $tracks;
$tplData['tracksNames'] = $tracksNames;
}
}*/
/*
$tplData['cars'] = [];
$builder = $this->db->table('races r');
@ -174,7 +175,7 @@ class Home extends BaseController
$query = $builder->get();
if ($query && $query->getNumRows() > 0) $tplData['cars'] = $query->getResult();
*/
echo get_header('Home', ['minidt.css']);
echo view('main', $tplData);
echo get_footer(['minidt.js', 'home_tables.js']);

View file

@ -1,10 +1,8 @@
<?php
$menu = '<nav>';
$menuSelect = '<select id="menu-select">';
/*################################
## generate the car category selection menu
################################
*/
// generate the car category selection menu
foreach ($carCategoriesList as $cat)
{
$class = '';
@ -16,19 +14,19 @@
//if no category has been chosen by the user, used the first valid (non empty) one
if ($carCatId == '') $carCatId = $cat->id;
//set a splecial class for the menu item that represent the currently selected class
//set a special class for the menu item that represent the currently selected class
if ($carCatId == $cat->id )
{
$class = 'class="selected"';
$selected = 'selected';
}
//echo "\n<a href='?cat=".$id."' $class>".$category->name."</a>";
$url = rewriteUrl('cat', $cat->id);
$menu .= "<a href=\"$url\" $class>{$cat->name}</a>";
$menuSelect .= "<option value=\"$url\" $selected>{$cat->name}</option>";
}
}
$menu .= '</nav>';
$menuSelect .= '</select>';
?>
@ -73,50 +71,18 @@
Most used Tracks<br />
<small><?php echo $periodString; ?></small>
</h3>
<table class="fullPage responsive cat-table">
<thead>
<tr>
<th>Track</th>
<th>Races</th>
</tr>
</thead>
<tbody>
<?php foreach ($tracks as $race): ?>
<tr>
<td data-title="Track">
<?= clickableName($race->track_id, 'track', $tracksNames[$race->track_id]) ?>
</td>
<td data-title="Races">
<?= $race->count ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<div class="table-container">
<table id="most_used_tracks" class="fullPage responsive cat-table"></table>
</div>
<h3>
Top cars<br />
<small><?php echo $periodString; ?></small>
</h3>
<table class="fullPage responsive cat-table">
<thead>
<tr>
<th>Car</th>
<th>Races</th>
</tr>
</thead>
<tbody>
<?php foreach ($cars as $car): ?>
<tr>
<td data-title="Car">
<?= clickableName($car->car_id, 'car', $car->name) ?>
</td>
<td data-title="Races">
<?= $car->count ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<div class="table-container">
<table id="most_used_cars" class="fullPage responsive cat-table"></table>
</div>
</div>
<script>
period = '<?= $period ?>';

View file

@ -80,4 +80,50 @@ const dt_bests_laps = new MiniDT({
period: period,
car_cat: car_cat
}
})
const dt_most_used_tracks = new MiniDT({
target: 'most_used_tracks',
url: `${base_url}/api/most_used_tracks`,
cols: [
{
title: 'Track',
col: 'track_id',
render: (row) => {
return linkTag(row.track_id, 'track', row.track_name)
}
},
{
title: 'Races',
col: 'count',
align: 'right'
},
],
params: {
period: period,
car_cat: car_cat
}
})
const dt_most_used_cars = new MiniDT({
target: 'most_used_cars',
url: `${base_url}/api/most_used_cars`,
cols: [
{
title: 'Car',
col: 'car_id',
render: (row) => {
return linkTag(row.car_id, 'track', row.name)
}
},
{
title: 'Races',
col: 'count',
align: 'right'
},
],
params: {
period: period,
car_cat: car_cat
}
})