src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\UserRepository;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. #[ORM\Table(name'`user`')]
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. class User implements UserInterface,PasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string'length180uniquetrue)]
  19.     private $email;
  20.     #[ORM\Column(type'json')]
  21.     private $roles = [];
  22.     /**
  23.      * @var string The hashed password
  24.      */
  25.     #[ORM\Column(type'string')]
  26.     private $password;
  27.     #[ORM\Column(type'string'length50nullabletrue)]
  28.     private $firstname;
  29.     #[ORM\Column(type'datetime'nullabletrue)]
  30.     private $lastLogin;
  31.     #[ORM\Column(type'string'length150nullabletrue)]
  32.     private $lastname;
  33.     private ?string $plainPassword '';
  34.     #[ORM\OneToMany(targetEntityLicense::class, mappedBy'user')]
  35.     private $licenses;
  36.     public function __construct()
  37.     {
  38.         $this->licenses = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getEmail(): ?string
  45.     {
  46.         return $this->email;
  47.     }
  48.     public function setEmail(string $email): self
  49.     {
  50.         $this->email $email;
  51.         return $this;
  52.     }
  53.     /**
  54.      * A visual identifier that represents this user.
  55.      *
  56.      * @see UserInterface
  57.      */
  58.     public function getUsername(): string
  59.     {
  60.         return (string) $this->email;
  61.     }
  62.     /**
  63.      * @see UserInterface
  64.      */
  65.     public function getRoles(): array
  66.     {
  67.         $roles $this->roles;
  68.         // guarantee every user at least has ROLE_USER
  69.         $roles[] = 'ROLE_USER';
  70.         return array_unique($roles);
  71.     }
  72.     public function setRoles(array $roles): self
  73.     {
  74.         $this->roles $roles;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @see UserInterface
  79.      */
  80.     public function getPassword(): string
  81.     {
  82.         return (string) $this->password;
  83.     }
  84.     public function setPassword(string $password): self
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function getSalt()
  93.     {
  94.         // not needed when using the "bcrypt" algorithm in security.yaml
  95.     }
  96.     /**
  97.      * @see UserInterface
  98.      */
  99.     public function eraseCredentials()
  100.     {
  101.         // If you store any temporary, sensitive data on the user, clear it here
  102.         // $this->plainPassword = null;
  103.     }
  104.     public function getFirstname(): ?string
  105.     {
  106.         return $this->firstname;
  107.     }
  108.     public function setFirstname(?string $firstname): self
  109.     {
  110.         $this->firstname $firstname;
  111.         return $this;
  112.     }
  113.     public function getLastname(): ?string
  114.     {
  115.         return $this->lastname;
  116.     }
  117.     public function setLastname(?string $lastname): self
  118.     {
  119.         $this->lastname $lastname;
  120.         return $this;
  121.     }
  122.     /**
  123.      * Get the value of lastLogin
  124.      */ 
  125.     public function getLastLogin()
  126.     {
  127.         return $this->lastLogin;
  128.     }
  129.     /**
  130.      * Set the value of lastLogin
  131.      *
  132.      * @return  self
  133.      */ 
  134.     public function setLastLogin($lastLogin)
  135.     {
  136.         $this->lastLogin $lastLogin;
  137.         return $this;
  138.     }
  139.     /**
  140.      * The public representation of the user (e.g. a username, an email address, etc.)
  141.      *
  142.      * @see UserInterface
  143.      */
  144.     public function getUserIdentifier(): string
  145.     {
  146.         return (string) $this->email;
  147.     }
  148.     public function getPlainPassword(): ?string
  149.     {
  150.         return $this->plainPassword;
  151.     }
  152.     public function setPlainPassword(?string $plainPassword): void
  153.     {
  154.         $this->plainPassword $plainPassword;
  155.     }
  156.     /**
  157.      * @return Collection<int, License>
  158.      */
  159.     public function getLicenses(): Collection
  160.     {
  161.         return $this->licenses;
  162.     }
  163.     public function addLicense(License $license): self
  164.     {
  165.         if (!$this->licenses->contains($license)) {
  166.             $this->licenses[] = $license;
  167.             $license->setUser($this);
  168.         }
  169.         return $this;
  170.     }
  171.     public function removeLicense(License $license): self
  172.     {
  173.         if ($this->licenses->removeElement($license)) {
  174.             // set the owning side to null (unless already changed)
  175.             if ($license->getUser() === $this) {
  176.                 $license->setUser(null);
  177.             }
  178.         }
  179.         return $this;
  180.     }
  181.     public function __toString(){
  182.         return $this->lastname.' '.$this->firstname;
  183.     }
  184. }