src/Entity/Client.php line 44

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\Patch;
  6. use ApiPlatform\Metadata\Post;
  7. use App\Controller\Legacy\UserInfoController;
  8. //use App\Dto\UserResetOutputPasswordDto;
  9. use App\Entity\Traits\CreatedAtTrait;
  10. use App\Entity\Traits\UpdatedAtTrait;
  11. use App\Repository\ClientRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. //use App\State\UserPatchStateProcessor;
  16. //use App\State\UserPostStateProcessor;
  17. //use App\State\UserResetPasswordProcessor;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  20. use Symfony\Component\Security\Core\User\UserInterface;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. use Symfony\Component\Validator\Constraints\Email;
  23. use Symfony\Component\Validator\Constraints\Length;
  24. use Symfony\Component\Validator\Constraints\NotBlank;
  25. #[ORM\HasLifecycleCallbacks]
  26. #[ORM\Entity(repositoryClassClientRepository::class)]
  27. #[ApiResource(operations: [
  28.     new Get(
  29.         uriTemplate'/user/profile',
  30.         controllerUserInfoController::class,
  31.         normalizationContext: ['groups' => ['client:profile']],
  32.         security"is_granted('ROLE_CLIENT')",
  33.         readfalse
  34.     ),
  35.     new Get()
  36. ],
  37.     paginationEnabledfalse
  38. )]
  39. class Client implements UserInterfacePasswordAuthenticatedUserInterface
  40. {
  41.     use CreatedAtTrait;
  42.     use UpdatedAtTrait;
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue]
  45.     #[ORM\Column]
  46.     #[Groups(['client:profile'])]
  47.     private ?int $id null;
  48.     #[ORM\Column(length180uniquetrue)]
  49.     #[Groups(['client:profile'])]
  50.     #[NotBlank]
  51.     #[Email]
  52.     private ?string $email null;
  53.     #[ORM\Column(length255)]
  54.     private ?string $address null;
  55.     #[ORM\Column]
  56.     #[Groups(['client:profile'])]
  57.     private array $roles = [];
  58.     /**
  59.      * @var string|null The hashed password
  60.      */
  61.     #[ORM\Column]
  62.     private ?string $password null;
  63.     private ?string $plainPassword null;
  64.     #[ORM\ManyToMany(targetEntityTerminal::class, mappedBy'clients')]
  65.     private Collection $terminals;
  66.     #[ORM\OneToMany(mappedBy'client'targetEntityFeedback::class, orphanRemovaltrue)]
  67.     private Collection $feedbacks;
  68.     #[ORM\Column(length255)]
  69.     #[Groups(['client:profile'])]
  70.     #[NotBlank]
  71.     #[Length(min1max255)]
  72.     private ?string $company null;
  73.     #[ORM\Column(length30nullabletrue)]
  74.     #[Groups(['client:profile'])]
  75.     #[Length(min0max30)]
  76.     private ?string $taxId null;
  77.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  78.     private ?string $comment null;
  79.     #[ORM\OneToMany(mappedBy'client'targetEntityProjects::class, cascade: ['all'])]
  80.     #[Groups(['client:profile'])]
  81.     private Collection $projects;
  82.     #[ORM\OneToMany(mappedBy'client'targetEntityMedia::class)]
  83.     #[Groups(['client:profile'])]
  84.     private Collection $medias;
  85.     public function __toString(): string
  86.     {
  87.         return $this->email;
  88.     }
  89.     public function __construct()
  90.     {
  91.         $this->terminals = new ArrayCollection();
  92.         $this->feedbacks = new ArrayCollection();
  93.         $this->projects = new ArrayCollection();
  94.         $this->medias = new ArrayCollection();
  95.     }
  96.     public function getId(): ?int
  97.     {
  98.         return $this->id;
  99.     }
  100.     public function getAddress(): ?string
  101.     {
  102.         return $this->address;
  103.     }
  104.     public function setAddress(?string $address): static
  105.     {
  106.         $this->address $address;
  107.         return $this;
  108.     }
  109.     public function getEmail(): ?string
  110.     {
  111.         return $this->email;
  112.     }
  113.     public function setEmail(string $email): self
  114.     {
  115.         $this->email $email;
  116.         return $this;
  117.     }
  118.     /**
  119.      * A visual identifier that represents this user.
  120.      *
  121.      * @see UserInterface
  122.      */
  123.     public function getUserIdentifier(): string
  124.     {
  125.         return (string)$this->email;
  126.     }
  127.     /**
  128.      * @see UserInterface
  129.      */
  130.     public function getRoles(): array
  131.     {
  132.         $roles $this->roles;
  133.         // guarantee every user at least has ROLE_USER
  134.         $roles[] = 'ROLE_USER';
  135.         return array_unique($roles);
  136.     }
  137.     public function setRoles(array $roles): self
  138.     {
  139.         $this->roles $roles;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @see PasswordAuthenticatedUserInterface
  144.      */
  145.     public function getPassword(): string
  146.     {
  147.         return $this->password;
  148.     }
  149.     public function setPassword(string $password): self
  150.     {
  151.         $this->password $password;
  152.         return $this;
  153.     }
  154.     public function getPlainPassword(): ?string
  155.     {
  156.         return $this->plainPassword;
  157.     }
  158.     public function setPlainPassword(?string $plainPassword): self
  159.     {
  160.         $this->plainPassword $plainPassword;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @see UserInterface
  165.      */
  166.     public function eraseCredentials()
  167.     {
  168.         // If you store any temporary, sensitive data on the user, clear it here
  169.         // $this->plainPassword = null;
  170.     }
  171.     /**
  172.      * @return Collection<int, Terminal>
  173.      */
  174.     public function getTerminals(): Collection
  175.     {
  176.         return $this->terminals;
  177.     }
  178.     public function addTerminal(Terminal $terminal): self
  179.     {
  180.         if (!$this->terminals->contains($terminal)) {
  181.             $this->terminals->add($terminal);
  182.             $terminal->addClient($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removeTerminal(Terminal $terminal): self
  187.     {
  188.         if ($this->terminals->removeElement($terminal)) {
  189.             $terminal->removeClient($this);
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, Feedback>
  195.      */
  196.     public function getFeedbacks(): Collection
  197.     {
  198.         return $this->feedbacks;
  199.     }
  200.     public function addFeedback(Feedback $feedback): self
  201.     {
  202.         if (!$this->feedbacks->contains($feedback)) {
  203.             $this->feedbacks->add($feedback);
  204.             $feedback->setClient($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeFeedback(Feedback $feedback): self
  209.     {
  210.         if ($this->feedbacks->removeElement($feedback)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($feedback->getClient() === $this) {
  213.                 $feedback->setClient(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getCompany(): ?string
  219.     {
  220.         return $this->company;
  221.     }
  222.     public function setCompany(string $company): self
  223.     {
  224.         $this->company $company;
  225.         return $this;
  226.     }
  227.     public function getTaxId(): ?string
  228.     {
  229.         return $this->taxId;
  230.     }
  231.     public function setTaxId(?string $taxId): self
  232.     {
  233.         $this->taxId $taxId;
  234.         return $this;
  235.     }
  236.     public function getComment(): ?string
  237.     {
  238.         return $this->comment;
  239.     }
  240.     public function setComment(?string $comment): self
  241.     {
  242.         $this->comment $comment;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return Collection<int, Projects>
  247.      */
  248.     public function getProjects(): Collection
  249.     {
  250.         return $this->projects;
  251.     }
  252.     public function addProject(Projects $project): static
  253.     {
  254.         if (!$this->projects->contains($project)) {
  255.             $this->projects->add($project);
  256.             $project->setClient($this);
  257.         }
  258.         return $this;
  259.     }
  260.     public function removeProject(Projects $project): static
  261.     {
  262.         if ($this->projects->removeElement($project)) {
  263.             // set the owning side to null (unless already changed)
  264.             if ($project->getClient() === $this) {
  265.                 $project->setClient(null);
  266.             }
  267.         }
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return Collection<int, Media>
  272.      */
  273.     public function getMedias(): Collection
  274.     {
  275.         return $this->medias;
  276.     }
  277.     public function addMedia(Media $media): static
  278.     {
  279.         if (!$this->medias->contains($media)) {
  280.             $this->medias->add($media);
  281.             $media->setClient($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeMedia(Media $media): static
  286.     {
  287.         if ($this->medias->removeElement($media)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($media->getClient() === $this) {
  290.                 $media->setClient(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295. }