src/Entity/User.php line 17

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. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="boolean")
  37.      */
  38.     private $isCancellato 0;
  39.     /**
  40.      * @ORM\Column(type="boolean")
  41.      */
  42.     private $isAttivo 1;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Azienda::class, inversedBy="users")
  45.      */
  46.     private $azienda;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $nome;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $cognome;
  55.     /**
  56.      * @ORM\Column(type="boolean")
  57.      */
  58.     private $completataRegistrazione 0;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=Domanda::class, mappedBy="user")
  61.      */
  62.     private $domandas;
  63.     public function __construct()
  64.     {
  65.         $this->domandas = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getEmail(): ?string
  72.     {
  73.         return $this->email;
  74.     }
  75.     public function setEmail(string $email): self
  76.     {
  77.         $this->email $email;
  78.         return $this;
  79.     }
  80.     /**
  81.      * A visual identifier that represents this user.
  82.      *
  83.      * @see UserInterface
  84.      */
  85.     public function getUserIdentifier(): string
  86.     {
  87.         return (string) $this->email;
  88.     }
  89.     /**
  90.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  91.      */
  92.     public function getUsername(): string
  93.     {
  94.         return (string) $this->email;
  95.     }
  96.     /**
  97.      * @see UserInterface
  98.      */
  99.     public function getRoles(): array
  100.     {
  101.         $roles $this->roles;
  102.         // guarantee every user at least has ROLE_USER
  103.         $roles[] = 'ROLE_USER';
  104.         return array_unique($roles);
  105.     }
  106.     public function setRoles(array $roles): self
  107.     {
  108.         $this->roles $roles;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @see PasswordAuthenticatedUserInterface
  113.      */
  114.     public function getPassword(): string
  115.     {
  116.         return $this->password;
  117.     }
  118.     public function setPassword(string $password): self
  119.     {
  120.         $this->password $password;
  121.         return $this;
  122.     }
  123.     /**
  124.      * Returning a salt is only needed, if you are not using a modern
  125.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  126.      *
  127.      * @see UserInterface
  128.      */
  129.     public function getSalt(): ?string
  130.     {
  131.         return null;
  132.     }
  133.     /**
  134.      * @see UserInterface
  135.      */
  136.     public function eraseCredentials()
  137.     {
  138.         // If you store any temporary, sensitive data on the user, clear it here
  139.         // $this->plainPassword = null;
  140.     }
  141.     public function isCancellato(): ?bool
  142.     {
  143.         return $this->isCancellato;
  144.     }
  145.     public function setCancellato(bool $isCancellato): self
  146.     {
  147.         $this->isCancellato $isCancellato;
  148.         return $this;
  149.     }
  150.     public function isAttivo(): ?bool
  151.     {
  152.         return $this->isAttivo;
  153.     }
  154.     public function setAttivo(bool $isAttivo): self
  155.     {
  156.         $this->isAttivo $isAttivo;
  157.         return $this;
  158.     }
  159.     public function getAzienda(): ?Azienda
  160.     {
  161.         return $this->azienda;
  162.     }
  163.     public function setAzienda(?Azienda $azienda): self
  164.     {
  165.         $this->azienda $azienda;
  166.         return $this;
  167.     }
  168.     public function getNome(): ?string
  169.     {
  170.         return $this->nome;
  171.     }
  172.     public function setNome(?string $nome): self
  173.     {
  174.         $this->nome $nome;
  175.         return $this;
  176.     }
  177.     public function getCognome(): ?string
  178.     {
  179.         return $this->cognome;
  180.     }
  181.     public function setCognome(?string $cognome): self
  182.     {
  183.         $this->cognome $cognome;
  184.         return $this;
  185.     }
  186.     public function isCompletataRegistrazione(): ?bool
  187.     {
  188.         return $this->completataRegistrazione;
  189.     }
  190.     public function setCompletataRegistrazione(bool $completataRegistrazione): self
  191.     {
  192.         $this->completataRegistrazione $completataRegistrazione;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection<int, Domanda>
  197.      */
  198.     public function getDomandas(): Collection
  199.     {
  200.         return $this->domandas;
  201.     }
  202.     public function addDomanda(Domanda $domanda): self
  203.     {
  204.         if (!$this->domandas->contains($domanda)) {
  205.             $this->domandas[] = $domanda;
  206.             $domanda->setUser($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeDomanda(Domanda $domanda): self
  211.     {
  212.         if ($this->domandas->removeElement($domanda)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($domanda->getUser() === $this) {
  215.                 $domanda->setUser(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220. }