src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\EntityTrait;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  */
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     use EntityTrait{
  16.         EntityTrait::__construct as private __entityConstruct;
  17.     }
  18.     /**
  19.      * @ORM\Column(type="string", length=180, unique=true)
  20.      */
  21.     private $email;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $lastname;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $firstname 'bug';
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      */
  33.     private $phone;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $position_in_company;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $avatar;
  42.     /**
  43.      * @ORM\Column(type="json")
  44.      */
  45.     private $roles = [];
  46.     /**
  47.      * @var string The hashed password
  48.      * @ORM\Column(type="string")
  49.      */
  50.     private $password;
  51.     private $plain_password;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private $forgot_token;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $forgot_time;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=Customer::class, mappedBy="user")
  62.      */
  63.     private $customers;
  64.     /**
  65.      * @ORM\ManyToMany(targetEntity=Event::class, mappedBy="users")
  66.      */
  67.     private $events;
  68.     /**
  69.      * @ORM\Column(type="string", length=255)
  70.      */
  71.     private $agenda_color;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=UserGroup::class, inversedBy="users")
  74.      * @ORM\JoinColumn(nullable=false)
  75.      */
  76.     private $userGroup;
  77.     /**
  78.      * @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
  79.      */
  80.     private $binome;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=Chantier::class, mappedBy="user")
  83.      */
  84.     private $chantiers;
  85.     /**
  86.      * @ORM\ManyToMany(targetEntity=Chantier::class, mappedBy="user_worker")
  87.      */
  88.     private $worker_chantiers;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user")
  91.      */
  92.     private $comments;
  93.     public function __construct()
  94.     {
  95.         $this->__entityConstruct();
  96.         $this->customers = new ArrayCollection();
  97.         $this->events = new ArrayCollection();
  98.         $this->chantiers = new ArrayCollection();
  99.         $this->worker_chantiers = new ArrayCollection();
  100.         $this->comments = new ArrayCollection();
  101.     }
  102.     public function getEmail(): ?string
  103.     {
  104.         return $this->email;
  105.     }
  106.     public function setEmail(string $email): self
  107.     {
  108.         $this->email $email;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return mixed
  113.      */
  114.     public function getLastname()
  115.     {
  116.         return $this->lastname;
  117.     }
  118.     /**
  119.      * @param mixed $lastname
  120.      */
  121.     public function setLastname($lastname): void
  122.     {
  123.         $this->lastname $lastname;
  124.     }
  125.     /**
  126.      * @return mixed
  127.      */
  128.     public function getFirstname()
  129.     {
  130.         return $this->firstname;
  131.     }
  132.     /**
  133.      * @param mixed $firstname
  134.      */
  135.     public function setFirstname($firstname): void
  136.     {
  137.         $this->firstname $firstname;
  138.     }
  139.     /**
  140.      * @return mixed
  141.      */
  142.     public function getPhone()
  143.     {
  144.         return $this->phone;
  145.     }
  146.     /**
  147.      * @param mixed $phone
  148.      */
  149.     public function setPhone($phone): void
  150.     {
  151.         $this->phone $phone;
  152.     }
  153.     /**
  154.      * @return mixed
  155.      */
  156.     public function getPositionInCompany()
  157.     {
  158.         return $this->position_in_company;
  159.     }
  160.     /**
  161.      * @param mixed $position_in_company
  162.      */
  163.     public function setPositionInCompany($position_in_company): void
  164.     {
  165.         $this->position_in_company $position_in_company;
  166.     }
  167.     /**
  168.      * @return string|null
  169.      */
  170.     public function getAvatar(): ?string
  171.     {
  172.         return $this->avatar;
  173.     }
  174.     /**
  175.      * @param string $avatar
  176.      * @return $this
  177.      */
  178.     public function setAvatar(string $avatar): self
  179.     {
  180.         $this->avatar $avatar;
  181.         return $this;
  182.     }
  183.     /**
  184.      * A visual identifier that represents this user.
  185.      *
  186.      * @see UserInterface
  187.      */
  188.     public function getUserIdentifier(): string
  189.     {
  190.         return (string) $this->email;
  191.     }
  192.     /**
  193.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  194.      */
  195.     public function getUsername(): string
  196.     {
  197.         return (string) $this->email;
  198.     }
  199.     /**
  200.      * @see UserInterface
  201.      */
  202.     public function getRoles(): array
  203.     {
  204.         $roles $this->roles;
  205.         // guarantee every user at least has ROLE_USER
  206.         $roles[] = 'ROLE_USER';
  207.         // Administration ou Secrétariat
  208.         if($this->getUserGroup() != null){
  209.             switch ($this->getUserGroup()->getId()) {
  210.                 case 1:
  211.                     $roles[] = 'ROLE_ADMIN';
  212.                     $roles[] = 'ROLE_ADMINISTRATION';
  213.                     break;
  214.                 case :
  215.                     $roles[] = 'ROLE_ADMIN';
  216.                     $roles[] = 'ROLE_SECRETARIAT';
  217.                     break;
  218.                 case 5:
  219.                     $roles[] = 'ROLE_POSEUR';
  220.                     break;
  221.                 default:
  222.                     break;
  223.             }
  224.             //if (($this->getUserGroup()->getId() == 1 || $this->getUserGroup()->getId() == 2)) {
  225.             //    $roles[] = 'ROLE_ADMIN';
  226.             //    if($this->getUserGroup()->getId() == 1){
  227.             //        $roles[] = 'ROLE_ADMINISTRATION';
  228.             //    }else if($this->getUserGroup()->getId() == 2){
  229.             //        $roles[] = 'ROLE_SECRETARIAT';
  230.             //    }
  231.             //}
  232.         }
  233.         return array_unique($roles);
  234.     }
  235.     public function setRoles(array $roles): self
  236.     {
  237.         $this->roles $roles;
  238.         return $this;
  239.     }
  240.     /**
  241.      * @see PasswordAuthenticatedUserInterface
  242.      */
  243.     public function getPassword(): string
  244.     {
  245.         return $this->password;
  246.     }
  247.     public function setPassword(string $password): self
  248.     {
  249.         $this->password $password;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Returning a salt is only needed, if you are not using a modern
  254.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  255.      *
  256.      * @see UserInterface
  257.      */
  258.     public function getSalt(): ?string
  259.     {
  260.         return null;
  261.     }
  262.     /**
  263.      * @see UserInterface
  264.      */
  265.     public function eraseCredentials()
  266.     {
  267.         // If you store any temporary, sensitive data on the user, clear it here
  268.         // $this->plainPassword = null;
  269.     }
  270.     public function __toString(){
  271.         return $this->getFirstname().' '.$this->getLastname();
  272.     }
  273.     public function getFullName()
  274.     {
  275.         return $this->getFirstname().' '.$this->getLastname();
  276.     }
  277.     public function getForgotToken(): ?string
  278.     {
  279.         return $this->forgot_token;
  280.     }
  281.     public function setForgotToken(?string $forgot_token): self
  282.     {
  283.         $this->forgot_token $forgot_token;
  284.         return $this;
  285.     }
  286.     public function getForgotTime(): ?\DateTimeInterface
  287.     {
  288.         return $this->forgot_time;
  289.     }
  290.     public function setForgotTime(?\DateTimeInterface $forgot_time): self
  291.     {
  292.         $this->forgot_time $forgot_time;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection|Customer[]
  297.      */
  298.     public function getCustomers(): Collection
  299.     {
  300.         return $this->customers;
  301.     }
  302.     public function addCustomer(Customer $customer): self
  303.     {
  304.         if (!$this->customers->contains($customer)) {
  305.             $this->customers[] = $customer;
  306.             $customer->setUser($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeCustomer(Customer $customer): self
  311.     {
  312.         if ($this->customers->removeElement($customer)) {
  313.             // set the owning side to null (unless already changed)
  314.             if ($customer->getUser() === $this) {
  315.                 $customer->setUser(null);
  316.             }
  317.         }
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return Collection|Event[]
  322.      */
  323.     public function getEvents(): Collection
  324.     {
  325.         return $this->events;
  326.     }
  327.     public function addEvent(Event $event): self
  328.     {
  329.         if (!$this->events->contains($event)) {
  330.             $this->events[] = $event;
  331.             $event->addUser($this);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeEvent(Event $event): self
  336.     {
  337.         if ($this->events->removeElement($event)) {
  338.             $event->removeUser($this);
  339.         }
  340.         return $this;
  341.     }
  342.     public function getAgendaColor(): ?string
  343.     {
  344.         return $this->agenda_color;
  345.     }
  346.     public function setAgendaColor(string $agenda_color): self
  347.     {
  348.         $this->agenda_color $agenda_color;
  349.         return $this;
  350.     }
  351.     public function getUserGroup(): ?UserGroup
  352.     {
  353.         return $this->userGroup;
  354.     }
  355.     public function setUserGroup(?UserGroup $userGroup): self
  356.     {
  357.         $this->userGroup $userGroup;
  358.         return $this;
  359.     }
  360.     public function getBinome(): ?self
  361.     {
  362.         return $this->binome;
  363.     }
  364.     public function setBinome(?self $binome): self
  365.     {
  366.         $this->binome $binome;
  367.         return $this;
  368.     }
  369.     /**
  370.      * @return Collection|Chantier[]
  371.      */
  372.     public function getChantiers(): Collection
  373.     {
  374.         return $this->chantiers;
  375.     }
  376.     public function addChantier(Chantier $chantier): self
  377.     {
  378.         if (!$this->chantiers->contains($chantier)) {
  379.             $this->chantiers[] = $chantier;
  380.             $chantier->setUser($this);
  381.         }
  382.         return $this;
  383.     }
  384.     public function removeChantier(Chantier $chantier): self
  385.     {
  386.         if ($this->chantiers->removeElement($chantier)) {
  387.             // set the owning side to null (unless already changed)
  388.             if ($chantier->getUser() === $this) {
  389.                 $chantier->setUser(null);
  390.             }
  391.         }
  392.         return $this;
  393.     }
  394.     /**
  395.      * Get the value of plain_password
  396.      */ 
  397.     public function getPlainPassword()
  398.     {
  399.         return $this->plain_password;
  400.     }
  401.     /**
  402.      * Set the value of plain_password
  403.      *
  404.      * @return  self
  405.      */ 
  406.     public function setPlainPassword($plain_password)
  407.     {
  408.         $this->plain_password $plain_password;
  409.         return $this;
  410.     }
  411.     /**
  412.      * @return Collection|Chantier[]
  413.      */
  414.     public function getWorkerChantiers(): Collection
  415.     {
  416.         return $this->worker_chantiers;
  417.     }
  418.     public function addWorkerChantier(Chantier $workerChantier): self
  419.     {
  420.         if (!$this->worker_chantiers->contains($workerChantier)) {
  421.             $this->worker_chantiers[] = $workerChantier;
  422.             $workerChantier->addUserWorker($this);
  423.         }
  424.         return $this;
  425.     }
  426.     public function removeWorkerChantier(Chantier $workerChantier): self
  427.     {
  428.         if ($this->worker_chantiers->removeElement($workerChantier)) {
  429.             $workerChantier->removeUserWorker($this);
  430.         }
  431.         return $this;
  432.     }
  433.     /**
  434.      * @return Collection|Comment[]
  435.      */
  436.     public function getComments(): Collection
  437.     {
  438.         return $this->comments;
  439.     }
  440.     public function addComment(Comment $comment): self
  441.     {
  442.         if (!$this->comments->contains($comment)) {
  443.             $this->comments[] = $comment;
  444.             $comment->setUser($this);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeComment(Comment $comment): self
  449.     {
  450.         if ($this->comments->removeElement($comment)) {
  451.             // set the owning side to null (unless already changed)
  452.             if ($comment->getUser() === $this) {
  453.                 $comment->setUser(null);
  454.             }
  455.         }
  456.         return $this;
  457.     }
  458. }