src/Entity/Administrator.php line 15
<?phpnamespace App\Entity;use ApiPlatform\Metadata\ApiResource;use App\Repository\AdministratorRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;#[ORM\Entity(repositoryClass: AdministratorRepository::class)]#[ApiResource]class Administrator implements UserInterface, PasswordAuthenticatedUserInterface{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 180, unique: true)]private ?string $username = null;#[ORM\Column]private array $roles = [];#[ORM\Embedded(class: UserInformation::class)]private UserInformation $userInformation;/*** @var string The hashed password*/#[ORM\Column]private ?string $password = null;#[ORM\ManyToMany(targetEntity: AdministratorGroup::class, mappedBy: 'administrators')]private Collection $administratorGroups;public function __construct(){$this->userInformation = new UserInformation();$this->getUserInformation()->setCreatedAt(new \DateTimeImmutable());$this->getUserInformation()->setBirthday(new \DateTime());$this->administratorGroups = new ArrayCollection();}public function __toString(): string{return $this->getUserInformation()->getFirstName().' '.$this->getUserInformation()->getLastName();}public function getId(): ?int{return $this->id;}public function getUsername(): ?string{return $this->username;}public function setUsername(string $username): self{$this->username = $username;return $this;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUserIdentifier(): string{return (string)$this->username;}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';return array_unique($roles);}public function setRoles(array $roles): self{$this->roles = $roles;return $this;}/*** @see PasswordAuthenticatedUserInterface*/public function getPassword(): string{return $this->password;}public function setPassword(string $password): self{$this->password = $password;return $this;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here// $this->plainPassword = null;}public function getUserInformation(): UserInformation{return $this->userInformation;}public function setUserInformation(UserInformation $userInformation): self{$this->userInformation = $userInformation;return $this;}/*** @return Collection<int, AdministratorGroup>*/public function getAdministratorGroups(): Collection{return $this->administratorGroups;}public function addAdministratorGroup(AdministratorGroup $administratorGroup): self{if (!$this->administratorGroups->contains($administratorGroup)) {$this->administratorGroups->add($administratorGroup);$administratorGroup->addAdministrator($this);}return $this;}public function removeAdministratorGroup(AdministratorGroup $administratorGroup): self{if ($this->administratorGroups->removeElement($administratorGroup)) {$administratorGroup->removeAdministrator($this);}return $this;}}