src/Entity/User.php line 17

  1. <?php
  2. namespace Cms\Entity;
  3. use Cms\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[ORM\Table(name'`user`')]
  12. #[ORM\ChangeTrackingPolicy('DEFERRED_EXPLICIT')]
  13. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length180uniquetrue)]
  21.     private ?string $email null;
  22.     #[ORM\Column]
  23.     private array $roles = [];
  24.     /**
  25.      * @var string The hashed password
  26.      */
  27.     #[ORM\Column]
  28.     private ?string $password null;
  29.     #[ORM\OneToMany(mappedBy'createdBy'targetEntityPost::class)]
  30.     private Collection $posts;
  31.     #[ORM\Column(type'boolean')]
  32.     private $isVerified false;
  33.     #[ORM\Column(length255)]
  34.     private ?string $firstname null;
  35.     #[ORM\Column(length255)]
  36.     private ?string $lastname null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $username null;
  39.     #[ORM\OneToMany(mappedBy'user'targetEntityPlatform::class, orphanRemovaltrue)]
  40.     private Collection $platforms;
  41.     public function __construct()
  42.     {
  43.         $this->posts = new ArrayCollection();
  44.         $this->platforms = new ArrayCollection();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getEmail(): ?string
  51.     {
  52.         return $this->email;
  53.     }
  54.     public function setEmail(string $email): self
  55.     {
  56.         $this->email $email;
  57.         return $this;
  58.     }
  59.     /**
  60.      * A visual identifier that represents this user.
  61.      *
  62.      * @see UserInterface
  63.      */
  64.     public function getUserIdentifier(): string
  65.     {
  66.         return (string) $this->email;
  67.     }
  68.     /**
  69.      * @see UserInterface
  70.      */
  71.     public function getRoles(): array
  72.     {
  73.         $roles $this->roles;
  74.         // guarantee every user at least has ROLE_USER
  75.         $roles[] = 'ROLE_USER';
  76.         return array_unique($roles);
  77.     }
  78.     public function setRoles(array $roles): self
  79.     {
  80.         $this->roles $roles;
  81.         return $this;
  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.     /**
  104.      * @return Collection<int, Post>
  105.      */
  106.     public function getPosts(): Collection
  107.     {
  108.         return $this->posts;
  109.     }
  110.     public function addPost(Post $post): self
  111.     {
  112.         if (!$this->posts->contains($post)) {
  113.             $this->posts->add($post);
  114.             $post->setCreatedBy($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removePost(Post $post): self
  119.     {
  120.         if ($this->posts->removeElement($post)) {
  121.             // set the owning side to null (unless already changed)
  122.             if ($post->getCreatedBy() === $this) {
  123.                 $post->setCreatedBy(null);
  124.             }
  125.         }
  126.         return $this;
  127.     }
  128.     public function isVerified(): bool
  129.     {
  130.         return $this->isVerified;
  131.     }
  132.     public function setIsVerified(bool $isVerified): self
  133.     {
  134.         $this->isVerified $isVerified;
  135.         return $this;
  136.     }
  137.     public function getFirstname(): ?string
  138.     {
  139.         return $this->firstname;
  140.     }
  141.     public function setFirstname(string $firstname): self
  142.     {
  143.         $this->firstname $firstname;
  144.         return $this;
  145.     }
  146.     public function getLastname(): ?string
  147.     {
  148.         return $this->lastname;
  149.     }
  150.     public function setLastname(string $lastname): self
  151.     {
  152.         $this->lastname $lastname;
  153.         return $this;
  154.     }
  155.     public function getUsername(): ?string
  156.     {
  157.         return $this->username;
  158.     }
  159.     public function setUsername(?string $username): self
  160.     {
  161.         $this->username $username;
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, Platform>
  166.      */
  167.     public function getPlatforms(): Collection
  168.     {
  169.         return $this->platforms;
  170.     }
  171.     public function addPlatform(Platform $platform): self
  172.     {
  173.         if (!$this->platforms->contains($platform)) {
  174.             $this->platforms->add($platform);
  175.             $platform->setUser($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removePlatform(Platform $platform): self
  180.     {
  181.         if ($this->platforms->removeElement($platform)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($platform->getUser() === $this) {
  184.                 $platform->setUser(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189. }