src/Entity/User.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use App\EntityListener\UserListener;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Repository\UserRepository;
  10. use Serializable;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. #[ORM\Entity(repositoryClassUserRepository::class)]
  17. #[ORM\Table(name'`user`')]
  18. #[ORM\HasLifecycleCallbacks]
  19. #[Vich\Uploadable]
  20. #[UniqueEntity(fields: ['username'], message'Il existe déjà un compte avec ce nom d\'utilisateur')]
  21. #[ORM\EntityListeners([UserListener::class])]
  22. class User implements UserInterfacePasswordAuthenticatedUserInterfaceSerializable
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     private ?int $id null;
  28.     #[ORM\Column(length180uniquetrue)]
  29.     private ?string $username null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $firstName null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     private ?string $lastName null;
  34.     #[ORM\ManyToOne(inversedBy'users')]
  35.     #[ORM\JoinColumn(nullabletrue)]
  36.     private ?Role $role null;
  37.     #[ORM\Column]
  38.     private ?string $password null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $email null;
  41.     #[ORM\Column(length255nullabletrue)]
  42.     private ?string $phone null;
  43.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueoptions: [
  44.         "default" => null
  45.     ])]
  46.     private ?string $imageName null;
  47.     #[Vich\UploadableField(mapping'user_img'fileNameProperty'imageName'size'imageSize')]
  48.     private ?File $imageFile null;
  49.     #[ORM\Column(type'integer'nullabletrue)]
  50.     private ?int $imageSize null;
  51.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  52.     private bool $isVerified false;
  53.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEoptions: [
  54.         "default" => "CURRENT_TIMESTAMP"
  55.     ])]
  56.     private ?DateTimeImmutable $createdAt null;
  57.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEoptions: [
  58.         "default" => "CURRENT_TIMESTAMP"
  59.     ])]
  60.     private ?DateTimeImmutable $updatedAt null;
  61.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  62.     private ?bool $isActivated false;
  63.     #[ORM\Column(typeTypes::BOOLEANoptions: ["default" => "0"])]
  64.     private ?bool $isDeleted false;
  65.     #[ORM\ManyToOne(inversedBy'users')]
  66.     private ?GasStation $gasStation null;
  67.     #[ORM\OneToMany(mappedBy'user'targetEntityOrder::class)]
  68.     private Collection $orders;
  69.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessage::class)]
  70.     private Collection $senders;
  71.     #[ORM\OneToMany(mappedBy'receiver'targetEntityMessage::class)]
  72.     private Collection $receivers;
  73.     #[ORM\OneToMany(mappedBy'copy'targetEntityMessage::class)]
  74.     private Collection $copies;
  75.     #[ORM\OneToMany(mappedBy'replyTo'targetEntityMessage::class)]
  76.     private Collection $repliesTo;
  77.     #[ORM\OneToMany(mappedBy'user'targetEntitySession::class)]
  78.     private Collection $sessions;
  79.     public function __construct()
  80.     {
  81.         $this->orders = new ArrayCollection();
  82.         $this->senders = new ArrayCollection();
  83.         $this->receivers = new ArrayCollection();
  84.         $this->copies = new ArrayCollection();
  85.         $this->repliesTo = new ArrayCollection();
  86.         $this->sessions = new ArrayCollection();
  87.     }
  88.     public function getId(): ?int
  89.     {
  90.         return $this->id;
  91.     }
  92.     /**
  93.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  94.      */
  95.     public function getUsername(): ?string
  96.     {
  97.         return (string)$this->username;
  98.     }
  99.     public function setUsername(?string $username): self
  100.     {
  101.         $this->username $username;
  102.         return $this;
  103.     }
  104.     /**
  105.      * A visual identifier that represents this user.
  106.      *
  107.      * @see UserInterface
  108.      */
  109.     public function getUserIdentifier(): string
  110.     {
  111.         return (string)$this->username;
  112.     }
  113.     /**
  114.      * @see PasswordAuthenticatedUserInterface
  115.      */
  116.     public function getPassword(): string
  117.     {
  118.         if($this->password != null)
  119.             return $this->password;
  120.         return "";
  121.     }
  122.     /**
  123.      * @param string|null $password
  124.      * @return $this
  125.      */
  126.     public function setPassword(?string $password): self
  127.     {
  128.         $this->password $password;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Returning a salt is only needed, if you are not using a modern
  133.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  134.      *
  135.      * @see UserInterface
  136.      */
  137.     public function getSalt(): ?string
  138.     {
  139.         return null;
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function eraseCredentials()
  145.     {
  146.         // If you store any temporary, sensitive data on the user, clear it here
  147.         //$this->plainPassword = null;
  148.     }
  149.     public function getFirstName(): ?string
  150.     {
  151.         return $this->firstName;
  152.     }
  153.     public function setFirstName(?string $firstName): self
  154.     {
  155.         $this->firstName $firstName;
  156.         return $this;
  157.     }
  158.     public function getLastName(): ?string
  159.     {
  160.         return $this->lastName;
  161.     }
  162.     public function setLastName(?string $lastName): self
  163.     {
  164.         $this->lastName $lastName;
  165.         return $this;
  166.     }
  167.     public function getEmail(): ?string
  168.     {
  169.         return $this->email;
  170.     }
  171.     public function setEmail(?string $email): self
  172.     {
  173.         $this->email $email;
  174.         return $this;
  175.     }
  176.     public function getPhone(): ?string
  177.     {
  178.         return $this->phone;
  179.     }
  180.     public function setPhone(?string $phone): self
  181.     {
  182.         $this->phone $phone;
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return string|null
  187.      */
  188.     public function getImageName(): ?string
  189.     {
  190.         return $this->imageName;
  191.     }
  192.     /**
  193.      * @param string|null $imageName
  194.      */
  195.     public function setImageName(?string $imageName): void
  196.     {
  197.         $this->imageName $imageName;
  198.     }
  199.     /**
  200.      * @param File|null $imageFile
  201.      */
  202.     public function setImageFile(?File $imageFile null): void
  203.     {
  204.         $this->imageFile $imageFile;
  205.         if (null !== $imageFile) {
  206.             $this->updatedAt = new DateTimeImmutable;
  207.         }
  208.     }
  209.     public function getImageFile(): ?File
  210.     {
  211.         return $this->imageFile;
  212.     }
  213.     public function setImageSize(?int $imageSize): void
  214.     {
  215.         $this->imageSize $imageSize;
  216.     }
  217.     public function getImageSize(): ?int
  218.     {
  219.         return $this->imageSize;
  220.     }
  221.     public function isVerified(): bool
  222.     {
  223.         return $this->isVerified;
  224.     }
  225.     public function setIsVerified(?bool $isVerified): self
  226.     {
  227.         $this->isVerified $isVerified;
  228.         return $this;
  229.     }
  230.     public function getCreatedAt(): ?\DateTimeImmutable
  231.     {
  232.         return $this->createdAt;
  233.     }
  234.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  235.     {
  236.         $this->createdAt $createdAt;
  237.         return $this;
  238.     }
  239.     public function getUpdatedAt(): ?\DateTimeImmutable
  240.     {
  241.         return $this->updatedAt;
  242.     }
  243.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  244.     {
  245.         $this->updatedAt $updatedAt;
  246.         return $this;
  247.     }
  248.     public function isIsActivated(): ?bool
  249.     {
  250.         return $this->isActivated;
  251.     }
  252.     public function setIsActivated(bool $isActivated): self
  253.     {
  254.         $this->isActivated $isActivated;
  255.         return $this;
  256.     }
  257.     public function isIsDeleted(): ?bool
  258.     {
  259.         return $this->isDeleted;
  260.     }
  261.     public function setIsDeleted(bool $isDeleted): self
  262.     {
  263.         $this->isDeleted $isDeleted;
  264.         return $this;
  265.     }
  266.     public function getRole(): ?Role
  267.     {
  268.         return $this->role;
  269.     }
  270.     public function setRole(?Role $role): self
  271.     {
  272.         $this->role $role;
  273.         return $this;
  274.     }
  275.     public function getRoles(): array
  276.     {
  277.         return [];
  278.     }
  279.     /** @see \Serializable::serialize() */
  280.     public function serialize(): ?string
  281.     {
  282.         return serialize(array(
  283.             $this->id,
  284.             $this->username,
  285.             $this->firstName,
  286.             $this->lastName,
  287.             $this->password,
  288.             $this->email,
  289.             $this->phone,
  290.             $this->isVerified,
  291.             $this->isActivated,
  292.             $this->gasStation,
  293.         ));
  294.     }
  295.     /** @param $serialized
  296.      * @see \Serializable::unserialize()
  297.      */
  298.     public function unserialize($serialized)
  299.     {
  300.         list (
  301.             $this->id,
  302.             $this->username,
  303.             $this->firstName,
  304.             $this->lastName,
  305.             $this->password,
  306.             $this->email,
  307.             $this->phone,
  308.             $this->isVerified,
  309.             $this->isActivated,
  310.             $this->gasStation,
  311.             ) = unserialize($serialized, array('allowed_classes' => false));
  312.     }
  313.     public function getGasStation(): ?GasStation
  314.     {
  315.         return $this->gasStation;
  316.     }
  317.     public function setGasStation(?GasStation $gasStation): self
  318.     {
  319.         $this->gasStation $gasStation;
  320.         return $this;
  321.     }
  322.     /**
  323.      * @return Collection<int, Order>
  324.      */
  325.     public function getOrders(): Collection
  326.     {
  327.         return $this->orders;
  328.     }
  329.     public function addOrder(Order $order): self
  330.     {
  331.         if (!$this->orders->contains($order)) {
  332.             $this->orders->add($order);
  333.             $order->setUser($this);
  334.         }
  335.         return $this;
  336.     }
  337.     public function removeOrder(Order $order): self
  338.     {
  339.         if ($this->orders->removeElement($order)) {
  340.             // set the owning side to null (unless already changed)
  341.             if ($order->getUser() === $this) {
  342.                 $order->setUser(null);
  343.             }
  344.         }
  345.         return $this;
  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. }