src/Entity/User.php line 22

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\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. /**
  12.  * User
  13.  *
  14.  * @UniqueEntity("username")
  15.  * @UniqueEntity("email")
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @Gedmo\Loggable
  18.  */
  19. class User implements UserInterface
  20. {
  21.     /**
  22.      * @var int
  23.      *  
  24.      * @ORM\Column(name="user_id", type="integer", nullable=false)
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="IDENTITY")
  27.      */
  28.     private $userId;
  29.     /**
  30.      * @var string
  31.      * @Gedmo\Versioned
  32.      * @ORM\Column(name="username", type="string", length=180, nullable=false, unique=true)
  33.      */
  34.     private $username;
  35.     /**
  36.      * @var string
  37.      * @Gedmo\Versioned
  38.      * 
  39.      * @ORM\Column(name="password", type="string", length=255, nullable=false)
  40.      */
  41.     private $password;
  42.     /**
  43.      * @var string
  44.      * @Gedmo\Versioned
  45.      *
  46.      * @ORM\Column(name="email", type="string", length=255, nullable=false)
  47.      * @Assert\Email(
  48.      *     message = "Email '{{ value }}' est invalide.",
  49.      * )
  50.      */
  51.     private $email;
  52.     /**
  53.      * @var string
  54.      * @Gedmo\Versioned
  55.      * @Assert\Length(min = 8, max = 20, minMessage = "Numéro Téléphone invalide !", maxMessage = "Numéro Téléphone invalide !")
  56.      * @Assert\Regex(pattern="/(\+212|0)([ \-_]*)(\d[ \-_]*){9}/", message="Numéro Téléphone invalide !") 
  57.      * @ORM\Column(name="tel", type="string", length=20, nullable=false)
  58.      */
  59.     private $tel;
  60.     /**
  61.      * @var \DateTime
  62.      * @Gedmo\Versioned
  63.      *
  64.      * @ORM\Column(name="date_naissance", type="date", nullable=false)
  65.      * @Assert\LessThan("today")
  66.      */
  67.     private $dateNaissance;
  68.     /**
  69.      * @var string
  70.      * @Gedmo\Versioned
  71.      *
  72.      * @ORM\Column(name="first_name", type="string", length=255, nullable=false)
  73.      */
  74.     private $firstName;
  75.     /**
  76.      * @var string
  77.      * @Gedmo\Versioned
  78.      *
  79.      * @ORM\Column(name="last_name", type="string", length=255, nullable=false)
  80.      */
  81.     private $lastName;
  82.     /**
  83.      * @ORM\Column(type="boolean")
  84.      * @Gedmo\Versioned
  85.      */
  86.     private $isSalarie;
  87.     /**
  88.      * @Gedmo\Versioned
  89.      * @ORM\Column(type="string", length=255, nullable=true)
  90.      */
  91.     private $usernameCourt;
  92.     /**
  93.      * @var integer
  94.      *
  95.      * @ORM\Column(name="nbr_conncetion", type="integer", nullable=true)
  96.      */
  97.     private $nbrConnection;
  98.     /**
  99.      * @var \DateTime
  100.      *
  101.      * @ORM\Column(name="last_connection", type="datetime", nullable=true)
  102.      */
  103.     private $lastConnection;
  104.     /**
  105.      * @var \Doctrine\Common\Collections\Collection
  106.      * @Assert\Count(
  107.      *      min = "1",
  108.      *      minMessage = "Il faut séléctionner au moins un profil"
  109.      * )
  110.      * @ORM\ManyToMany(targetEntity="Profil", inversedBy="user")
  111.      * @ORM\JoinTable(name="lnk_user_profil",
  112.      *   joinColumns={
  113.      *     @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
  114.      *   },
  115.      *   inverseJoinColumns={
  116.      *     @ORM\JoinColumn(name="profil_id", referencedColumnName="profil_id")
  117.      *   }
  118.      * )
  119.      */
  120.     private $profil;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=TblMouvement::class, mappedBy="consommateur")
  123.      */
  124.     private $mouvements;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=TblOperationVente::class, mappedBy="vendeur")
  127.      */
  128.     private $tblOperationVentes;
  129.     public function __construct()
  130.     {
  131.         $this->profil = new ArrayCollection();
  132.         $this->mouvements = new ArrayCollection();
  133.         $this->tblOperationVentes = new ArrayCollection();
  134.     }
  135.     public function __toString()
  136.     {
  137.         return $this->getFirstName() . ' ' $this->getLastName();
  138.     }
  139.     public function getUserId(): ?int
  140.     {
  141.         return $this->userId;
  142.     }
  143.     /**
  144.      * A visual identifier that represents this user.
  145.      *
  146.      * @see UserInterface
  147.      */
  148.     public function getUsername(): ?string
  149.     {
  150.         return $this->username;
  151.     }
  152.     public function setUsername(string $username): self
  153.     {
  154.         $this->username $username;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, Profil>
  159.      */
  160.     public function getProfil(): Collection
  161.     {
  162.         return $this->profil;
  163.     }
  164.     public function addProfil(Profil $profil): self
  165.     {
  166.         if (!$this->profil->contains($profil)) {
  167.             $this->profil[] = $profil;
  168.         }
  169.         return $this;
  170.     }
  171.     public function removeProfil(Profil $profil): self
  172.     {
  173.         $this->profil->removeElement($profil);
  174.         return $this;
  175.     }
  176.     /**
  177.      * @see UserInterface
  178.      */
  179.     public function getRoles(): array
  180.     {
  181.         $roles = [];
  182.         foreach ($this->profil as $p) {
  183.             $roles[] = $p->getProfilSf();
  184.         }
  185.         return $roles;
  186.     }
  187.     public function hasRole($profilLib)
  188.     {
  189.         /** @var Profil $profil */
  190.         foreach ($this->profil as $profil) {
  191.             if ($profilLib == $profil->getProfilSf()) {
  192.                 return true;
  193.             }
  194.         }
  195.         return false;
  196.     }
  197.     public function getProfilLibs()
  198.     {
  199.         $profilLibs = [];
  200.         foreach ($this->getProfil() as $profil) {
  201.             $profilLibs[] = (string) $profil;
  202.         }
  203.         return implode(", "$profilLibs);
  204.     }
  205.     public function setRoles(array $roles): self
  206.     {
  207.         $this->roles $roles;
  208.         return $this;
  209.     }
  210.     /**
  211.      * @see UserInterface
  212.      */
  213.     public function getPassword(): ?string
  214.     {
  215.         return $this->password;
  216.     }
  217.     public function setPassword(string $password): self
  218.     {
  219.         $this->password $password;
  220.         return $this;
  221.     }
  222.      /**
  223.      * Returning a salt is only needed, if you are not using a modern
  224.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  225.      *
  226.      * @see UserInterface
  227.      */
  228.     public function getSalt(): ?string
  229.     {
  230.         return null;
  231.     }
  232.     /**
  233.      * @see UserInterface
  234.      */
  235.     public function eraseCredentials()
  236.     {
  237.         // If you store any temporary, sensitive data on the user, clear it here
  238.         // $this->plainPassword = null;
  239.     }
  240.     public function getEmail(): ?string
  241.     {
  242.         return $this->email;
  243.     }
  244.     public function setEmail(string $email): self
  245.     {
  246.         $this->email $email;
  247.         return $this;
  248.     }
  249.     public function getTel(): ?string
  250.     {
  251.         return $this->tel;
  252.     }
  253.     public function setTel(string $tel): self
  254.     {
  255.         $this->tel $tel;
  256.         return $this;
  257.     }
  258.     public function getDateNaissance(): ?\DateTimeInterface
  259.     {
  260.         return $this->dateNaissance;
  261.     }
  262.     public function setDateNaissance(\DateTimeInterface $dateNaissance): self
  263.     {
  264.         $this->dateNaissance $dateNaissance;
  265.         return $this;
  266.     }
  267.     public function getFirstName(): ?string
  268.     {
  269.         return $this->firstName;
  270.     }
  271.     public function setFirstName(string $firstName): self
  272.     {
  273.         $this->firstName $firstName;
  274.         return $this;
  275.     }
  276.     public function getLastName(): ?string
  277.     {
  278.         return $this->lastName;
  279.     }
  280.     public function setLastName(string $lastName): self
  281.     {
  282.         $this->lastName $lastName;
  283.         return $this;
  284.     }
  285.     public function isisSalarie(): ?bool
  286.     {
  287.         return $this->isSalarie;
  288.     }
  289.     public function setisSalarie(bool $isSalarie): self
  290.     {
  291.         $this->isSalarie $isSalarie;
  292.         return $this;
  293.     }
  294.     public function getUsernameCourt(): ?string
  295.     {
  296.         return $this->usernameCourt;
  297.     }
  298.     public function setUsernameCourt(?string $usernameCourt): self
  299.     {
  300.         $this->usernameCourt $usernameCourt;
  301.         return $this;
  302.     }
  303.     public function getNbrConnection(): ?int
  304.     {
  305.         return $this->nbrConnection;
  306.     }
  307.     public function setNbrConnection(?int $nbrConnection): self
  308.     {
  309.         $this->nbrConnection $nbrConnection;
  310.         return $this;
  311.     }
  312.     public function getLastConnection(): ?\DateTimeInterface
  313.     {
  314.         return $this->lastConnection;
  315.     }
  316.     public function setLastConnection(\DateTimeInterface $lastConnection): self
  317.     {
  318.         $this->lastConnection $lastConnection;
  319.         return $this;
  320.     }
  321.     /**
  322.      * @return Collection<int, TblMouvement>
  323.      */
  324.     public function getMouvements(): Collection
  325.     {
  326.         return $this->mouvements;
  327.     }
  328.     public function addMouvement(TblMouvement $mouvement): self
  329.     {
  330.         if (!$this->mouvements->contains($mouvement)) {
  331.             $this->mouvements[] = $mouvement;
  332.             $mouvement->setConsommateur($this);
  333.         }
  334.         return $this;
  335.     }
  336.     public function removeMouvement(TblMouvement $mouvement): self
  337.     {
  338.         if ($this->mouvements->removeElement($mouvement)) {
  339.             // set the owning side to null (unless already changed)
  340.             if ($mouvement->getConsommateur() === $this) {
  341.                 $mouvement->setConsommateur(null);
  342.             }
  343.         }
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return Collection<int, TblOperationVente>
  348.      */
  349.     public function getTblOperationVentes(): Collection
  350.     {
  351.         return $this->tblOperationVentes;
  352.     }
  353.     public function addTblOperationVente(TblOperationVente $tblOperationVente): self
  354.     {
  355.         if (!$this->tblOperationVentes->contains($tblOperationVente)) {
  356.             $this->tblOperationVentes[] = $tblOperationVente;
  357.             $tblOperationVente->setVendeur($this);
  358.         }
  359.         return $this;
  360.     }
  361.     public function removeTblOperationVente(TblOperationVente $tblOperationVente): self
  362.     {
  363.         if ($this->tblOperationVentes->removeElement($tblOperationVente)) {
  364.             // set the owning side to null (unless already changed)
  365.             if ($tblOperationVente->getVendeur() === $this) {
  366.                 $tblOperationVente->setVendeur(null);
  367.             }
  368.         }
  369.         return $this;
  370.     }
  371. }