src/Entity/User.php line 15

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\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. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private ?int $id;
  18.     #[ORM\Column(type'string'length180uniquetrue)]
  19.     private ?string $email;
  20.     #[ORM\Column(type'json')]
  21.     private array $roles = [];
  22.     #[ORM\Column(type'string'length255)]
  23.     private ?string $firstName;
  24.     #[ORM\Column(type'string'length255)]
  25.     private ?string $lastName;
  26.     #[ORM\Column(type'string'length255)]
  27.     private $password;
  28.     private $plainPassword;
  29.     #[ORM\Column(type'boolean')]
  30.     private $isVerified false;
  31.     #[ORM\OneToMany(mappedBy'school'targetEntitySchoolClass::class)]
  32.     private $schoolClasses;
  33.     #[ORM\OneToMany(mappedBy'user'targetEntitySchoolRegistration::class)]
  34.     private $schoolRegistrations;
  35.     public function __construct()
  36.     {
  37.         $this->schoolClasses = new ArrayCollection();
  38.         $this->schoolRegistrations = new ArrayCollection();
  39.     }
  40.     
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getEmail(): ?string
  46.     {
  47.         return $this->email;
  48.     }
  49.     public function setEmail(string $email): self
  50.     {
  51.         $this->email $email;
  52.         return $this;
  53.     }
  54.     /**
  55.      * A visual identifier that represents this user.
  56.      *
  57.      * @see UserInterface
  58.      */
  59.     public function getUserIdentifier(): string
  60.     {
  61.         return (string) $this->email;
  62.     }
  63.     /**
  64.      * @see UserInterface
  65.      */
  66.     public function getRoles(): array
  67.     {
  68.         $roles $this->roles;
  69.         // guarantee every user at least has ROLE_USER
  70.         $roles[] = 'ROLE_USER';
  71.         return array_unique($roles);
  72.     }
  73.     public function setRoles(array $roles): self
  74.     {
  75.         $this->roles $roles;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @see UserInterface
  80.      */
  81.     public function eraseCredentials()
  82.     {
  83.         $this->plainPassword null;
  84.     }
  85.     public function getFirstName(): ?string
  86.     {
  87.         return $this->firstName;
  88.     }
  89.     public function setFirstName(string $firstName): self
  90.     {
  91.         $this->firstName $firstName;
  92.         return $this;
  93.     }
  94.     public function getLastName(): ?string
  95.     {
  96.         return $this->lastName;
  97.     }
  98.     public function setLastName(string $lastName): self
  99.     {
  100.         $this->lastName $lastName;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return string|null
  105.      */
  106.     public function getPassword(): ?string
  107.     {
  108.         return $this->password;
  109.     }
  110.     public function setPassword(string $password): self
  111.     {
  112.         $this->password $password;
  113.         return $this;
  114.     }
  115.     public function getPlainPassword(): ?string
  116.     {
  117.         return $this->plainPassword;
  118.     }
  119.     public function setPlainPassword(string $plainPassword): self
  120.     {
  121.         $this->plainPassword $plainPassword;
  122.         return $this;
  123.     }
  124.     public function getIsVerified(): ?bool
  125.     {
  126.         return $this->isVerified;
  127.     }
  128.     public function setIsVerified(bool $isVerified): self
  129.     {
  130.         $this->isVerified $isVerified;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, SchoolClass>
  135.      */
  136.     public function getSchoolClasses(): Collection
  137.     {
  138.         return $this->schoolClasses;
  139.     }
  140.     public function addSchoolClass(SchoolClass $schoolClass): self
  141.     {
  142.         if (!$this->schoolClasses->contains($schoolClass)) {
  143.             $this->schoolClasses[] = $schoolClass;
  144.             $schoolClass->setSchool($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeSchoolClass(SchoolClass $schoolClass): self
  149.     {
  150.         if ($this->schoolClasses->removeElement($schoolClass)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($schoolClass->getSchool() === $this) {
  153.                 $schoolClass->setSchool(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection<int, SchoolRegistration>
  160.      */
  161.     public function getSchoolRegistrations(): Collection
  162.     {
  163.         return $this->schoolRegistrations;
  164.     }
  165.     public function addSchoolRegistration(SchoolRegistration $schoolRegistration): self
  166.     {
  167.         if (!$this->schoolRegistrations->contains($schoolRegistration)) {
  168.             $this->schoolRegistrations[] = $schoolRegistration;
  169.             $schoolRegistration->setUser($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeSchoolRegistration(SchoolRegistration $schoolRegistration): self
  174.     {
  175.         if ($this->schoolRegistrations->removeElement($schoolRegistration)) {
  176.             // set the owning side to null (unless already changed)
  177.             if ($schoolRegistration->getUser() === $this) {
  178.                 $schoolRegistration->setUser(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183. }