41 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Model;
class Context
{
public ?int $requestTime = null;
public ?Session $session = null;
public ?string $currentPage = null;
public ?array $navigation = null;
protected function initNavigation()
{
$this->navigation = [];
$this->navigation[] = new NavigationEntry('Startseite', '/');
if ($this->session === null) {
$this->navigation[] = new NavigationEntry('Registrieren', '/register.php');
$this->navigation[] = new NavigationEntry('Einloggen', '/login.php');
} else {
$this->navigation[] = new NavigationEntry('Umsatzübersicht', '/bookings.php');
if ($this->session->user->isAdmin) {
$this->navigation[] = new NavigationEntry('Einzahlen', '/deposit.php');
$this->navigation[] = new NavigationEntry('Auszahlen', '/withdraw.php');
}
$this->navigation[] = new NavigationEntry('Überweisen', '/transfer.php');
$this->navigation[] = new NavigationEntry('Ausloggen', '/logout.php');
}
}
public static function init(string $url): self
{
$context = new self();
$context->requestTime = time();
$context->currentPage = $url;
$context->session = Session::load();
$context->initNavigation();
return $context;
}
}