src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="json")
  29.      */
  30.     private $roles = [];
  31.     /**
  32.      * @Assert\NotBlank()
  33.      * @Assert\Length(max=4096)
  34.      */
  35.     private $plainPassword;
  36.     /**
  37.      * The below length depends on the "algorithm" you use for encoding
  38.      * the password, but this works well with bcrypt.
  39.      ** @var string The hashed password
  40.      * @ORM\Column(type="string", length=255)
  41.      */
  42.     private $password;
  43.     /**
  44.      * @ORM\OneToOne(targetEntity=Compte::class, inversedBy="user", cascade={"persist", "remove"})
  45.      * @ORM\JoinColumn(nullable=true)
  46.      */
  47.     private $compte;
  48.     /**
  49.      * @ORM\OneToOne(targetEntity=Client::class, inversedBy="user", cascade={"persist", "remove"})
  50.      * @ORM\JoinColumn(nullable=true)
  51.      */
  52.     private $client;
  53.     /**
  54.      * @ORM\Column(type="boolean", options={"default":"1"})
  55.      */
  56.     private $isFirstConnexion true;   
  57.     
  58.     /**
  59.      * @ORM\OneToMany(targetEntity="App\Entity\StockBandeau", mappedBy="user")
  60.      */
  61.     private $stockBandeaux;    
  62.     public function __construct()
  63.     {
  64.         $this->roles = array('ROLE_USER');
  65.         $this->stockBandeaux = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getEmail(): ?string
  72.     {
  73.         return $this->email;
  74.     }
  75.     public function setEmail(string $email): self
  76.     {
  77.         $this->email $email;
  78.         return $this;
  79.     }
  80.     /**
  81.      * A visual identifier that represents this user.
  82.      *
  83.      * @see UserInterface
  84.      */
  85.     public function getUserIdentifier(): string
  86.     {
  87.         return (string) $this->email;
  88.     }
  89.     /**
  90.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  91.      */
  92.     public function getUsername(): string
  93.     {
  94.         return (string) $this->email;
  95.     }
  96.     /**
  97.      * @see UserInterface
  98.      */
  99.     public function getRoles(): array
  100.     {
  101.         $roles $this->roles;
  102.         // guarantee every user at least has ROLE_USER
  103.         $roles[] = 'ROLE_USER';
  104.         return array_unique($roles);
  105.     }
  106.     public function setRoles(array $roles): self
  107.     {
  108.         $this->roles $roles;
  109.         return $this;
  110.     }
  111.     public function getPlainPassword()
  112.     {
  113.         return $this->plainPassword;
  114.     }
  115.     public function setPlainPassword($password)
  116.     {
  117.         $this->plainPassword $password;
  118.     }
  119.     /**
  120.      * @see PasswordAuthenticatedUserInterface
  121.      */
  122.     public function getPassword(): string
  123.     {
  124.         return $this->password;
  125.     }
  126.     public function setPassword(string $password): self
  127.     {
  128.         $this->password $password;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Returning a salt is only needed, if you are not using a modern
  133.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  134.      *
  135.      * @see UserInterface
  136.      */
  137.     public function getSalt(): ?string
  138.     {
  139.         return null;
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function eraseCredentials()
  145.     {
  146.         // If you store any temporary, sensitive data on the user, clear it here
  147.         // $this->plainPassword = null;
  148.     }
  149.     public function getCompte(): ?Compte
  150.     {
  151.         return $this->compte;
  152.     }
  153.     public function setCompte(Compte $compte): self
  154.     {
  155.         $this->compte $compte;
  156.         return $this;
  157.     }
  158.     public function getClient(): ?Client
  159.     {
  160.         return $this->client;
  161.     }
  162.     public function setClient(Client $client): self
  163.     {
  164.         $this->client $client;
  165.         return $this;
  166.     }
  167.     public function isIsFirstConnexion(): ?bool
  168.     {
  169.         return $this->isFirstConnexion;
  170.     }
  171.     public function setIsFirstConnexion(bool $isFirstConnexion): self
  172.     {
  173.         $this->isFirstConnexion $isFirstConnexion;
  174.         return $this;
  175.     }    
  176.     /**
  177.      * @return Collection<int, StockBandeau>
  178.      */
  179.     public function getStockBandeaux(): Collection
  180.     {
  181.         return $this->stockBandeaux;
  182.     }
  183.     public function addStockBandeau(StockBandeau $stockBandeau): self
  184.     {
  185.         if (!$this->stockBandeaux->contains($stockBandeau)) {
  186.             $this->stockBandeaux[] = $stockBandeau;
  187.             $stockBandeau->setUser($this); // Mise à jour côté propriétaire
  188.         }
  189.         return $this;
  190.     }
  191.     public function removeStockBandeau(StockBandeau $stockBandeau): self
  192.     {
  193.         if ($this->stockBandeaux->removeElement($stockBandeau)) {
  194.             // Mettre à jour l'autre côté de la relation si nécessaire
  195.             if ($stockBandeau->getUser() === $this) {
  196.                 $stockBandeau->setUser(null);
  197.             }
  198.         }
  199.         return $this;
  200.     }    
  201. }