src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\InheritanceType('JOINED')]
  13. #[ORM\DiscriminatorColumn(name"type"type"string")]
  14. #[ORM\DiscriminatorMap(['commercial' => Commercial::class, 'prescriber' => Prescriber::class, 'employee' => Employee::class])]
  15. #[Vich\Uploadable]
  16. abstract class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     use IdentifiableTrait;
  19.     #[ORM\Column(length180uniquetrue)]
  20.     private ?string $username null;
  21.     #[ORM\Column]
  22.     protected array $roles = [];
  23.     /**
  24.      * @var string|null The hashed password
  25.      */
  26.     #[ORM\Column]
  27.     private ?string $password null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $email null;
  30.     #[ORM\OneToMany(mappedBy'prescriberValidationUser'targetEntityInvoice::class)]
  31.     private Collection $prescriberValidatedInvoices;
  32.     #[ORM\OneToMany(mappedBy'origin'targetEntityPrescriberPoint::class)]
  33.     private Collection $prescriberPoints;
  34.     #[ORM\OneToMany(mappedBy'user'targetEntityLogHistory::class)]
  35.     private Collection $logHistory;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?bool $active null;
  38.     #[ORM\Column(nullabletrue)]
  39.     private ?\DateTimeImmutable $lastConnexionDate null;
  40.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessage::class, orphanRemovaltrue)]
  41.     private Collection $senderMessages;
  42.     #[ORM\ManyToMany(targetEntityMessageReceiver::class, mappedBy'users')]
  43.     private Collection $messageReceivers;
  44.     #[ORM\Column(type"string"length255nullabletrue)]
  45.     private ?string $photoFilename '';
  46.     #[Vich\UploadableField(mapping"user_photo"fileNameProperty"photoFilename")]
  47.     private ?File $photoFile null;
  48.     #[ORM\OneToMany(mappedBy'targetUser'targetEntityLogHistory::class)]
  49.     private Collection $logHistories;
  50.     #[ORM\OneToMany(mappedBy'owner'targetEntityBooking::class)]
  51.     private Collection $bookings;
  52.     #[ORM\OneToMany(mappedBy'attributedTo'targetEntityPrescriptionPad::class)]
  53.     private Collection $prescriptionPads;
  54.     #[ORM\ManyToMany(targetEntityBookingUserGroup::class, mappedBy'user')]
  55.     private Collection $bookingUserGroups;
  56.     #[ORM\ManyToMany(targetEntityBookingEvent::class, mappedBy'users')]
  57.     private Collection $bookingEvents;
  58.     public function __construct()
  59.     {
  60.         $this->prescriberValidatedInvoices = new ArrayCollection();
  61.         $this->prescriberPoints            = new ArrayCollection();
  62.         $this->logHistory                  = new ArrayCollection();
  63.         $this->senderMessages              = new ArrayCollection();
  64.         $this->messageReceivers            = new ArrayCollection();
  65.         $this->logHistories                = new ArrayCollection();
  66.         $this->bookings                    = new ArrayCollection();
  67.         $this->prescriptionPads            = new ArrayCollection();
  68.         $this->bookingUserGroups           = new ArrayCollection();
  69.         $this->bookingEvents               = new ArrayCollection();
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     /**
  76.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  77.      */
  78.     public function getUsername(): string
  79.     {
  80.         return (string)$this->username;
  81.     }
  82.     public function getFullName(): ?string
  83.     {
  84.         return (string)$this->username;
  85.     }
  86.     public function setUsername(string $username): self
  87.     {
  88.         $this->username strtolower($username);
  89.         return $this;
  90.     }
  91.     /**
  92.      * A visual identifier that represents this user.
  93.      *
  94.      * @see UserInterface
  95.      */
  96.     public function getUserIdentifier(): string
  97.     {
  98.         return (string)$this->username;
  99.     }
  100.     /**
  101.      * @see UserInterface
  102.      */
  103.     public function getRoles(): array
  104.     {
  105.         $roles $this->roles;
  106.         // guarantee every user at least has ROLE_USER
  107.         $roles[] = 'ROLE_USER';
  108.         return array_unique($roles);
  109.     }
  110.     public function setRoles(array $roles): self
  111.     {
  112.         $this->roles $roles;
  113.         return $this;
  114.     }
  115.     public function hasRole(string $role): bool
  116.     {
  117.         return in_array($role$this->rolestrue);
  118.     }
  119.     /**
  120.      * @see PasswordAuthenticatedUserInterface
  121.      */
  122.     public function getPassword(): string
  123.     {
  124.         return $this->password;
  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 getEmail(): ?string
  150.     {
  151.         return $this->email;
  152.     }
  153.     public function setEmail(?string $email): self
  154.     {
  155.         $this->email strtolower($email);
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection<int, Invoice>
  160.      */
  161.     public function getPrescriberValidatedInvoices(): Collection
  162.     {
  163.         return $this->prescriberValidatedInvoices;
  164.     }
  165.     public function addPrescriberValidatedInvoice(Invoice $prescriberValidatedInvoice): self
  166.     {
  167.         if (!$this->prescriberValidatedInvoices->contains($prescriberValidatedInvoice)) {
  168.             $this->prescriberValidatedInvoices->add($prescriberValidatedInvoice);
  169.             $prescriberValidatedInvoice->setPrescriberValidationUser($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removePrescriberValidatedInvoice(Invoice $prescriberValidatedInvoice): self
  174.     {
  175.         if ($this->prescriberValidatedInvoices->removeElement($prescriberValidatedInvoice)) {
  176.             // set the owning side to null (unless already changed)
  177.             if ($prescriberValidatedInvoice->getPrescriberValidationUser() === $this) {
  178.                 $prescriberValidatedInvoice->setPrescriberValidationUser(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection<int, PrescriberPoint>
  185.      */
  186.     public function getPrescriberPoints(): Collection
  187.     {
  188.         return $this->prescriberPoints;
  189.     }
  190.     public function addPrescriberPoint(PrescriberPoint $prescriberPoint): self
  191.     {
  192.         if (!$this->prescriberPoints->contains($prescriberPoint)) {
  193.             $this->prescriberPoints->add($prescriberPoint);
  194.             $prescriberPoint->setOrigin($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removePrescriberPoint(PrescriberPoint $prescriberPoint): self
  199.     {
  200.         if ($this->prescriberPoints->removeElement($prescriberPoint)) {
  201.             // set the owning side to null (unless already changed)
  202.             if ($prescriberPoint->getOrigin() === $this) {
  203.                 $prescriberPoint->setOrigin(null);
  204.             }
  205.         }
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return Collection<int, LogHistory>
  210.      */
  211.     public function getLogHistory(): Collection
  212.     {
  213.         return $this->logHistory;
  214.     }
  215.     public function addLogHistory(LogHistory $logHistory): self
  216.     {
  217.         if (!$this->logHistory->contains($logHistory)) {
  218.             $this->logHistory->add($logHistory);
  219.             $logHistory->setUser($this);
  220.         }
  221.         return $this;
  222.     }
  223.     public function removeLogHistory(LogHistory $logHistory): self
  224.     {
  225.         if ($this->logHistory->removeElement($logHistory)) {
  226.             // set the owning side to null (unless already changed)
  227.             if ($logHistory->getUser() === $this) {
  228.                 $logHistory->setUser(null);
  229.             }
  230.         }
  231.         return $this;
  232.     }
  233.     public function isActive(): ?bool
  234.     {
  235.         return $this->active;
  236.     }
  237.     public function setActive(?bool $active): self
  238.     {
  239.         $this->active $active;
  240.         return $this;
  241.     }
  242.     public function getLastConnexionDate(): ?\DateTimeImmutable
  243.     {
  244.         return $this->lastConnexionDate;
  245.     }
  246.     public function setLastConnexionDate(?\DateTimeImmutable $lastConnexionDate): self
  247.     {
  248.         $this->lastConnexionDate $lastConnexionDate;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, Message>
  253.      */
  254.     public function getSenderMessages(): Collection
  255.     {
  256.         return $this->senderMessages;
  257.     }
  258.     public function addSenderMessage(Message $senderMessage): self
  259.     {
  260.         if (!$this->senderMessages->contains($senderMessage)) {
  261.             $this->senderMessages->add($senderMessage);
  262.             $senderMessage->setSender($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removeSenderMessage(Message $senderMessage): self
  267.     {
  268.         if ($this->senderMessages->removeElement($senderMessage)) {
  269.             // set the owning side to null (unless already changed)
  270.             if ($senderMessage->getSender() === $this) {
  271.                 $senderMessage->setSender(null);
  272.             }
  273.         }
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return Collection<int, MessageReceiver>
  278.      */
  279.     public function getMessageReceivers(): Collection
  280.     {
  281.         return $this->messageReceivers;
  282.     }
  283.     public function addMessageReceiver(MessageReceiver $messageReceiver): self
  284.     {
  285.         if (!$this->messageReceivers->contains($messageReceiver)) {
  286.             $this->messageReceivers->add($messageReceiver);
  287.             $messageReceiver->addUser($this);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeMessageReceiver(MessageReceiver $messageReceiver): self
  292.     {
  293.         if ($this->messageReceivers->removeElement($messageReceiver)) {
  294.             $messageReceiver->removeUser($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function getPhotoFilename(): ?string
  299.     {
  300.         return $this->photoFilename;
  301.     }
  302.     public function setPhotoFilename(?string $photoFilename): self
  303.     {
  304.         $this->photoFilename $photoFilename;
  305.         return $this;
  306.     }
  307.     public function getPhotoFile(): ?File
  308.     {
  309.         return $this->photoFile;
  310.     }
  311.     public function setPhotoFile(?File $photoFile): self
  312.     {
  313.         $this->photoFile $photoFile;
  314.         if (null !== $photoFile) {
  315.             // Ceci est nécessaire pour forcer la mise à jour de l'entité lorsque le fichier est modifié
  316.             $this->updatedAt = new \DateTimeImmutable();
  317.         }
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return Collection<int, LogHistory>
  322.      */
  323.     public function getLogHistories(): Collection
  324.     {
  325.         return $this->logHistories;
  326.     }
  327.     /**
  328.      * @return Collection<int, Booking>
  329.      */
  330.     public function getBookings(): Collection
  331.     {
  332.         return $this->bookings;
  333.     }
  334.     public function addBooking(Booking $booking): static
  335.     {
  336.         if (!$this->bookings->contains($booking)) {
  337.             $this->bookings->add($booking);
  338.             $booking->setOwner($this);
  339.         }
  340.         return $this;
  341.     }
  342.     public function removeBooking(Booking $booking): static
  343.     {
  344.         if ($this->bookings->removeElement($booking)) {
  345.             // set the owning side to null (unless already changed)
  346.             if ($booking->getOwner() === $this) {
  347.                 $booking->setOwner(null);
  348.             }
  349.         }
  350.         return $this;
  351.     }
  352.     /**
  353.      * @return Collection<int, PrescriptionPad>
  354.      */
  355.     public function getPrescriptionPads(): Collection
  356.     {
  357.         return $this->prescriptionPads;
  358.     }
  359.     public function addPrescriptionPad(PrescriptionPad $prescriptionPad): static
  360.     {
  361.         if (!$this->prescriptionPads->contains($prescriptionPad)) {
  362.             $this->prescriptionPads->add($prescriptionPad);
  363.             $prescriptionPad->setAttributedTo($this);
  364.         }
  365.         return $this;
  366.     }
  367.     public function removePrescriptionPad(PrescriptionPad $prescriptionPad): static
  368.     {
  369.         if ($this->prescriptionPads->removeElement($prescriptionPad)) {
  370.             // set the owning side to null (unless already changed)
  371.             if ($prescriptionPad->getAttributedTo() === $this) {
  372.                 $prescriptionPad->setAttributedTo(null);
  373.             }
  374.         }
  375.         return $this;
  376.     }
  377.     /**
  378.      * @return Collection<int, BookingUserGroup>
  379.      */
  380.     public function getBookingUserGroups(): Collection
  381.     {
  382.         return $this->bookingUserGroups;
  383.     }
  384.     public function addBookingUserGroup(BookingUserGroup $bookingUserGroup): static
  385.     {
  386.         if (!$this->bookingUserGroups->contains($bookingUserGroup)) {
  387.             $this->bookingUserGroups->add($bookingUserGroup);
  388.             $bookingUserGroup->addUser($this);
  389.         }
  390.         return $this;
  391.     }
  392.     public function removeBookingUserGroup(BookingUserGroup $bookingUserGroup): static
  393.     {
  394.         if ($this->bookingUserGroups->removeElement($bookingUserGroup)) {
  395.             $bookingUserGroup->removeUser($this);
  396.         }
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection<int, BookingEvent>
  401.      */
  402.     public function getPrescriberSpeakersBookingEvents(): Collection
  403.     {
  404.         return $this->bookingEvents;
  405.     }
  406.     public function addBookingEvent(BookingEvent $bookingEvent): static
  407.     {
  408.         if (!$this->bookingEvents->contains($bookingEvent)) {
  409.             $this->bookingEvents->add($bookingEvent);
  410.             $bookingEvent->addUser($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeBookingEvent(BookingEvent $bookingEvent): static
  415.     {
  416.         if ($this->bookingEvents->removeElement($bookingEvent)) {
  417.             $bookingEvent->removeUser($this);
  418.         }
  419.         return $this;
  420.     }
  421. }