src/Entity/Charterer.php line 81

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use App\Trait\TimestampableEntity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Serializer\Annotation\MaxDepth;
  17. use Ramsey\Uuid\Uuid;
  18. use Ramsey\Uuid\UuidInterface;
  19. /**
  20.  * @see https://schema.org/Organization
  21.  * 
  22.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  23.  */
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     iri'Charterer',
  27.     itemOperations: [
  28.         'get' => ['normalization_context' => ['groups' => 'charterer:item:get''enable_max_depth' => true]],
  29.         'put' => [
  30.             'normalization_context' => ['groups' => 'charterer:item:put''enable_max_depth' => true],
  31.             'denormalization_context' => ['groups' => 'charterer:item:put''enable_max_depth' => true],
  32.         ],
  33.         'delete' => [],
  34.     ],
  35.     collectionOperations: [
  36.         'get' => [
  37.             'normalization_context' => [
  38.                 'groups' => ['charterer:collection:get''createdAt'],
  39.                 'enable_max_depth' => true,
  40.             ],
  41.         ],
  42.         'post' => [
  43.             'normalization_context' => ['groups' => 'charterer:collection:post''enable_max_depth' => true],
  44.             'denormalization_context' => ['groups' => 'charterer:collection:post''enable_max_depth' => true],
  45.         ],
  46.     ],
  47. )]
  48. #[ApiFilter(
  49.     SearchFilter::class,
  50.     properties: [
  51.         'companyName' => 'partial',
  52.         'addressLine1' => 'partial',
  53.         'addressLine2' => 'partial',
  54.         'addressLine3' => 'partial',
  55.         'charteringEmail' => 'partial',
  56.         'operationsEmail' => 'partial',
  57.         'accountingEmail' => 'partial',
  58.         'createdAt' => 'start',
  59.         'detailedCompanyName' => 'partial',
  60.     ],
  61. )]
  62. #[ApiFilter(
  63.     OrderFilter::class,
  64.     properties: [
  65.         'companyName',
  66.         'addressLine1',
  67.         'addressLine2',
  68.         'addressLine3',
  69.         'charteringEmail',
  70.         'operationsEmail',
  71.         'accountingEmail',
  72.         'createdAt',
  73.         'detailedCompanyName',
  74.     ],
  75. )]
  76. #[ApiFilter(PropertyFilter::class)]
  77. class Charterer
  78. {
  79.     use TimestampableEntity;
  80.     
  81.     #[ORM\Id]
  82.     #[ORM\GeneratedValue(strategy'NONE')]
  83.     #[ORM\Column(type'uuid'uniquetrue)]
  84.     ##[ApiProperty(iri: 'https://schema.org/identifier')]
  85.     private ?UuidInterface $id null;
  86.     #[ORM\Column(type'string'nullablefalse)]
  87.     #[ApiProperty(iri'https://schema.org/name')]
  88.     #[Assert\NotBlank]
  89.     #[Assert\Type('string')]
  90.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  91.     private ?string $companyName null;
  92.     #[ORM\Column(type'string'nullabletrue)]
  93.     #[ApiProperty(iri'https://schema.org/addressLine')]
  94.     #[Assert\Type('string')]
  95.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  96.     private ?string $addressLine1 null;
  97.     #[ORM\Column(type'string'nullabletrue)]
  98.     #[ApiProperty(iri'https://schema.org/addressLine')]
  99.     #[Assert\Type('string')]
  100.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  101.     private ?string $addressLine2 null;
  102.     #[ORM\Column(type'string'nullabletrue)]
  103.     #[ApiProperty(iri'https://schema.org/addressLine')]
  104.     #[Assert\Type('string')]
  105.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  106.     private ?string $addressLine3 null;
  107.     #[ORM\Column(type'text'nullabletrue)]
  108.     #[ApiProperty(iri'https://schema.org/email')]
  109.     ##[Assert\Email]
  110.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  111.     private ?string $charteringEmail null;
  112.     #[ORM\Column(type'text'nullabletrue)]
  113.     #[ApiProperty(iri'https://schema.org/email')]
  114.     ##[Assert\Email]
  115.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  116.     private ?string $operationsEmail null;
  117.     #[ORM\Column(type'text'nullabletrue)]
  118.     #[ApiProperty(iri'https://schema.org/email')]
  119.     ##[Assert\Email]
  120.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  121.     private ?string $accountingEmail null;
  122.     // #[ORM\OneToMany(targetEntity: 'App\Entity\Contact', mappedBy: 'charterer', cascade: ['persist', 'remove'], orphanRemoval: true)]
  123.     // #[ApiProperty(iri: 'https://schema.org/Contact')]
  124.     // #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get'])]
  125.     // #[MaxDepth(1)]
  126.     // private Collection $contacts;
  127.     // #[ORM\OneToOne(targetEntity: 'App\Entity\Contact')]
  128.     // #[ApiProperty(iri: 'https://schema.org/Contact')]
  129.     // #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
  130.     // #[MaxDepth(1)]
  131.     // private ?Contact $primaryContact = null;
  132.     #[ORM\ManyToMany(targetEntity'App\Entity\Contract')]
  133.     #[ApiProperty(iri'https://schema.org/Contract')]
  134.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  135.     private Collection $transactionHistory;
  136.     #[ORM\Column(type'text'nullabletrue)]
  137.     #[ApiProperty(iri'https://schema.org/observation')]
  138.     #[Assert\Type('string')]
  139.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  140.     private ?string $observations null;
  141.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'charterer')]
  142.     #[ApiProperty(iri'https://schema.org/Contract')]
  143.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  144.     #[MaxDepth(1)]
  145.     private ?Collection $contracts null;
  146.     public function __construct()
  147.     {
  148.         $this->id Uuid::uuid4();
  149.         // $this->contacts = new ArrayCollection();
  150.         $this->transactionHistory = new ArrayCollection();
  151.         $this->contracts = new ArrayCollection();
  152.     }
  153.     public function getId(): ?UuidInterface
  154.     {
  155.         return $this->id;
  156.     }
  157.     public function setCompanyName(?string $companyName): void
  158.     {
  159.         $this->companyName $companyName;
  160.     }
  161.     public function getCompanyName(): ?string
  162.     {
  163.         return $this->companyName;
  164.     }
  165.     public function setAddressLine1(?string $addressLine1): void
  166.     {
  167.         $this->addressLine1 $addressLine1;
  168.     }
  169.     public function getAddressLine1(): ?string
  170.     {
  171.         return $this->addressLine1;
  172.     }
  173.     public function setAddressLine2(?string $addressLine2): void
  174.     {
  175.         $this->addressLine2 $addressLine2;
  176.     }
  177.     public function getAddressLine2(): ?string
  178.     {
  179.         return $this->addressLine2;
  180.     }
  181.     public function setAddressLine3(?string $addressLine3): void
  182.     {
  183.         $this->addressLine3 $addressLine3;
  184.     }
  185.     public function getAddressLine3(): ?string
  186.     {
  187.         return $this->addressLine3;
  188.     }
  189.     public function setCharteringEmail(?string $charteringEmail): void
  190.     {
  191.         $this->charteringEmail $charteringEmail;
  192.     }
  193.     public function getCharteringEmail(): ?string
  194.     {
  195.         return $this->charteringEmail;
  196.     }
  197.     public function setOperationsEmail(?string $operationsEmail): void
  198.     {
  199.         $this->operationsEmail $operationsEmail;
  200.     }
  201.     public function getOperationsEmail(): ?string
  202.     {
  203.         return $this->operationsEmail;
  204.     }
  205.     public function setAccountingEmail(?string $accountingEmail): void
  206.     {
  207.         $this->accountingEmail $accountingEmail;
  208.     }
  209.     public function getAccountingEmail(): ?string
  210.     {
  211.         return $this->accountingEmail;
  212.     }
  213.     // public function addContact(Contact $contact): void
  214.     // {
  215.     //     if (!$this->contacts->contains($contact)) {
  216.     //         $this->contacts->add($contact);
  217.     //     }
  218.     // }
  219.     // public function removeContact(Contact $contact): void
  220.     // {
  221.     //     $this->contacts->removeElement($contact);
  222.     // }
  223.     // public function getContacts(): Collection
  224.     // {
  225.     //     return $this->contacts;
  226.     // }
  227.     // public function setPrimaryContact(?Contact $primaryContact): void
  228.     // {
  229.     //     $this->primaryContact = $primaryContact;
  230.     // }
  231.     // public function getPrimaryContact(): ?Contact
  232.     // {
  233.     //     return $this->primaryContact;
  234.     // }
  235.     public function addTransactionHistory(Contract $transactionHistory): void
  236.     {
  237.         if (!$this->transactionHistory->contains($transactionHistory)) {
  238.             $this->transactionHistory->add($transactionHistory);
  239.         }
  240.     }
  241.     public function removeTransactionHistory(Contract $transactionHistory): void
  242.     {
  243.         $this->transactionHistory->removeElement($transactionHistory);
  244.     }
  245.     public function getTransactionHistory(): Collection
  246.     {
  247.         return $this->transactionHistory;
  248.     }
  249.     public function setObservations(?string $observations): void
  250.     {
  251.         $this->observations $observations;
  252.     }
  253.     public function getObservations(): ?string
  254.     {
  255.         return $this->observations;
  256.     }
  257.     public function getContracts(): Collection
  258.     {
  259.         return $this->contracts;
  260.     }
  261.     public function addContract(Contract $contract): self
  262.     {
  263.         if (!$this->contracts->contains($contract)) {
  264.             $this->contracts[] = $contract;
  265.             $contract->setCharterer($this);
  266.         }
  267.         return $this;
  268.     }
  269.     public function removeContract(Contract $contract): self
  270.     {
  271.         if ($this->contracts->removeElement($contract)) {
  272.             if ($contract->getCharterer() === $this) {
  273.                 $contract->setCharterer(null);
  274.             }
  275.         }
  276.         
  277.         return $this;
  278.     }
  279. }