src/Entity/User.php line 14

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\UserInterface;
  8. /**
  9.  * @ORM\Entity(repositoryClass=UserRepository::class)
  10.  */
  11. class User implements UserInterface
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=180, unique=true)
  21.      */
  22.     private $email;
  23.     /**
  24.      * @ORM\Column(type="json")
  25.      */
  26.     private $roles = [];
  27.     /**
  28.      * @var string The hashed password
  29.      * @ORM\Column(type="string")
  30.      */
  31.     private $password;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      */
  35.     private $firstname;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=true)
  38.      */
  39.     private $lastname;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=UserNotification::class, mappedBy="user", cascade={"remove"})
  42.      */
  43.     private $userNotifications;
  44.     /**
  45.      * @ORM\Column(type="boolean")
  46.      */
  47.     private $isDefault false;
  48.     public function __construct()
  49.     {
  50.         $this->userNotifications = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getEmail(): ?string
  57.     {
  58.         return $this->email;
  59.     }
  60.     public function setEmail(string $email): self
  61.     {
  62.         $this->email $email;
  63.         return $this;
  64.     }
  65.     /**
  66.      * A visual identifier that represents this user.
  67.      *
  68.      * @see UserInterface
  69.      */
  70.     public function getUsername(): string
  71.     {
  72.         return (string) $this->email;
  73.     }
  74.     /**
  75.      * @see UserInterface
  76.      */
  77.     public function getRoles(): array
  78.     {
  79.         $roles $this->roles;
  80.         // guarantee every user at least has ROLE_USER
  81.         $roles[] = 'ROLE_USER';
  82.         return array_unique($roles);
  83.     }
  84.     public function setRoles(array $roles): self
  85.     {
  86.         $this->roles $roles;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function getPassword(): string
  93.     {
  94.         return (string) $this->password;
  95.     }
  96.     public function setPassword(string $password): self
  97.     {
  98.         $this->password $password;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function getSalt(): ?string
  105.     {
  106.         return null;
  107.     }
  108.     /**
  109.      * @see UserInterface
  110.      */
  111.     public function eraseCredentials()
  112.     {
  113.         // If you store any temporary, sensitive data on the user, clear it here
  114.         // $this->plainPassword = null;
  115.     }
  116.     public function getFirstname(): ?string
  117.     {
  118.         return $this->firstname;
  119.     }
  120.     public function setFirstname(string $firstname): self
  121.     {
  122.         $this->firstname $firstname;
  123.         return $this;
  124.     }
  125.     public function getLastname(): ?string
  126.     {
  127.         return $this->lastname;
  128.     }
  129.     public function setLastname(?string $lastname): self
  130.     {
  131.         $this->lastname $lastname;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection|UserNotification[]
  136.      */
  137.     public function getUserNotifications(): Collection
  138.     {
  139.         return $this->userNotifications;
  140.     }
  141.     public function addUserNotification(UserNotification $userNotification): self
  142.     {
  143.         if (!$this->userNotifications->contains($userNotification)) {
  144.             $this->userNotifications[] = $userNotification;
  145.             $userNotification->setUser($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeUserNotification(UserNotification $userNotification): self
  150.     {
  151.         if ($this->userNotifications->removeElement($userNotification)) {
  152.             // set the owning side to null (unless already changed)
  153.             if ($userNotification->getUser() === $this) {
  154.                 $userNotification->setUser(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     public function getIsDefault(): ?bool
  160.     {
  161.         return $this->isDefault;
  162.     }
  163.     public function setIsDefault(bool $isDefault): self
  164.     {
  165.         $this->isDefault $isDefault;
  166.         return $this;
  167.     }
  168. }