sdwebserver/app/Controllers/Users.php

66 lines
2.0 KiB
PHP
Raw Normal View History

2022-03-14 19:13:10 +01:00
<?php
namespace App\Controllers;
use App\Models\UsersModel;
class Users extends BaseController
{
protected object $usersModel;
2022-03-14 19:13:10 +01:00
public function __construct()
{
$this->usersModel = new UsersModel();
2022-03-14 19:13:10 +01:00
}
public function index()
{
$users = $this->usersModel->findAll();
2022-03-14 19:13:10 +01:00
$tplData = [];
$tplData['users'] = $users;
echo get_header('Users');
echo view('users', $tplData);
echo get_footer();
}
public function user($username)
{
//$this->cachePage(3600);
$user = $this->usersModel->getUser($username);
$userraces = $this->usersModel->getRaces();
$raceswon = $this->usersModel->getWon();
$racespodiums = $this->usersModel->getPodiums();
$racesretired = $this->usersModel->getUnfinisced();
$practices = $this->usersModel->getPractices();
$qualifies = $this->usersModel->getQualifies();
2022-03-14 19:13:10 +01:00
$tplData = [
'raceSessions' => $this->usersModel->getRaceSessions(),
2022-03-14 19:13:10 +01:00
'userRaces' => $userraces,
'racesWon' => $raceswon,
'raceswonpercent' => percentStr($raceswon, count($userraces)),
'racespodiums' => $racespodiums,
'racespodiumpercent' => percentStr($racespodiums->totalPodiums, count($userraces)),
'practicescount' => $practices,
'qualifiescount' => $qualifies,
'racesretired' => $racesretired,
'racesretiredpercent' => percentStr($racesretired, count($userraces)),
'mostusedcar' => $this->usersModel->getMostUsedCar(),
'mostusedtrack' => $this->usersModel->getMostUsedTrack(),
'timeontrackPractice' => $this->usersModel->getTimePractice(),
'timeontrackQualify' => $this->usersModel->getTimeQualify(),
'timeontrackRace' => $this->usersModel->getTimeOnRace(),
'timeontrack' => $this->usersModel->getTimeOnTracks(),
2022-03-14 19:13:10 +01:00
'user' => $user
];
log_message('debug', json_encode($tplData['raceSessions']));
2022-03-14 19:13:10 +01:00
echo get_header("User: $username");
echo view('user', $tplData);
echo get_footer();
}
public function login()
{
echo get_header("Log In");
echo view('login');
echo get_footer(['dashboard.js']);
}
2022-03-14 19:13:10 +01:00
}