2022-03-14 19:13:10 +01:00
< ? php
namespace App\Controllers ;
use App\Models\UsersModel ;
use App\Models\CarsModel ;
use App\Models\TracksModel ;
class Races extends BaseController
{
2024-04-07 22:40:57 +02:00
protected object $users ;
protected object $carsModel ;
protected object $tracksModel ;
2022-03-14 19:13:10 +01:00
public function __construct ()
{
$this -> users = new UsersModel ();
2024-04-07 22:40:57 +02:00
$this -> carsModel = new CarsModel ();
$this -> tracksModel = new TracksModel ();
2022-03-14 19:13:10 +01:00
}
public function index ( $race )
{
//$this->cachePage(360);
2024-04-07 22:40:57 +02:00
$builder = $this -> db -> table ( 'races r' );
$builder -> join ( 'cars c' , 'c.id = r.car_id' );
$builder -> join ( 'tracks t' , 't.id = r.track_id' );
$builder -> join ( 'users u' , 'u.id = r.user_id' );
$builder -> select ( 'r.id, r.type, r.timestamp, r.car_id, c.name AS car_name, c.img as car_img, r.track_id, t.name AS track_name, t.img AS track_img, u.username' );
$builder -> where ( 'r.id' , $race );
2022-03-14 19:13:10 +01:00
$query = $builder -> get ( 1 );
$tplData = [];
if ( $query && $query -> getNumRows () == 1 )
{
$tplData [ 'race' ] = $query -> getRow ();
$builder = $this -> db -> table ( 'laps' );
$builder -> where ( 'race_id' , $tplData [ 'race' ] -> id );
$query = $builder -> get ();
2022-11-27 09:20:37 +01:00
$tplData [ 'race' ] -> n_laps = 0 ;
2022-03-14 19:13:10 +01:00
if ( $query && $query -> getNumRows () > 0 )
{
$tplData [ 'laps' ] = json_encode ( $query -> getResult ());
2022-11-27 09:20:37 +01:00
$tplData [ 'race' ] -> n_laps = $query -> getNumRows ();
2022-03-14 19:13:10 +01:00
}
}
2022-11-27 09:20:37 +01:00
2022-03-14 19:13:10 +01:00
echo get_header ( 'Races' );
echo view ( 'race' , $tplData );
echo get_footer ([ 'chart.min.js' ]);
}
}