src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\System\usersRoles;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string',length255nullabletrue)]
  19.     private $email;
  20.     #[ORM\Column(type'array')]
  21.     private $roles = [];
  22.     #[ORM\Column(type'string',length255nullabletrue)]
  23.     private $password;
  24.     #[ORM\Column(type'string',length255nullabletrue)]
  25.     private $firstName;
  26.     #[ORM\Column(type'string',length255nullabletrue)]
  27.     private $lastName;
  28.     #[ORM\Column(type'boolean'options:["default"=>false])]
  29.     private $isEnabled;
  30.     #[ORM\Column(type'datetime'nullabletrue)]
  31.     private $createdAt;
  32.     #[ORM\Column(type'datetime'nullabletrue)]
  33.     private $lastConnectionAt;
  34.     #[ORM\OneToMany(mappedBy'users'targetEntityusersRoles::class)]
  35.     private $usersRoles;
  36.     public function __construct()
  37.     {
  38.         $this->createdAt = new \DateTime();
  39.         $this->isEnabled true;
  40.         $this->usersRoles = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function setId(int $id): self
  47.     {
  48.         $this->id $id;
  49.         return $this;
  50.     }
  51.     public function getEmail(): ?string
  52.     {
  53.         return $this->email;
  54.     }
  55.     public function setEmail(string $email): self
  56.     {
  57.         $this->email $email;
  58.         return $this;
  59.     }
  60.     public function getRoles()
  61.     {
  62.         $roles $this->roles;
  63.         // guarantee every user at least has ROLE_USER
  64.         $roles[] = 'ROLE_USER';
  65.         return array_unique($roles);
  66.     }
  67.     /**
  68.      * A visual identifier that represents this user.
  69.      *
  70.      * @see UserInterface
  71.      */
  72.     public function getUsername(): string
  73.     {
  74.         return (string) $this->email;
  75.     }
  76.     public function setRoles($roles) {
  77.         $this->roles $roles;
  78.     }
  79.     /**
  80.      * @see UserInterface
  81.      */
  82.     public function getPassword(): string
  83.     {
  84.         return (string) $this->password;
  85.     }
  86.     public function setPassword(string $password): self
  87.     {
  88.         $this->password $password;
  89.         return $this;
  90.     }
  91.     public function getFirstName(): ?string
  92.     {
  93.         return $this->firstName;
  94.     }
  95.     public function setFirstName(string $firstName): self
  96.     {
  97.         $this->firstName $firstName;
  98.         return $this;
  99.     }
  100.     public function getLastName(): ?string
  101.     {
  102.         return $this->lastName;
  103.     }
  104.     public function setLastName(string $lastName): self
  105.     {
  106.         $this->lastName $lastName;
  107.         return $this;
  108.     }
  109.     public function getIsEnabled(): ?bool
  110.     {
  111.         return $this->isEnabled;
  112.     }
  113.     public function setIsEnabled(bool $isEnabled): self
  114.     {
  115.         $this->isEnabled $isEnabled;
  116.         return $this;
  117.     }
  118.     public function getCreatedAt(): ?\DateTimeInterface
  119.     {
  120.         return $this->createdAt;
  121.     }
  122.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  123.     {
  124.         $this->createdAt $createdAt;
  125.         return $this;
  126.     }
  127.     public function getLastConnectionAt(): ?\DateTimeInterface
  128.     {
  129.         return $this->lastConnectionAt;
  130.     }
  131.     public function setLastConnectionAt(?\DateTimeInterface $lastConnectionAt): self
  132.     {
  133.         $this->lastConnectionAt $lastConnectionAt;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @see UserInterface
  138.      */
  139.     public function getSalt()
  140.     {
  141.         // not needed when using the "bcrypt" algorithm in original.security.yaml.old
  142.     }
  143.     /**
  144.      * @see UserInterface
  145.      */
  146.     public function eraseCredentials()
  147.     {
  148.         // If you store any temporary, sensitive data on the user, clear it here
  149.         // $this->plainPassword = null;
  150.     }
  151.     /**
  152.      * @return Collection<int, usersRoles>
  153.      */
  154.     public function getUsersRoles(): Collection
  155.     {
  156.         return $this->usersRoles;
  157.     }
  158.     public function addUsersRole(usersRoles $usersRole): self
  159.     {
  160.         if (!$this->usersRoles->contains($usersRole)) {
  161.             $this->usersRoles[] = $usersRole;
  162.             $usersRole->setUsersId($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeUsersRole(usersRoles $usersRole): self
  167.     {
  168.         if ($this->usersRoles->removeElement($usersRole)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($usersRole->getUsersId() === $this) {
  171.                 $usersRole->setUsersId(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176. }