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' => isset($this->language) ? $this->language->getName() : null, ]; } public function update(SQL $sql): bool { $this->lastOnline = new \DateTime(); return $this->save($sql, ["lastOnline", "language"]); } public function setTwoFactorToken(TwoFactorToken $twoFactorToken) { $this->twoFactorToken = $twoFactorToken; } public function canAccess(\ReflectionClass|DatabaseEntity|string $entityOrClass, string $propertyName): bool { try { $reflectionClass = ($entityOrClass instanceof \ReflectionClass ? $entityOrClass : new \ReflectionClass($entityOrClass)); $property = $reflectionClass->getProperty($propertyName); $visibility = DatabaseEntityHandler::getAttribute($property, Visibility::class); if ($visibility === null) { return true; } $visibilityType = $visibility->getType(); if ($visibilityType === Visibility::NONE) { return false; } else if ($visibilityType === Visibility::BY_GROUP) { // allow access to own entity if ($entityOrClass instanceof User && $entityOrClass->getId() === $this->id) { return true; } // missing required group if (empty(array_intersect(array_keys($this->groups), $visibility->getGroups()))) { return false; } } return true; } catch (\Exception $exception) { return false; } } public function getDisplayName(): string { return !empty($this->fullName) ? $this->fullName : $this->name; } public static function buildSQLDisplayName(SQL $sql, string $joinColumn, string $alias = "user"): Alias { return new Alias( $sql->select(new Coalesce( new NullIf(new Column("User.full_name"), ""), new NullIf(new Column("User.name"), "")) )->from("User")->whereEq("User.id", new Column($joinColumn)), $alias); } }