errorMessages = array(); $this->notifications = array(); } private function getNotifications() : array { $req = new \Api\Notifications\Fetch($this->getDocument()->getUser()); if(!$req->execute()) { $this->errorMessages[] = $req->getLastError(); return array(); } else { return $req->getResult()['notifications']; } } private function getUsers() : array { $req = new \Api\User\Fetch($this->getDocument()->getUser()); if(!$req->execute()) { $this->errorMessages[] = $req->getLastError(); return array(); } else { return $req->getResult()['users']; } } private function getHeader() { // Locale $home = L("Home"); $search = L("Search"); // Icons $iconMenu = $this->createIcon("bars"); $iconNotification = $this->createIcon("bell", "far"); $iconSearch = $this->createIcon("search"); $iconMail = $this->createIcon("envelope", "fas"); // Notifications $numNotifications = count($this->notifications); if ($numNotifications === 0) { $notificationText = L("No new notifications"); } else if($numNotifications === 1) { $notificationText = L("1 new notification"); } else { $notificationText = sprintf(L("%d new notification"), $numNotifications); } $html = ""; return $html; } private function getSidebar() { $menuEntries = array( "dashboard" => array( "name" => "Dashboard", "icon" => "tachometer-alt" ), "users" => array( "name" => "Users", "icon" => "users" ), "settings" => array( "name" => "Settings", "icon" => "tools" ), "help" => array( "name" => "Help", "icon" => "question-circle" ), ); $notificationCount = count($this->notifications); if ($notificationCount > 0) { $menuEntries["dashboard"]["badge"] = array("type" => "warning", "value" => $notificationCount); } $currentView = $_GET["view"] ?? "dashboard"; $html = ""; return $html; } private function getView() { $views = array( "dashboard" => Dashboard::class, "users" => UserOverview::class, "404" => View404::class, ); $currentView = $_GET["view"] ?? "dashboard"; if (!isset($views[$currentView])) { $currentView = "404"; } $view = new $views[$currentView]($this->getDocument()); assert($view instanceof View); $code = $view->getCode(); if ($view instanceof AdminView) { $this->errorMessages = array_merge($this->errorMessages, $view->getErrorMessages()); } return $code; } public function loadView() { parent::loadView(); $head = $this->getDocument()->getHead(); $head->addJS(Script::BOOTSTRAP); $head->loadAdminlte(); $this->notifications = $this->getNotifications(); } private function getContent() { $this->getUsers(); $view = $this->getView(); $html = "