src/Entity/Account.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\AccountBlock;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\Post;
  6. use Doctrine\DBAL\Types\Types;
  7. use Symfony\Component\Uid\Ulid;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Entity\CompletedDialogue;
  10. use ApiPlatform\Metadata\ApiResource;
  11. use App\Repository\AccountRepository;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Bridge\Doctrine\Types\UlidType;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  20. #[ORM\Entity(repositoryClassAccountRepository::class)]
  21. #[UniqueEntity('email')]
  22. class Account implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     private ?int $id null;
  28.     #[Assert\NotBlank]
  29.     #[Assert\Email]
  30.     #[ORM\Column(length180uniquetrue)]
  31.     private ?string $email null;
  32.     #[ORM\Column(type'json')]
  33.     private array $roles = [];
  34.     #[ORM\Column]
  35.     private ?\DateTimeImmutable $createdAt null;
  36.     #[ORM\Column]
  37.     private ?bool $active null;
  38.     #[ORM\Column(length255nullabletrue)]
  39.     private ?string $diocese null;
  40.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  41.     private ?\DateTimeInterface $nextDialogue null;
  42.     #[ORM\Column(typeUlidType::NAMEuniquetruenullabletrue)]
  43.     private ?Ulid $hash null;
  44.     #[ORM\Column(nullabletrue)]
  45.     private ?\DateTimeImmutable $hashedAt null;
  46.     #[ORM\OneToMany(mappedBy'account'targetEntityCompletedDialogue::class)]
  47.     private Collection $completedDialogues;
  48.     #[ORM\OneToMany(mappedBy'account'targetEntityAccountBlock::class)]
  49.     private Collection $accountBlocks;
  50.     /**
  51.      * @var string The hashed password
  52.      */
  53.     #[ORM\Column]
  54.     private ?string $password null;
  55.     private ?string $plainPassword null;
  56.     public function __construct()
  57.     {
  58.         $this->completedDialogues = new ArrayCollection();
  59.         $this->accountBlocks = new ArrayCollection();
  60.     }
  61.     public function getId(): ?int
  62.     {
  63.         return $this->id;
  64.     }
  65.     public function getEmail(): ?string
  66.     {
  67.         return $this->email;
  68.     }
  69.     public function setEmail(string $email): self
  70.     {
  71.         $this->email $email;
  72.         return $this;
  73.     }
  74.     /**
  75.      * A visual identifier that represents this user..
  76.      *
  77.      * @see UserInterface
  78.      */
  79.     public function getUserIdentifier(): string
  80.     {
  81.         return (string) $this->email;
  82.     }
  83.     /**
  84.      * @see UserInterface
  85.      */
  86.     public function getRoles(): array
  87.     {
  88.         $roles $this->roles;
  89.         // guarantee every user at least has ROLE_USER
  90.         $roles[] = 'ROLE_USER';
  91.         return array_unique($roles);
  92.     }
  93.     public function setRoles(array $roles): self
  94.     {
  95.         $this->roles $roles;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @see PasswordAuthenticatedUserInterface
  100.      */
  101.     public function getPassword(): string
  102.     {
  103.         return $this->password;
  104.     }
  105.     public function setPassword(string $password): self
  106.     {
  107.         $this->password $password;
  108.         return $this;
  109.     }
  110.     public function getPlainPassword(): ?string
  111.     {
  112.         return $this->plainPassword;
  113.     }
  114.     public function setPlainPassword(?string $plainPassword): self
  115.     {
  116.         $this->plainPassword $plainPassword;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @see UserInterface
  121.      */
  122.     public function eraseCredentials()
  123.     {
  124.         // If you store any temporary, sensitive data on the user, clear it here
  125.         // $this->plainPassword = null;
  126.     }
  127.     public function getCreatedAt(): ?\DateTimeImmutable
  128.     {
  129.         return $this->createdAt;
  130.     }
  131.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  132.     {
  133.         $this->createdAt $createdAt;
  134.         return $this;
  135.     }
  136.     public function isActive(): ?bool
  137.     {
  138.         return $this->active;
  139.     }
  140.     public function setActive(bool $active): self
  141.     {
  142.         $this->active $active;
  143.         return $this;
  144.     }
  145.     public function getDiocese(): ?string
  146.     {
  147.         return $this->diocese;
  148.     }
  149.     public function setDiocese(?string $diocese): self
  150.     {
  151.         $this->diocese $diocese;
  152.         return $this;
  153.     }
  154.     public function getNextDialogue(): ?\DateTimeInterface
  155.     {
  156.         return $this->nextDialogue;
  157.     }
  158.     public function setNextDialogue(?\DateTimeInterface $nextDialogue): self
  159.     {
  160.         $this->nextDialogue $nextDialogue;
  161.         return $this;
  162.     }
  163.     public function getHash(): ?Ulid
  164.     {
  165.         return $this->hash;
  166.     }
  167.     public function setHash(?Ulid $hash): self
  168.     {
  169.         $this->hash $hash;
  170.         return $this;
  171.     }
  172.     public function getHashedAt(): ?\DateTimeImmutable
  173.     {
  174.         return $this->hashedAt;
  175.     }
  176.     public function setHashedAt(?\DateTimeImmutable $hashedAt): static
  177.     {
  178.         $this->hashedAt $hashedAt;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return Collection<int, CompletedDialogue>
  183.      */
  184.     public function getCompletedDialogues(): Collection
  185.     {
  186.         return $this->completedDialogues;
  187.     }
  188.     public function addCompletedDialogue(CompletedDialogue $completedDialogue): self
  189.     {
  190.         if (!$this->completedDialogues->contains($completedDialogue)) {
  191.             $this->completedDialogues->add($completedDialogue);
  192.             $completedDialogue->setAccount($this);
  193.         }
  194.         return $this;
  195.     }
  196.     public function removeCompletedDialogue(CompletedDialogue $completedDialogue): self
  197.     {
  198.         if ($this->completedDialogues->removeElement($completedDialogue)) {
  199.             // set the owning side to null (unless already changed)
  200.             if ($completedDialogue->getAccount() === $this) {
  201.                 $completedDialogue->setAccount(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection<int, AccountBlock>
  208.      */
  209.     public function getAccountBlocks(): Collection
  210.     {
  211.         return $this->accountBlocks;
  212.     }
  213.     public function addAccountBlock(AccountBlock $accountBlock): self
  214.     {
  215.         if (!$this->accountBlocks->contains($accountBlock)) {
  216.             $this->accountBlocks->add($accountBlock);
  217.             $accountBlock->setAccount($this);
  218.         }
  219.         return $this;
  220.     }
  221.     public function removeAccountBlock(AccountBlock $accountBlock): self
  222.     {
  223.         if ($this->accountBlocks->removeElement($accountBlock)) {
  224.             // set the owning side to null (unless already changed)
  225.             if ($accountBlock->getAccount() === $this) {
  226.                 $accountBlock->setAccount(null);
  227.             }
  228.         }
  229.         return $this;
  230.     }
  231. }