Now the getBests method is passed the text indicating the period and not the elapsed time
This commit is contained in:
parent
dbef4fa4d4
commit
85dc41c868
2 changed files with 26 additions and 2 deletions
|
@ -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'] = [];
|
$tplData['tracks'] = [];
|
||||||
$builder = $this->db->table('races');
|
$builder = $this->db->table('races');
|
||||||
|
|
|
@ -7,11 +7,35 @@ class BestLapsModel extends BaseModel
|
||||||
protected $table = 'bests_laps bl';
|
protected $table = 'bests_laps bl';
|
||||||
protected $allowedFields = ['race_id', 'lap_id', 'track_id', 'car_cat', 'car_id', 'laptime', 'user_id', 'setup'];
|
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;
|
$from = $page * $limit;
|
||||||
$list = [];
|
$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 = $this->builder();
|
||||||
$builder->join('laps l', 'l.id = bl.lap_id');
|
$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');
|
$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');
|
||||||
|
|
Loading…
Reference in a new issue