src/Entity/PortCall.php line 33

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. #[ORM\Entity]
  14. #[ApiResource(
  15.     iri'PortCall',
  16.     collectionOperations: [],
  17.     itemOperations: [
  18.         'get' => [
  19.             'security' => "is_granted('ROLE_USER')",
  20.             'method' => 'GET',
  21.             'path' => '/contracts/ports/{id}',
  22.             'openapi_context' => [
  23.                 'tags' => ['Contract / Port']
  24.             ]
  25.         ]
  26.     ],
  27.     attributes: ['pagination_enabled' => false]
  28. )]
  29. class PortCall
  30. {
  31.     use TimestampableEntity;
  32.     public const PORT_CALL_TYPE_LOAD 'Load';
  33.     public const PORT_CALL_TYPE_DISCHARGE 'Discharge';
  34.     public const PORT_CALL_TYPES = [
  35.         self::PORT_CALL_TYPE_LOAD,
  36.         self::PORT_CALL_TYPE_DISCHARGE
  37.     ];
  38.     
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue(strategy'NONE')]
  41.     #[ORM\Column(type'uuid'uniquetrue)]
  42.     private ?UuidInterface $id null;
  43.     #[ORM\Column(type'string'nullablefalse)]
  44.     #[ApiProperty()]
  45.     #[Assert\NotBlank]
  46.     #[Assert\Type('string')]
  47.     #[Assert\Choice(
  48.         choicesself::PORT_CALL_TYPES
  49.         message'The type is not valid.'
  50.     )]
  51.     #[Groups([
  52.         'contract:item:get'
  53.         'contract:item:put'
  54.         'contract:collection:get'
  55.         'contract:collection:post'
  56.     ])]
  57.     private ?string $portCallType null;
  58.     #[ORM\Column(type'datetime'nullabletrue)]
  59.     #[ApiProperty()]
  60.     #[Assert\NotBlank]
  61.     #[Assert\Type(\DateTimeInterface::class)]
  62.     #[Groups([
  63.         'contract:item:get'
  64.         'contract:item:put'
  65.         // 'contract:collection:get', 
  66.         'contract:collection:post'
  67.     ])]
  68.     private ?\DateTimeInterface $arrival null;
  69.     #[ApiProperty()]
  70.     #[Groups([
  71.         'contract:item:get'
  72.     ])]
  73.     private ?string $arrivalDate null;
  74.     #[ApiProperty()]
  75.     #[Groups([
  76.         'contract:item:get'
  77.     ])]
  78.     private ?string $arrivalTime null;
  79.     #[ORM\Column(type'datetime'nullabletrue)]
  80.     #[ApiProperty()]
  81.     #[Assert\NotBlank]
  82.     #[Assert\Type(\DateTimeInterface::class)]
  83.     #[Groups([
  84.         'contract:item:get'
  85.         'contract:item:put'
  86.         // 'contract:collection:get', 
  87.         'contract:collection:post'
  88.     ])]
  89.     private ?\DateTimeInterface $berthing null;
  90.     #[ApiProperty()]
  91.     #[Groups([
  92.         'contract:item:get'
  93.     ])]
  94.     private ?string $berthingDate null;
  95.     #[ApiProperty()]
  96.     #[Groups([
  97.         'contract:item:get'
  98.     ])]
  99.     private ?string $berthingTime null;
  100.     #[ORM\Column(type'datetime'nullabletrue)]
  101.     #[ApiProperty()]
  102.     #[Assert\NotBlank]
  103.     #[Assert\Type(\DateTimeInterface::class)]
  104.     #[Groups([
  105.         'contract:item:get'
  106.         'contract:item:put'
  107.         // 'contract:collection:get', 
  108.         'contract:collection:post'
  109.     ])]
  110.     private ?\DateTimeInterface $departure null;
  111.     #[ApiProperty()]
  112.     #[Groups([
  113.         'contract:item:get'
  114.     ])]
  115.     private ?string $departureDate null;
  116.     #[ApiProperty()]
  117.     #[Groups([
  118.         'contract:item:get'
  119.     ])]
  120.     private ?string $departureTime null;
  121.     #[ORM\ManyToOne(
  122.         targetEntityPort::class, 
  123.         inversedBy'portCalls'
  124.     )]
  125.     #[ORM\JoinColumn(nullabletrue)]
  126.     #[ApiProperty()]
  127.     #[Groups([
  128.         'contract:item:get'
  129.         'contract:item:put'
  130.         'contract:collection:get'
  131.         'contract:collection:post'
  132.     ])]
  133.     #[MaxDepth(1)]
  134.     private ?Port $port null;
  135.     #[ORM\Column(type'integer')]
  136.     #[Assert\NotNull]
  137.     #[ApiProperty()]
  138.     #[Groups([
  139.         'contract:item:get'
  140.         'contract:item:put'
  141.         'contract:collection:get'
  142.         'contract:collection:post'
  143.     ])]
  144.     private ?int $portIndex 0;
  145.     #[ORM\ManyToOne(
  146.         targetEntityContract::class, 
  147.         inversedBy'portCalls'
  148.     )]
  149.     #[ORM\JoinColumn(nullabletrue)]
  150.     private ?Contract $contract null;
  151.     public function __construct()
  152.     {
  153.         $this->id Uuid::uuid4();
  154.     }
  155.     public function getId(): ?UuidInterface
  156.     {
  157.         return $this->id;
  158.     }
  159.     public function setPortCallType(?string $portCallType): void
  160.     {
  161.         $this->portCallType $portCallType;
  162.     }
  163.     public function getPortCallType(): ?string
  164.     {
  165.         return $this->portCallType;
  166.     }
  167.     public function setArrival(?\DateTimeInterface $arrival): void
  168.     {
  169.         $this->arrival $arrival;
  170.     }
  171.     public function getArrival(): ?\DateTimeInterface
  172.     {
  173.         return $this->arrival;
  174.     }
  175.     public function getArrivalDate(): ?string
  176.     {
  177.         return $this->arrival $this->arrival->format('Y-m-d') : null;
  178.     }
  179.     public function getArrivalTime(): ?string
  180.     {
  181.         return $this->arrival $this->arrival->format('H:i') : null;
  182.     }
  183.     public function setBerthing(?\DateTimeInterface $berthing): void
  184.     {
  185.         $this->berthing $berthing;
  186.     }
  187.     public function getBerthing(): ?\DateTimeInterface
  188.     {
  189.         return $this->berthing;
  190.     }
  191.     public function getBerthingDate(): ?string
  192.     {
  193.         return $this->berthing $this->berthing->format('Y-m-d') : null;
  194.     }
  195.     public function getBerthingTime(): ?string
  196.     {
  197.         return $this->berthing $this->berthing->format('H:i') : null;
  198.     }
  199.     public function setDeparture(?\DateTimeInterface $departure): void
  200.     {
  201.         $this->departure $departure;
  202.     }
  203.     public function getDeparture(): ?\DateTimeInterface
  204.     {
  205.         return $this->departure;
  206.     }
  207.     public function getDepartureDate(): ?string
  208.     {
  209.         return $this->departure $this->departure->format('Y-m-d') : null;
  210.     }
  211.     public function getDepartureTime(): ?string
  212.     {
  213.         return $this->departure $this->departure->format('H:i') : null;
  214.     }
  215.     public function setPort(?Port $port): void
  216.     {
  217.         $this->port $port;
  218.     }
  219.     public function getPort(): ?Port
  220.     {
  221.         return $this->port;
  222.     }
  223.     public function setPortIndex(?int $portIndex): void
  224.     {
  225.         $this->portIndex $portIndex;
  226.     }
  227.     public function getPortIndex(): ?int
  228.     {
  229.         return $this->portIndex;
  230.     }
  231.     public function setContract(?Contract $contract): void
  232.     {
  233.         $this->contract $contract;
  234.     }
  235.     public function getContract(): ?Contract
  236.     {
  237.         return $this->contract;
  238.     }
  239. }