You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
<?php
|
|
|
|
namespace IQBall\App\Controller;
|
|
|
|
use IQBall\App\Session\MutableSessionHandle;
|
|
use IQBall\App\Session\SessionHandle;
|
|
use IQBall\App\ViewHttpResponse;
|
|
use IQBall\Core\Http\HttpResponse;
|
|
use IQBall\Core\Model\TacticModel;
|
|
use IQBall\Core\Model\TeamModel;
|
|
|
|
class UserController {
|
|
private TacticModel $tactics;
|
|
private ?TeamModel $teams;
|
|
|
|
|
|
/**
|
|
* @param TacticModel $tactics
|
|
*/
|
|
public function __construct(TacticModel $tactics, ?TeamModel $teams = null) {
|
|
$this->tactics = $tactics;
|
|
$this->teams = $teams;
|
|
}
|
|
|
|
/**
|
|
* @param SessionHandle $session
|
|
* @return ViewHttpResponse the home page view
|
|
*/
|
|
public function home(SessionHandle $session): ViewHttpResponse {
|
|
$limitNbTactics = 5;
|
|
$lastTactics = $this->tactics->getLast($limitNbTactics, $session->getAccount()->getId());
|
|
$allTactics = $this->tactics->getAll($session->getAccount()->getId());
|
|
$name = $session->getAccount()->getName();
|
|
|
|
if ($this->teams != null) {
|
|
$teams = $this->teams->getAll($session->getAccount()->getId());
|
|
} else {
|
|
$teams = [];
|
|
}
|
|
|
|
return ViewHttpResponse::react("views/Home.tsx", [
|
|
"lastTactics" => $lastTactics,
|
|
"allTactics" => $allTactics,
|
|
"teams" => $teams,
|
|
"username" => $name,
|
|
]);
|
|
}
|
|
|
|
public function homeTwig(SessionHandle $session): ViewHttpResponse {
|
|
return ViewHttpResponse::twig("home.twig", []);
|
|
}
|
|
|
|
/**
|
|
* @return ViewHttpResponse account settings page
|
|
*/
|
|
public function settings(SessionHandle $session): ViewHttpResponse {
|
|
return ViewHttpResponse::react("views/Settings.tsx", []);
|
|
}
|
|
|
|
public function disconnect(MutableSessionHandle $session): HttpResponse {
|
|
$session->destroy();
|
|
return HttpResponse::redirect("/");
|
|
}
|
|
|
|
}
|