src/Entity/Charterer.php line 61

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: ['companyName' => 'partial''createdAt' => 'start'],
  51. )]
  52. #[ApiFilter(
  53.     OrderFilter::class,
  54.     properties: ['companyName''createdAt'],
  55. )]
  56. #[ApiFilter(PropertyFilter::class)]
  57. class Charterer
  58. {
  59.     use TimestampableEntity;
  60.     
  61.     #[ORM\Id]
  62.     #[ORM\GeneratedValue(strategy'NONE')]
  63.     #[ORM\Column(type'uuid'uniquetrue)]
  64.     ##[ApiProperty(iri: 'https://schema.org/identifier')]
  65.     private ?UuidInterface $id null;
  66.     #[ORM\Column(type'string'nullablefalse)]
  67.     #[ApiProperty(iri'https://schema.org/name')]
  68.     #[Assert\NotBlank]
  69.     #[Assert\Type('string')]
  70.     #[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'])]
  71.     private ?string $companyName null;
  72.     #[ORM\Column(type'string'nullabletrue)]
  73.     #[ApiProperty(iri'https://schema.org/addressLine')]
  74.     #[Assert\Type('string')]
  75.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  76.     private ?string $addressLine1 null;
  77.     #[ORM\Column(type'string'nullabletrue)]
  78.     #[ApiProperty(iri'https://schema.org/addressLine')]
  79.     #[Assert\Type('string')]
  80.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  81.     private ?string $addressLine2 null;
  82.     #[ORM\Column(type'string'nullabletrue)]
  83.     #[ApiProperty(iri'https://schema.org/addressLine')]
  84.     #[Assert\Type('string')]
  85.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  86.     private ?string $addressLine3 null;
  87.     #[ORM\Column(type'text'nullabletrue)]
  88.     #[ApiProperty(iri'https://schema.org/email')]
  89.     ##[Assert\Email]
  90.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  91.     private ?string $charteringEmail null;
  92.     #[ORM\Column(type'text'nullabletrue)]
  93.     #[ApiProperty(iri'https://schema.org/email')]
  94.     ##[Assert\Email]
  95.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  96.     private ?string $operationsEmail null;
  97.     #[ORM\Column(type'text'nullabletrue)]
  98.     #[ApiProperty(iri'https://schema.org/email')]
  99.     ##[Assert\Email]
  100.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  101.     private ?string $accountingEmail null;
  102.     // #[ORM\OneToMany(targetEntity: 'App\Entity\Contact', mappedBy: 'charterer', cascade: ['persist', 'remove'], orphanRemoval: true)]
  103.     // #[ApiProperty(iri: 'https://schema.org/Contact')]
  104.     // #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get'])]
  105.     // #[MaxDepth(1)]
  106.     // private Collection $contacts;
  107.     // #[ORM\OneToOne(targetEntity: 'App\Entity\Contact')]
  108.     // #[ApiProperty(iri: 'https://schema.org/Contact')]
  109.     // #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
  110.     // #[MaxDepth(1)]
  111.     // private ?Contact $primaryContact = null;
  112.     #[ORM\ManyToMany(targetEntity'App\Entity\Contract')]
  113.     #[ApiProperty(iri'https://schema.org/Contract')]
  114.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  115.     private Collection $transactionHistory;
  116.     #[ORM\Column(type'text'nullabletrue)]
  117.     #[ApiProperty(iri'https://schema.org/observation')]
  118.     #[Assert\Type('string')]
  119.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  120.     private ?string $observations null;
  121.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'charterer')]
  122.     #[ApiProperty(iri'https://schema.org/Contract')]
  123.     #[Groups(['charterer:collection:get''charterer:collection:post''charterer:item:get''charterer:item:put'])]
  124.     #[MaxDepth(1)]
  125.     private ?Collection $contracts null;
  126.     public function __construct()
  127.     {
  128.         $this->id Uuid::uuid4();
  129.         // $this->contacts = new ArrayCollection();
  130.         $this->transactionHistory = new ArrayCollection();
  131.         $this->contracts = new ArrayCollection();
  132.     }
  133.     public function getId(): ?UuidInterface
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function setCompanyName(?string $companyName): void
  138.     {
  139.         $this->companyName $companyName;
  140.     }
  141.     public function getCompanyName(): ?string
  142.     {
  143.         return $this->companyName;
  144.     }
  145.     public function setAddressLine1(?string $addressLine1): void
  146.     {
  147.         $this->addressLine1 $addressLine1;
  148.     }
  149.     public function getAddressLine1(): ?string
  150.     {
  151.         return $this->addressLine1;
  152.     }
  153.     public function setAddressLine2(?string $addressLine2): void
  154.     {
  155.         $this->addressLine2 $addressLine2;
  156.     }
  157.     public function getAddressLine2(): ?string
  158.     {
  159.         return $this->addressLine2;
  160.     }
  161.     public function setAddressLine3(?string $addressLine3): void
  162.     {
  163.         $this->addressLine3 $addressLine3;
  164.     }
  165.     public function getAddressLine3(): ?string
  166.     {
  167.         return $this->addressLine3;
  168.     }
  169.     public function setCharteringEmail(?string $charteringEmail): void
  170.     {
  171.         $this->charteringEmail $charteringEmail;
  172.     }
  173.     public function getCharteringEmail(): ?string
  174.     {
  175.         return $this->charteringEmail;
  176.     }
  177.     public function setOperationsEmail(?string $operationsEmail): void
  178.     {
  179.         $this->operationsEmail $operationsEmail;
  180.     }
  181.     public function getOperationsEmail(): ?string
  182.     {
  183.         return $this->operationsEmail;
  184.     }
  185.     public function setAccountingEmail(?string $accountingEmail): void
  186.     {
  187.         $this->accountingEmail $accountingEmail;
  188.     }
  189.     public function getAccountingEmail(): ?string
  190.     {
  191.         return $this->accountingEmail;
  192.     }
  193.     // public function addContact(Contact $contact): void
  194.     // {
  195.     //     if (!$this->contacts->contains($contact)) {
  196.     //         $this->contacts->add($contact);
  197.     //     }
  198.     // }
  199.     // public function removeContact(Contact $contact): void
  200.     // {
  201.     //     $this->contacts->removeElement($contact);
  202.     // }
  203.     // public function getContacts(): Collection
  204.     // {
  205.     //     return $this->contacts;
  206.     // }
  207.     // public function setPrimaryContact(?Contact $primaryContact): void
  208.     // {
  209.     //     $this->primaryContact = $primaryContact;
  210.     // }
  211.     // public function getPrimaryContact(): ?Contact
  212.     // {
  213.     //     return $this->primaryContact;
  214.     // }
  215.     public function addTransactionHistory(Contract $transactionHistory): void
  216.     {
  217.         if (!$this->transactionHistory->contains($transactionHistory)) {
  218.             $this->transactionHistory->add($transactionHistory);
  219.         }
  220.     }
  221.     public function removeTransactionHistory(Contract $transactionHistory): void
  222.     {
  223.         $this->transactionHistory->removeElement($transactionHistory);
  224.     }
  225.     public function getTransactionHistory(): Collection
  226.     {
  227.         return $this->transactionHistory;
  228.     }
  229.     public function setObservations(?string $observations): void
  230.     {
  231.         $this->observations $observations;
  232.     }
  233.     public function getObservations(): ?string
  234.     {
  235.         return $this->observations;
  236.     }
  237.     public function getContracts(): Collection
  238.     {
  239.         return $this->contracts;
  240.     }
  241.     public function addContract(Contract $contract): self
  242.     {
  243.         if (!$this->contracts->contains($contract)) {
  244.             $this->contracts[] = $contract;
  245.             $contract->setCharterer($this);
  246.         }
  247.         return $this;
  248.     }
  249.     public function removeContract(Contract $contract): self
  250.     {
  251.         if ($this->contracts->removeElement($contract)) {
  252.             if ($contract->getCharterer() === $this) {
  253.                 $contract->setCharterer(null);
  254.             }
  255.         }
  256.         
  257.         return $this;
  258.     }
  259. }