src/Entity/Port.php line 125

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. #[ORM\Entity]
  20. #[ApiResource(
  21.     iri'Port',
  22.     itemOperations: [
  23.         'get' => [
  24.             'security' => "
  25.                 is_granted('ROLE_ADMIN') or 
  26.                 is_granted('ROLE_OPERATOR') or
  27.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  28.                 is_granted('ROLE_RESEARCH_ANALYST') or
  29.                 is_granted('ROLE_BROKER') or 
  30.                 is_granted('ROLE_INTERN')
  31.             ",
  32.             'normalization_context' => [
  33.                 'groups' => 'port:item:get'
  34.                 'enable_max_depth' => true
  35.             ]
  36.         ],
  37.         'put' => [
  38.             'security' => "
  39.                 is_granted('ROLE_ADMIN') or 
  40.                 is_granted('ROLE_OPERATOR') or
  41.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  42.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  43.                 is_granted('ROLE_BROKER')
  44.             ",
  45.             'normalization_context' => [
  46.                 'groups' => 'port:item:put'
  47.                 'enable_max_depth' => true
  48.             ],
  49.             'denormalization_context' => [
  50.                 'groups' => 'port:item:put'
  51.                 'enable_max_depth' => true
  52.             ],
  53.         ],
  54.         'delete' => [
  55.             'security' => "
  56.                 is_granted('ROLE_ADMIN') or 
  57.                 is_granted('ROLE_OPERATOR') or
  58.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  59.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  60.                 is_granted('ROLE_BROKER')
  61.             ",
  62.         ],
  63.     ],
  64.     collectionOperations: [
  65.         'get' => [
  66.             'security' => "
  67.                 is_granted('ROLE_ADMIN') or 
  68.                 is_granted('ROLE_OPERATOR') or
  69.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  70.                 is_granted('ROLE_RESEARCH_ANALYST') or
  71.                 is_granted('ROLE_BROKER') or 
  72.                 is_granted('ROLE_INTERN')
  73.             ",
  74.             'normalization_context' => [
  75.                 'groups' => [
  76.                     'port:collection:get'
  77.                     'createdAt'
  78.                 ], 
  79.                 'enable_max_depth' => true],
  80.         ],
  81.         'post' => [
  82.             'security' => "
  83.                 is_granted('ROLE_ADMIN') or 
  84.                 is_granted('ROLE_OPERATOR') or
  85.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  86.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  87.                 is_granted('ROLE_BROKER')
  88.             ",
  89.             'normalization_context' => [
  90.                 'groups' => 'port:collection:post'
  91.                 'enable_max_depth' => true
  92.             ],
  93.             'denormalization_context' => [
  94.                 'groups' => 'port:collection:post'
  95.                 'enable_max_depth' => true
  96.             ],
  97.         ],
  98.     ],
  99. )]
  100. #[ApiFilter(
  101.     SearchFilter::class,
  102.     properties: [
  103.         'portName' => 'partial'
  104.         'state' => 'partial'
  105.         'country' => 'partial'
  106.         'geographicLocation' => 'partial'
  107.         'createdAt' => 'start'
  108.     ]
  109. )]
  110. #[ApiFilter(
  111.     OrderFilter::class,
  112.     properties: [
  113.         'portName'
  114.         'state'
  115.         'country'
  116.         'geographicLocation'
  117.         'createdAt'
  118.     ],
  119. )]
  120. #[ApiFilter(PropertyFilter::class)]
  121. class Port
  122. {
  123.     use TimestampableEntity;
  124.     
  125.     #[ORM\Id]
  126.     #[ORM\GeneratedValue(strategy'NONE')]
  127.     #[ORM\Column(type'uuid'uniquetrue)]
  128.     private ?UuidInterface $id null;
  129.     #[ORM\Column(type'string'nullablefalse)]
  130.     #[Assert\NotNull]
  131.     #[Assert\Type('string')]
  132.     #[ApiProperty()]
  133.     #[Groups([
  134.         'port:item:get'
  135.         'port:item:put'
  136.         'port:collection:get'
  137.         'port:collection:post'
  138.         'contract:item:get'
  139.         'contract:item:put'
  140.         'contract:collection:get'
  141.         'contract:collection:post',
  142.         'market_rumor:item:get'
  143.         'market_rumor:item:put'
  144.         'market_rumor:collection:get'
  145.         'market_rumor:collection:post'
  146.     ])]
  147.     private ?string $portName null;
  148.     #[ORM\Column(type'string'nullabletrue)]
  149.     ##[Assert\Type('string')]
  150.     #[ApiProperty()]
  151.     #[Groups([
  152.         'port:item:get'
  153.         'port:item:put'
  154.         'port:collection:get'
  155.         'port:collection:post'
  156.     ])]
  157.     private ?string $geographicLocation null;
  158.     #[ORM\OneToMany(
  159.         targetEntityBerth::class, 
  160.         mappedBy'port'
  161.         cascade: ['persist''remove'], 
  162.         orphanRemovaltrue
  163.     )]
  164.     #[ApiProperty()]
  165.     #[Groups([
  166.         'port:item:get',
  167.         'port:item:put',
  168.         // 'port:collection:get', 
  169.         'port:collection:post'
  170.     ])]
  171.     #[MaxDepth(1)]
  172.     private ?Collection $berths null;
  173.     #[ApiProperty()]
  174.     #[Groups(['port:collection:get'])]
  175.     private ?int $berthCount null;
  176.     #[ORM\Column(type'string'nullabletrue)]
  177.     ##[Assert\Type('string')]
  178.     #[ApiProperty()]
  179.     #[Groups([
  180.         'port:item:get'
  181.         'port:item:put'
  182.         'port:collection:get'
  183.         'port:collection:post'
  184.     ])]
  185.     private ?string $costInformationSource null;
  186.     #[ORM\Column(type'string'nullabletrue)]
  187.     ##[Assert\Type('string')]
  188.     #[ApiProperty()]
  189.     #[Groups([
  190.         'port:item:get'
  191.         'port:item:put'
  192.         'port:collection:get'
  193.         'port:collection:post'
  194.     ])]
  195.     private ?string $state null;
  196.     #[ORM\Column(type'string'nullablefalse)]
  197.     #[Assert\NotNull]
  198.     #[Assert\Type('string')]
  199.     #[ApiProperty()]
  200.     #[Groups([
  201.         'port:item:get'
  202.         'port:item:put'
  203.         'port:collection:get'
  204.         'port:collection:post'
  205.     ])]
  206.     private ?string $country null;
  207.     #[ORM\OneToMany(
  208.         targetEntityPortCall::class, 
  209.         mappedBy'port'
  210.     )]
  211.     private ?Collection $portCalls null;
  212.     #[ORM\OneToMany(
  213.         targetEntityOperationReport::class, 
  214.         mappedBy'port'
  215.     )]
  216.     private ?Collection $operationReports null;
  217.     #[ORM\OneToMany(
  218.         targetEntityContract::class, 
  219.         mappedBy'deliveryPort1'
  220.     )]
  221.     private ?Collection $deliveryPorts1 null;
  222.     #[ORM\OneToMany(
  223.         targetEntityContract::class, 
  224.         mappedBy'deliveryPort2'
  225.     )]
  226.     private ?Collection $deliveryPorts2 null;
  227.     #[ORM\OneToMany(
  228.         targetEntityContract::class, 
  229.         mappedBy'redeliveryPort1'
  230.     )]
  231.     private ?Collection $redeliveryPorts1 null;
  232.     #[ORM\OneToMany(
  233.         targetEntityContract::class, 
  234.         mappedBy'redeliveryPort2'
  235.     )]
  236.     private ?Collection $redeliveryPorts2 null;
  237.     public function __construct()
  238.     {
  239.         $this->id Uuid::uuid4();
  240.         $this->berths = new ArrayCollection();
  241.         $this->portCalls = new ArrayCollection();
  242.         $this->operationReports = new ArrayCollection();
  243.         $this->deliveryPorts1 = new ArrayCollection();
  244.         $this->deliveryPorts2 = new ArrayCollection();
  245.         $this->redeliveryPorts1 = new ArrayCollection();
  246.         $this->redeliveryPorts2 = new ArrayCollection();
  247.     }
  248.     public function getId(): ?UuidInterface
  249.     {
  250.         return $this->id;
  251.     }
  252.     public function setPortName(?string $portName): void
  253.     {
  254.         $this->portName $portName;
  255.     }
  256.     public function getPortName(): ?string
  257.     {
  258.         return $this->portName;
  259.     }
  260.     public function setGeographicLocation(?string $geographicLocation): void
  261.     {
  262.         $this->geographicLocation $geographicLocation;
  263.     }
  264.     public function getGeographicLocation(): ?string
  265.     {
  266.         return $this->geographicLocation;
  267.     }
  268.     public function addBerth(Berth $berth): void
  269.     {
  270.         $berth->setPort($this);
  271.         $this->berths[] = $berth;
  272.     }
  273.     public function removeBerth(Berth $berth): void
  274.     {
  275.         $this->berths->removeElement($berth);
  276.     }
  277.     public function getBerths(): Collection
  278.     {
  279.         return $this->berths;
  280.     }
  281.     public function getBerthCount(): ?int
  282.     {
  283.         return $this->berths->count();
  284.     }
  285.     public function setCostInformationSource(?string $costInformationSource): void
  286.     {
  287.         $this->costInformationSource $costInformationSource;
  288.     }
  289.     public function getCostInformationSource(): ?string
  290.     {
  291.         return $this->costInformationSource;
  292.     }
  293.     public function setState(?string $state): void
  294.     {
  295.         $this->state $state;
  296.     }
  297.     public function getState(): ?string
  298.     {
  299.         return $this->state;
  300.     }
  301.     public function setCountry(?string $country): void
  302.     {
  303.         $this->country $country;
  304.     }
  305.     public function getCountry(): ?string
  306.     {
  307.         return $this->country;
  308.     }
  309.     public function addPortCall(PortCall $portCall): void
  310.     {
  311.         $this->portCalls[] = $portCall;
  312.     }
  313.     public function removePortCall(PortCall $portCall): void
  314.     {
  315.         $this->portCalls->removeElement($portCall);
  316.     }
  317.     public function getPortCalls(): Collection
  318.     {
  319.         return $this->portCalls;
  320.     }
  321.     public function addOperationReport(OperationReport $operationReport): void
  322.     {
  323.         $this->operationReports[] = $operationReport;
  324.     }
  325.     public function removeOperationReport(OperationReport $operationReport): void
  326.     {
  327.         $this->operationReports->removeElement($operationReport);
  328.     }
  329.     public function getOperationReports(): Collection
  330.     {
  331.         return $this->operationReports;
  332.     }
  333.     public function addDeliveryPort1(Contract $deliveryPort): void
  334.     {
  335.         $this->deliveryPorts1[] = $deliveryPort;
  336.     }
  337.     public function removeDeliveryPort1(Contract $deliveryPort): void
  338.     {
  339.         $this->deliveryPorts1->removeElement($deliveryPort);
  340.     }
  341.     public function getDeliveryPorts1(): Collection
  342.     {
  343.         return $this->deliveryPorts1;
  344.     }
  345.     public function addDeliveryPort2(Contract $deliveryPort): void
  346.     {
  347.         $this->deliveryPorts2[] = $deliveryPort;
  348.     }
  349.     public function removeDeliveryPort2(Contract $deliveryPort): void
  350.     {
  351.         $this->deliveryPorts2->removeElement($deliveryPort);
  352.     }
  353.     public function getDeliveryPorts2(): Collection
  354.     {
  355.         return $this->deliveryPorts2;
  356.     }
  357.     public function addRedeliveryPort1(Contract $redeliveryPort): void
  358.     {
  359.         $this->redeliveryPorts1[] = $redeliveryPort;
  360.     }
  361.     public function removeRedeliveryPort1(Contract $redeliveryPort): void
  362.     {
  363.         $this->redeliveryPorts1->removeElement($redeliveryPort);
  364.     }
  365.     public function getRedeliveryPorts1(): Collection
  366.     {
  367.         return $this->redeliveryPorts1;
  368.     }
  369.     public function addRedeliveryPort2(Contract $redeliveryPort): void
  370.     {
  371.         $this->redeliveryPorts2[] = $redeliveryPort;
  372.     }
  373.     public function removeRedeliveryPort2(Contract $redeliveryPort): void
  374.     {
  375.         $this->redeliveryPorts2->removeElement($redeliveryPort);
  376.     }
  377.     public function getRedeliveryPorts2(): Collection
  378.     {
  379.         return $this->redeliveryPorts2;
  380.     }
  381. }