src/Entity/Port.php line 64

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/Location
  21.  *
  22.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  23.  */
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     iri'Port',
  27.     itemOperations: [
  28.         'get' => ['normalization_context' => ['groups' => 'port:item:get''enable_max_depth' => true]],
  29.         'put' => [
  30.             'normalization_context' => ['groups' => 'port:item:put''enable_max_depth' => true],
  31.             'denormalization_context' => ['groups' => 'port:item:put''enable_max_depth' => true],
  32.         ],
  33.         'delete' => [],
  34.     ],
  35.     collectionOperations: [
  36.         'get' => [
  37.             'normalization_context' => ['groups' => ['port:collection:get''createdAt'], 'enable_max_depth' => true],
  38.         ],
  39.         'post' => [
  40.             'normalization_context' => ['groups' => 'port:collection:post''enable_max_depth' => true],
  41.             'denormalization_context' => ['groups' => 'port:collection:post''enable_max_depth' => true],
  42.         ],
  43.     ],
  44. )]
  45. #[ApiFilter(
  46.     SearchFilter::class,
  47.     properties: [
  48.         'portName' => 'partial'
  49.         'state' => 'partial'
  50.         'country' => 'partial'
  51.         'geographicLocation' => 'partial'
  52.         'createdAt' => 'start'
  53.     ]
  54. )]
  55. #[ApiFilter(
  56.     OrderFilter::class,
  57.     properties: ['portName''state''country''geographicLocation''createdAt'],
  58. )]
  59. #[ApiFilter(PropertyFilter::class)]
  60. class Port
  61. {
  62.     use TimestampableEntity;
  63.     
  64.     #[ORM\Id]
  65.     #[ORM\GeneratedValue(strategy'NONE')]
  66.     #[ORM\Column(type'uuid'uniquetrue)]
  67.     ##[ApiProperty(iri: 'https://schema.org/identifier')]
  68.     ##[Groups(['port:item:get', 'port:collection:get'])]
  69.     private ?UuidInterface $id null;
  70.     #[ORM\Column(type'string'nullablefalse)]
  71.     #[Assert\NotNull]
  72.     #[Assert\Type('string')]
  73.     #[ApiProperty(iri'https://schema.org/name')]
  74.     #[Groups(['port:item:get''port:item:put''port:collection:get''port:collection:post''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  75.     private ?string $portName null;
  76.     #[ORM\Column(type'string'nullablefalse)]
  77.     #[Assert\NotNull]
  78.     #[Assert\Type('string')]
  79.     #[ApiProperty(iri'https://schema.org/geographicLocation')]
  80.     #[Groups(['port:item:get''port:item:put''port:collection:get''port:collection:post'])]
  81.     private ?string $geographicLocation null;
  82.     #[ORM\OneToMany(targetEntity'App\Entity\Berth'mappedBy'port'cascade: ['persist''remove'], orphanRemovaltrue)]
  83.     #[ApiProperty(iri'https://schema.org/Berth')]
  84.     #[Groups(['port:item:get''port:collection:get''port:collection:post'])]
  85.     #[MaxDepth(1)]
  86.     private ?Collection $berths null;
  87.     // #[ORM\ManyToMany(targetEntity: 'App\Entity\PortCost')]
  88.     // #[ApiProperty(iri: 'https://schema.org/portCosts')]
  89.     // #[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
  90.     // private ?Collection $portCosts = null;
  91.     #[ORM\Column(type'string'nullabletrue)]
  92.     #[Assert\NotNull]
  93.     #[Assert\Type('string')]
  94.     #[ApiProperty(iri'https://schema.org/costInformationSource')]
  95.     #[Groups(['port:item:get''port:item:put''port:collection:get''port:collection:post'])]
  96.     private ?string $costInformationSource null;
  97.     #[ORM\Column(type'string'nullabletrue)]
  98.     #[Assert\NotNull]
  99.     #[Assert\Type('string')]
  100.     #[ApiProperty(iri'https://schema.org/State')]
  101.     #[Groups(['port:item:get''port:item:put''port:collection:get''port:collection:post'])]
  102.     private ?string $state null;
  103.     #[ORM\Column(type'string'nullablefalse)]
  104.     #[Assert\NotNull]
  105.     #[Assert\Type('string')]
  106.     #[ApiProperty(iri'https://schema.org/Country')]
  107.     #[Groups(['port:item:get''port:item:put''port:collection:get''port:collection:post'])]
  108.     private ?string $country null;
  109.     #[ORM\OneToMany(targetEntity'App\Entity\PortCall'mappedBy'port')]
  110.     #[ApiProperty(iri'https://schema.org/PortCall')]
  111.     #[Groups(['port:collection:get''port:collection:post''port:item:get''port:item:put'])]
  112.     #[MaxDepth(1)]
  113.     private ?Collection $portCalls null;
  114.     #[ORM\OneToMany(targetEntity'App\Entity\ReportedPort'mappedBy'port')]
  115.     #[ApiProperty(iri'https://schema.org/ReportedPort')]
  116.     #[Groups(['port:collection:get''port:collection:post''port:item:get''port:item:put'])]
  117.     #[MaxDepth(1)]
  118.     private ?Collection $reportedPorts null;
  119.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'deliveryPort1')]
  120.     #[ApiProperty(iri'https://schema.org/Contract')]
  121.     #[Groups(['port:collection:get''port:collection:post''port:item:get''port:item:put'])]
  122.     #[MaxDepth(1)]
  123.     private ?Collection $deliveryPorts1 null;
  124.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'deliveryPort2')]
  125.     #[ApiProperty(iri'https://schema.org/Contract')]
  126.     #[Groups(['port:collection:get''port:collection:post''port:item:get''port:item:put'])]
  127.     #[MaxDepth(1)]
  128.     private ?Collection $deliveryPorts2 null;
  129.     public function __construct()
  130.     {
  131.         $this->id Uuid::uuid4();
  132.         $this->berths = new ArrayCollection();
  133.         $this->portCalls = new ArrayCollection();
  134.         $this->reportedPorts = new ArrayCollection();
  135.         $this->deliveryPorts1 = new ArrayCollection();
  136.         $this->deliveryPorts2 = new ArrayCollection();
  137.     }
  138.     public function getId(): ?UuidInterface
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function setPortName(?string $portName): void
  143.     {
  144.         $this->portName $portName;
  145.     }
  146.     public function getPortName(): ?string
  147.     {
  148.         return $this->portName;
  149.     }
  150.     public function setGeographicLocation(?string $geographicLocation): void
  151.     {
  152.         $this->geographicLocation $geographicLocation;
  153.     }
  154.     public function getGeographicLocation(): ?string
  155.     {
  156.         return $this->geographicLocation;
  157.     }
  158.     public function addBerth(Berth $berth): void
  159.     {
  160.         $this->berths[] = $berth;
  161.     }
  162.     public function removeBerth(Berth $berth): void
  163.     {
  164.         $this->berths->removeElement($berth);
  165.     }
  166.     public function getBerths(): Collection
  167.     {
  168.         return $this->berths;
  169.     }
  170.     public function setCostInformationSource(?string $costInformationSource): void
  171.     {
  172.         $this->costInformationSource $costInformationSource;
  173.     }
  174.     public function getCostInformationSource(): ?string
  175.     {
  176.         return $this->costInformationSource;
  177.     }
  178.     public function setState(?string $state): void
  179.     {
  180.         $this->state $state;
  181.     }
  182.     public function getState(): ?string
  183.     {
  184.         return $this->state;
  185.     }
  186.     public function setCountry(?string $country): void
  187.     {
  188.         $this->country $country;
  189.     }
  190.     public function getCountry(): ?string
  191.     {
  192.         return $this->country;
  193.     }
  194.     public function addPortCall(PortCall $portCall): void
  195.     {
  196.         $this->portCalls[] = $portCall;
  197.     }
  198.     public function removePortCall(PortCall $portCall): void
  199.     {
  200.         $this->portCalls->removeElement($portCall);
  201.     }
  202.     public function getPortCalls(): Collection
  203.     {
  204.         return $this->portCalls;
  205.     }
  206.     public function addReportedPort(ReportedPort $reportedPort): void
  207.     {
  208.         $this->reportedPorts[] = $reportedPort;
  209.     }
  210.     public function removeReportedPort(ReportedPort $reportedPort): void
  211.     {
  212.         $this->reportedPorts->removeElement($reportedPort);
  213.     }
  214.     public function getReportedPorts(): Collection
  215.     {
  216.         return $this->reportedPorts;
  217.     }
  218.     public function addDeliveryPort1(Contract $deliveryPort): void
  219.     {
  220.         $this->deliveryPorts1[] = $deliveryPort;
  221.     }
  222.     public function removeDeliveryPort1(Contract $deliveryPort): void
  223.     {
  224.         $this->deliveryPorts1->removeElement($deliveryPort);
  225.     }
  226.     public function getDeliveryPorts1(): Collection
  227.     {
  228.         return $this->deliveryPorts1;
  229.     }
  230.     public function addDeliveryPort2(Contract $deliveryPort): void
  231.     {
  232.         $this->deliveryPorts2[] = $deliveryPort;
  233.     }
  234.     public function removeDeliveryPort2(Contract $deliveryPort): void
  235.     {
  236.         $this->deliveryPorts2->removeElement($deliveryPort);
  237.     }
  238.     public function getDeliveryPorts2(): Collection
  239.     {
  240.         return $this->deliveryPorts2;
  241.     }
  242. }