src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Pointage\HeureAgent;
  4. use App\Entity\Pointage\Pointage;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $username;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $nom;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $prenom;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $email;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=HeureAgent::class, mappedBy="agent")
  49.      */
  50.     private $heureAgents;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=Pointage::class, mappedBy="agent")
  53.      */
  54.     private $pointages;
  55.     public function __toString()
  56.     {
  57.         return $this->nom " " $this->prenom;
  58.     }
  59.     public function __construct()
  60.     {
  61.         $this->heureAgents = new ArrayCollection();
  62.         $this->pointages = new ArrayCollection();
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     /**
  69.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  70.      */
  71.     public function getUsername(): string
  72.     {
  73.         return (string) $this->username;
  74.     }
  75.     public function setUsername(string $username): self
  76.     {
  77.         $this->username $username;
  78.         return $this;
  79.     }
  80.     /**
  81.      * A visual identifier that represents this user.
  82.      *
  83.      * @see UserInterface
  84.      */
  85.     public function getUserIdentifier(): string
  86.     {
  87.         return (string) $this->username;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function getRoles(): array
  93.     {
  94.         $roles $this->roles;
  95.         // guarantee every user at least has ROLE_USER
  96.         $roles[] = 'ROLE_USER';
  97.         return array_unique($roles);
  98.     }
  99.     public function setRoles(array $roles): self
  100.     {
  101.         $this->roles $roles;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @see PasswordAuthenticatedUserInterface
  106.      */
  107.     public function getPassword(): string
  108.     {
  109.         return $this->password;
  110.     }
  111.     public function setPassword(string $password): self
  112.     {
  113.         $this->password $password;
  114.         return $this;
  115.     }
  116.     /**
  117.      * Returning a salt is only needed, if you are not using a modern
  118.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  119.      *
  120.      * @see UserInterface
  121.      */
  122.     public function getSalt(): ?string
  123.     {
  124.         return null;
  125.     }
  126.     /**
  127.      * @see UserInterface
  128.      */
  129.     public function eraseCredentials()
  130.     {
  131.         // If you store any temporary, sensitive data on the user, clear it here
  132.         // $this->plainPassword = null;
  133.     }
  134.     public function getNom(): ?string
  135.     {
  136.         return $this->nom;
  137.     }
  138.     public function setNom(?string $nom): self
  139.     {
  140.         $this->nom $nom;
  141.         return $this;
  142.     }
  143.     public function getPrenom(): ?string
  144.     {
  145.         return $this->prenom;
  146.     }
  147.     public function setPrenom(?string $prenom): self
  148.     {
  149.         $this->prenom $prenom;
  150.         return $this;
  151.     }
  152.     public function getEmail(): ?string
  153.     {
  154.         return $this->email;
  155.     }
  156.     public function setEmail(?string $email): self
  157.     {
  158.         $this->email $email;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return Collection<int, HeureAgent>
  163.      */
  164.     public function getHeureAgents(): Collection
  165.     {
  166.         return $this->heureAgents;
  167.     }
  168.     public function addHeureAgent(HeureAgent $heureAgent): self
  169.     {
  170.         if (!$this->heureAgents->contains($heureAgent)) {
  171.             $this->heureAgents[] = $heureAgent;
  172.             $heureAgent->setAgent($this);
  173.         }
  174.         return $this;
  175.     }
  176.     public function removeHeureAgent(HeureAgent $heureAgent): self
  177.     {
  178.         if ($this->heureAgents->removeElement($heureAgent)) {
  179.             // set the owning side to null (unless already changed)
  180.             if ($heureAgent->getAgent() === $this) {
  181.                 $heureAgent->setAgent(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection<int, Pointage>
  188.      */
  189.     public function getPointages(): Collection
  190.     {
  191.         return $this->pointages;
  192.     }
  193.     public function addPointage(Pointage $pointage): self
  194.     {
  195.         if (!$this->pointages->contains($pointage)) {
  196.             $this->pointages[] = $pointage;
  197.             $pointage->setAgent($this);
  198.         }
  199.         return $this;
  200.     }
  201.     public function removePointage(Pointage $pointage): self
  202.     {
  203.         if ($this->pointages->removeElement($pointage)) {
  204.             // set the owning side to null (unless already changed)
  205.             if ($pointage->getAgent() === $this) {
  206.                 $pointage->setAgent(null);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211. }