init(); return self::$eventPage; } private static $db = null; private static $message = ['error' => null, 'success' => null, 'notice' => null]; /** id of session user * * Session user describes the currently logged in user * * @var int>0 */ private static $userId = null; private static $sessionUser = null; /** get session users id * * if not set so far it is loaded from the session cookies * * @return int id of session user */ public static function getSessionUserId() { if (!isset(self::$userId)) { self::$userId = $_SESSION['user']['userId'] ?? null; } self::$userId = filterId(self::$userId); return self::$userId; } /** lazy loading of the session user */ public static function sessionUser(bool $forceLoading = true) { if (is_null(self::$sessionUser) || $forceLoading) { self::$sessionUser = User::loadFromDb(self::getSessionUserId()); } return self::$sessionUser; } /** Returns the current login status * * The login status is stored in the session cookie. If it is not even set it means the login is invalid. * * @return bool true if the login status is true, false otherwise */ public static function isLoginValid() { return (isset($_SESSION) && array_key_exists('login', $_SESSION) && $_SESSION['login'] == true); } /** Remove all login data from the session data * * @return void */ public static function logout() { foreach (['login', 'user'] as $key) { unset($_SESSION[$key]); } } /** A little Box with the login status as html entity * * @return string htmlEntity showing the login status */ public static function htmlLoginStatus() { return '
' . $this->description . '
' . '| userName | lastLogin |
|---|---|
| ' . $userName . ' | ' . $lastLogin . ' |