src/Entity/Client.php line 38

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\Repository\ClientRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use ApiPlatform\Metadata as Api;
  13. #[ORM\Entity(repositoryClassClientRepository::class)]
  14. #[Api\ApiResource(
  15.     normalizationContext: ['groups' => ['user.read''timestamp.read']],
  16.     denormalizationContext: ['groups' => ['user.write']]
  17. )]
  18. #[Api\Get(
  19.     security"is_granted('IS_AUTHENTICATED_FULLY')",
  20.     providerUserDataGetProvider::class
  21. )]
  22. #[Api\Get(
  23.     uriTemplate'/clients/by-email/{email}',
  24.     uriVariables: ['email'],
  25.     security"is_granted('IS_AUTHENTICATED_FULLY')",
  26.     providerUserByEmailProvider::class
  27. )]
  28. #[Api\Post(processorUserDataProcessor::class)]
  29. #[Api\Patch(
  30.     security"is_granted('IS_AUTHENTICATED_FULLY')"
  31. )]
  32. #[Api\GetCollection(
  33.     security"is_granted('IS_AUTHENTICATED_FULLY')",
  34. )]
  35. class Client extends User implements NotificationInterface
  36. {
  37.     #[ORM\Column(type'string'length255nullabletrue)]
  38.     #[Groups(["user.read""user.write"])]
  39.     private $companyName;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     #[Groups(["user.read""user.write"])]
  42.     private $companyCode;
  43.     #[ORM\Column(type'string'length255nullabletrue)]
  44.     #[Groups(["user.read""user.write"])]
  45.     private $vatCode;
  46.     #[ORM\OneToMany(mappedBy'client'targetEntityPurchase::class)]
  47.     private $purchases;
  48.     #[ORM\OneToMany(mappedBy'client'targetEntityDelivery::class)]
  49.     private $deliveries;
  50.     #[ORM\OneToMany(mappedBy'client'targetEntityInvoice::class)]
  51.     private $invoices;
  52.     public function toArray(): array
  53.     {
  54.         return [
  55.             'id' => $this->getId(),
  56.             'email' => $this->getEmail(),
  57.             'firstName' => $this->getFirstName(),
  58.             'lastName' => $this->getLastName(),
  59.             'isActive' => $this->getIsActive(),
  60.             'privacyPolicy' => $this->getPrivacyPolicy(),
  61.             'termsConditions' => $this->getTermsConditions(),
  62.             'newsletterSubscription' => $this->getNewsletterSubscription(),
  63.             'phoneCountryCode' => $this->getPhoneCountryCode(),
  64.             'phoneNo' => $this->getPhoneNo(),
  65.             'profileImage' => $this->getProfileImage(),
  66.             'jobPosition' => $this->getJobPosition(),
  67.             'userHeaderColor' => $this->getUserHeaderColor(),
  68.             'userSideNavDark' => $this->getUserSideNavDark(),
  69.             'userFoldedMenu' => $this->getUserFoldedMenu(),
  70.             'routePermissions' => $this->getRoutePermissions(),
  71.             'locale' => $this->getLocale(),
  72.             'comment' => $this->getComment(),
  73.             'address' => $this->getAddress(),
  74.             'country' => $this->getCountry(),
  75.             'dateOfBirth' => $this->getDateOfBirth(),
  76.             'isVerified' => $this->isVerified(),
  77.             'zipCode' => $this->getZipCode(),
  78.             'isLocked' => $this->isIsLocked(),
  79.             'verificationCode' => $this->getVerificationCode(),
  80.             'createdAt' => $this->getCreatedAt(),
  81.             'updatedAt' => $this->getUpdatedAt(),
  82.             'companyName' => $this->getCompanyName(),
  83.             'companyCode' => $this->getCompanyCode(),
  84.             'vatCode' => $this->getVatCode(),
  85.         ];
  86.     }
  87.     public function __construct()
  88.     {
  89.         parent::__construct();
  90.         $this->purchases = new ArrayCollection();
  91.         $this->deliveries = new ArrayCollection();
  92.         $this->invoices = new ArrayCollection();
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function isLegal(): bool
  99.     {
  100.         return $this->companyName !== null;
  101.     }
  102.     public function getCompanyName(): ?string
  103.     {
  104.         return $this->companyName;
  105.     }
  106.     public function setCompanyName(?string $companyName): self
  107.     {
  108.         $this->companyName $companyName;
  109.         return $this;
  110.     }
  111.     public function getCompanyCode(): ?string
  112.     {
  113.         return $this->companyCode;
  114.     }
  115.     public function setCompanyCode(?string $companyCode): self
  116.     {
  117.         $this->companyCode $companyCode;
  118.         return $this;
  119.     }
  120.     public function getVatCode(): ?string
  121.     {
  122.         return $this->vatCode;
  123.     }
  124.     public function setVatCode(?string $vatCode): self
  125.     {
  126.         $this->vatCode $vatCode;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return Collection<int, Purchase>
  131.      */
  132.     public function getPurchases(): Collection
  133.     {
  134.         return $this->purchases;
  135.     }
  136.     public function addPurchase(Purchase $purchase): self
  137.     {
  138.         if (!$this->purchases->contains($purchase)) {
  139.             $this->purchases[] = $purchase;
  140.             $purchase->setClient($this);
  141.         }
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return Collection<int, Invoice>
  146.      */
  147.     public function getInvoices(): Collection
  148.     {
  149.         return $this->invoices;
  150.     }
  151.     public function addInvoice(Invoice $invoice): self
  152.     {
  153.         if (!$this->invoices->contains($invoice)) {
  154.             $this->invoices[] = $invoice;
  155.             $invoice->setClient($this);
  156.         }
  157.         return $this;
  158.     }
  159.     public function removePurchase(Purchase $purchase): self
  160.     {
  161.         if ($this->purchases->removeElement($purchase)) {
  162.             // set the owning side to null (unless already changed)
  163.             if ($purchase->getClient() === $this) {
  164.                 $purchase->setClient(null);
  165.             }
  166.         }
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Delivery>
  171.      */
  172.     public function getDeliveries(): Collection
  173.     {
  174.         return $this->deliveries;
  175.     }
  176.     public function addDelivery(Delivery $delivery): self
  177.     {
  178.         if (!$this->deliveries->contains($delivery)) {
  179.             $this->deliveries[] = $delivery;
  180.             $delivery->setClient($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeDelivery(Delivery $delivery): self
  185.     {
  186.         if ($this->deliveries->removeElement($delivery)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($delivery->getClient() === $this) {
  189.                 $delivery->setClient(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeInvoice(Invoice $invoice): self
  195.     {
  196.         if ($this->invoices->removeElement($invoice)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($invoice->getClient() === $this) {
  199.                 $invoice->setClient(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204. }