users = array(); $this->pageCount = 0; $this->page = 1; } public function loadView() { parent::loadView(); $this->title = L("User Control"); $this->requestUsers(); } private function requestUsers() { if(isset($_GET["page"]) && is_numeric($_GET["page"])) { $this->page = intval($_GET["page"]); } else { $this->page = 1; } $req = new \Api\User\Fetch($this->getDocument()->getUser()); if (!$req->execute(array("page" => $this->page))) { $this->errorMessages[] = $req->getLastError(); } else { $result = $req->getResult(); $this->users = $result["users"]; $this->pageCount = $result["pages"]; } } private function getGroups($groups) { $badges = []; foreach($groups as $groupId => $group) { $badgeClass = "secondary"; if ($groupId === USER_GROUP_ADMIN) { $badgeClass = "danger"; } $badges[] = $this->createBadge($badgeClass, $group); } return implode(" ", $badges); } private function getPagination() { $userPageNavigation = L("User page navigation"); $previousDisabled = ($this->page == 1 ? " disabled" : ""); $nextDisabled = ($this->page >= $this->pageCount ? " disabled" : ""); $html = ""; return $html; } private function getUserRows() { $dateFormat = L("Y/m/d"); $userRows = array(); foreach($this->users as $uid => $user) { $name = $user["name"]; $email = $user["email"] ?? ""; $registeredAt = (new DateTime($user["created_at"]))->format($dateFormat); $groups = $this->getGroups($user["groups"]); $userRows[] = " $name $email $groups $registeredAt "; } return implode("", $userRows); } public function getCode() { $html = parent::getCode(); // Icons $iconRefresh = $this->createIcon("sync"); // Locale $users = L("Users"); $name = L("Name"); $email = L("Email"); $groups = L("Groups"); $registeredAt = L("Registered At"); // Content $pagination = $this->getPagination(); $userRows = $this->getUserRows(); $html .= "
$userRows
$name $email $groups $registeredAt
$pagination
"; return $html; } }