src/Entity/User.php line 28

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  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 Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
  13. use Scheb\TwoFactorBundle\Model\TrustedDeviceInterface;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use ApiPlatform\Metadata\Delete;
  16. use ApiPlatform\Metadata\Get;
  17. use ApiPlatform\Metadata\GetCollection;
  18. use ApiPlatform\Metadata\Link;
  19. use ApiPlatform\Metadata\Patch;
  20. use ApiPlatform\Metadata\Post;
  21. use ApiPlatform\Metadata\Put;
  22. #[ORM\Entity(repositoryClassUserRepository::class)]
  23. #[ApiResource]
  24. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  25. class User implements UserInterfacePasswordAuthenticatedUserInterfaceTwoFactorInterfaceTrustedDeviceInterface
  26. {
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30. #[Groups(['user:read','service:read','reservation:read','serviceswithoutuserservices:read','notification:read'])]
  31.     private ?int $id null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     private ?string $gender null;
  34.     #[ORM\Column(length255)]
  35. #[Groups(['user:read','service:read','reservation:read','serviceswithoutuserservices:read','notification:read'])]
  36.     private ?string $fname null;
  37.     #[ORM\Column(length255)]
  38. #[Groups(['user:read','service:read','reservation:read','serviceswithoutuserservices:read','notification:read'])]
  39.     private ?string $lname null;
  40.     #[ORM\Column(length255)]
  41. #[Groups(['service:read','reservation:read','serviceswithoutuserservices:read','notification:read'])]
  42.     private ?string $email null;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $email_token null;
  45.     #[ORM\Column(length255nullabletrue)]
  46.     private ?string $username null;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     private ?string $password null;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $password_token null;
  51.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  52.     private ?\DateTimeInterface $birthday null;
  53.     #[ORM\Column(length255nullabletrue)]
  54. #[Groups(['user:read','service:read','reservation:read','serviceswithoutuserservices:read','notification:read'])]
  55.     private ?string $phone null;
  56.     #[ORM\Column(length255nullabletrue)]
  57.     private ?string $phone_token null;
  58.     #[ORM\Column(length255nullabletrue)]
  59. #[Groups(['user:read','service:read','reservation:read','notification:read'])]
  60.     private ?string $avatar null;
  61.      #[ORM\Column(length255nullabletrue)]
  62. #[Groups(['user:read','service:read','reservation:read','notification:read'])]
  63.     private ?string $type "1";
  64.     #[ORM\Column]
  65.     private ?int $status 0;
  66.     #[ORM\Column]
  67.     private array $roles = [];
  68.     #[ORM\Column(length255nullabletrue)]
  69.     private ?string $lang null;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     private ?string $address1 null;
  72.     #[ORM\Column(length255nullabletrue)]
  73.     private ?string $address2 null;
  74.     #[ORM\Column(length255nullabletrue)]
  75.     private ?string $zipcode null;
  76.     #[ORM\Column(length255nullabletrue)]
  77. #[Groups(['service:read'])]
  78.     private ?string $city null;
  79.     #[ORM\Column(length255nullabletrue)]
  80.     private ?string $social_brand null;
  81.     #[ORM\Column(length255nullabletrue)]
  82.     private ?string $social_id null;
  83.     #[ORM\Column(length255nullabletrue)]
  84.     private ?string $country null;
  85.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  86.     private ?\DateTimeInterface $created_at null;
  87.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  88.     private ?\DateTimeInterface $updated_at null;
  89.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  90.     private ?\DateTimeInterface $last_login null;
  91.     #[ORM\Column(typeTypes::INTEGER)]
  92.     private int $trustedVersion 0;
  93.     private ?string $password_update null;
  94.     #[ORM\Column(type'boolean')]
  95.     private $isVerified false;
  96.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  97.     private ?string $description null;
  98.     #[ORM\Column(length255nullabletrue)]
  99.     private ?string $location null;
  100.     #[ORM\OneToMany(mappedBy'user'targetEntityMedia::class, orphanRemovaltrue)]
  101.     private Collection $medias;
  102.     #[ORM\OneToMany(mappedBy'user'targetEntityPrice::class, orphanRemovaltrue)]
  103.     private Collection $prices;
  104.     #[ORM\OneToMany(mappedBy'user'targetEntityService::class)]
  105.     
  106.     private Collection $services;
  107.     #[ORM\OneToMany(mappedBy'user'targetEntityReservation::class)]
  108.     private Collection $reservations;
  109.  
  110.     #[ORM\OneToMany(mappedBy'user'targetEntityNotification::class)]
  111.     private Collection $notifications;
  112.     #[ORM\OneToMany(mappedBy'user'targetEntityFavorite::class)]
  113.     private Collection $favorites;
  114.     #[ORM\OneToMany(mappedBy'user'targetEntityGallery::class)]
  115.     #[Groups(['service:read'])]
  116.     private Collection $galleries;
  117.     #[ORM\OneToMany(mappedBy'user'targetEntityReview::class)]
  118.     private Collection $reviews;
  119.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessage::class)]
  120.     private Collection $messages;
  121.     #[ORM\Column(length255nullabletrue)]
  122.     private ?string $expoPushToken null;
  123.     #[ORM\Column(length255nullabletrue)]
  124.     private ?string $identity null;
  125.     public function __construct()
  126.     {
  127.         $this->setCreatedAt(new \DateTime());
  128.         $this->medias = new ArrayCollection();
  129.         $this->prices = new ArrayCollection();
  130.         $this->services = new ArrayCollection();
  131.         $this->reservations = new ArrayCollection();
  132.       
  133.         $this->notifications = new ArrayCollection();
  134.         $this->favorites = new ArrayCollection();
  135.         $this->galleries = new ArrayCollection();
  136.         $this->reviews = new ArrayCollection();
  137.         $this->messages = new ArrayCollection();
  138.     }
  139.     public function getId(): ?int
  140.     {
  141.         return $this->id;
  142.     }
  143.     public function getGender(): ?string
  144.     {
  145.         return $this->gender;
  146.     }
  147.     public function setGender(?string $gender): self
  148.     {
  149.         $this->gender $gender;
  150.         return $this;
  151.     }
  152.     public function getFname(): ?string
  153.     {
  154.         return $this->fname;
  155.     }
  156.     public function setFname(string $fname): self
  157.     {
  158.         $this->fname $fname;
  159.         return $this;
  160.     }
  161.     public function getLname(): ?string
  162.     {
  163.         return $this->lname;
  164.     }
  165.     public function setLname(string $lname): self
  166.     {
  167.         $this->lname $lname;
  168.         return $this;
  169.     }
  170.     public function getEmail(): ?string
  171.     {
  172.         return $this->email;
  173.     }
  174.     public function setEmail(string $email): self
  175.     {
  176.         $this->email $email;
  177.         return $this;
  178.     }
  179.     public function getUsername(): ?string
  180.     {
  181.         return $this->email;
  182.     }
  183.     public function setUsername(?string $username): self
  184.     {
  185.         $this->username $username;
  186.         return $this;
  187.     }
  188.     public function getPassword(): ?string
  189.     {
  190.         return $this->password;
  191.     }
  192.     public function setPassword(?string $password): self
  193.     {
  194.         $this->password $password;
  195.         return $this;
  196.     }
  197.     public function getPasswordToken(): ?string
  198.     {
  199.         return $this->password_token;
  200.     }
  201.     public function setPasswordToken(?string $password_token): self
  202.     {
  203.         $this->password_token $password_token;
  204.         return $this;
  205.     }
  206.     public function getBirthday(): ?\DateTimeInterface
  207.     {
  208.         return $this->birthday;
  209.     }
  210.     public function setBirthday(?\DateTimeInterface $birthday): self
  211.     {
  212.         $this->birthday $birthday;
  213.         return $this;
  214.     }
  215.     public function getPhone(): ?string
  216.     {
  217.         return $this->phone;
  218.     }
  219.     public function setPhone(?string $phone): self
  220.     {
  221.         $this->phone $phone;
  222.         return $this;
  223.     }
  224.     public function getPhoneToken(): ?string
  225.     {
  226.         return $this->phone_token;
  227.     }
  228.     public function setPhoneToken(?string $phone_token): self
  229.     {
  230.         $this->phone_token $phone_token;
  231.         return $this;
  232.     }
  233.     public function getAvatar(): ?string
  234.     {
  235.      if (empty($this->avatar)) {
  236.         return 'placeholder.png';
  237.     }
  238.         return $this->avatar;
  239.     }
  240.     public function setAvatar(?string $avatar): self
  241.     {
  242.         $this->avatar $avatar;
  243.         return $this;
  244.     }
  245.     public function getType(): ?string
  246.     {
  247.         return $this->type;
  248.     }
  249.     public function setType(string $type): self
  250.     {
  251.         $this->type $type;
  252.         return $this;
  253.     }
  254.     public function getStatus(): ?int
  255.     {
  256.         return $this->status;
  257.     }
  258.     public function setStatus(int $status): self
  259.     {
  260.         $this->status $status;
  261.         return $this;
  262.     }
  263.     public function getRoles(): array
  264.     {
  265.         $roles $this->roles;
  266.         // guarantee every user at least has ROLE_USER
  267.         $roles[] = 'ROLE_USER';
  268.         if($this->getType() == 0)
  269.             $roles[]  = 'ROLE_ADMIN';
  270.         return array_unique($roles);
  271.     }
  272.     public function setRoles(array $roles): self
  273.     {
  274.         $this->roles $roles;
  275.         return $this;
  276.     }
  277.     public function getLang(): ?string
  278.     {
  279.         return $this->lang;
  280.     }
  281.     public function setLang(?string $lang): self
  282.     {
  283.         $this->lang $lang;
  284.         return $this;
  285.     }
  286.     public function getAddress1(): ?string
  287.     {
  288.         return $this->address1;
  289.     }
  290.     public function setAddress1(?string $address1): self
  291.     {
  292.         $this->address1 $address1;
  293.         return $this;
  294.     }
  295.     public function getAddress2(): ?string
  296.     {
  297.         return $this->address2;
  298.     }
  299.     public function setAddress2(?string $address2): self
  300.     {
  301.         $this->address2 $address2;
  302.         return $this;
  303.     }
  304.     public function getZipcode(): ?string
  305.     {
  306.         return $this->zipcode;
  307.     }
  308.     public function setZipcode(?string $zipcode): self
  309.     {
  310.         $this->zipcode $zipcode;
  311.         return $this;
  312.     }
  313.     public function getCity(): ?string
  314.     {
  315.         return $this->city;
  316.     }
  317.     public function setCity(?string $city): self
  318.     {
  319.         $this->city $city;
  320.         return $this;
  321.     }
  322.     public function getSocialBrand(): ?string
  323.     {
  324.         return $this->social_brand;
  325.     }
  326.     public function setSocialBrand(?string $social_brand): self
  327.     {
  328.         $this->social_brand $social_brand;
  329.         return $this;
  330.     }
  331.     public function getSocialId(): ?string
  332.     {
  333.         return $this->social_id;
  334.     }
  335.     public function setSocialId(string $social_id): self
  336.     {
  337.         $this->social_id $social_id;
  338.         return $this;
  339.     }
  340.     public function getCountry(): ?string
  341.     {
  342.         return $this->country;
  343.     }
  344.     public function setCountry(?string $country): self
  345.     {
  346.         $this->country $country;
  347.         return $this;
  348.     }
  349.     public function getCreatedAt(): ?\DateTimeInterface
  350.     {
  351.         return $this->created_at;
  352.     }
  353.     public function setCreatedAt(\DateTimeInterface $created_at): self
  354.     {
  355.         $this->created_at $created_at;
  356.         return $this;
  357.     }
  358.     public function getUpdatedAt(): ?\DateTimeInterface
  359.     {
  360.         return $this->updated_at;
  361.     }
  362.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  363.     {
  364.         $this->updated_at $updated_at;
  365.         return $this;
  366.     }
  367.     public function getLastLogin(): ?\DateTimeInterface
  368.     {
  369.         return $this->last_login;
  370.     }
  371.     public function setLastLogin(\DateTimeInterface $last_login): self
  372.     {
  373.         $this->last_login $last_login;
  374.         return $this;
  375.     }
  376.     public function eraseCredentials()
  377.     {
  378.         // TODO: Implement eraseCredentials() method.
  379.     }
  380.     public function getUserIdentifier(): string
  381.     {
  382.         return $this->getEmail();
  383.     }
  384.     public function getPasswordUpdate(): ?string
  385.     {
  386.         return $this->password_update;
  387.     }
  388.     public function setPasswordUpdate(?string $password_update): void
  389.     {
  390.         $this->password_update $password_update;
  391.     }
  392.     public function isEmailAuthEnabled(): bool
  393.     {
  394.         return true// This can be a persisted field to switch email code authentication on/off
  395.     }
  396.     public function getEmailAuthRecipient(): string
  397.     {
  398.         return $this->email;
  399.     }
  400.     public function getEmailAuthCode(): string
  401.     {
  402.         if (null === $this->email_token) {
  403.             throw new \LogicException('The email authentication code was not set');
  404.         }
  405.         return $this->email_token;
  406.     }
  407.     public function setEmailAuthCode(string $email_token): void
  408.     {
  409.         $this->email_token $email_token;
  410.     }
  411.     public function getTrustedTokenVersion(): int
  412.     {
  413.         return $this->trustedVersion;
  414.     }
  415.     public function isVerified(): bool
  416.     {
  417.         return $this->isVerified;
  418.     }
  419.     public function setIsVerified(bool $isVerified): self
  420.     {
  421.         $this->isVerified $isVerified;
  422.         return $this;
  423.     }
  424.     public function getDescription(): ?string
  425.     {
  426.         return $this->description;
  427.     }
  428.     public function setDescription(?string $description): self
  429.     {
  430.         $this->description $description;
  431.         return $this;
  432.     }
  433.     public function getLocation(): ?string
  434.     {
  435.         return $this->location;
  436.     }
  437.     public function setLocation(?string $location): self
  438.     {
  439.         $this->location $location;
  440.         return $this;
  441.     }
  442.     /**
  443.      * @return Collection<int, Media>
  444.      */
  445.     public function getMedias(): Collection
  446.     {
  447.         return $this->medias;
  448.     }
  449.     public function addMedia(Media $media): self
  450.     {
  451.         if (!$this->medias->contains($media)) {
  452.             $this->medias->add($media);
  453.             $media->setUser($this);
  454.         }
  455.         return $this;
  456.     }
  457.     public function removeMedia(Media $media): self
  458.     {
  459.         if ($this->medias->removeElement($media)) {
  460.             // set the owning side to null (unless already changed)
  461.             if ($media->getUser() === $this) {
  462.                 $media->setUser(null);
  463.             }
  464.         }
  465.         return $this;
  466.     }
  467.     /**
  468.      * @return Collection<int, Price>
  469.      */
  470.     public function getPrices(): Collection
  471.     {
  472.         return $this->prices;
  473.     }
  474.     public function addPrice(Price $price): self
  475.     {
  476.         if (!$this->prices->contains($price)) {
  477.             $this->prices->add($price);
  478.             $price->setUser($this);
  479.         }
  480.         return $this;
  481.     }
  482.     public function removePrice(Price $price): self
  483.     {
  484.         if ($this->prices->removeElement($price)) {
  485.             // set the owning side to null (unless already changed)
  486.             if ($price->getUser() === $this) {
  487.                 $price->setUser(null);
  488.             }
  489.         }
  490.         return $this;
  491.     }
  492.     public function __toString(): string
  493.     {
  494.         return $this->fname.' ('.$this->email.')';
  495.     }
  496.     /**
  497.      * @return Collection<int, Service>
  498.      */
  499.     public function getServices(): Collection
  500.     {
  501.         return $this->services;
  502.     }
  503.     public function addService(Service $service): self
  504.     {
  505.         if (!$this->services->contains($service)) {
  506.             $this->services->add($service);
  507.             $service->setUser($this);
  508.         }
  509.         return $this;
  510.     }
  511.     public function removeService(Service $service): self
  512.     {
  513.         if ($this->services->removeElement($service)) {
  514.             // set the owning side to null (unless already changed)
  515.             if ($service->getUser() === $this) {
  516.                 $service->setUser(null);
  517.             }
  518.         }
  519.         return $this;
  520.     }
  521.     /**
  522.      * @return Collection<int, Reservation>
  523.      */
  524.     public function getReservations(): Collection
  525.     {
  526.         return $this->reservations;
  527.     }
  528.     public function addReservation(Reservation $reservation): self
  529.     {
  530.         if (!$this->reservations->contains($reservation)) {
  531.             $this->reservations->add($reservation);
  532.             $reservation->setUser($this);
  533.         }
  534.         return $this;
  535.     }
  536.     public function removeReservation(Reservation $reservation): self
  537.     {
  538.         if ($this->reservations->removeElement($reservation)) {
  539.             // set the owning side to null (unless already changed)
  540.             if ($reservation->getUser() === $this) {
  541.                 $reservation->setUser(null);
  542.             }
  543.         }
  544.         return $this;
  545.     }
  546.    
  547.     /**
  548.      * @return Collection<int, Notification>
  549.      */
  550.     public function getNotifications(): Collection
  551.     {
  552.         return $this->notifications;
  553.     }
  554.     public function addNotification(Notification $notification): self
  555.     {
  556.         if (!$this->notifications->contains($notification)) {
  557.             $this->notifications->add($notification);
  558.             $notification->setUser($this);
  559.         }
  560.         return $this;
  561.     }
  562.     public function removeNotification(Notification $notification): self
  563.     {
  564.         if ($this->notifications->removeElement($notification)) {
  565.             // set the owning side to null (unless already changed)
  566.             if ($notification->getUser() === $this) {
  567.                 $notification->setUser(null);
  568.             }
  569.         }
  570.         return $this;
  571.     }
  572.     /**
  573.      * @return Collection<int, Favorite>
  574.      */
  575.     public function getFavorites(): Collection
  576.     {
  577.         return $this->favorites;
  578.     }
  579.     public function addFavorite(Favorite $favorite): self
  580.     {
  581.         if (!$this->favorites->contains($favorite)) {
  582.             $this->favorites->add($favorite);
  583.             $favorite->setUser($this);
  584.         }
  585.         return $this;
  586.     }
  587.     public function removeFavorite(Favorite $favorite): self
  588.     {
  589.         if ($this->favorites->removeElement($favorite)) {
  590.             // set the owning side to null (unless already changed)
  591.             if ($favorite->getUser() === $this) {
  592.                 $favorite->setUser(null);
  593.             }
  594.         }
  595.         return $this;
  596.     }
  597.     /**
  598.      * @return Collection<int, Gallery>
  599.      */
  600.     public function getGalleries(): Collection
  601.     {
  602.         return $this->galleries;
  603.     }
  604.     public function addGallery(Gallery $gallery): self
  605.     {
  606.         if (!$this->galleries->contains($gallery)) {
  607.             $this->galleries->add($gallery);
  608.             $gallery->setUser($this);
  609.         }
  610.         return $this;
  611.     }
  612.     public function removeGallery(Gallery $gallery): self
  613.     {
  614.         if ($this->galleries->removeElement($gallery)) {
  615.             // set the owning side to null (unless already changed)
  616.             if ($gallery->getUser() === $this) {
  617.                 $gallery->setUser(null);
  618.             }
  619.         }
  620.         return $this;
  621.     }
  622.     /**
  623.      * @return Collection<int, Review>
  624.      */
  625.     public function getReviews(): Collection
  626.     {
  627.         return $this->reviews;
  628.     }
  629.     public function addReview(Review $review): self
  630.     {
  631.         if (!$this->reviews->contains($review)) {
  632.             $this->reviews->add($review);
  633.             $review->setUser($this);
  634.         }
  635.         return $this;
  636.     }
  637.     public function removeReview(Review $review): self
  638.     {
  639.         if ($this->reviews->removeElement($review)) {
  640.             // set the owning side to null (unless already changed)
  641.             if ($review->getUser() === $this) {
  642.                 $review->setUser(null);
  643.             }
  644.         }
  645.         return $this;
  646.     }
  647.     /**
  648.      * @return Collection<int, Message>
  649.      */
  650.     public function getMessages(): Collection
  651.     {
  652.         return $this->messages;
  653.     }
  654.     public function addMessage(Message $message): self
  655.     {
  656.         if (!$this->messages->contains($message)) {
  657.             $this->messages->add($message);
  658.             $message->setSender($this);
  659.         }
  660.         return $this;
  661.     }
  662.     public function removeMessage(Message $message): self
  663.     {
  664.         if ($this->messages->removeElement($message)) {
  665.             // set the owning side to null (unless already changed)
  666.             if ($message->getSender() === $this) {
  667.                 $message->setSender(null);
  668.             }
  669.         }
  670.         return $this;
  671.     }
  672.     public function getExpoPushToken(): ?string
  673.     {
  674.         return $this->expoPushToken;
  675.     }
  676.     public function setExpoPushToken(string $expoPushToken): static
  677.     {
  678.         $this->expoPushToken $expoPushToken;
  679.         return $this;
  680.     }
  681.     public function getIdentity(): ?string
  682.     {
  683.         return $this->identity;
  684.     }
  685.     public function setIdentity(?string $identity): static
  686.     {
  687.         $this->identity $identity;
  688.         return $this;
  689.     }
  690. }