src/Entity/User.php line 45

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Controller\CustomController;
  7. use App\EntityListener\UserListener;
  8. use DateTimeImmutable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use App\Repository\UserRepository;
  14. use Serializable;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\HttpFoundation\File\File;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  21. #[ORM\Entity(repositoryClassUserRepository::class)]
  22. #[ORM\Table(name'`user`')]
  23. #[ORM\HasLifecycleCallbacks]
  24. #[Vich\Uploadable]
  25. #[UniqueEntity(fields: ['email'], message'Il existe déjà un compte avec cette adresse mail.')]
  26. #[ORM\EntityListeners([UserListener::class])]
  27. #[ApiResource(
  28.     operations: [
  29.         new Get(
  30.             normalizationContext: [
  31.                 'groups' => 'user:item'
  32.             ]
  33.         ),
  34.         new GetCollection(
  35.             normalizationContext: [
  36.                 'groups' => 'user:list'
  37.             ]
  38.         ),
  39.     ],
  40.     paginationEnabledfalse,
  41. )]
  42. class User implements UserInterfacePasswordAuthenticatedUserInterfaceSerializable
  43. {
  44.     #[ORM\Id]
  45.     #[ORM\GeneratedValue]
  46.     #[ORM\Column]
  47.     #[Groups(['user:list''user:item''assignment:item''assignment:list'])]
  48.     private ?int $id null;
  49.     #[ORM\Column(length180nullabletrue)]
  50.     #[Groups(['user:list''user:item'])]
  51.     private ?string $username null;
  52.     #[ORM\Column(length255nullabletrue)]
  53.     #[Groups(['user:list''user:item''assignment:item'])]
  54.     private ?string $firstName null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     #[Groups(['user:list''user:item''assignment:item'])]
  57.     private ?string $lastName null;
  58.     #[ORM\ManyToOne(inversedBy'users')]
  59.     #[ORM\JoinColumn(nullabletrue)]
  60.     #[Groups(['user:list''user:item'])]
  61.     private ?Role $role null;
  62.     #[ORM\Column]
  63.     #[Groups(['user:list''user:item'])]
  64.     private ?string $password null;
  65.     #[ORM\Column(length255uniquetrue)]
  66.     #[Groups(['user:list''user:item'])]
  67.     private ?string $email null;
  68.     #[ORM\Column(length255nullabletrue)]
  69.     #[Groups(['user:list''user:item'])]
  70.     private ?string $phone null;
  71.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueoptions: [
  72.         "default" => null
  73.     ])]
  74.     #[Groups(['user:list''user:item'])]
  75.     private ?string $imageName null;
  76.     #[Vich\UploadableField(mapping'user_img'fileNameProperty'imageName'size'imageSize')]
  77.     private ?File $imageFile null;
  78.     #[ORM\Column(type'integer'nullabletrue)]
  79.     private ?int $imageSize null;
  80.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  81.     private bool $isVerified false;
  82.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEoptions: [
  83.         "default" => "CURRENT_TIMESTAMP"
  84.     ])]
  85.     private ?DateTimeImmutable $createdAt null;
  86.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEoptions: [
  87.         "default" => "CURRENT_TIMESTAMP"
  88.     ])]
  89.     private ?DateTimeImmutable $updatedAt null;
  90.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  91.     #[Groups(['user:list''user:item'])]
  92.     private ?bool $isActivated false;
  93.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  94.     #[Groups(['user:list''user:item'])]
  95.     private ?bool $isDeleted false;
  96.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessage::class)]
  97.     private Collection $senders;
  98.     #[ORM\OneToMany(mappedBy'receiver'targetEntityMessage::class)]
  99.     private Collection $receivers;
  100.     #[ORM\OneToMany(mappedBy'copy'targetEntityMessage::class)]
  101.     private Collection $copies;
  102.     #[ORM\OneToMany(mappedBy'replyTo'targetEntityMessage::class)]
  103.     private Collection $repliesTo;
  104.     #[ORM\OneToMany(mappedBy'user'targetEntitySession::class)]
  105.     private Collection $sessions;
  106.     #[ORM\OneToMany(mappedBy'user'targetEntityMailNotification::class)]
  107.     private Collection $mailNotifcations;
  108.     #[ORM\OneToMany(mappedBy'user'targetEntityAssignment::class)]
  109.     private Collection $assignments;
  110.     public function __construct()
  111.     {
  112.         $this->senders = new ArrayCollection();
  113.         $this->receivers = new ArrayCollection();
  114.         $this->copies = new ArrayCollection();
  115.         $this->repliesTo = new ArrayCollection();
  116.         $this->sessions = new ArrayCollection();
  117.         $this->mailNotifcations = new ArrayCollection();
  118.         $this->assignments = new ArrayCollection();
  119.     }
  120.     public function getId(): ?int
  121.     {
  122.         return $this->id;
  123.     }
  124.     /**
  125.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  126.      */
  127.     public function getUsername(): ?string
  128.     {
  129.         return (string)$this->username;
  130.     }
  131.     public function setUsername(?string $username): self
  132.     {
  133.         $this->username $username;
  134.         return $this;
  135.     }
  136.     /**
  137.      * A visual identifier that represents this user.
  138.      *
  139.      * @see UserInterface
  140.      */
  141.     public function getUserIdentifier(): string
  142.     {
  143.         return (string)$this->email;
  144.     }
  145.     /**
  146.      * @see PasswordAuthenticatedUserInterface
  147.      */
  148.     public function getPassword(): string
  149.     {
  150.         if ($this->password != null)
  151.             return $this->password;
  152.         return "";
  153.     }
  154.     /**
  155.      * @param string|null $password
  156.      * @return $this
  157.      */
  158.     public function setPassword(?string $password): self
  159.     {
  160.         $this->password $password;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Returning a salt is only needed, if you are not using a modern
  165.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  166.      *
  167.      * @see UserInterface
  168.      */
  169.     public function getSalt(): ?string
  170.     {
  171.         return null;
  172.     }
  173.     /**
  174.      * @see UserInterface
  175.      */
  176.     public function eraseCredentials()
  177.     {
  178.         // If you store any temporary, sensitive data on the user, clear it here
  179.         //$this->plainPassword = null;
  180.     }
  181.     public function getFirstName(): ?string
  182.     {
  183.         return $this->firstName;
  184.     }
  185.     public function setFirstName(?string $firstName): self
  186.     {
  187.         $this->firstName $firstName;
  188.         return $this;
  189.     }
  190.     public function getLastName(): ?string
  191.     {
  192.         return $this->lastName;
  193.     }
  194.     public function setLastName(?string $lastName): self
  195.     {
  196.         $this->lastName $lastName;
  197.         return $this;
  198.     }
  199.     public function getEmail(): ?string
  200.     {
  201.         return $this->email;
  202.     }
  203.     public function setEmail(?string $email): self
  204.     {
  205.         $this->email $email;
  206.         return $this;
  207.     }
  208.     public function getPhone(): ?string
  209.     {
  210.         return $this->phone;
  211.     }
  212.     public function setPhone(?string $phone): self
  213.     {
  214.         $this->phone $phone;
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return string|null
  219.      */
  220.     public function getImageName(): ?string
  221.     {
  222.         return $this->imageName;
  223.     }
  224.     /**
  225.      * @param string|null $imageName
  226.      */
  227.     public function setImageName(?string $imageName): void
  228.     {
  229.         $this->imageName $imageName;
  230.     }
  231.     /**
  232.      * @param File|null $imageFile
  233.      */
  234.     public function setImageFile(?File $imageFile null): void
  235.     {
  236.         $this->imageFile $imageFile;
  237.         if (null !== $imageFile) {
  238.             $this->updatedAt = new DateTimeImmutable;
  239.         }
  240.     }
  241.     public function getImageFile(): ?File
  242.     {
  243.         return $this->imageFile;
  244.     }
  245.     public function setImageSize(?int $imageSize): void
  246.     {
  247.         $this->imageSize $imageSize;
  248.     }
  249.     public function getImageSize(): ?int
  250.     {
  251.         return $this->imageSize;
  252.     }
  253.     public function isVerified(): bool
  254.     {
  255.         return $this->isVerified;
  256.     }
  257.     public function setIsVerified(?bool $isVerified): self
  258.     {
  259.         $this->isVerified $isVerified;
  260.         return $this;
  261.     }
  262.     public function getCreatedAt(): ?\DateTimeImmutable
  263.     {
  264.         return $this->createdAt;
  265.     }
  266.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  267.     {
  268.         $this->createdAt $createdAt;
  269.         return $this;
  270.     }
  271.     public function getUpdatedAt(): ?\DateTimeImmutable
  272.     {
  273.         return $this->updatedAt;
  274.     }
  275.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  276.     {
  277.         $this->updatedAt $updatedAt;
  278.         return $this;
  279.     }
  280.     public function isIsActivated(): ?bool
  281.     {
  282.         return $this->isActivated;
  283.     }
  284.     public function setIsActivated(bool $isActivated): self
  285.     {
  286.         $this->isActivated $isActivated;
  287.         return $this;
  288.     }
  289.     public function isIsDeleted(): ?bool
  290.     {
  291.         return $this->isDeleted;
  292.     }
  293.     public function setIsDeleted(bool $isDeleted): self
  294.     {
  295.         $this->isDeleted $isDeleted;
  296.         return $this;
  297.     }
  298.     public function getRole(): ?Role
  299.     {
  300.         return $this->role;
  301.     }
  302.     public function setRole(?Role $role): self
  303.     {
  304.         $this->role $role;
  305.         return $this;
  306.     }
  307.     public function getRoles(): array
  308.     {
  309.         $roles = [];
  310.         $roles[] = 'ROLE_USER';
  311.         if ($this->getRole() != null)
  312.             $roles[] = $this->getRole()->getAlias();
  313.         return array_unique($roles);
  314.     }
  315.     /** @see \Serializable::serialize() */
  316.     public function serialize(): ?string
  317.     {
  318.         return serialize(array(
  319.             $this->id,
  320.             $this->username,
  321.             $this->firstName,
  322.             $this->lastName,
  323.             $this->password,
  324.             $this->email,
  325.             $this->phone,
  326.             $this->isVerified,
  327.             $this->isActivated,
  328.         ));
  329.     }
  330.     /** @param $serialized
  331.      * @see \Serializable::unserialize()
  332.      */
  333.     public function unserialize($serialized)
  334.     {
  335.         list (
  336.             $this->id,
  337.             $this->username,
  338.             $this->firstName,
  339.             $this->lastName,
  340.             $this->password,
  341.             $this->email,
  342.             $this->phone,
  343.             $this->isVerified,
  344.             $this->isActivated,
  345.             ) = unserialize($serialized, array('allowed_classes' => false));
  346.     }
  347.     /**
  348.      * @return Collection<int, Message>
  349.      */
  350.     public function getSenders(): Collection
  351.     {
  352.         return $this->senders;
  353.     }
  354.     public function addSender(Message $sender): self
  355.     {
  356.         if (!$this->senders->contains($sender)) {
  357.             $this->senders->add($sender);
  358.             $sender->setSender($this);
  359.         }
  360.         return $this;
  361.     }
  362.     public function removeSender(Message $sender): self
  363.     {
  364.         if ($this->senders->removeElement($sender)) {
  365.             // set the owning side to null (unless already changed)
  366.             if ($sender->getSender() === $this) {
  367.                 $sender->setSender(null);
  368.             }
  369.         }
  370.         return $this;
  371.     }
  372.     /**
  373.      * @return Collection<int, Message>
  374.      */
  375.     public function getReceivers(): Collection
  376.     {
  377.         return $this->receivers;
  378.     }
  379.     public function addReceiver(Message $receiver): self
  380.     {
  381.         if (!$this->receivers->contains($receiver)) {
  382.             $this->receivers->add($receiver);
  383.             $receiver->setReceiver($this);
  384.         }
  385.         return $this;
  386.     }
  387.     public function removeReceiver(Message $receiver): self
  388.     {
  389.         if ($this->receivers->removeElement($receiver)) {
  390.             // set the owning side to null (unless already changed)
  391.             if ($receiver->getReceiver() === $this) {
  392.                 $receiver->setReceiver(null);
  393.             }
  394.         }
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return Collection<int, Message>
  399.      */
  400.     public function getCopies(): Collection
  401.     {
  402.         return $this->copies;
  403.     }
  404.     public function addCopy(Message $copy): self
  405.     {
  406.         if (!$this->copies->contains($copy)) {
  407.             $this->copies->add($copy);
  408.             $copy->setCopy($this);
  409.         }
  410.         return $this;
  411.     }
  412.     public function removeCopy(Message $copy): self
  413.     {
  414.         if ($this->copies->removeElement($copy)) {
  415.             // set the owning side to null (unless already changed)
  416.             if ($copy->getCopy() === $this) {
  417.                 $copy->setCopy(null);
  418.             }
  419.         }
  420.         return $this;
  421.     }
  422.     /**
  423.      * @return Collection<int, Message>
  424.      */
  425.     public function getRepliesTo(): Collection
  426.     {
  427.         return $this->repliesTo;
  428.     }
  429.     public function addRepliesTo(Message $repliesTo): self
  430.     {
  431.         if (!$this->repliesTo->contains($repliesTo)) {
  432.             $this->repliesTo->add($repliesTo);
  433.             $repliesTo->setReplyTo($this);
  434.         }
  435.         return $this;
  436.     }
  437.     public function removeRepliesTo(Message $repliesTo): self
  438.     {
  439.         if ($this->repliesTo->removeElement($repliesTo)) {
  440.             // set the owning side to null (unless already changed)
  441.             if ($repliesTo->getReplyTo() === $this) {
  442.                 $repliesTo->setReplyTo(null);
  443.             }
  444.         }
  445.         return $this;
  446.     }
  447.     /**
  448.      * @return Collection<int, Session>
  449.      */
  450.     public function getSessions(): Collection
  451.     {
  452.         return $this->sessions;
  453.     }
  454.     public function addSession(Session $session): self
  455.     {
  456.         if (!$this->sessions->contains($session)) {
  457.             $this->sessions->add($session);
  458.             $session->setUser($this);
  459.         }
  460.         return $this;
  461.     }
  462.     public function removeSession(Session $session): self
  463.     {
  464.         if ($this->sessions->removeElement($session)) {
  465.             // set the owning side to null (unless already changed)
  466.             if ($session->getUser() === $this) {
  467.                 $session->setUser(null);
  468.             }
  469.         }
  470.         return $this;
  471.     }
  472.     /**
  473.      * @return Collection<int, MailNotification>
  474.      */
  475.     public function getMailNotifcations(): Collection
  476.     {
  477.         return $this->mailNotifcations;
  478.     }
  479.     public function addMailNotifcation(MailNotification $mailNotifcation): self
  480.     {
  481.         if (!$this->mailNotifcations->contains($mailNotifcation)) {
  482.             $this->mailNotifcations->add($mailNotifcation);
  483.             $mailNotifcation->setUser($this);
  484.         }
  485.         return $this;
  486.     }
  487.     public function removeMailNotifcation(MailNotification $mailNotifcation): self
  488.     {
  489.         if ($this->mailNotifcations->removeElement($mailNotifcation)) {
  490.             // set the owning side to null (unless already changed)
  491.             if ($mailNotifcation->getUser() === $this) {
  492.                 $mailNotifcation->setUser(null);
  493.             }
  494.         }
  495.         return $this;
  496.     }
  497.     /**
  498.      * @return Collection<int, Assignment>
  499.      */
  500.     public function getAssignments(): Collection
  501.     {
  502.         return $this->assignments;
  503.     }
  504.     public function addAssignment(Assignment $assignment): self
  505.     {
  506.         if (!$this->assignments->contains($assignment)) {
  507.             $this->assignments->add($assignment);
  508.             $assignment->setUser($this);
  509.         }
  510.         return $this;
  511.     }
  512.     public function removeAssignment(Assignment $assignment): self
  513.     {
  514.         if ($this->assignments->removeElement($assignment)) {
  515.             // set the owning side to null (unless already changed)
  516.             if ($assignment->getUser() === $this) {
  517.                 $assignment->setUser(null);
  518.             }
  519.         }
  520.         return $this;
  521.     }
  522. }