src/Entity/User.php line 17

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[UniqueEntity('email'message"Cet e-mail existe déja")]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     #[Groups(["getTimes""getReservation"])]
  20.     private ?int $id null;
  21.     #[ORM\Column(length180uniquetrue)]
  22.     #[Groups(["getTimes"])]
  23.     #[Assert\NotBlank]
  24.     #[Assert\Email]
  25.     private ?string $email null;
  26.     #[ORM\Column]
  27.     private array $roles = [];
  28.     #[ORM\Column]
  29.     private ?string $password null;
  30.     #[ORM\Column(length45)]
  31.     #[Groups(["getTimes""getReservation"])]
  32.     #[Assert\NotBlank]
  33.     #[Assert\Length(min2max45)]
  34.     private ?string $firstName null;
  35.     #[ORM\Column(length45)]
  36.     #[Groups(["getTimes""getReservation"])]
  37.     #[Assert\NotBlank]
  38.     private ?string $lastName null;
  39.     #[ORM\Column]
  40.     #[Groups(["getTimes"])]
  41.     private ?\DateTimeImmutable $createdAt null;
  42.     #[ORM\ManyToMany(targetEntityProject::class, inversedBy'users')]
  43.     private Collection $projects;
  44.     #[ORM\ManyToMany(targetEntityClient::class, inversedBy'users')]
  45.     private Collection $clients;
  46.     #[ORM\OneToMany(mappedBy'employee'targetEntityReservation::class)]
  47.     private Collection $reservation;
  48.     #[ORM\OneToMany(mappedBy'employee'targetEntityAbsence::class, orphanRemovaltrue)]
  49.     private Collection $absences;
  50.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  51.     private bool $archived false;
  52.     
  53.     public function __construct()
  54.     {
  55.         $this->projects = new ArrayCollection();
  56.         $this->clients = new ArrayCollection();
  57.         $this->reservation = new ArrayCollection();
  58.         $this->absences = new ArrayCollection();
  59.     }
  60.     public function __toString(): string
  61.     {
  62.         return $this->firstName ' ' $this->lastName;
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getEmail(): ?string
  69.     {
  70.         return $this->email;
  71.     }
  72.     public function setEmail(string $email): self
  73.     {
  74.         $this->email $email;
  75.         return $this;
  76.     }
  77.     /**
  78.      * A visual identifier that represents this user.
  79.      *
  80.      * @see UserInterface
  81.      */
  82.     public function getUserIdentifier(): string
  83.     {
  84.         return (string)$this->email;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function getRoles(): array
  90.     {
  91.         $roles $this->roles;
  92.         // guarantee every user at least has ROLE_USER
  93.         $roles[] = 'ROLE_USER';
  94.         return array_unique($roles);
  95.     }
  96.     public function setRoles(array $roles): self
  97.     {
  98.         $this->roles $roles;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @see PasswordAuthenticatedUserInterface
  103.      */
  104.     public function getPassword(): string
  105.     {
  106.         return $this->password;
  107.     }
  108.     public function setPassword(string $password): self
  109.     {
  110.         $this->password $password;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @see UserInterface
  115.      */
  116.     public function eraseCredentials()
  117.     {
  118.         // If you store any temporary, sensitive data on the user, clear it here
  119.         // $this->plainPassword = null;
  120.     }
  121.     public function getFirstName(): ?string
  122.     {
  123.         return $this->firstName;
  124.     }
  125.     public function setFirstName(string $firstName): self
  126.     {
  127.         $this->firstName $firstName;
  128.         return $this;
  129.     }
  130.     public function getLastName(): ?string
  131.     {
  132.         return $this->lastName;
  133.     }
  134.     public function setLastName(string $lastName): self
  135.     {
  136.         $this->lastName $lastName;
  137.         return $this;
  138.     }
  139.     public function getCreatedAt(): ?\DateTimeImmutable
  140.     {
  141.         return $this->createdAt;
  142.     }
  143.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  144.     {
  145.         $this->createdAt $createdAt;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, Project>
  150.      */
  151.     public function getProjects(): Collection
  152.     {
  153.         return $this->projects;
  154.     }
  155.     public function addProject(Project $project): self
  156.     {
  157.         if (!$this->projects->contains($project)) {
  158.             $this->projects->add($project);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeProject(Project $project): self
  163.     {
  164.         $this->projects->removeElement($project);
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection<int, Client>
  169.      */
  170.     public function getClient(): Collection
  171.     {
  172.         return $this->clients;
  173.     }
  174.     public function addClient(Client $client): self
  175.     {
  176.         if (!$this->clients->contains($client)) {
  177.             $this->clients->add($client);
  178.         }
  179.         return $this;
  180.     }
  181.     public function removeClient(Client $client): self
  182.     {
  183.         $this->clients->removeElement($client);
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection<int, Reservation>
  188.      */
  189.     public function getReservation(): Collection
  190.     {
  191.         return $this->reservation;
  192.     }
  193.     public function addReservation(Reservation $reservation): self
  194.     {
  195.         if (!$this->reservation->contains($reservation)) {
  196.             $this->reservation->add($reservation);
  197.             $reservation->setEmployee($this);
  198.         }
  199.         return $this;
  200.     }
  201.     public function removeReservation(Reservation $reservation): self
  202.     {
  203.         if ($this->reservation->removeElement($reservation)) {
  204.             // set the owning side to null (unless already changed)
  205.             if ($reservation->getEmployee() === $this) {
  206.                 $reservation->setEmployee(null);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Collection<int, Absence>
  213.      */
  214.     public function getAbsences(): Collection
  215.     {
  216.         return $this->absences;
  217.     }
  218.     public function addAbsence(Absence $absence): self
  219.     {
  220.         if (!$this->absences->contains($absence)) {
  221.             $this->absences->add($absence);
  222.             $absence->setEmployee($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeAbsence(Absence $absence): self
  227.     {
  228.         if ($this->absences->removeElement($absence)) {
  229.             // set the owning side to null (unless already changed)
  230.             if ($absence->getEmployee() === $this) {
  231.                 $absence->setEmployee(null);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236.     public function getFullName(): string
  237.     {
  238.         return $this->firstName ' ' $this->lastName;
  239.     }
  240.     public function isArchived(): ?bool
  241.     {
  242.         return $this->archived;
  243.     }
  244.     public function setArchived(bool $archived): static
  245.     {
  246.         $this->archived $archived;
  247.         return $this;
  248.     }
  249. }