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