src/Entity/User.php line 21

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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  *  @UniqueEntity(
  14.  *      fields={"email"},
  15.  *      message="Ce mail est déjà utilisé."
  16.  * )
  17.  * @UniqueEntity(fields={"telephone"},message="Ce téléphone est déjà utilisé." )
  18.  */
  19. class User implements UserInterfacePasswordAuthenticatedUserInterface
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=180, unique=true)
  29.      * @Assert\Email(message = "L'email '{{ value }}' n'est pas valide.")
  30.      */
  31.     private $email;
  32.     /**
  33.      * @ORM\Column(type="json")
  34.      */
  35.     private $roles = [];
  36.     /**
  37.      * @var string The hashed password
  38.      * @ORM\Column(type="string")
  39.      */
  40.     private $password;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=Role::class, inversedBy="users")
  43.      * @ORM\JoinColumn(nullable=false)
  44.      */
  45.     private $role;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=Site::class, inversedBy="users")
  48.      * @ORM\JoinColumn(nullable=true)
  49.      */
  50.     private $site;
  51.     /**
  52.      * @ORM\Column(type="string", length=255)
  53.      */
  54.     private $lastname;
  55.     /**
  56.      * @ORM\Column(type="string", length=255)
  57.      */
  58.     private $firstname;
  59.     /**
  60.      * @ORM\Column(type="string", length=15, nullable=true)
  61.      * @Assert\Length(min=8,minMessage = "La taille minimum doit être de {{ limit }} caractères")
  62.      */
  63.     private $telephone;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Task::class, mappedBy="executant")
  66.      */
  67.     private $tasks;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=Task::class, mappedBy="createdby")
  70.      */
  71.     private $tasksemit;
  72.     
  73.     /**
  74.      * @ORM\Column(type="boolean",nullable=true)
  75.     */
  76.     private $firstconnexion;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=DemandeByCanal::class, mappedBy="executant")
  79.      */
  80.     private $demandeByCanals;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=DemandePro::class, mappedBy="executant")
  83.      */
  84.     private $demandePros;
  85.     
  86.     public function __construct()
  87.     {
  88.         $this->tasks = new ArrayCollection();
  89.         $this->tasksemit = new ArrayCollection();
  90.       //  $this->demandeByCanals = new ArrayCollection();
  91.       $this->demandePros = new ArrayCollection();
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getEmail(): ?string
  98.     {
  99.         return $this->email;
  100.     }
  101.     public function setEmail(string $email): self
  102.     {
  103.         $this->email $email;
  104.         return $this;
  105.     }
  106.     /**
  107.      * A visual identifier that represents this user.
  108.      *
  109.      * @see UserInterface
  110.      */
  111.     public function getUserIdentifier(): string
  112.     {
  113.         return (string) $this->email;
  114.     }
  115.     /**
  116.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  117.      */
  118.     public function getUsername(): string
  119.     {
  120.         return (string) $this->email;
  121.     }
  122.     /**
  123.      * @see UserInterface
  124.      */
  125.     public function getRoles(): array
  126.     {
  127.         $roles $this->roles;
  128.         // guarantee every user at least has ROLE_USER
  129.         $roles[] = 'ROLE_USER';
  130.         return array_unique($roles);
  131.     }
  132.     public function setRoles(array $roles): self
  133.     {
  134.         $this->roles $roles;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @see PasswordAuthenticatedUserInterface
  139.      */
  140.     public function getPassword(): string
  141.     {
  142.         return $this->password;
  143.     }
  144.     public function setPassword(string $password): self
  145.     {
  146.         $this->password $password;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Returning a salt is only needed, if you are not using a modern
  151.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  152.      *
  153.      * @see UserInterface
  154.      */
  155.     public function getSalt(): ?string
  156.     {
  157.         return null;
  158.     }
  159.     /**
  160.      * @see UserInterface
  161.      */
  162.     public function eraseCredentials()
  163.     {
  164.         // If you store any temporary, sensitive data on the user, clear it here
  165.         // $this->plainPassword = null;
  166.     }
  167.     public function getRole(): ?Role
  168.     {
  169.         return $this->role;
  170.     }
  171.     public function setRole(?Role $role): self
  172.     {
  173.         $this->role $role;
  174.         return $this;
  175.     }
  176.     public function getSite(): ?Site
  177.     {
  178.         return $this->site;
  179.     }
  180.     public function setSite(?Site $site): self
  181.     {
  182.         $this->site $site;
  183.         return $this;
  184.     }
  185.     public function getLastname(): ?string
  186.     {
  187.         return $this->lastname;
  188.     }
  189.     public function setLastname(string $lastname): self
  190.     {
  191.         $this->lastname $lastname;
  192.         return $this;
  193.     }
  194.     public function getFirstname(): ?string
  195.     {
  196.         return $this->firstname;
  197.     }
  198.     public function setFirstname(string $firstname): self
  199.     {
  200.         $this->firstname $firstname;
  201.         return $this;
  202.     }
  203.     public function getTelephone(): ?string
  204.     {
  205.         return $this->telephone;
  206.     }
  207.     public function setTelephone(?string $telephone): self
  208.     {
  209.         $this->telephone $telephone;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return Collection<int, Task>
  214.      */
  215.     public function getTasks(): Collection
  216.     {
  217.         return $this->tasks;
  218.     }
  219.     public function addTask(Task $task): self
  220.     {
  221.         if (!$this->tasks->contains($task)) {
  222.             $this->tasks[] = $task;
  223.             $task->setExecutant($this);
  224.         }
  225.         return $this;
  226.     }
  227.     public function removeTask(Task $task): self
  228.     {
  229.         if ($this->tasks->removeElement($task)) {
  230.             // set the owning side to null (unless already changed)
  231.             if ($task->getExecutant() === $this) {
  232.                 $task->setExecutant(null);
  233.             }
  234.         }
  235.         return $this;
  236.     }
  237.     /**
  238.      * @return Collection<int, Task>
  239.      */
  240.     public function getTasksemit(): Collection
  241.     {
  242.         return $this->tasksemit;
  243.     }
  244.     public function addTasksemit(Task $tasksemit): self
  245.     {
  246.         if (!$this->tasksemit->contains($tasksemit)) {
  247.             $this->tasksemit[] = $tasksemit;
  248.             $tasksemit->setCreatedby($this);
  249.         }
  250.         return $this;
  251.     }
  252.     public function removeTasksemit(Task $tasksemit): self
  253.     {
  254.         if ($this->tasksemit->removeElement($tasksemit)) {
  255.             // set the owning side to null (unless already changed)
  256.             if ($tasksemit->getCreatedby() === $this) {
  257.                 $tasksemit->setCreatedby(null);
  258.             }
  259.         }
  260.         return $this;
  261.     } 
  262.     public function getFirstconnexion(): ?bool
  263.     {
  264.         return $this->firstconnexion;
  265.     }
  266.     public function setFirstconnexion(bool $firstconnexion): self
  267.     {
  268.         $this->firstconnexion $firstconnexion;
  269.         return $this
  270.     }
  271.     /**
  272.      * @return Collection<int, DemandeByCanal>
  273.      */
  274.     public function getDemandeByCanals(): Collection
  275.     {
  276.         return $this->demandeByCanals;
  277.     }
  278.     public function addDemandeByCanal(DemandeByCanal $demandeByCanal): self
  279.     {
  280.         if (!$this->demandeByCanals->contains($demandeByCanal)) {
  281.             $this->demandeByCanals[] = $demandeByCanal;
  282.             $demandeByCanal->setExecutant($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeDemandeByCanal(DemandeByCanal $demandeByCanal): self
  287.     {
  288.         if ($this->demandeByCanals->removeElement($demandeByCanal)) {
  289.             // set the owning side to null (unless already changed)
  290.             if ($demandeByCanal->getExecutant() === $this) {
  291.                 $demandeByCanal->setExecutant(null);
  292.             }
  293.         }
  294.         return $this;
  295.     }
  296.     
  297.      /**
  298.      * @return Collection<int, DemandePro>
  299.      */
  300.     public function getDemandePros(): Collection
  301.     {
  302.         return $this->demandePros;
  303.     }
  304.     public function addDemandePro(DemandePro $demandePro): self
  305.     {
  306.         if (!$this->demandePros->contains($demandePro)) {
  307.             $this->demandePros[] = $demandePro;
  308.             $demandePro->setExecutant($this);
  309.         }
  310.         return $this;
  311.     }
  312.     public function removeDemandePro(DemandePro $demandePro): self
  313.     {
  314.         if ($this->demandePros->removeElement($demandePro)) {
  315.             // set the owning side to null (unless already changed)
  316.             if ($demandePro->getExecutant() === $this) {
  317.                 $demandePro->setExecutant(null);
  318.             }
  319.         }
  320.         return $this;
  321.     }