src/Entity/User.php line 18

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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`user`')]
  14. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     private $id;
  21.     #[ORM\Column(type'string'length180uniquetrue)]
  22.     private $email;
  23.     #[ORM\Column(type'json')]
  24.     private $roles = [];
  25.     #[ORM\Column(type'string'nullabletrue)]
  26.     private $password;
  27.     #[ORM\Column(type'string'length255)]
  28.     private $nom;
  29.     #[ORM\Column(type'string'length255)]
  30.     private $prenom;
  31.     #[ORM\Column(type'string'length255nullabletrue)]
  32.     private $telephone;
  33.     #[ORM\Column(type'date'nullabletrue)]
  34.     private $arrivee;
  35.     #[ORM\Column(type'date'nullabletrue)]
  36.     private $depart;
  37.     #[ORM\Column(type'boolean'nullabletrue)]
  38.     private $enabled=true;
  39.     #[ORM\ManyToOne(targetEntityPtf::class, inversedBy'users')]
  40.     private $ptf;
  41.     #[ORM\ManyToOne(targetEntityPoste::class, inversedBy'users')]
  42.     private $poste;
  43.     #[Gedmo\Timestampable(on'create')]
  44.     #[ORM\Column(type'datetime')]
  45.     private $created_at;
  46.     #[Gedmo\Timestampable(on'update')]
  47.     #[ORM\Column(type'datetime')]
  48.     private $updated_at;
  49.     #[ORM\Column(type'integer')]
  50.     private $created_by;
  51.     #[ORM\Column(type'integer')]
  52.     private $updated_by;
  53.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  54.     private ?string $file 'avatars/null.png';
  55.     #[ORM\Column]
  56.     private ?bool $changepwd true;
  57.     #[ORM\Column]
  58.     private ?bool $resetpwd true;
  59.     #[ORM\OneToMany(mappedBy'user'targetEntityCommentaire::class)]
  60.     private Collection $commentaires;
  61.     #[ORM\OneToMany(mappedBy'user'targetEntityGroupe::class)]
  62.     private Collection $groupes;
  63.     public function __construct()
  64.     {
  65.         $this->commentaires = new ArrayCollection();
  66.         $this->groupes = new ArrayCollection();
  67.     }
  68.     public function __toString()
  69.     {
  70.         return $this->getPrenom()." ".$this->getNom();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getEmail(): ?string
  77.     {
  78.         return $this->email;
  79.     }
  80.     public function setEmail(string $email): self
  81.     {
  82.         $this->email $email;
  83.         return $this;
  84.     }
  85.     /**
  86.      * A visual identifier that represents this user.
  87.      *
  88.      * @see UserInterface
  89.      */
  90.     public function getUserIdentifier(): string
  91.     {
  92.         return (string) $this->email;
  93.     }
  94.     /**
  95.      * @see UserInterface
  96.      */
  97.     public function getRoles(): array
  98.     {
  99.         $roles $this->roles;
  100.         // guarantee every user at least has ROLE_USER
  101.         $roles[] = 'ROLE_USER';
  102.         return array_unique($roles);
  103.     }
  104.     public function setRoles(array $roles): self
  105.     {
  106.         $this->roles $roles;
  107.         return $this;
  108.     }
  109.     public function hasRole($role)
  110.     {
  111.         return in_array($role$this->getRoles(), true);
  112.     }
  113.     public function addRole($role)
  114.     {
  115.         if (!in_array($role$this->rolestrue)) {
  116.             $this->roles[] = $role;
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeRole($role)
  121.     {
  122.         if (false !== $key array_search($role$this->rolestrue)) {
  123.             unset($this->roles[$key]);
  124.             $this->roles array_values($this->roles);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeAllRole(): self
  129.     {
  130.         foreach ($this->roles as $role) {
  131.             $this->removeRole($role);
  132.         }
  133.         return $this;
  134.     }
  135.     /**
  136.      * @see PasswordAuthenticatedUserInterface
  137.      */
  138.     public function getPassword(): string
  139.     {
  140.         return $this->password;
  141.     }
  142.     public function setPassword(string $password): self
  143.     {
  144.         $this->password $password;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @see UserInterface
  149.      */
  150.     public function eraseCredentials()
  151.     {
  152.         // If you store any temporary, sensitive data on the user, clear it here
  153.         // $this->plainPassword = null;
  154.     }
  155.     public function getNom(): ?string
  156.     {
  157.         return $this->nom;
  158.     }
  159.     public function setNom(string $nom): self
  160.     {
  161.         $this->nom $nom;
  162.         return $this;
  163.     }
  164.     public function getPrenom(): ?string
  165.     {
  166.         return $this->prenom;
  167.     }
  168.     public function setPrenom(string $prenom): self
  169.     {
  170.         $this->prenom $prenom;
  171.         return $this;
  172.     }
  173.     public function getTelephone(): ?string
  174.     {
  175.         return $this->telephone;
  176.     }
  177.     public function setTelephone(?string $telephone): self
  178.     {
  179.         $this->telephone $telephone;
  180.         return $this;
  181.     }
  182.     public function getArrivee(): ?\DateTimeInterface
  183.     {
  184.         return $this->arrivee;
  185.     }
  186.     public function setArrivee(?\DateTimeInterface $arrivee): self
  187.     {
  188.         $this->arrivee $arrivee;
  189.         return $this;
  190.     }
  191.     public function getDepart(): ?\DateTimeInterface
  192.     {
  193.         return $this->depart;
  194.     }
  195.     public function setDepart(?\DateTimeInterface $depart): self
  196.     {
  197.         $this->depart $depart;
  198.         return $this;
  199.     }
  200.     public function isEnabled(): ?bool
  201.     {
  202.         return $this->enabled;
  203.     }
  204.     public function setEnabled(?bool $enabled): self
  205.     {
  206.         $this->enabled $enabled;
  207.         return $this;
  208.     }
  209.     public function getPtf(): ?Ptf
  210.     {
  211.         return $this->ptf;
  212.     }
  213.     public function setPtf(?Ptf $ptf): self
  214.     {
  215.         $this->ptf $ptf;
  216.         return $this;
  217.     }
  218.     public function getPoste(): ?Poste
  219.     {
  220.         return $this->poste;
  221.     }
  222.     public function setPoste(?Poste $poste): self
  223.     {
  224.         $this->poste $poste;
  225.         return $this;
  226.     }
  227.     public function getCreatedAt(): ?\DateTimeInterface
  228.     {
  229.         return $this->created_at;
  230.     }
  231.     public function setCreatedAt(\DateTimeInterface $created_at): self
  232.     {
  233.         $this->created_at $created_at;
  234.         return $this;
  235.     }
  236.     public function getUpdatedAt(): ?\DateTimeInterface
  237.     {
  238.         return $this->updated_at;
  239.     }
  240.     public function setUpdatedAt(\DateTimeInterface $updated_at): self
  241.     {
  242.         $this->updated_at $updated_at;
  243.         return $this;
  244.     }
  245.     public function getCreatedBy(): ?int
  246.     {
  247.         return $this->created_by;
  248.     }
  249.     public function setCreatedBy(int $created_by): self
  250.     {
  251.         $this->created_by $created_by;
  252.         return $this;
  253.     }
  254.     public function getUpdatedBy(): ?int
  255.     {
  256.         return $this->updated_by;
  257.     }
  258.     public function setUpdatedBy(int $updated_by): self
  259.     {
  260.         $this->updated_by $updated_by;
  261.         return $this;
  262.     }
  263.     public function getFile(): ?string
  264.     {
  265.         return $this->file;
  266.     }
  267.     public function setFile(?string $file): self
  268.     {
  269.         $this->file $file;
  270.         return $this;
  271.     }
  272.     public function isChangepwd(): ?bool
  273.     {
  274.         return $this->changepwd;
  275.     }
  276.     public function setChangepwd(bool $changepwd): self
  277.     {
  278.         $this->changepwd $changepwd;
  279.         return $this;
  280.     }
  281.     public function isResetpwd(): ?bool
  282.     {
  283.         return $this->resetpwd;
  284.     }
  285.     public function setResetpwd(bool $resetpwd): self
  286.     {
  287.         $this->resetpwd $resetpwd;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return Collection<int, Commentaire>
  292.      */
  293.     public function getCommentaires(): Collection
  294.     {
  295.         return $this->commentaires;
  296.     }
  297.     public function addCommentaire(Commentaire $commentaire): self
  298.     {
  299.         if (!$this->commentaires->contains($commentaire)) {
  300.             $this->commentaires->add($commentaire);
  301.             $commentaire->setUser($this);
  302.         }
  303.         return $this;
  304.     }
  305.     public function removeCommentaire(Commentaire $commentaire): self
  306.     {
  307.         if ($this->commentaires->removeElement($commentaire)) {
  308.             // set the owning side to null (unless already changed)
  309.             if ($commentaire->getUser() === $this) {
  310.                 $commentaire->setUser(null);
  311.             }
  312.         }
  313.         return $this;
  314.     }
  315.     /**
  316.      * @return Collection<int, Groupe>
  317.      */
  318.     public function getGroupes(): Collection
  319.     {
  320.         return $this->groupes;
  321.     }
  322.     public function addGroupe(Groupe $groupe): self
  323.     {
  324.         if (!$this->groupes->contains($groupe)) {
  325.             $this->groupes->add($groupe);
  326.             $groupe->setUser($this);
  327.         }
  328.         return $this;
  329.     }
  330.     public function removeGroupe(Groupe $groupe): self
  331.     {
  332.         if ($this->groupes->removeElement($groupe)) {
  333.             // set the owning side to null (unless already changed)
  334.             if ($groupe->getUser() === $this) {
  335.                 $groupe->setUser(null);
  336.             }
  337.         }
  338.         return $this;
  339.     }
  340. }