src/Entity/User.php line 24

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