src/Entity/PortCall.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Serializer\Annotation\MaxDepth;
  11. use Ramsey\Uuid\Uuid;
  12. use Ramsey\Uuid\UuidInterface;
  13. /**
  14.  * @see https://schema.org/Thing
  15.  *
  16.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  17.  */
  18. #[ORM\Entity]
  19. #[ApiResource(
  20.     iri'PortCall',
  21.     itemOperations: [
  22.         'get' => ['normalization_context' => ['groups' => 'port_call:item:get''enable_max_depth' => true]],
  23.         'put' => [
  24.             'normalization_context' => ['groups' => 'port_call:item:put''enable_max_depth' => true],
  25.             'denormalization_context' => ['groups' => 'port_call:item:put''enable_max_depth' => true],
  26.         ],
  27.         'delete' => [],
  28.     ],
  29.     collectionOperations: [
  30.         'get' => [
  31.             'normalization_context' => [
  32.                 'groups' => ['port_call:collection:get''createdAt'],
  33.                 'enable_max_depth' => true,
  34.             ],
  35.         ],
  36.         'post' => [
  37.             'normalization_context' => ['groups' => 'port_call:collection:post''enable_max_depth' => true],
  38.             'denormalization_context' => ['groups' => 'port_call:collection:post''enable_max_depth' => true],
  39.         ],
  40.     ],
  41. )]
  42. class PortCall
  43. {
  44.     use TimestampableEntity;
  45.     public const PORT_CALL_TYPES = [
  46.         'Load',
  47.         'Discharge'
  48.     ];
  49.     
  50.     #[ORM\Id]
  51.     #[ORM\GeneratedValue(strategy'NONE')]
  52.     #[ORM\Column(type'uuid'uniquetrue)]
  53.     private ?UuidInterface $id null;
  54.     #[ORM\Column(type'string'nullablefalse)]
  55.     #[ApiProperty(iri'https://schema.org/portCallType')]
  56.     #[Assert\NotBlank]
  57.     #[Assert\Type('string')]
  58.     #[Assert\Choice(choicesself::PORT_CALL_TYPESmessage'The type is not valid.')]
  59.     #[Groups(['port_call:item:get''port_call:item:put''port_call:collection:get''port_call:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  60.     private ?string $portCallType null;
  61.     #[ORM\Column(type'datetime'nullabletrue)]
  62.     #[ApiProperty(iri'https://schema.org/arrival')]
  63.     #[Assert\NotBlank]
  64.     #[Assert\Type(\DateTimeInterface::class)]
  65.     #[Groups(['contract:item:get''contract:item:put''contract:collection:get''contract:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  66.     private ?\DateTimeInterface $arrival null;
  67.     #[ApiProperty(iri'https://schema.org/arrivalDate')]
  68.     #[Groups(['contract:item:get'])]
  69.     private ?string $arrivalDate null;
  70.     #[ApiProperty(iri'https://schema.org/arrivalTime')]
  71.     #[Groups(['contract:item:get'])]
  72.     private ?string $arrivalTime null;
  73.     #[ORM\Column(type'datetime'nullabletrue)]
  74.     #[ApiProperty(iri'https://schema.org/berthing')]
  75.     #[Assert\NotBlank]
  76.     #[Assert\Type(\DateTimeInterface::class)]
  77.     #[Groups(['contract:item:get''contract:item:put''contract:collection:get''contract:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  78.     private ?\DateTimeInterface $berthing null;
  79.     #[ApiProperty(iri'https://schema.org/berthingDate')]
  80.     #[Groups(['contract:item:get'])]
  81.     private ?string $berthingDate null;
  82.     #[ApiProperty(iri'https://schema.org/berthingTime')]
  83.     #[Groups(['contract:item:get'])]
  84.     private ?string $berthingTime null;
  85.     #[ORM\Column(type'datetime'nullabletrue)]
  86.     #[ApiProperty(iri'https://schema.org/departure')]
  87.     #[Assert\NotBlank]
  88.     #[Assert\Type(\DateTimeInterface::class)]
  89.     #[Groups(['contract:item:get''contract:item:put''contract:collection:get''contract:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  90.     private ?\DateTimeInterface $departure null;
  91.     #[ApiProperty(iri'https://schema.org/departureDate')]
  92.     #[Groups(['contract:item:get'])]
  93.     private ?string $departureDate null;
  94.     #[ApiProperty(iri'https://schema.org/departureTime')]
  95.     #[Groups(['contract:item:get'])]
  96.     private ?string $departureTime null;
  97.     #[ORM\ManyToOne(targetEntity'App\Entity\Port'inversedBy'portCalls')]
  98.     #[ORM\JoinColumn(nullabletrue)]
  99.     #[ApiProperty(iri'https://schema.org/port')]
  100.     #[Groups(['port_call:collection:get''port_call:collection:post''port_call:item:get''port_call:item:put''contract:collection:post''contract:item:get''contract:item:put'])]
  101.     #[MaxDepth(1)]
  102.     private ?Port $port null;
  103.     #[ORM\ManyToOne(targetEntity'App\Entity\Contract'inversedBy'portCalls')]
  104.     #[ORM\JoinColumn(nullabletrue)]
  105.     #[ApiProperty(iri'https://schema.org/Contract')]
  106.     #[Groups(['port_call:collection:get''port_call:collection:post''port_call:item:get''port_call:item:put'])]
  107.     #[MaxDepth(1)]
  108.     private ?Contract $contract null;
  109.     public function __construct()
  110.     {
  111.         $this->id Uuid::uuid4();
  112.     }
  113.     public function getId(): ?UuidInterface
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function setPortCallType(?string $portCallType): void
  118.     {
  119.         $this->portCallType $portCallType;
  120.     }
  121.     public function getPortCallType(): ?string
  122.     {
  123.         return $this->portCallType;
  124.     }
  125.     public function setArrival(?\DateTimeInterface $arrival): void
  126.     {
  127.         $this->arrival $arrival;
  128.     }
  129.     public function getArrival(): ?\DateTimeInterface
  130.     {
  131.         return $this->arrival;
  132.     }
  133.     public function getArrivalDate(): ?string
  134.     {
  135.         return $this->arrival $this->arrival->format('Y-m-d') : null;
  136.     }
  137.     public function getArrivalTime(): ?string
  138.     {
  139.         return $this->arrival $this->arrival->format('H:i') : null;
  140.     }
  141.     public function setBerthing(?\DateTimeInterface $berthing): void
  142.     {
  143.         $this->berthing $berthing;
  144.     }
  145.     public function getBerthing(): ?\DateTimeInterface
  146.     {
  147.         return $this->berthing;
  148.     }
  149.     public function getBerthingDate(): ?string
  150.     {
  151.         return $this->berthing $this->berthing->format('Y-m-d') : null;
  152.     }
  153.     public function getBerthingTime(): ?string
  154.     {
  155.         return $this->berthing $this->berthing->format('H:i') : null;
  156.     }
  157.     public function setDeparture(?\DateTimeInterface $departure): void
  158.     {
  159.         $this->departure $departure;
  160.     }
  161.     public function getDeparture(): ?\DateTimeInterface
  162.     {
  163.         return $this->departure;
  164.     }
  165.     public function getDepartureDate(): ?string
  166.     {
  167.         return $this->departure $this->departure->format('Y-m-d') : null;
  168.     }
  169.     public function getDepartureTime(): ?string
  170.     {
  171.         return $this->departure $this->departure->format('H:i') : null;
  172.     }
  173.     public function setPort(?Port $port): void
  174.     {
  175.         $this->port $port;
  176.     }
  177.     public function getPort(): ?Port
  178.     {
  179.         return $this->port;
  180.     }
  181.     public function setContract(?Contract $contract): void
  182.     {
  183.         $this->contract $contract;
  184.     }
  185.     public function getContract(): ?Contract
  186.     {
  187.         return $this->contract;
  188.     }
  189. }