diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 92f2078..e305ca1 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -127,7 +127,7 @@ class Home extends BaseController ################################ */ - $tplData['mylaps'] = $bestLapsModel->getBests($backto, $carCatId, 0, 0); + $tplData['mylaps'] = $bestLapsModel->getBests($period, $carCatId, 0, 0); $tplData['tracks'] = []; $builder = $this->db->table('races'); diff --git a/app/Models/BestLapsModel.php b/app/Models/BestLapsModel.php index a66db7d..21e4168 100644 --- a/app/Models/BestLapsModel.php +++ b/app/Models/BestLapsModel.php @@ -7,11 +7,35 @@ class BestLapsModel extends BaseModel protected $table = 'bests_laps bl'; protected $allowedFields = ['race_id', 'lap_id', 'track_id', 'car_cat', 'car_id', 'laptime', 'user_id', 'setup']; - public function getBests(int $backto, string $carCat, int $page=0, int $limit=20) + public function getBests(string $period, string $carCat, int $page=0, int $limit=20) { $from = $page * $limit; $list = []; + switch ($period) + { + case 'today': //today + $datediff = 1 * 24 * 60 * 60; + $backto = time() - $datediff; + break; + case 'week': //last week + $datediff = 7 * 24 * 60 * 60; + $backto = time() - $datediff; + break; + case 'month': //last month + $datediff = 30 * 24 * 60 * 60; + $backto = time() - $datediff; + break; + case 'year': //last year + $datediff = 365 * 24 * 60 * 60; + $backto = time() - $datediff; + break; + default://always + $datediff = 50000 * 24 * 60 * 60; + $backto = time() - $datediff; + break; + } + $builder = $this->builder(); $builder->join('laps l', 'l.id = bl.lap_id'); $builder->select('l.race_id, r.track_id, r.car_id, r.user_id, r.timestamp, l.wettness, bl.laptime AS bestlap, c.name AS car_name, t.name AS track_name, u.username');