src/Entity/Utilisateur.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. /**
  9.  * Utilisateur
  10.  *
  11.  * @ORM\Table(name="utilisateur")
  12.  * @ORM\Entity
  13.  */
  14. class Utilisateur implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Column(name="id", type="integer", nullable=false)
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="IDENTITY")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @var bool
  26.      *
  27.      * @ORM\Column(name="sexe", type="boolean", nullable=false, options={"default"="1"})
  28.      */
  29.     private $sexe = '1';
  30.     /**
  31.      * @var string|null
  32.      *
  33.      * @ORM\Column(name="nom", type="string", length=100, nullable=true)
  34.      */
  35.     private $nom;
  36.     /**
  37.      * @var string|null
  38.      *
  39.      * @ORM\Column(name="prenom", type="string", length=100, nullable=true)
  40.      */
  41.     private $prenom;
  42.     /**
  43.      * @var string|null
  44.      *
  45.      * @ORM\Column(name="email", type="string", length=255, nullable=true)
  46.      */
  47.     private $email;
  48.     /**
  49.      * @var string|null
  50.      *
  51.      * @ORM\Column(name="login", type="string", length=100, nullable=true)
  52.      */
  53.     private $login;
  54.     /**
  55.      * @var string|null
  56.      *
  57.      * @ORM\Column(name="motdepasse", type="string", length=255, nullable=true)
  58.      */
  59.     private $motdepasse;
  60.     /**
  61.      * @var string|null
  62.      * @ORM\Column(name="keycloak_sub", type="string", length=36, nullable=true)
  63.      */
  64.     private $keycloakSub;
  65.     /**
  66.      * @var bool
  67.      *
  68.      * @ORM\Column(name="etat", type="boolean", nullable=false, options={"default"="1"})
  69.      */
  70.     private $etat = '1';
  71.     
  72.     /**
  73.      * @var bool
  74.      *
  75.      * @ORM\Column(name="webservice", type="boolean", nullable=false, options={"default"="1"})
  76.      */
  77.     // Colonne gardée en base mais plus utilisée ; mappée pour que les INSERT écrivent 0 (défaut SQL = 1).
  78.     private $webservice = '0';
  79.     
  80.     
  81.     /**
  82.      * @var \Doctrine\Common\Collections\Collection
  83.      *
  84.      * @ORM\OneToMany(targetEntity="Token", mappedBy="utilisateur", cascade={"persist"})
  85.      */
  86.     private $tokens;
  87.     
  88.     
  89.     /**
  90.      * @var bool
  91.      *
  92.      * @ORM\Column(name="DroitValidation", type="boolean", nullable=false, options={"default"="1"})
  93.      */
  94.     private $droitValidation= '1';
  95.     
  96.     /**
  97.      * @var bool
  98.      *
  99.      * @ORM\Column(name="DroitModificationListe", type="boolean", nullable=false, options={"default"="0"})
  100.      */
  101.     private $droitModificationListe= '0';
  102.     
  103.     /**
  104.      * @var bool
  105.      *
  106.      * @ORM\Column(name="DroitModificationListeException", type="boolean", nullable=false, options={"default"="0"})
  107.      */
  108.     private $droitModificationListeException= '0';
  109.     
  110.     /**
  111.      * @var bool
  112.      *
  113.      * @ORM\Column(name="DroitAdmin", type="boolean", nullable=false, options={"default"="0"})
  114.      */
  115.     private $droitAdmin= '0';
  116.     
  117.     /**
  118.      * @var bool
  119.      *
  120.      * @ORM\Column(name="DroitMenuParametre", type="boolean", nullable=false, options={"default"="1"})
  121.      */
  122.     private $droitMenuParametre= '1';
  123.     
  124.     /**
  125.      * @var bool
  126.      *
  127.      * @ORM\Column(name="DroitMenuListe", type="boolean", nullable=false, options={"default"="1"})
  128.      */
  129.     private $droitMenuListe= '1';
  130.     
  131.     /**
  132.      * @var bool
  133.      *
  134.      * @ORM\Column(name="DroitMenuConventionCollective", type="boolean", nullable=false, options={"default"="1"})
  135.      */
  136.     private $droitMenuConventionCollective= '1';
  137.     
  138.     /**
  139.      * @var bool
  140.      *
  141.      * @ORM\Column(name="DroitMenuExport", type="boolean", nullable=false, options={"default"="1"})
  142.      */
  143.     private $droitMenuExport= '1';
  144.     
  145.     /**
  146.      * @var bool
  147.      *
  148.      * @ORM\Column(name="DroitMenuCalcul", type="boolean", nullable=false, options={"default"="0"})
  149.      */
  150.     private $droitMenuCalcul= '0';
  151.     
  152.     /**
  153.      * @var bool
  154.      *
  155.      * @ORM\Column(name="DroitMenuRegle", type="boolean", nullable=false, options={"default"="0"})
  156.      */
  157.     private $droitMenuRegle= '0';
  158.     
  159.     /**
  160.      * @var bool
  161.      *
  162.      * @ORM\Column(name="DroitModificationRegleAvance", type="boolean", nullable=false, options={"default"="0"})
  163.      */
  164.     private $droitModificationRegleAvance= '0';
  165.     
  166.     public function __construct() {
  167.         $this->tokens=new ArrayCollection();
  168.     }
  169.     
  170.     public function getUserIdentifier()
  171.     {
  172.         return $this->id;
  173.     }
  174.     
  175.     public function getId(): ?int
  176.     {
  177.         return $this->id;
  178.     }
  179.     public function getSexe(): ?bool
  180.     {
  181.         return $this->sexe;
  182.     }
  183.     public function setSexe(bool $sexe): self
  184.     {
  185.         $this->sexe = $sexe;
  186.         return $this;
  187.     }
  188.     public function getNom(): ?string
  189.     {
  190.         return $this->nom;
  191.     }
  192.     public function setNom(?string $nom): self
  193.     {
  194.         $this->nom = $nom;
  195.         return $this;
  196.     }
  197.     public function getPrenom(): ?string
  198.     {
  199.         return $this->prenom;
  200.     }
  201.     public function setPrenom(?string $prenom): self
  202.     {
  203.         $this->prenom = $prenom;
  204.         return $this;
  205.     }
  206.     public function getEmail(): ?string
  207.     {
  208.         return $this->email;
  209.     }
  210.     public function setEmail(?string $email): self
  211.     {
  212.         $this->email = $email;
  213.         return $this;
  214.     }
  215.     public function getLogin(): ?string
  216.     {
  217.         return $this->login;
  218.     }
  219.     public function setLogin(?string $login): self
  220.     {
  221.         $this->login = $login;
  222.         return $this;
  223.     }
  224.     public function getMotdepasse(): ?string
  225.     {
  226.         return $this->motdepasse;
  227.     }
  228.     public function setMotdepasse(?string $motdepasse): self
  229.     {
  230.         $this->motdepasse = $motdepasse;
  231.         return $this;
  232.     }
  233.     public function getKeycloakSub(): ?string
  234.     {
  235.         return $this->keycloakSub;
  236.     }
  237.     public function setKeycloakSub(?string $keycloakSub): self
  238.     {
  239.         $this->keycloakSub = $keycloakSub;
  240.         return $this;
  241.     }
  242.     
  243.     public function getEtat(): ?bool
  244.     {
  245.         return $this->etat;
  246.     }
  247.     
  248.     public function setEtat(bool $etat): self
  249.     {
  250.         $this->etat = $etat;
  251.         
  252.         return $this;
  253.     }
  254.     
  255.     public function getDroitValidation(): ?bool
  256.     {
  257.         return $this->droitValidation;
  258.     }
  259.     
  260.     public function setDroitValidation(bool $droitValidation): self
  261.     {
  262.         $this->droitValidation = $droitValidation;
  263.         
  264.         return $this;
  265.     }
  266.     
  267.     public function getDroitModificationListe(): ?bool
  268.     {
  269.         return $this->droitModificationListe;
  270.     }
  271.     
  272.     public function setDroitModificationListe(bool $droitModificationListe): self
  273.     {
  274.         $this->droitModificationListe = $droitModificationListe;
  275.         
  276.         return $this;
  277.     }
  278.     
  279.     public function getDroitModificationListeException(): ?bool
  280.     {
  281.         return $this->droitModificationListeException;
  282.     }
  283.     
  284.     public function setDroitModificationListeException(bool $droitModificationListeException): self
  285.     {
  286.         $this->droitModificationListeException = $droitModificationListeException;
  287.         
  288.         return $this;
  289.     }
  290.     
  291.     public function getDroitAdmin(): ?bool
  292.     {
  293.         return $this->droitAdmin;
  294.     }
  295.     
  296.     public function setDroitAdmin(bool $droitAdmin): self
  297.     {
  298.         $this->droitAdmin = $droitAdmin;
  299.         
  300.         return $this;
  301.     }
  302.     
  303.     public function getDroitMenuParametre(): ?bool
  304.     {
  305.         return $this->droitMenuParametre;
  306.     }
  307.     
  308.     public function setDroitMenuParametre(bool $droit): self
  309.     {
  310.         $this->droitMenuParametre = $droit;
  311.         
  312.         return $this;
  313.     }
  314.     
  315.     public function getDroitMenuListe(): ?bool
  316.     {
  317.         return $this->droitMenuListe;
  318.     }
  319.     
  320.     public function setDroitMenuListe(bool $droit): self
  321.     {
  322.         $this->droitMenuListe = $droit;
  323.         
  324.         return $this;
  325.     }
  326.     
  327.     public function getDroitMenuConventionCollective(): ?bool
  328.     {
  329.         return $this->droitMenuConventionCollective;
  330.     }
  331.     
  332.     public function setDroitMenuConventionCollective(bool $droit): self
  333.     {
  334.         $this->droitMenuConventionCollective = $droit;
  335.         
  336.         return $this;
  337.     }
  338.     
  339.     public function getDroitMenuExport(): ?bool
  340.     {
  341.         return $this->droitMenuExport;
  342.     }
  343.     
  344.     public function setDroitMenuExport(bool $droit): self
  345.     {
  346.         $this->droitMenuExport = $droit;
  347.         
  348.         return $this;
  349.     }
  350.     
  351.     public function getDroitMenuCalcul(): ?bool
  352.     {
  353.         return $this->droitMenuCalcul;
  354.     }
  355.     
  356.     public function setDroitMenuCalcul(bool $droit): self
  357.     {
  358.         $this->droitMenuCalcul = $droit;
  359.         
  360.         return $this;
  361.     }
  362.     
  363.     public function getDroitMenuRegle(): ?bool
  364.     {
  365.         return $this->droitMenuRegle;
  366.     }
  367.     
  368.     public function setDroitMenuRegle(bool $droit): self
  369.     {
  370.         $this->droitMenuRegle = $droit;
  371.         
  372.         return $this;
  373.     }
  374.     
  375.     public function getDroitModificationRegleAvance(): ?bool
  376.     {
  377.         return $this->droitModificationRegleAvance;
  378.     }
  379.     
  380.     public function setDroitModificationRegleAvance(bool $droit): self
  381.     {
  382.         $this->droitModificationRegleAvance = $droit;
  383.         
  384.         return $this;
  385.     }
  386.     
  387.     /**
  388.      * A visual identifier that represents this user.
  389.      *
  390.      * @see UserInterface
  391.      */
  392.     public function getUsername(): string
  393.     {
  394.         return (string) $this->login;
  395.     }
  396.     
  397.     
  398.     
  399.     /**
  400.      * @see UserInterface
  401.      */
  402.     public function getRoles(): array
  403.     {
  404.         $roles =[];// $this->roles;
  405.         // guarantee every user at least has ROLE_USER
  406.         $roles[] = 'ROLE_USER';
  407.         if ($this->getEtat())
  408.             $roles[] = 'ROLE_ADMIN';
  409.             
  410.             return array_unique($roles);
  411.     }
  412.     
  413.     /**
  414.      * @see UserInterface
  415.      */
  416.     public function getPassword(): string
  417.     {
  418.         return (string) $this->motdepasse;
  419.     }
  420.     
  421.     
  422.     
  423.     /**
  424.      * @see UserInterface
  425.      */
  426.     public function getSalt()
  427.     {
  428.         // not needed when using the "bcrypt" algorithm in security.yaml
  429.     }
  430.     
  431.     /**
  432.      * @see UserInterface
  433.      */
  434.     public function eraseCredentials()
  435.     {
  436.         // If you store any temporary, sensitive data on the user, clear it here
  437.         // $this->plainPassword = null;
  438.     }
  439.     
  440.     /**
  441.      * @return Collection|Token[]
  442.      */
  443.     public function getTokens(): Collection
  444.     {
  445.         return $this->tokens;
  446.     }
  447.     
  448.     public function addTokens(Token $token): self
  449.     {
  450.         if (!$this->tokens->contains($token)) {
  451.             $this->tokens[] = $token;
  452.         }
  453.         
  454.         return $this;
  455.     }
  456.     
  457.     public function removeTokens(Token $token): self
  458.     {
  459.         if ($this->tokens->contains($token)) {
  460.             $this->tokens->removeElement($token);
  461.         }
  462.         
  463.         return $this;
  464.     }
  465.     
  466.     public function serialize()
  467.     {
  468.         return serialize(array(
  469.             $this->getId(),
  470.             $this->getLogin(),
  471.             $this->getPassword()
  472.         ));
  473.     }
  474.     public function unserialize($serialized)
  475.     {
  476.         list(
  477.             $this->id,
  478.             $this->login,
  479.             $this->motdepasse
  480.             // voir remarques sur salt plus haut
  481.             // $this->salt
  482.         ) = unserialize($serialized);
  483.     }
  484. }