src/Entity/User.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. #[ORM\Table(name'`user`')]
  15. #[UniqueEntity(fields: ['email'])]
  16. #[ApiResource(normalizationContext: ['groups' => ['profile']],denormalizationContext: ['groups' => ['profile']])]
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.    #[Groups("profile")]
  23.    
  24.     private $id;
  25.     #[ORM\Column(type'string'length180uniquetrue)]
  26.     #[Groups("profile")]
  27.     private $email;
  28.     #[ORM\Column(type'json')]
  29.     
  30.     private $roles = [];
  31.     #[ORM\Column(type'string')]
  32.     #[Groups("profile")]
  33.     private $password;
  34.     #[ORM\ManyToMany(targetEntityAnswer::class, inversedBy'users'cascade: ["persist"])]
  35.     private $answers;
  36.     #[ORM\OneToOne(mappedBy'user'targetEntityProfile::class, cascade: ['persist''remove'])]
  37.     private $profile;
  38.     
  39.     #[ORM\Column(type'boolean'nullabletrue)]
  40.     private $isDisabled;
  41.     #[ORM\Column(nullabletrue)]
  42.    #[Groups("profile")]
  43.     private ?bool $isCompleted null;
  44.     #[ORM\Column(type'boolean')]
  45.    #[Groups("profile")]
  46.     private $isVerified false;
  47.     public function __toString()
  48.     {
  49.         return (string)$this->email;
  50.     }
  51.     public function __construct()
  52.     {
  53.         $this->answers = new ArrayCollection();
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getEmail(): ?string
  60.     {
  61.         return $this->email;
  62.     }
  63.     public function setEmail(string $email): self
  64.     {
  65.         $this->email $email;
  66.         return $this;
  67.     }
  68.     
  69.     public function isIsCompleted(): ?bool
  70.     {
  71.         return $this->isCompleted;
  72.     }
  73.     public function setIsCompleted(?bool $isCompleted): self
  74.     {
  75.         $this->isCompleted $isCompleted;
  76.         return $this;
  77.     }
  78.     /**
  79.      * A visual identifier that represents this user.
  80.      *
  81.      * @see UserInterface
  82.      */
  83.     public function getUserIdentifier(): string
  84.     {
  85.         return (string) $this->email;
  86.     }
  87.     /**
  88.      * @see UserInterface
  89.      */
  90.     public function getRoles(): array
  91.     {
  92.         $roles $this->roles;
  93.         // guarantee every user at least has ROLE_USER
  94.         $roles[] = 'ROLE_USER';
  95.         return array_unique($roles);
  96.     }
  97.     public function setRoles(array $roles): self
  98.     {
  99.         $this->roles $roles;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @see PasswordAuthenticatedUserInterface
  104.      */
  105.     public function getPassword(): string
  106.     {
  107.         return $this->password;
  108.     }
  109.     public function setPassword(string $password): self
  110.     {
  111.         $this->password $password;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @see UserInterface
  116.      */
  117.     public function eraseCredentials()
  118.     {
  119.         // If you store any temporary, sensitive data on the user, clear it here
  120.         // $this->plainPassword = null;
  121.     }
  122.     /**
  123.      * @return Collection<int, Answer>
  124.      */
  125.     public function getAnswers(): Collection
  126.     {
  127.         return $this->answers;
  128.     }
  129.     public function addAnswer(Answer $answer): self
  130.     {
  131.         if (!$this->answers->contains($answer)) {
  132.             $this->answers[] = $answer;
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeAnswer(Answer $answer): self
  137.     {
  138.         $this->answers->removeElement($answer);
  139.         return $this;
  140.     }
  141.     public function getProfile(): ?Profile
  142.     {
  143.         return $this->profile;
  144.     }
  145.     public function setProfile(?Profile $profile): self
  146.     {
  147.         $this->profile $profile;
  148.         return $this;
  149.     }
  150.     public function isIsDisabled(): ?bool
  151.     {
  152.         return $this->isDisabled;
  153.     }
  154.     public function setIsDisabled(?bool $isDisabled): self
  155.     {
  156.         $this->isDisabled $isDisabled;
  157.         return $this;
  158.     }
  159.     public function isVerified(): bool
  160.     {
  161.         return $this->isVerified;
  162.     }
  163.     public function setIsVerified(bool $isVerified): self
  164.     {
  165.         $this->isVerified $isVerified;
  166.         return $this;
  167.     }
  168. }