src/Entity/User.php line 25

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  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. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. use \App\IlaveU\ShopBundle\Entity\Store\Store;
  15. #[ApiResource(
  16.     normalizationContext: ['groups' => ['read']],
  17.     denormalizationContext: ['groups' => ['write']],
  18. )]
  19. #[ApiFilter(SearchFilter::class, properties: ['username' => 'exact','googleId' => 'exact'])]
  20. #[ORM\Table(name'user')]
  21. #[ORM\Entity(repositoryClassUserRepository::class)]
  22. #[UniqueEntity(fields: ['username'], message'There is already an account with this username')]
  23. class User implements UserInterfacePasswordAuthenticatedUserInterface
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column(type'integer')]
  28.     private $id;
  29.     #[Groups(["read","write"])]
  30.     #[ORM\Column(type'string'length180uniquetrue)]
  31.     private ?string $username null;
  32.     #[Groups(["read","write"])]
  33.     #[ORM\Column(type'json')]
  34.     private array $roles = [];
  35.     #[Groups(["read","write"])]
  36.     #[ORM\Column(type'string')]
  37.     private ?string $password "";
  38.     
  39.     #[ORM\Column(type'boolean'nullabletrue)]
  40.     #[Groups(["read","write"])]
  41.     private ?bool $isValid null;
  42.     #[ORM\Column(type'boolean')]
  43.     #[Groups(["read","write"])]
  44.     private bool $isVerified false;
  45.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy'users')]
  46.     private Collection $storedRoles;
  47.     
  48.     #[Groups(["read","write"])]
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $exponentPushToken null;
  51.     #[Groups(["read","write"])]
  52.     #[ORM\Column(length255nullabletrue)]
  53.     private ?string $googleId null;
  54.     #[Groups(["read","write"])]
  55.     #[ORM\Column(length255nullabletrue)]
  56.     private ?string $avatar null;
  57.     #[Groups(["read","write"])]
  58.     #[ORM\Column(length255nullabletrue)]
  59.     private ?string $facebookId null;
  60.     #[ORM\OneToMany(mappedBy'user'targetEntityAiRequest::class)]
  61.     private Collection $aiRequests;
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?bool $isAutoConnectUsed null;
  64.     #[ORM\ManyToOne(inversedBy'users')]
  65.     private ?Store $store null;
  66.     public function __construct()
  67.     {
  68.         $this->storedRoles = new ArrayCollection();
  69.         $this->isValid true;
  70.         $this->aiRequests = new ArrayCollection();
  71.     }
  72.     public function __toString()
  73.     {
  74.         return $this->getUserIdentifier();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     /**
  81.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  82.      */
  83.     public function getUsername(): string
  84.     {
  85.         return (string) $this->username;
  86.     }
  87.     public function setUsername(string $username): self
  88.     {
  89.         $this->username $username;
  90.         return $this;
  91.     }
  92.     /**
  93.      * A visual identifier that represents this user.
  94.      *
  95.      * @see UserInterface
  96.      */
  97.     public function getUserIdentifier(): string
  98.     {
  99.         return (string) $this->username;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function getRoles(): array
  105.     {
  106.         $roles $this->roles;
  107.         // guarantee every user at least has ROLE_USER
  108.         $roles[] = 'ROLE_USER';
  109.         foreach($this->getStoredRoles() as $singleRole){
  110.             $roles[] = $singleRole->getName();
  111.         }
  112.         return array_unique($roles);
  113.     }
  114.     public function setRoles(array $roles): self
  115.     {
  116.         $this->roles $roles;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @see PasswordAuthenticatedUserInterface
  121.      */
  122.     public function getPassword(): string
  123.     {
  124.         return $this->password;
  125.     }
  126.     public function setPassword(string $password): self
  127.     {
  128.         $this->password $password;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Returning a salt is only needed, if you are not using a modern
  133.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  134.      *
  135.      * @see UserInterface
  136.      */
  137.     public function getSalt(): ?string
  138.     {
  139.         return null;
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function eraseCredentials()
  145.     {
  146.         // If you store any temporary, sensitive data on the user, clear it here
  147.         // $this->plainPassword = null;
  148.     }
  149.     public function getIsValid(): ?bool
  150.     {
  151.         return $this->isValid;
  152.     }
  153.     public function setIsValid(?bool $isValid): self
  154.     {
  155.         $this->isValid $isValid;
  156.         return $this;
  157.     }
  158.     public function isVerified(): bool
  159.     {
  160.         return $this->isVerified;
  161.     }
  162.     public function setIsVerified(bool $isVerified): self
  163.     {
  164.         $this->isVerified $isVerified;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection<int, Role>
  169.      */
  170.     public function getStoredRoles(): Collection
  171.     {
  172.         return $this->storedRoles;
  173.     }
  174.     public function addStoredRole(Role $storedRole): self
  175.     {
  176.         if (!$this->storedRoles->contains($storedRole)) {
  177.             $this->storedRoles->add($storedRole);
  178.             $storedRole->addUser($this);
  179.         }
  180.         return $this;
  181.     }
  182.     public function removeStoredRole(Role $storedRole): self
  183.     {
  184.         if ($this->storedRoles->removeElement($storedRole)) {
  185.             $storedRole->removeUser($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function getExponentPushToken(): ?string
  190.     {
  191.         return $this->exponentPushToken;
  192.     }
  193.     public function setExponentPushToken(?string $exponentPushToken): self
  194.     {
  195.         $this->exponentPushToken $exponentPushToken;
  196.         return $this;
  197.     }
  198.     public function getGoogleId(): ?string
  199.     {
  200.         return $this->googleId;
  201.     }
  202.     public function setGoogleId(?string $googleId): self
  203.     {
  204.         $this->googleId $googleId;
  205.         return $this;
  206.     }
  207.     public function getAvatar(): ?string
  208.     {
  209.         return $this->avatar;
  210.     }
  211.     public function setAvatar(?string $avatar): self
  212.     {
  213.         $this->avatar $avatar;
  214.         return $this;
  215.     }
  216.     public function getFacebookId(): ?string
  217.     {
  218.         return $this->facebookId;
  219.     }
  220.     public function setFacebookId(?string $facebookId): self
  221.     {
  222.         $this->facebookId $facebookId;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection<int, AiRequest>
  227.      */
  228.     public function getAiRequests(): Collection
  229.     {
  230.         return $this->aiRequests;
  231.     }
  232.     public function addAiRequest(AiRequest $aiRequest): static
  233.     {
  234.         if (!$this->aiRequests->contains($aiRequest)) {
  235.             $this->aiRequests->add($aiRequest);
  236.             $aiRequest->setUser($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeAiRequest(AiRequest $aiRequest): static
  241.     {
  242.         if ($this->aiRequests->removeElement($aiRequest)) {
  243.             // set the owning side to null (unless already changed)
  244.             if ($aiRequest->getUser() === $this) {
  245.                 $aiRequest->setUser(null);
  246.             }
  247.         }
  248.         return $this;
  249.     }
  250.     public function isIsAutoConnectUsed(): ?bool
  251.     {
  252.         return $this->isAutoConnectUsed;
  253.     }
  254.     public function setIsAutoConnectUsed(?bool $isAutoConnectUsed): static
  255.     {
  256.         $this->isAutoConnectUsed $isAutoConnectUsed;
  257.         return $this;
  258.     }
  259.     public function getStore(): ?Store
  260.     {
  261.         return $this->store;
  262.     }
  263.     public function setStore(?Store $store): static
  264.     {
  265.         $this->store $store;
  266.         return $this;
  267.     }
  268. }