src/Entity/User.php line 23

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\Traits\TimeStampTrait;
  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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. #[ORM\Table(name'User')]
  14. #[ORM\Entity(repositoryClassUserRepository::class)]
  15. #[ORM\HasLifecycleCallbacks]
  16. #[UniqueEntity(
  17.     fields: ['username'],
  18.     message'Ce nom utilisateur est déjà pris.',
  19. )]
  20. class User implements UserInterfacePasswordAuthenticatedUserInterface
  21. {
  22.     use TimeStampTrait;
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\Column(length180uniquetrue)]
  28.     private ?string $username null;
  29.     /**
  30.      * @var string The hashed password
  31.      */
  32.     #[ORM\Column]
  33.     private ?string $password null;
  34.     #[ORM\ManyToOne(inversedBy'users')]
  35.     private ?Role $role null;
  36.     #[ORM\Column(length50nullabletrue)]
  37.     private ?string $name null;
  38.     #[ORM\Column(length50nullabletrue)]
  39.     private ?string $lastname null;
  40.     #[ORM\Column(length100nullabletrue)]
  41.     private ?string $code null;
  42.     #[ORM\Column(nullabletrue)]
  43.     private ?bool $status null;
  44.     #[ORM\Column(nullabletrue)]
  45.     private ?bool $reset null;
  46.     #[ORM\Column(length25nullabletrue)]
  47.     private ?string $sexe null;
  48.     #[ORM\Column(length25nullabletrue)]
  49.     private ?string $phone null;
  50.     #[ORM\Column(length150nullabletrue)]
  51.     private ?string $picture null;
  52.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityLocation::class)]
  53.     private Collection $locations;
  54.     #[ORM\ManyToOne(inversedBy'users')]
  55.     private ?Entreprise $entreprise null;
  56.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'users')]
  57.     private ?self $createdBy null;
  58.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityself::class)]
  59.     private Collection $users;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?bool $notif null;
  62.     /**
  63.      * @Assert\NotBlank()
  64.      * @Assert\Email()
  65.      */
  66.     #[ORM\Column(length100nullabletrue)]
  67.     private ?string $email null;
  68.     #[ORM\Column(length50nullabletrue)]
  69.     private ?string $profil null;
  70.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityCountry::class)]
  71.     private Collection $countries;
  72.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityLog::class)]
  73.     private Collection $logs;
  74.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityTemplate::class)]
  75.     private Collection $templates;
  76.     #[ORM\Column(nullabletrue)]
  77.     private ?int $level null;
  78.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityIncident::class)]
  79.     private Collection $incidents;
  80.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityIncidentUpdate::class)]
  81.     private Collection $incidentUpdates;
  82.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityService::class)]
  83.     private Collection $services;
  84.     #[ORM\Column(length100nullabletrue)]
  85.     private ?string $adress null;
  86.     #[ORM\Column(length50nullabletrue)]
  87.     private ?string $city null;
  88.     #[ORM\Column(length50nullabletrue)]
  89.     private ?string $province null;
  90.     #[ORM\ManyToOne(inversedBy'users')]
  91.     private ?Country $country null;
  92.     #[ORM\ManyToMany(targetEntityAnnouncement::class, mappedBy'user')]
  93.     private Collection $announcements;
  94.     #[ORM\Column(length25nullabletrue)]
  95.     private ?string $mode null;
  96.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  97.     private ?\DateTimeInterface $lastAction null;
  98.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityReservation::class)]
  99.     private Collection $reservations;
  100.     #[ORM\OneToMany(mappedBy'user'targetEntityUserEntreprise::class)]
  101.     private Collection $userEntreprises;
  102.     #[ORM\OneToMany(mappedBy'owner'targetEntityEntreprise::class)]
  103.     private Collection $entreprises;
  104.     public function __construct()
  105.     {
  106.         $this->locations = new ArrayCollection();
  107.         $this->users = new ArrayCollection();
  108.         $this->countries = new ArrayCollection();
  109.         $this->logs = new ArrayCollection();
  110.         $this->templates = new ArrayCollection();
  111.         $this->incidents = new ArrayCollection();
  112.         $this->incidentUpdates = new ArrayCollection();
  113.         $this->services = new ArrayCollection();
  114.         $this->announcements = new ArrayCollection();
  115.         $this->reservations = new ArrayCollection();
  116.         $this->userEntreprises = new ArrayCollection();
  117.         $this->entreprises = new ArrayCollection();
  118.     }
  119.     public function getId(): ?int
  120.     {
  121.         return $this->id;
  122.     }
  123.     public function getUsername(): ?string
  124.     {
  125.         return $this->username;
  126.     }
  127.     public function setUsername(string $username): self
  128.     {
  129.         $this->username $username;
  130.         return $this;
  131.     }
  132.     /**
  133.      * A visual identifier that represents this user.
  134.      *
  135.      * @see UserInterface
  136.      */
  137.     public function getUserIdentifier(): string
  138.     {
  139.         return (string) $this->username;
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function getRoles(): array
  145.     {
  146.         $rs = [];
  147.         $rs[] = 'ROLE_ADMIN';
  148.         if ($this->role != null) {
  149.             foreach ($this->role->getPrivilege() as $role)
  150.             {
  151.                 $rs[] = 'ROLE_'.$role->getlibelle();
  152.             }
  153.         }
  154.         return $rs;
  155.     }
  156.     /**
  157.      * @see PasswordAuthenticatedUserInterface
  158.      */
  159.     public function getPassword(): string
  160.     {
  161.         return $this->password;
  162.     }
  163.     public function setPassword(string $password): self
  164.     {
  165.         $this->password $password;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @see UserInterface
  170.      */
  171.     public function eraseCredentials()
  172.     {
  173.         // If you store any temporary, sensitive data on the user, clear it here
  174.         // $this->plainPassword = null;
  175.     }
  176.     public function getRole(): ?Role
  177.     {
  178.         return $this->role;
  179.     }
  180.     public function setRole(?Role $role): self
  181.     {
  182.         $this->role $role;
  183.         return $this;
  184.     }
  185.     public function getName(): ?string
  186.     {
  187.         return $this->name;
  188.     }
  189.     public function setName(?string $name): self
  190.     {
  191.         $this->name $name;
  192.         return $this;
  193.     }
  194.     public function getLastname(): ?string
  195.     {
  196.         return $this->lastname;
  197.     }
  198.     public function setLastname(?string $lastname): self
  199.     {
  200.         $this->lastname $lastname;
  201.         return $this;
  202.     }
  203.     public function getCode(): ?string
  204.     {
  205.         return $this->code;
  206.     }
  207.     public function setCode(?string $code): self
  208.     {
  209.         $this->code $code;
  210.         return $this;
  211.     }
  212.     public function isStatus(): ?bool
  213.     {
  214.         return $this->status;
  215.     }
  216.     public function setStatus(?bool $status): self
  217.     {
  218.         $this->status $status;
  219.         return $this;
  220.     }
  221.     public function isReset(): ?bool
  222.     {
  223.         return $this->reset;
  224.     }
  225.     public function setReset(?bool $reset): self
  226.     {
  227.         $this->reset $reset;
  228.         return $this;
  229.     }
  230.     public function __toString(): string
  231.     {
  232.         return $this->name ' ' $this->lastname;
  233.     }
  234.     public function getSexe(): ?string
  235.     {
  236.         return $this->sexe;
  237.     }
  238.     public function setSexe(?string $sexe): static
  239.     {
  240.         $this->sexe $sexe;
  241.         return $this;
  242.     }
  243.     public function getPhone(): ?string
  244.     {
  245.         return $this->phone;
  246.     }
  247.     public function setPhone(?string $phone): static
  248.     {
  249.         $this->phone $phone;
  250.         return $this;
  251.     }
  252.     public function getPicture(): ?string
  253.     {
  254.         return $this->picture;
  255.     }
  256.     public function setPicture(?string $picture): static
  257.     {
  258.         $this->picture $picture;
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection<int, Location>
  263.      */
  264.     public function getLocations(): Collection
  265.     {
  266.         return $this->locations;
  267.     }
  268.     public function addLocation(Location $location): static
  269.     {
  270.         if (!$this->locations->contains($location)) {
  271.             $this->locations->add($location);
  272.             $location->setCreatedBy($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeLocation(Location $location): static
  277.     {
  278.         if ($this->locations->removeElement($location)) {
  279.             // set the owning side to null (unless already changed)
  280.             if ($location->getCreatedBy() === $this) {
  281.                 $location->setCreatedBy(null);
  282.             }
  283.         }
  284.         return $this;
  285.     }
  286.     public function getEntreprise(): ?Entreprise
  287.     {
  288.         return $this->entreprise;
  289.     }
  290.     public function setEntreprise(?Entreprise $entreprise): static
  291.     {
  292.         $this->entreprise $entreprise;
  293.         return $this;
  294.     }
  295.     public function getCreatedBy(): ?self
  296.     {
  297.         return $this->createdBy;
  298.     }
  299.     public function setCreatedBy(?self $createdBy): static
  300.     {
  301.         $this->createdBy $createdBy;
  302.         return $this;
  303.     }
  304.     /**
  305.      * @return Collection<int, self>
  306.      */
  307.     public function getUsers(): Collection
  308.     {
  309.         return $this->users;
  310.     }
  311.     public function addUser(self $user): static
  312.     {
  313.         if (!$this->users->contains($user)) {
  314.             $this->users->add($user);
  315.             $user->setCreatedBy($this);
  316.         }
  317.         return $this;
  318.     }
  319.     public function removeUser(self $user): static
  320.     {
  321.         if ($this->users->removeElement($user)) {
  322.             // set the owning side to null (unless already changed)
  323.             if ($user->getCreatedBy() === $this) {
  324.                 $user->setCreatedBy(null);
  325.             }
  326.         }
  327.         return $this;
  328.     }
  329.     public function isNotif(): ?bool
  330.     {
  331.         return $this->notif;
  332.     }
  333.     public function setNotif(?bool $notif): static
  334.     {
  335.         $this->notif $notif;
  336.         return $this;
  337.     }
  338.     public function getEmail(): ?string
  339.     {
  340.         return $this->email;
  341.     }
  342.     public function setEmail(?string $email): static
  343.     {
  344.         $this->email $email;
  345.         return $this;
  346.     }
  347.     public function getProfil(): ?string
  348.     {
  349.         return $this->profil;
  350.     }
  351.     public function setProfil(?string $profil): static
  352.     {
  353.         $this->profil $profil;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return Collection<int, Country>
  358.      */
  359.     public function getCountries(): Collection
  360.     {
  361.         return $this->countries;
  362.     }
  363.     public function addCountry(Country $country): static
  364.     {
  365.         if (!$this->countries->contains($country)) {
  366.             $this->countries->add($country);
  367.             $country->setCreatedBy($this);
  368.         }
  369.         return $this;
  370.     }
  371.     public function removeCountry(Country $country): static
  372.     {
  373.         if ($this->countries->removeElement($country)) {
  374.             // set the owning side to null (unless already changed)
  375.             if ($country->getCreatedBy() === $this) {
  376.                 $country->setCreatedBy(null);
  377.             }
  378.         }
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return Collection<int, Log>
  383.      */
  384.     public function getLogs(): Collection
  385.     {
  386.         return $this->logs;
  387.     }
  388.     public function addLog(Log $log): static
  389.     {
  390.         if (!$this->logs->contains($log)) {
  391.             $this->logs->add($log);
  392.             $log->setCreatedBy($this);
  393.         }
  394.         return $this;
  395.     }
  396.     public function removeLog(Log $log): static
  397.     {
  398.         if ($this->logs->removeElement($log)) {
  399.             // set the owning side to null (unless already changed)
  400.             if ($log->getCreatedBy() === $this) {
  401.                 $log->setCreatedBy(null);
  402.             }
  403.         }
  404.         return $this;
  405.     }
  406.     /**
  407.      * @return Collection<int, Template>
  408.      */
  409.     public function getTemplates(): Collection
  410.     {
  411.         return $this->templates;
  412.     }
  413.     public function addTemplate(Template $template): static
  414.     {
  415.         if (!$this->templates->contains($template)) {
  416.             $this->templates->add($template);
  417.             $template->setCreatedBy($this);
  418.         }
  419.         return $this;
  420.     }
  421.     public function removeTemplate(Template $template): static
  422.     {
  423.         if ($this->templates->removeElement($template)) {
  424.             // set the owning side to null (unless already changed)
  425.             if ($template->getCreatedBy() === $this) {
  426.                 $template->setCreatedBy(null);
  427.             }
  428.         }
  429.         return $this;
  430.     }
  431.     public function getLevel(): ?int
  432.     {
  433.         return $this->level;
  434.     }
  435.     public function setLevel(?int $level): static
  436.     {
  437.         $this->level $level;
  438.         return $this;
  439.     }
  440.     /**
  441.      * @return Collection<int, Incident>
  442.      */
  443.     public function getIncidents(): Collection
  444.     {
  445.         return $this->incidents;
  446.     }
  447.     public function addIncident(Incident $incident): static
  448.     {
  449.         if (!$this->incidents->contains($incident)) {
  450.             $this->incidents->add($incident);
  451.             $incident->setCreatedBy($this);
  452.         }
  453.         return $this;
  454.     }
  455.     public function removeIncident(Incident $incident): static
  456.     {
  457.         if ($this->incidents->removeElement($incident)) {
  458.             // set the owning side to null (unless already changed)
  459.             if ($incident->getCreatedBy() === $this) {
  460.                 $incident->setCreatedBy(null);
  461.             }
  462.         }
  463.         return $this;
  464.     }
  465.     /**
  466.      * @return Collection<int, IncidentUpdate>
  467.      */
  468.     public function getIncidentUpdates(): Collection
  469.     {
  470.         return $this->incidentUpdates;
  471.     }
  472.     public function addIncidentUpdate(IncidentUpdate $incidentUpdate): static
  473.     {
  474.         if (!$this->incidentUpdates->contains($incidentUpdate)) {
  475.             $this->incidentUpdates->add($incidentUpdate);
  476.             $incidentUpdate->setCreatedBy($this);
  477.         }
  478.         return $this;
  479.     }
  480.     public function removeIncidentUpdate(IncidentUpdate $incidentUpdate): static
  481.     {
  482.         if ($this->incidentUpdates->removeElement($incidentUpdate)) {
  483.             // set the owning side to null (unless already changed)
  484.             if ($incidentUpdate->getCreatedBy() === $this) {
  485.                 $incidentUpdate->setCreatedBy(null);
  486.             }
  487.         }
  488.         return $this;
  489.     }
  490.     /**
  491.      * @return Collection<int, Service>
  492.      */
  493.     public function getServices(): Collection
  494.     {
  495.         return $this->services;
  496.     }
  497.     public function addService(Service $service): static
  498.     {
  499.         if (!$this->services->contains($service)) {
  500.             $this->services->add($service);
  501.             $service->setCreatedBy($this);
  502.         }
  503.         return $this;
  504.     }
  505.     public function removeService(Service $service): static
  506.     {
  507.         if ($this->services->removeElement($service)) {
  508.             // set the owning side to null (unless already changed)
  509.             if ($service->getCreatedBy() === $this) {
  510.                 $service->setCreatedBy(null);
  511.             }
  512.         }
  513.         return $this;
  514.     }
  515.     public function getAdress(): ?string
  516.     {
  517.         return $this->adress;
  518.     }
  519.     public function setAdress(?string $adress): static
  520.     {
  521.         $this->adress $adress;
  522.         return $this;
  523.     }
  524.     public function getCity(): ?string
  525.     {
  526.         return $this->city;
  527.     }
  528.     public function setCity(?string $city): static
  529.     {
  530.         $this->city $city;
  531.         return $this;
  532.     }
  533.     public function getProvince(): ?string
  534.     {
  535.         return $this->province;
  536.     }
  537.     public function setProvince(?string $province): static
  538.     {
  539.         $this->province $province;
  540.         return $this;
  541.     }
  542.     public function getCountry(): ?Country
  543.     {
  544.         return $this->country;
  545.     }
  546.     public function setCountry(?Country $country): static
  547.     {
  548.         $this->country $country;
  549.         return $this;
  550.     }
  551.     /**
  552.      * @return Collection<int, Announcement>
  553.      */
  554.     public function getAnnouncements(): Collection
  555.     {
  556.         return $this->announcements;
  557.     }
  558.     public function addAnnouncement(Announcement $announcement): static
  559.     {
  560.         if (!$this->announcements->contains($announcement)) {
  561.             $this->announcements->add($announcement);
  562.             $announcement->addUser($this);
  563.         }
  564.         return $this;
  565.     }
  566.     public function removeAnnouncement(Announcement $announcement): static
  567.     {
  568.         if ($this->announcements->removeElement($announcement)) {
  569.             $announcement->removeUser($this);
  570.         }
  571.         return $this;
  572.     }
  573.     public function getMode(): ?string
  574.     {
  575.         return $this->mode;
  576.     }
  577.     public function setMode(?string $mode): static
  578.     {
  579.         $this->mode $mode;
  580.         return $this;
  581.     }
  582.     public function getLastAction(): ?\DateTimeInterface
  583.     {
  584.         return $this->lastAction;
  585.     }
  586.     public function setLastAction(?\DateTimeInterface $lastAction): static
  587.     {
  588.         $this->lastAction $lastAction;
  589.         return $this;
  590.     }
  591.     /**
  592.      * @return Collection<int, Reservation>
  593.      */
  594.     public function getReservations(): Collection
  595.     {
  596.         return $this->reservations;
  597.     }
  598.     public function addReservation(Reservation $reservation): static
  599.     {
  600.         if (!$this->reservations->contains($reservation)) {
  601.             $this->reservations->add($reservation);
  602.             $reservation->setCreatedBy($this);
  603.         }
  604.         return $this;
  605.     }
  606.     public function removeReservation(Reservation $reservation): static
  607.     {
  608.         if ($this->reservations->removeElement($reservation)) {
  609.             // set the owning side to null (unless already changed)
  610.             if ($reservation->getCreatedBy() === $this) {
  611.                 $reservation->setCreatedBy(null);
  612.             }
  613.         }
  614.         return $this;
  615.     }
  616.     /**
  617.      * @return Collection<int, UserEntreprise>
  618.      */
  619.     public function getUserEntreprises(): Collection
  620.     {
  621.         return $this->userEntreprises;
  622.     }
  623.     public function addUserEntreprise(UserEntreprise $userEntreprise): static
  624.     {
  625.         if (!$this->userEntreprises->contains($userEntreprise)) {
  626.             $this->userEntreprises->add($userEntreprise);
  627.             $userEntreprise->setUser($this);
  628.         }
  629.         return $this;
  630.     }
  631.     public function removeUserEntreprise(UserEntreprise $userEntreprise): static
  632.     {
  633.         if ($this->userEntreprises->removeElement($userEntreprise)) {
  634.             // set the owning side to null (unless already changed)
  635.             if ($userEntreprise->getUser() === $this) {
  636.                 $userEntreprise->setUser(null);
  637.             }
  638.         }
  639.         return $this;
  640.     }
  641.     /**
  642.      * @return Collection<int, Entreprise>
  643.      */
  644.     public function getEntreprises(): Collection
  645.     {
  646.         return $this->entreprises;
  647.     }
  648.     public function addEntreprise(Entreprise $entreprise): static
  649.     {
  650.         if (!$this->entreprises->contains($entreprise)) {
  651.             $this->entreprises->add($entreprise);
  652.             $entreprise->setOwner($this);
  653.         }
  654.         return $this;
  655.     }
  656.     public function removeEntreprise(Entreprise $entreprise): static
  657.     {
  658.         if ($this->entreprises->removeElement($entreprise)) {
  659.             // set the owning side to null (unless already changed)
  660.             if ($entreprise->getOwner() === $this) {
  661.                 $entreprise->setOwner(null);
  662.             }
  663.         }
  664.         return $this;
  665.     }
  666. }