The user roles. Admin only property. */ #[ORM\Column] private array $roles = []; #[ORM\OneToOne(inversedBy: 'user', cascade: ['persist'])] private ?Accounting $accounting = null; /** * The projects owned by this User. */ #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Project::class, cascade: ['persist'])] private Collection $projects; /** * The UserTokens owned by this User. Owner only property. */ #[ORM\OneToMany(mappedBy: 'owner', targetEntity: UserToken::class, orphanRemoval: true)] private Collection $tokens; /** * A flag determined by the platform for Users who are known to be active. */ #[ORM\Column] private ?bool $active = null; /** * Path to the Users's avatar image. */ #[ORM\Column(length: 255, nullable: true)] private ?string $avatar = null; /** * Conventional name of the person owning this User. */ #[ORM\Column(length: 255, nullable: true)] private ?string $name = null; #[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])] private ?UserPersonal $personalData = null; /** * @var string The user password */ #[ORM\Column] private ?string $password = null; public function __construct() { $this->accounting = Accounting::of($this); $this->emailConfirmed = false; $this->active = false; $this->tokens = new ArrayCollection(); $this->projects = new ArrayCollection(); } public function getId(): ?int { return $this->id; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUserIdentifier(): string { return (string) $this->username; } public function getEmail(): ?string { return $this->email; } public function setEmail(string $email): static { $this->email = $email; return $this; } public function isEmailConfirmed(): ?bool { return $this->emailConfirmed; } public function setEmailConfirmed(bool $emailConfirmed): static { $this->emailConfirmed = $emailConfirmed; return $this; } public function getUsername(): ?string { return $this->username; } public function setUsername(?string $username): static { $this->username = strtolower($username); return $this; } /** * @see UserInterface * * @return list */ public function getRoles(): array { $roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; return array_unique($roles); } /** * @param list $roles */ public function setRoles(array $roles): static { $this->roles = $roles; return $this; } public function hasRoles(array $roles): bool { return count(array_intersect($this->getRoles(), $roles)) > 0; } public function getAccounting(): ?Accounting { return $this->accounting; } public function setAccounting(?Accounting $accounting): static { $this->accounting = $accounting; return $this; } /** * @return Collection */ public function getProjects(): Collection { return $this->projects; } public function addProject(Project $project): static { if (!$this->projects->contains($project)) { $this->projects->add($project); $project->setOwner($this); } return $this; } public function removeProject(Project $project): static { if ($this->projects->removeElement($project)) { // set the owning side to null (unless already changed) if ($project->getOwner() === $this) { $project->setOwner(null); } } return $this; } /** * @return Collection */ public function getTokens(): Collection { return $this->tokens; } public function addToken(UserToken $token): static { if (!$this->tokens->contains($token)) { $this->tokens->add($token); $token->setOwner($this); } return $this; } public function removeToken(UserToken $token): static { if ($this->tokens->removeElement($token)) { // set the owning side to null (unless already changed) if ($token->getOwner() === $this) { $token->setOwner(null); } } return $this; } public function isActive(): ?bool { return $this->active; } public function setActive(bool $active): static { $this->active = $active; return $this; } public function getAvatar(): ?string { return $this->avatar; } public function setAvatar(?string $avatar): static { $this->avatar = $avatar; return $this; } public function getName(): ?string { return $this->name; } public function setName(?string $name): static { $this->name = $name; return $this; } public function getPersonalData(): ?UserPersonal { return $this->personalData; } public function setPersonalData(UserPersonal $personalData): static { // set the owning side of the relation if necessary if ($personalData->getUser() !== $this) { $personalData->setUser($this); } $this->personalData = $personalData; return $this; } /** * @see PasswordAuthenticatedUserInterface */ public function getPassword(): string { return $this->password; } public function setPassword(string $password): static { $this->password = $password; return $this; } public function eraseCredentials(): void { // If you store any temporary, sensitive data on the user, clear it here } }