src/Entity/User.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\DataProcessor\UserDataProcessor;
  4. use App\DataProvider\UserByEmailProvider;
  5. use App\DataProvider\UserDataGetProvider;
  6. use App\Entity\Interface\NotificationInterface;
  7. use App\Entity\Traits\TimestampTrait;
  8. use App\Repository\UserRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\Ignore;
  17. use Symfony\Component\Serializer\Annotation\SerializedName;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. use ApiPlatform\Metadata as Api;
  20. #[ORM\InheritanceType('JOINED')]
  21. #[ORM\DiscriminatorColumn(name'discr'type'string')]
  22. #[ORM\DiscriminatorMap(['user' => 'User''client' => 'App\Entity\Client'])]
  23. #[ORM\Entity(repositoryClassUserRepository::class)]
  24. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  25. #[Api\ApiResource(
  26.     normalizationContext: ['groups' => ['user.read''timestamp.read']],
  27.     denormalizationContext: ['groups' => ['user.write']],
  28.     security"is_granted('IS_AUTHENTICATED_FULLY')",
  29. )]
  30. #[Api\Get(providerUserDataGetProvider::class)]
  31. #[Api\Get(
  32.     uriTemplate'/users/by-email/{email}',
  33.     uriVariables: ['email'],
  34.     providerUserByEmailProvider::class
  35. )]
  36. #[Api\Post(processorUserDataProcessor::class)]
  37. #[Api\Patch]
  38. #[Api\GetCollection(security'is_granted("'.RoleManagement::REGULAR_ADMIN.'")')]
  39. class User implements UserInterfacePasswordAuthenticatedUserInterfaceNotificationInterface
  40. {
  41.     use TimestampTrait;
  42.     #[ORM\Id]
  43.     #[ORM\GeneratedValue]
  44.     #[ORM\Column(type'integer')]
  45.     #[Groups(["user.read"])]
  46.     protected $id;
  47.     #[ORM\Column(type'string'length180uniquetrue)]
  48.     #[Groups(["user.read""user.write"])]
  49.     #[Assert\NotBlank]
  50.     private $email;
  51.     #[ORM\Column(type'json')]
  52.     #[Ignore()]
  53.     private $roles = [];
  54.     #[ORM\Column(type'string')]
  55.     #[Ignore()]
  56.     private $password;
  57.     #[ORM\Column(type'boolean')]
  58.     #[Groups(["user.read""user.write"])]
  59.     private $isVerified false;
  60.     #[ORM\Column(type'string'length255nullabletrue)]
  61.     #[Groups(["user.read""user.write"])]
  62.     private $firstName;
  63.     #[ORM\Column(type'string'length255nullabletrue)]
  64.     #[Groups(["user.read""user.write"])]
  65.     private $lastName;
  66.     #[ORM\Column(type'boolean')]
  67.     #[Groups(["user.read""user.write"])]
  68.     private $isActive true;
  69.     #[ORM\Column(type'boolean')]
  70.     #[Groups(["user.read""user.write"])]
  71.     private $privacyPolicy true;
  72.     #[ORM\Column(type'boolean')]
  73.     #[Groups(["user.read""user.write"])]
  74.     private $termsConditions true;
  75.     #[ORM\Column(type'boolean')]
  76.     #[Groups(["user.read""user.write"])]
  77.     private $newsletterSubscription false;
  78.     #[ORM\Column(type'string'length255nullabletrue)]
  79.     #[Groups(["user.read""user.write"])]
  80.     private $phoneCountryCode;
  81.     #[ORM\Column(type'string'length255nullabletrue)]
  82.     #[Groups(["user.read""user.write"])]
  83.     private $phoneNo;
  84.     #[ORM\Column(type'string'length255nullabletrue)]
  85.     #[Groups(["user.read""user.write"])]
  86.     private $profileImage;
  87.     #[ORM\Column(type'string'length255nullabletrue)]
  88.     #[Groups(["user.read""user.write"])]
  89.     private $jobPosition;
  90.     #[ORM\Column(type'string'length255nullabletrue)]
  91.     #[Ignore()]
  92.     private $userHeaderColor;
  93.     #[ORM\Column(type'boolean'nullabletrue)]
  94.     #[Ignore()]
  95.     private $userSideNavDark false;
  96.     #[ORM\Column(type'boolean'nullabletrue)]
  97.     #[Ignore()]
  98.     private $userFoldedMenu false;
  99.     #[ORM\Column(type'json'nullabletrue)]
  100.     #[Ignore()]
  101.     private $routePermissions = [];
  102.     #[ORM\OneToMany(mappedBy'notificationUser'targetEntityNotification::class, cascade: ['persist'])]
  103.     #[ORM\JoinColumn(onDelete'SET NULL')]
  104.     #[Ignore()]
  105.     private $notifications;
  106.     #[ORM\Column(type'string'length255nullabletrue)]
  107.     #[Groups(["user.read""user.write"])]
  108.     private $locale 'lt';
  109.     #[ORM\Column(type'text'nullabletrue)]
  110.     #[Groups(["user.read""user.write"])]
  111.     private $comment;
  112.     #[ORM\Column(type'string'length255nullabletrue)]
  113.     #[Groups(["user.read""user.write"])]
  114.     private $address;
  115.     #[ORM\Column(type'string'length255nullabletrue)]
  116.     #[Groups(["user.read""user.write"])]
  117.     private $country;
  118.     #[ORM\Column(type'datetime'nullabletrue)]
  119.     #[Groups(["user.read""user.write"])]
  120.     private $dateOfBirth;
  121.     #[Groups(["user.write"])]
  122.     #[SerializedName("password")]
  123.     #[Assert\Regex('/^(?=.*?[0-9])(?=.*[A-Z]).{6,}$/')]
  124.     private $plainPassword;
  125.     #[Groups(["user.read"])]
  126.     private bool $isMe false;
  127.     # TODO get from db
  128.     private $transactions = [];
  129.     #[ORM\OneToMany(mappedBy'createdByUser'targetEntityPurchaseMessage::class)]
  130.     private $purchaseMessages;
  131.     #[ORM\ManyToMany(targetEntityRoleManagement::class, inversedBy'users')]
  132.     private $userRole;
  133.     #[ORM\Column(type'string'length255nullabletrue)]
  134.     #[Groups(["user.read""user.write"])]
  135.     private $zipCode;
  136.     #[ORM\Column(nullabletrue)]
  137.     private ?bool $isLocked false;
  138.     #[ORM\OneToMany(mappedBy'user'targetEntityUserCar::class, cascade: ['persist'])]
  139.     private Collection $userCars;
  140.     #[ORM\Column(length255nullabletrue)]
  141.     private ?string $verificationCode null;
  142.     #[ORM\OneToMany(mappedBy'user'targetEntityLaborAct::class)]
  143.     private Collection $laborActs;
  144.     public function toArray(): array
  145.     {
  146.         return [
  147.             'id' => $this->getId(),
  148.             'email' => $this->getEmail(),
  149.             'firstName' => $this->getFirstName(),
  150.             'lastName' => $this->getLastName(),
  151.             'isActive' => $this->getIsActive(),
  152.             'privacyPolicy' => $this->getPrivacyPolicy(),
  153.             'termsConditions' => $this->getTermsConditions(),
  154.             'newsletterSubscription' => $this->getNewsletterSubscription(),
  155.             'phoneCountryCode' => $this->getPhoneCountryCode(),
  156.             'phoneNo' => $this->getPhoneNo(),
  157.             'profileImage' => $this->getProfileImage(),
  158.             'jobPosition' => $this->getJobPosition(),
  159.             'userHeaderColor' => $this->getUserHeaderColor(),
  160.             'userSideNavDark' => $this->getUserSideNavDark(),
  161.             'userFoldedMenu' => $this->getUserFoldedMenu(),
  162.             'routePermissions' => $this->getRoutePermissions(),
  163.             'locale' => $this->getLocale(),
  164.             'comment' => $this->getComment(),
  165.             'address' => $this->getAddress(),
  166.             'country' => $this->getCountry(),
  167.             'dateOfBirth' => $this->getDateOfBirth(),
  168.             'isVerified' => $this->isVerified(),
  169.             'zipCode' => $this->getZipCode(),
  170.             'isLocked' => $this->isIsLocked(),
  171.             'verificationCode' => $this->getVerificationCode(),
  172.             'createdAt' => $this->getCreatedAt(),
  173.             'updatedAt' => $this->getUpdatedAt()
  174.         ];
  175.     }
  176.     public function __construct()
  177.     {
  178.         $this->notifications = new ArrayCollection();
  179.         $this->purchaseMessages = new ArrayCollection();
  180.         $this->userRole = new ArrayCollection();
  181.         $this->userCars = new ArrayCollection();
  182.         $this->laborActs = new ArrayCollection();
  183.     }
  184.     public function getId(): ?int
  185.     {
  186.         return $this->id;
  187.     }
  188.     public function getEmail(): ?string
  189.     {
  190.         return $this->email;
  191.     }
  192.     public function setEmail(string $email): self
  193.     {
  194.         $this->email $email;
  195.         return $this;
  196.     }
  197.     /**
  198.      * A visual identifier that represents this user.
  199.      *
  200.      * @see UserInterface
  201.      */
  202.     #[Ignore()]
  203.     public function getUserIdentifier(): string
  204.     {
  205.         return (string) $this->email;
  206.     }
  207.     /**
  208.      * @see UserInterface
  209.      */
  210.     public function getRoles(): array
  211.     {
  212.         $roles $this->roles;
  213.         // guarantee every user at least has ROLE_USER
  214.         //$roles[] = 'ROLE_USER';
  215.         return array_unique($roles);
  216.     }
  217.     public function setRoles(array $roles): self
  218.     {
  219.         $this->roles $roles;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @see PasswordAuthenticatedUserInterface
  224.      */
  225.     public function getPassword(): string
  226.     {
  227.         return $this->password;
  228.     }
  229.     public function setPassword(string $password): self
  230.     {
  231.         $this->password $password;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @see UserInterface
  236.      */
  237.     public function eraseCredentials()
  238.     {
  239.         $this->plainPassword null;
  240.     }
  241.     public function isVerified(): bool
  242.     {
  243.         return $this->isVerified;
  244.     }
  245.     public function setIsVerified(bool $isVerified): self
  246.     {
  247.         $this->isVerified $isVerified;
  248.         return $this;
  249.     }
  250.     public function getFirstName(): ?string
  251.     {
  252.         return $this->firstName;
  253.     }
  254.     public function setFirstName(?string $firstName): self
  255.     {
  256.         $this->firstName $firstName;
  257.         return $this;
  258.     }
  259.     public function getLastName(): ?string
  260.     {
  261.         return $this->lastName;
  262.     }
  263.     public function setLastName(?string $lastName): self
  264.     {
  265.         $this->lastName $lastName;
  266.         return $this;
  267.     }
  268.     public function getIsActive(): ?bool
  269.     {
  270.         return $this->isActive;
  271.     }
  272.     public function setIsActive(bool $isActive): self
  273.     {
  274.         $this->isActive $isActive;
  275.         return $this;
  276.     }
  277.     public function getPrivacyPolicy(): ?bool
  278.     {
  279.         return $this->privacyPolicy;
  280.     }
  281.     public function setPrivacyPolicy(bool $privacyPolicy): self
  282.     {
  283.         $this->privacyPolicy $privacyPolicy;
  284.         return $this;
  285.     }
  286.     public function getTermsConditions(): ?bool
  287.     {
  288.         return $this->termsConditions;
  289.     }
  290.     public function setTermsConditions(bool $termsConditions): self
  291.     {
  292.         $this->termsConditions $termsConditions;
  293.         return $this;
  294.     }
  295.     public function getNewsletterSubscription(): ?bool
  296.     {
  297.         return $this->newsletterSubscription;
  298.     }
  299.     public function setNewsletterSubscription(bool $newsletterSubscription): self
  300.     {
  301.         $this->newsletterSubscription $newsletterSubscription;
  302.         return $this;
  303.     }
  304.     public function getPhoneCountryCode(): ?string
  305.     {
  306.         return $this->phoneCountryCode;
  307.     }
  308.     public function setPhoneCountryCode(?string $phoneCountryCode): self
  309.     {
  310.         $this->phoneCountryCode $phoneCountryCode;
  311.         return $this;
  312.     }
  313.     public function getPhoneNo(): ?string
  314.     {
  315.         return $this->phoneNo;
  316.     }
  317.     public function setPhoneNo(?string $phoneNo): self
  318.     {
  319.         $this->phoneNo $phoneNo;
  320.         return $this;
  321.     }
  322.     public function getProfileImage(): ?string
  323.     {
  324.         return $this->profileImage;
  325.     }
  326.     public function setProfileImage(?string $profileImage): self
  327.     {
  328.         $this->profileImage $profileImage;
  329.         return $this;
  330.     }
  331.     public function getJobPosition(): ?string
  332.     {
  333.         return $this->jobPosition;
  334.     }
  335.     public function setJobPosition(?string $jobPosition): self
  336.     {
  337.         $this->jobPosition $jobPosition;
  338.         return $this;
  339.     }
  340.     public function getUserHeaderColor(): ?string
  341.     {
  342.         return $this->userHeaderColor;
  343.     }
  344.     public function setUserHeaderColor(?string $userHeaderColor): self
  345.     {
  346.         $this->userHeaderColor $userHeaderColor;
  347.         return $this;
  348.     }
  349.     public function getUserSideNavDark(): ?bool
  350.     {
  351.         return $this->userSideNavDark;
  352.     }
  353.     public function setUserSideNavDark(?bool $userSideNavDark): self
  354.     {
  355.         $this->userSideNavDark $userSideNavDark;
  356.         return $this;
  357.     }
  358.     public function getUserFoldedMenu(): ?bool
  359.     {
  360.         return $this->userFoldedMenu;
  361.     }
  362.     public function setUserFoldedMenu(?bool $userFoldedMenu): self
  363.     {
  364.         $this->userFoldedMenu $userFoldedMenu;
  365.         return $this;
  366.     }
  367.     public function getRoutePermissions(): ?array
  368.     {
  369.         return $this->routePermissions;
  370.     }
  371.     public function setRoutePermissions(?array $routePermissions): self
  372.     {
  373.         $this->routePermissions $routePermissions;
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection<int, Notification>
  378.      */
  379.     public function getNotifications(): Collection
  380.     {
  381.         return $this->notifications;
  382.     }
  383.     public function addNotification(Notification $notification): self
  384.     {
  385.         if (!$this->notifications->contains($notification)) {
  386.             $this->notifications[] = $notification;
  387.             $notification->setNotificationUser($this);
  388.         }
  389.         return $this;
  390.     }
  391.     public function removeNotification(Notification $notification): self
  392.     {
  393.         if ($this->notifications->removeElement($notification)) {
  394.             // set the owning side to null (unless already changed)
  395.             if ($notification->getNotificationUser() === $this) {
  396.                 $notification->setNotificationUser(null);
  397.             }
  398.         }
  399.         return $this;
  400.     }
  401.     public function getLocale(): ?string
  402.     {
  403.         return $this->locale;
  404.     }
  405.     public function setLocale(?string $locale): self
  406.     {
  407.         $this->locale $locale;
  408.         return $this;
  409.     }
  410.     public function getComment(): ?string
  411.     {
  412.         return $this->comment;
  413.     }
  414.     public function setComment(?string $comment): self
  415.     {
  416.         $this->comment $comment;
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return Collection<int, RoleManagement>
  421.      */
  422.     public function getUserRole(): Collection
  423.     {
  424.         return $this->userRole;
  425.     }
  426.     public function addUserRole(RoleManagement $userRole): self
  427.     {
  428.         if (!$this->userRole->contains($userRole)) {
  429.             $this->userRole[] = $userRole;
  430.         }
  431.         return $this;
  432.     }
  433.     public function getAddress(): ?string
  434.     {
  435.         return $this->address;
  436.     }
  437.     public function setAddress(?string $address): self
  438.     {
  439.         $this->address $address;
  440.         return $this;
  441.     }
  442.     public function getCountry(): ?string
  443.     {
  444.         return $this->country;
  445.     }
  446.     public function setCountry(?string $country): self
  447.     {
  448.         $this->country $country;
  449.         return $this;
  450.     }
  451.     public function getDateOfBirth(): ?\DateTimeInterface
  452.     {
  453.         return $this->dateOfBirth;
  454.     }
  455.     public function setDateOfBirth(?\DateTimeInterface $dateOfBirth): self
  456.     {
  457.         $this->dateOfBirth $dateOfBirth;
  458.         return $this;
  459.     }
  460.     public function getZipCode(): ?string
  461.     {
  462.         return $this->zipCode;
  463.     }
  464.     public function setZipCode(?string $zipCode): self
  465.     {
  466.         $this->zipCode $zipCode;
  467.         return $this;
  468.     }
  469.     public function getPlainPassword(): ?string
  470.     {
  471.         return $this->plainPassword;
  472.     }
  473.     public function setPlainPassword($plainPassword): void
  474.     {
  475.         $this->plainPassword $plainPassword;
  476.     }
  477.     public function getIsMe(): bool
  478.     {
  479.         return $this->isMe;
  480.     }
  481.     public function setIsMe(bool $isMe): void
  482.     {
  483.         $this->isMe $isMe;
  484.     }
  485.     public function getTransactions(): array
  486.     {
  487.         return $this->transactions;
  488.     }
  489.     public function setTransactions(array $transactions): void
  490.     {
  491.         $this->transactions $transactions;
  492.     }
  493.     /**
  494.      * @return Collection<int, PurchaseMessage>
  495.      */
  496.     public function getPurchaseMessages(): Collection
  497.     {
  498.         return $this->purchaseMessages;
  499.     }
  500.     public function addPurchaseMessage(PurchaseMessage $purchaseMessage): self
  501.     {
  502.         if (!$this->purchaseMessages->contains($purchaseMessage)) {
  503.             $this->purchaseMessages[] = $purchaseMessage;
  504.             $purchaseMessage->setCreatedByUser($this);
  505.         }
  506.         return $this;
  507.     }
  508.     public function removePurchaseMessage(PurchaseMessage $purchaseMessage): self
  509.     {
  510.         if ($this->purchaseMessages->removeElement($purchaseMessage)) {
  511.             // set the owning side to null (unless already changed)
  512.             if ($purchaseMessage->getCreatedByUser() === $this) {
  513.                 $purchaseMessage->setCreatedByUser(null);
  514.             }
  515.         }
  516.         return $this;
  517.     }
  518.     public function removeUserRole(RoleManagement $userRole): self
  519.     {
  520.         $this->userRole->removeElement($userRole);
  521.         return $this;
  522.     }
  523.     public function isIsLocked(): ?bool
  524.     {
  525.         return $this->isLocked;
  526.     }
  527.     public function setIsLocked(?bool $isLocked): self
  528.     {
  529.         $this->isLocked $isLocked;
  530.         return $this;
  531.     }
  532.     /**
  533.      * @return Collection<int, UserCar>
  534.      */
  535.     public function getUserCars(): Collection
  536.     {
  537.         return $this->userCars;
  538.     }
  539.     public function addUserCar(UserCar $userCar): self
  540.     {
  541.         if (!$this->userCars->contains($userCar)) {
  542.             $this->userCars->add($userCar);
  543.             $userCar->setUser($this);
  544.         }
  545.         return $this;
  546.     }
  547.     public function removeUserCar(UserCar $userCar): self
  548.     {
  549.         if ($this->userCars->removeElement($userCar)) {
  550.             // set the owning side to null (unless already changed)
  551.             if ($userCar->getUser() === $this) {
  552.                 $userCar->setUser(null);
  553.             }
  554.         }
  555.         return $this;
  556.     }
  557.     public function getVerificationCode(): ?string
  558.     {
  559.         return $this->verificationCode;
  560.     }
  561.     public function setVerificationCode(?string $verificationCode): self
  562.     {
  563.         $this->verificationCode $verificationCode;
  564.         return $this;
  565.     }
  566.     /**
  567.      * @return Collection<int, LaborAct>
  568.      */
  569.     public function getLaborActs(): Collection
  570.     {
  571.         return $this->laborActs;
  572.     }
  573.     public function addLaborAct(LaborAct $laborAct): self
  574.     {
  575.         if (!$this->laborActs->contains($laborAct)) {
  576.             $this->laborActs->add($laborAct);
  577.             $laborAct->setUser($this);
  578.         }
  579.         return $this;
  580.     }
  581.     public function removeLaborAct(LaborAct $laborAct): self
  582.     {
  583.         if ($this->laborActs->removeElement($laborAct)) {
  584.             // set the owning side to null (unless already changed)
  585.             if ($laborAct->getUser() === $this) {
  586.                 $laborAct->setUser(null);
  587.             }
  588.         }
  589.         return $this;
  590.     }
  591. }