<?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;
#[ORM\Entity]
#[ApiResource(
iri: 'Port',
itemOperations: [
'get' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER') or
is_granted('ROLE_INTERN')
",
'normalization_context' => [
'groups' => 'port:item:get',
'enable_max_depth' => true
]
],
'put' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
'normalization_context' => [
'groups' => 'port:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'port:item:put',
'enable_max_depth' => true
],
],
'delete' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
],
],
collectionOperations: [
'get' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER') or
is_granted('ROLE_INTERN')
",
'normalization_context' => [
'groups' => [
'port:collection:get',
'createdAt'
],
'enable_max_depth' => true],
],
'post' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR') or
is_granted('ROLE_RESEARCH_ANALYST') or
is_granted('ROLE_BROKER')
",
'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)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty()]
#[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',
'market_rumor:item:get',
'market_rumor:item:put',
'market_rumor:collection:get',
'market_rumor:collection:post'
])]
private ?string $portName = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'port:item:get',
'port:item:put',
'port:collection:get',
'port:collection:post'
])]
private ?string $geographicLocation = null;
#[ORM\OneToMany(
targetEntity: Berth::class,
mappedBy: 'port',
cascade: ['persist', 'remove'],
orphanRemoval: true
)]
#[ApiProperty()]
#[Groups([
'port:item:get',
'port:item:put',
// 'port:collection:get',
'port:collection:post'
])]
#[MaxDepth(1)]
private ?Collection $berths = null;
#[ApiProperty()]
#[Groups(['port:collection:get'])]
private ?int $berthCount = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'port:item:get',
'port:item:put',
'port:collection:get',
'port:collection:post'
])]
private ?string $costInformationSource = null;
#[ORM\Column(type: 'string', nullable: true)]
##[Assert\Type('string')]
#[ApiProperty()]
#[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()]
#[Groups([
'port:item:get',
'port:item:put',
'port:collection:get',
'port:collection:post'
])]
private ?string $country = null;
#[ORM\OneToMany(
targetEntity: PortCall::class,
mappedBy: 'port'
)]
private ?Collection $portCalls = null;
#[ORM\OneToMany(
targetEntity: OperationReport::class,
mappedBy: 'port'
)]
private ?Collection $operationReports = null;
#[ORM\OneToMany(
targetEntity: Contract::class,
mappedBy: 'deliveryPort1'
)]
private ?Collection $deliveryPorts1 = null;
#[ORM\OneToMany(
targetEntity: Contract::class,
mappedBy: 'deliveryPort2'
)]
private ?Collection $deliveryPorts2 = null;
#[ORM\OneToMany(
targetEntity: Contract::class,
mappedBy: 'redeliveryPort1'
)]
private ?Collection $redeliveryPorts1 = null;
#[ORM\OneToMany(
targetEntity: Contract::class,
mappedBy: 'redeliveryPort2'
)]
private ?Collection $redeliveryPorts2 = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->berths = new ArrayCollection();
$this->portCalls = new ArrayCollection();
$this->operationReports = new ArrayCollection();
$this->deliveryPorts1 = new ArrayCollection();
$this->deliveryPorts2 = new ArrayCollection();
$this->redeliveryPorts1 = new ArrayCollection();
$this->redeliveryPorts2 = 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
{
$berth->setPort($this);
$this->berths[] = $berth;
}
public function removeBerth(Berth $berth): void
{
$this->berths->removeElement($berth);
}
public function getBerths(): Collection
{
return $this->berths;
}
public function getBerthCount(): ?int
{
return $this->berths->count();
}
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 addOperationReport(OperationReport $operationReport): void
{
$this->operationReports[] = $operationReport;
}
public function removeOperationReport(OperationReport $operationReport): void
{
$this->operationReports->removeElement($operationReport);
}
public function getOperationReports(): Collection
{
return $this->operationReports;
}
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;
}
public function addRedeliveryPort1(Contract $redeliveryPort): void
{
$this->redeliveryPorts1[] = $redeliveryPort;
}
public function removeRedeliveryPort1(Contract $redeliveryPort): void
{
$this->redeliveryPorts1->removeElement($redeliveryPort);
}
public function getRedeliveryPorts1(): Collection
{
return $this->redeliveryPorts1;
}
public function addRedeliveryPort2(Contract $redeliveryPort): void
{
$this->redeliveryPorts2[] = $redeliveryPort;
}
public function removeRedeliveryPort2(Contract $redeliveryPort): void
{
$this->redeliveryPorts2->removeElement($redeliveryPort);
}
public function getRedeliveryPorts2(): Collection
{
return $this->redeliveryPorts2;
}
}