<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* @see https://schema.org/Location
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Port',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'port:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'port:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'port:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => ['groups' => ['port:collection:get', 'createdAt'], 'enable_max_depth' => true],
],
'post' => [
'normalization_context' => ['groups' => 'port:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'port:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'portName' => 'partial',
'state' => 'partial',
'country' => 'partial',
'geographicLocation' => 'partial',
'createdAt' => 'start'
]
)]
#[ApiFilter(
OrderFilter::class,
properties: ['portName', 'state', 'country', 'geographicLocation', 'createdAt'],
)]
#[ApiFilter(PropertyFilter::class)]
class Port
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
##[ApiProperty(iri: 'https://schema.org/identifier')]
##[Groups(['port:item:get', 'port:collection:get'])]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/name')]
#[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'])]
private ?string $portName = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/geographicLocation')]
#[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
private ?string $geographicLocation = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\Berth', mappedBy: 'port', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ApiProperty(iri: 'https://schema.org/Berth')]
#[Groups(['port:item:get', 'port:collection:get', 'port:collection:post'])]
#[MaxDepth(1)]
private ?Collection $berths = null;
// #[ORM\ManyToMany(targetEntity: 'App\Entity\PortCost')]
// #[ApiProperty(iri: 'https://schema.org/portCosts')]
// #[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
// private ?Collection $portCosts = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/costInformationSource')]
#[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
private ?string $costInformationSource = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/State')]
#[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
private ?string $state = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/Country')]
#[Groups(['port:item:get', 'port:item:put', 'port:collection:get', 'port:collection:post'])]
private ?string $country = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\PortCall', mappedBy: 'port')]
#[ApiProperty(iri: 'https://schema.org/PortCall')]
#[Groups(['port:collection:get', 'port:collection:post', 'port:item:get', 'port:item:put'])]
#[MaxDepth(1)]
private ?Collection $portCalls = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\ReportedPort', mappedBy: 'port')]
#[ApiProperty(iri: 'https://schema.org/ReportedPort')]
#[Groups(['port:collection:get', 'port:collection:post', 'port:item:get', 'port:item:put'])]
#[MaxDepth(1)]
private ?Collection $reportedPorts = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\Contract', mappedBy: 'deliveryPort1')]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['port:collection:get', 'port:collection:post', 'port:item:get', 'port:item:put'])]
#[MaxDepth(1)]
private ?Collection $deliveryPorts1 = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\Contract', mappedBy: 'deliveryPort2')]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['port:collection:get', 'port:collection:post', 'port:item:get', 'port:item:put'])]
#[MaxDepth(1)]
private ?Collection $deliveryPorts2 = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->berths = new ArrayCollection();
$this->portCalls = new ArrayCollection();
$this->reportedPorts = new ArrayCollection();
$this->deliveryPorts1 = new ArrayCollection();
$this->deliveryPorts2 = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setPortName(?string $portName): void
{
$this->portName = $portName;
}
public function getPortName(): ?string
{
return $this->portName;
}
public function setGeographicLocation(?string $geographicLocation): void
{
$this->geographicLocation = $geographicLocation;
}
public function getGeographicLocation(): ?string
{
return $this->geographicLocation;
}
public function addBerth(Berth $berth): void
{
$this->berths[] = $berth;
}
public function removeBerth(Berth $berth): void
{
$this->berths->removeElement($berth);
}
public function getBerths(): Collection
{
return $this->berths;
}
public function setCostInformationSource(?string $costInformationSource): void
{
$this->costInformationSource = $costInformationSource;
}
public function getCostInformationSource(): ?string
{
return $this->costInformationSource;
}
public function setState(?string $state): void
{
$this->state = $state;
}
public function getState(): ?string
{
return $this->state;
}
public function setCountry(?string $country): void
{
$this->country = $country;
}
public function getCountry(): ?string
{
return $this->country;
}
public function addPortCall(PortCall $portCall): void
{
$this->portCalls[] = $portCall;
}
public function removePortCall(PortCall $portCall): void
{
$this->portCalls->removeElement($portCall);
}
public function getPortCalls(): Collection
{
return $this->portCalls;
}
public function addReportedPort(ReportedPort $reportedPort): void
{
$this->reportedPorts[] = $reportedPort;
}
public function removeReportedPort(ReportedPort $reportedPort): void
{
$this->reportedPorts->removeElement($reportedPort);
}
public function getReportedPorts(): Collection
{
return $this->reportedPorts;
}
public function addDeliveryPort1(Contract $deliveryPort): void
{
$this->deliveryPorts1[] = $deliveryPort;
}
public function removeDeliveryPort1(Contract $deliveryPort): void
{
$this->deliveryPorts1->removeElement($deliveryPort);
}
public function getDeliveryPorts1(): Collection
{
return $this->deliveryPorts1;
}
public function addDeliveryPort2(Contract $deliveryPort): void
{
$this->deliveryPorts2[] = $deliveryPort;
}
public function removeDeliveryPort2(Contract $deliveryPort): void
{
$this->deliveryPorts2->removeElement($deliveryPort);
}
public function getDeliveryPorts2(): Collection
{
return $this->deliveryPorts2;
}
}