src/Entity/UserPlatform.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserPlatformRepository;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Component\Validator\Mapping\ClassMetadata;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserPlatformRepository::class)
  13.  */
  14. class UserPlatform implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, nullable=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     
  31.     /**
  32.      * @ORM\Column(type="json", nullable=true)
  33.      */
  34.     private $classes = [];
  35.     
  36.     /**
  37.      * @ORM\Column(type="json", nullable=true)
  38.      */
  39.     private $matieres = [];
  40.     /**
  41.      * @var string The hashed password
  42.      * @ORM\Column(type="string")
  43.      */
  44.     private $password;
  45.     /**
  46.      * @ORM\Column(type="string", length=255)
  47.      */
  48.     private $nameuser;
  49.     /**
  50.      * @ORM\Column(type="string", length=255)
  51.      */
  52.     private $adresse;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $phone;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $mail;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $mdpnoncrypt;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=Consultactivite::class, mappedBy="user", cascade={"persist", "remove"})
  67.      */
  68.     private $consultActivites;
  69.     public function __construct()
  70.     {
  71.         $this->consultActivites = new ArrayCollection();
  72.     }
  73.     public function getMdpnoncrypt(): ?string
  74.     {
  75.         return $this->mdpnoncrypt;
  76.     }
  77.     public function setMdpnoncrypt(?string $mdpnoncrypt): self
  78.     {
  79.         $this->mdpnoncrypt $mdpnoncrypt;
  80.         return $this;
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getEmail(): ?string
  87.     {
  88.         return $this->email;
  89.     }
  90.     public function setEmail(?string $email): self
  91.     {
  92.         $this->email = empty($email) ? null $email;
  93.         return $this;
  94.     }
  95.     public static function loadValidatorMetadata(ClassMetadata $metadata): void
  96.     {
  97.         $metadata->addConstraint(new Assert\Callback('validateEmailOrPhone'));
  98.     }
  99.     public function validateEmailOrPhone(\Symfony\Component\Validator\Context\ExecutionContextInterface $context): void
  100.     {
  101.         if (empty($this->email) && empty($this->phone)) {
  102.             $context->buildViolation('Veuillez remplir au moins l\'email ou le numéro de téléphone.')
  103.                 ->atPath('email'// Vous pouvez aussi choisir 'phone' ou les deux
  104.                 ->addViolation();
  105.         }
  106.     }
  107.     /**
  108.      * A visual identifier that represents this user.
  109.      *
  110.      * @see UserInterface
  111.      */
  112.     public function getUserIdentifier(): string
  113.     {
  114.         return (string) $this->email;
  115.     }
  116.     /**
  117.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  118.      */
  119.     public function getUsername(): string
  120.     {
  121.         return (string) $this->email;
  122.     }
  123.     /**
  124.      * @see UserInterface
  125.      */
  126.     public function getRoles(): array
  127.     {
  128.         $roles $this->roles;
  129.         // guarantee every user at least has ROLE_USER
  130.         $roles[] = 'ROLE_USER';
  131.         return array_unique($roles);
  132.     }
  133.     public function setRoles(array $roles): self
  134.     {
  135.         $this->roles $roles;
  136.         return $this;
  137.     }
  138.     
  139.     /**
  140.      * @see UserInterface
  141.      */
  142.     public function getClasses(): array
  143.     {
  144.         $classes $this->classes;
  145.         // guarantee every user at least has ROLE_USER
  146.         $classes[] = null ;
  147.         return array_unique($classes);
  148.     }
  149.     public function setClasses(array $classes): self
  150.     {
  151.         $this->classes $classes;
  152.         return $this;
  153.     }
  154.     
  155.     /**
  156.      * @see UserInterface
  157.      */
  158.     public function getMatieres(): array
  159.     {
  160.         $matieres $this->matieres;
  161.         // guarantee every user at least has ROLE_USER
  162.         $matieres[] = null ;
  163.         return array_unique($matieres);
  164.     }
  165.     public function setMatieres(array $matieres): self
  166.     {
  167.         $this->matieres $matieres;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @see PasswordAuthenticatedUserInterface
  172.      */
  173.     public function getPassword(): string
  174.     {
  175.         return $this->password;
  176.     }
  177.     public function setPassword(string $password): self
  178.     {
  179.         $this->password $password;
  180.         return $this;
  181.     }
  182.     /**
  183.      * Returning a salt is only needed, if you are not using a modern
  184.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  185.      *
  186.      * @see UserInterface
  187.      */
  188.     public function getSalt(): ?string
  189.     {
  190.         return null;
  191.     }
  192.     /**
  193.      * @see UserInterface
  194.      */
  195.     public function eraseCredentials()
  196.     {
  197.         // If you store any temporary, sensitive data on the user, clear it here
  198.         // $this->plainPassword = null;
  199.     }
  200.     public function getNameuser(): ?string
  201.     {
  202.         return $this->nameuser;
  203.     }
  204.     public function setNameuser(string $nameuser): self
  205.     {
  206.         $this->nameuser $nameuser;
  207.         return $this;
  208.     }
  209.     public function getAdresse(): ?string
  210.     {
  211.         return $this->adresse;
  212.     }
  213.     public function setAdresse(string $adresse): self
  214.     {
  215.         $this->adresse $adresse;
  216.         return $this;
  217.     }
  218.     public function getPhone(): ?string
  219.     {
  220.         return $this->phone;
  221.     }
  222.     public function setPhone(?string $phone): self
  223.     {
  224.         $this->phone $phone;
  225.         return $this;
  226.     }
  227.     public function getMail(): ?string
  228.     {
  229.         return $this->mail;
  230.     }
  231.     public function setMail(?string $mail): self
  232.     {
  233.         $this->mail $mail;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection|Consultactivite[]
  238.      */
  239.     public function getConsultActivites(): Collection
  240.     {
  241.         return $this->consultActivites;
  242.     }
  243.     public function addConsultActivite(Consultactivite $consultActivite): self
  244.     {
  245.         if (!$this->consultActivites->contains($consultActivite)) {
  246.             $this->consultActivites[] = $consultActivite;
  247.             $consultActivite->setUser($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeConsultActivite(Consultactivite $consultActivite): self
  252.     {
  253.         if ($this->consultActivites->removeElement($consultActivite)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($consultActivite->getUser() === $this) {
  256.                 $consultActivite->setUser(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261. }