groups = []; } public function postFetch(SQL $sql, array $row) { parent::postFetch($sql, $row); $this->groups = []; $groups = Group::findAllBuilder($sql) ->addJoin(new Join("INNER", "UserGroup", "UserGroup.group_id", "Group.id")) ->where(new Compare("UserGroup.user_id", $this->id)) ->execute(); if ($groups) { $this->groups = $groups; } } public function getUsername(): string { return $this->name; } public function getFullName(): string { return $this->fullName; } public function getEmail(): ?string { return $this->email; } public function getGroups(): array { return $this->groups; } public function hasGroup(int $group): bool { return isset($this->groups[$group]); } public function getGPG(): ?GpgKey { return $this->gpgKey; } public function getTwoFactorToken(): ?TwoFactorToken { return $this->twoFactorToken; } public function getProfilePicture(): ?string { return $this->profilePicture; } public function __debugInfo(): array { return [ 'id' => $this->getId(), 'username' => $this->name, 'language' => $this->language->getName(), ]; } public function jsonSerialize(): array { return [ 'id' => $this->getId(), 'name' => $this->name, 'fullName' => $this->fullName, 'profilePicture' => $this->profilePicture, 'email' => $this->email, 'groups' => $this->groups ?? null, 'language' => (isset($this->language) ? $this->language->jsonSerialize() : null), 'session' => (isset($this->session) ? $this->session->jsonSerialize() : null), "gpg" => (isset($this->gpgKey) ? $this->gpgKey->jsonSerialize() : null), "2fa" => (isset($this->twoFactorToken) ? $this->twoFactorToken->jsonSerialize() : null), "reqisteredAt" => $this->registeredAt->getTimestamp(), "lastOnline" => $this->lastOnline->getTimestamp(), "confirmed" => $this->confirmed ]; } public function update(SQL $sql): bool { $this->lastOnline = new \DateTime(); return $this->save($sql, ["last_online", "language_id"]); } }