src/Entity/User.php line 13

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\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length180uniquetrue)]
  17.     private $email;
  18.     #[ORM\Column(type'json')]
  19.     private $roles = [];
  20.     #[ORM\Column(type'string')]
  21.     private $password;
  22.     #[ORM\Column(type'string'length255nullabletrue)]
  23.     private $firstname;
  24.     #[ORM\Column(type'string'length255nullabletrue)]
  25.     private $lastname1;
  26.     #[ORM\Column(type'string'length255nullabletrue)]
  27.     private $lastname2;
  28.     #[ORM\Column(type'string'length180uniquetrue)]
  29.     private ?string $login null;
  30.     #[ORM\Column]
  31.     private ?bool $isEnable null;
  32.     #[ORM\OneToMany(mappedBy'auteur'targetEntityBlogArticle::class)]
  33.     private Collection $blogArticles;
  34.     public function __construct()
  35.     {
  36.         $this->blogArticles = new ArrayCollection();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getEmail(): ?string
  43.     {
  44.         return $this->email;
  45.     }
  46.     public function setEmail(string $email): self
  47.     {
  48.         $this->email $email;
  49.         return $this;
  50.     }
  51.     /**
  52.      * A visual identifier that represents this user.
  53.      *
  54.      * @see UserInterface
  55.      */
  56.     public function getUserIdentifier(): string
  57.     {
  58.         return (string) $this->email;
  59.     }
  60.     /**
  61.      * @see UserInterface
  62.      */
  63.     public function getRoles(): array
  64.     {
  65.         $roles $this->roles;
  66.         // guarantee every user at least has ROLE_USER
  67.         $roles[] = 'ROLE_USER';
  68.         return array_unique($roles);
  69.     }
  70.     public function setRoles(array $roles): self
  71.     {
  72.         $this->roles $roles;
  73.         return $this;
  74.     }
  75.     public function hasRole($role){
  76.         if(!empty($this->getRoles())){
  77.             if(in_array($role$this->getRoles())){
  78.                 return true;
  79.             }
  80.         }
  81.         return false;
  82.     }
  83.     /**
  84.      * @see PasswordAuthenticatedUserInterface
  85.      */
  86.     public function getPassword(): string
  87.     {
  88.         return $this->password;
  89.     }
  90.     public function setPassword(string $password): self
  91.     {
  92.         $this->password $password;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @see UserInterface
  97.      */
  98.     public function eraseCredentials()
  99.     {
  100.         // If you store any temporary, sensitive data on the user, clear it here
  101.         // $this->plainPassword = null;
  102.     }
  103.     public function getFirstname(): ?string
  104.     {
  105.         return $this->firstname;
  106.     }
  107.     public function setFirstname(?string $firstname): self
  108.     {
  109.         $this->firstname $firstname;
  110.         return $this;
  111.     }
  112.     public function getLastname1(): ?string
  113.     {
  114.         return $this->lastname1;
  115.     }
  116.     public function setLastname1(?string $lastname1): self
  117.     {
  118.         $this->lastname1 $lastname1;
  119.         return $this;
  120.     }
  121.     public function getLastname2(): ?string
  122.     {
  123.         return $this->lastname2;
  124.     }
  125.     public function setLastname2(?string $lastname2): self
  126.     {
  127.         $this->lastname2 $lastname2;
  128.         return $this;
  129.     }
  130.     public function getLogin(): ?string
  131.     {
  132.         return $this->login;
  133.     }
  134.     public function setLogin(string $login): self
  135.     {
  136.         $this->login $login;
  137.         return $this;
  138.     }
  139.     public function isIsEnable(): ?bool
  140.     {
  141.         return $this->isEnable;
  142.     }
  143.     public function setIsEnable(bool $isEnable): self
  144.     {
  145.         $this->isEnable $isEnable;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, BlogArticle>
  150.      */
  151.     public function getBlogArticles(): Collection
  152.     {
  153.         return $this->blogArticles;
  154.     }
  155.     public function addBlogArticle(BlogArticle $blogArticle): static
  156.     {
  157.         if (!$this->blogArticles->contains($blogArticle)) {
  158.             $this->blogArticles->add($blogArticle);
  159.             $blogArticle->setAuteur($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeBlogArticle(BlogArticle $blogArticle): static
  164.     {
  165.         if ($this->blogArticles->removeElement($blogArticle)) {
  166.             // set the owning side to null (unless already changed)
  167.             if ($blogArticle->getAuteur() === $this) {
  168.                 $blogArticle->setAuteur(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173. }