src/Entity/Users.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UsersRepository;
  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(repositoryClassUsersRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class Users implements UserInterfacePasswordAuthenticatedUserInterface
  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.     #[ORM\Column(type'string')]
  23.     private $password;
  24.     #[ORM\Column(type'boolean')]
  25.     private $is_verified false;
  26.     #[ORM\OneToMany(mappedBy'user'targetEntityQuestionari::class, orphanRemovaltrue)]
  27.     private $questionaris;
  28.     #[ORM\OneToMany(mappedBy'user'targetEntityUsersAmbienti::class, orphanRemovaltrue)]
  29.     private $usersAmbientis;
  30.     #[ORM\Column(nullabletrue)]
  31.     private $corsi_moodle;
  32.     public function __construct()
  33.     {
  34.         $this->questionaris = new ArrayCollection();
  35.         $this->usersAmbientis = new ArrayCollection();
  36.     }
  37.     
  38.     public function __toString()
  39.     {
  40.         return $this->email;
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getEmail(): ?string
  47.     {
  48.         return $this->email;
  49.     }
  50.     public function setEmail(string $email): self
  51.     {
  52.         $this->email $email;
  53.         return $this;
  54.     }
  55.     /**
  56.      * A visual identifier that represents this user.
  57.      *
  58.      * @see UserInterface
  59.      */
  60.     public function getUserIdentifier(): string
  61.     {
  62.         return (string) $this->email;
  63.     }
  64.     /**
  65.      * @see UserInterface
  66.      */
  67.     public function getRoles(): array
  68.     {
  69.         $roles $this->roles;
  70.         // guarantee every user at least has ROLE_USER
  71.         $roles[] = 'ROLE_USER';
  72.         return array_unique($roles);
  73.     }
  74.     public function setRoles(array $roles): self
  75.     {
  76.         $this->roles $roles;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @see PasswordAuthenticatedUserInterface
  81.      */
  82.     public function getPassword(): string
  83.     {
  84.         return $this->password;
  85.     }
  86.     public function setPassword(string $password): self
  87.     {
  88.         $this->password $password;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @see UserInterface
  93.      */
  94.     public function eraseCredentials()
  95.     {
  96.         // If you store any temporary, sensitive data on the user, clear it here
  97.         // $this->plainPassword = null;
  98.     }
  99.     public function isVerified(): bool
  100.     {
  101.         return $this->is_verified;
  102.     }
  103.     public function setIsVerified(bool $isVerified): self
  104.     {
  105.         $this->is_verified $isVerified;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection<int, Questionari>
  110.      */
  111.     public function getQuestionaris(): Collection
  112.     {
  113.         return $this->questionaris;
  114.     }
  115.     public function addQuestionari(Questionari $questionari): self
  116.     {
  117.         if (!$this->questionaris->contains($questionari)) {
  118.             $this->questionaris[] = $questionari;
  119.             $questionari->setUser($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeQuestionari(Questionari $questionari): self
  124.     {
  125.         if ($this->questionaris->removeElement($questionari)) {
  126.             // set the owning side to null (unless already changed)
  127.             if ($questionari->getUser() === $this) {
  128.                 $questionari->setUser(null);
  129.             }
  130.         }
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, UsersAmbienti>
  135.      */
  136.     public function getUsersAmbientis(): Collection
  137.     {
  138.         return $this->usersAmbientis;
  139.     }
  140.     public function addUsersAmbienti(UsersAmbienti $usersAmbienti): self
  141.     {
  142.         if (!$this->usersAmbientis->contains($usersAmbienti)) {
  143.             $this->usersAmbientis[] = $usersAmbienti;
  144.             $usersAmbienti->setUser($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeUsersAmbienti(UsersAmbienti $usersAmbienti): self
  149.     {
  150.         if ($this->usersAmbientis->removeElement($usersAmbienti)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($usersAmbienti->getUser() === $this) {
  153.                 $usersAmbienti->setUser(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function getCorsiMoodle(): ?string
  159.     {
  160.         return $this->corsi_moodle;
  161.     }
  162.     public function setCorsiMoodle(string $corsi_moodle): self
  163.     {
  164.         $this->corsi_moodle $corsi_moodle;
  165.         return $this;
  166.     }
  167. }