The {@see Tag tags} of the user */ #[ORM\OneToMany(mappedBy: 'user', targetEntity: Tag::class, orphanRemoval: true)] #[Assert\Valid] private Collection $tags; /** * @var User|null The administrator who had validated this user or Null if not validated yet */ #[ORM\ManyToOne(targetEntity: self::class)] #[Assert\Valid] private ?self $validationAdministrator = null; /** * @var DateTimeImmutable|null The date and time of the validation of this user or Null if not validated yet */ #[ORM\Column(nullable: true)] private ?DateTimeImmutable $validationDate = null; /** * Initialization */ public function __construct () { $this->tags = new ArrayCollection(); } /** * The email * * @return string|null The email */ public function getEmail (): ?string { return $this->email; } /** * Change the email * * @param string $email The new email * * @return $this */ public function setEmail (string $email): self { $this->email = $email; return $this; } /** * The hashed password * * @return string The hashed password * * @see PasswordAuthenticatedUserInterface */ public function getPassword (): string { return $this->password; } /** * Change the hashed password * * @param string $password The new hashed password * * @return $this */ public function setPassword (string $password): self { $this->password = $password; return $this; } /** * The name * * @return string|null The name */ public function getName (): ?string { return $this->name; } /** * Change the name * * @param string|null $name The new name * * @return $this */ public function setName (?string $name): self { $this->name = $name; return $this; } /** * A visual identifier that represents this user * * @see UserInterface */ public function getUserIdentifier (): string { return (string)$this->email; } /** * The roles * * @return string[] The roles * * @see UserInterface */ public function getRoles (): array { $roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; return array_unique($roles); } /** * Set the roles * * @param array $roles The new roles * * @return void */ public function setRoles (array $roles): void { $this->roles = $roles; } /** * Removes sensitive data from the user * * @see UserInterface */ public function eraseCredentials () { } /** * The {@see Tag tags} of the user * * @return Collection The {@see Tag tags} of the user */ public function getTags (): Collection { return $this->tags; } /** * Add a {@see Tag tag} to the user * * Do nothing if the {@see Tag tag} already exists * * @param Tag $tag The new {@see Tag tag} * * @return $this */ public function addTag (Tag $tag): static { if (!$this->tags->contains($tag)) { $this->tags->add($tag); $tag->setOwner($this); } return $this; } /** * Remove a {@see Tag tag} from the user * * Do nothing if the {@see Tag tag} don't exist * * @param Tag $tag The {@see Tag tag} to remove * * @return $this */ public function removeTag (Tag $tag): static { if ($this->tags->removeElement($tag)) { if ($tag->getOwner() === $this) { $tag->setOwner(null); } } return $this; } /** * The administrator who had validated this user or Null if not validated yet * * @return self|null The administrator who had validated this user or Null if not validated yet * * @see self::validate() */ public function getValidationAdministrator (): ?self { return $this->validationAdministrator; } /** * The date and time of the validation of this user or Null if not validated yet * * @return DateTimeImmutable|null The date and time of the validation of this user or Null if not validated yet * * @see self::validate() */ public function getValidationDate (): ?DateTimeImmutable { return $this->validationDate; } /** * Validate this user * * Set validation administrator and date-time * * @param User $administrator The administrator doing the validation * * @return $this */ public function validate (self $administrator): static { $this->validationAdministrator = $administrator; $this->validationDate = new DateTimeImmutable(); return $this; } }