email = $email; } public function setUsername(?string $username): void { $this->username = $username; } public function setPassword(?string $hashedPassword): void { $this->password = $hashedPassword; } public function setPlainPassword(string $plainPassword): void { $this->password = password_hash($plainPassword, PASSWORD_BCRYPT); } public function setType(string $type): void { if (in_array($type, self::$types)) { $this->type = $type; } } public function setGoogleSub(?string $googleSub): void { $this->googleSub = $googleSub; } public function setCreatedDate(DateTime $created): void { $this->created = $created; } public function setCreated(string $created): void { $this->created = new DateTime($created); } public function setFullName(string $fullName): void { $this->fullName = $fullName; } public function setNickname(string $nickname): void { $this->nickname = $nickname; } public function setPhone(string $phone): void { $this->phone = $phone; } public function setIdNumber(string $idNumber): void { $this->idNumber = $idNumber; } public function getEmail(): string { return $this->email; } public function getUsername(): ?string { return $this->username; } public function getPassword(): ?string { return $this->password; } public function getType(): string { return $this->type; } public function getGoogleSub(): ?string { return $this->googleSub; } public function getCreatedDate(): DateTime { return $this->created; } public function getCreated(): string { return $this->created->format('Y-m-d H:i:s'); } public function getFullName(): string { return $this->fullName; } public function getNickname(): string { return $this->nickname; } public function getPhone(): string { return $this->phone; } public function getIdNumber(): string { return $this->idNumber; } public function hasPermission(int $permission): bool { switch ($permission) { case IUser::PERMISSION_NORMAL: return true; case IUser::PERMISSION_ADMIN: return $this->type === 'admin'; default: throw new \Exception('Permission does not exist: ' . $permission); } } public function getUniqueId() { return $this->id; } public function getDisplayName(): string { return $this->nickname ?: $this->fullName; } public function getFullDisplayName(): string { return $this->nickname ? $this->nickname . ' (' . $this->fullName . ')' : $this->fullName; } public function checkPassword(string $password): bool { if ($this->password === null) { return false; } return password_verify($password, $this->password); } }