src/Entity/Vessel.php line 89

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\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  10. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  11. use App\Trait\TimestampableEntity;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use EasyRdf\Literal\Boolean;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\Serializer\Annotation\MaxDepth;
  19. use Ramsey\Uuid\Uuid;
  20. use Ramsey\Uuid\UuidInterface;
  21. /**
  22.  * @see https://schema.org/Thing
  23.  *
  24.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  25.  */
  26. #[ORM\Entity]
  27. #[ApiResource(
  28.     iri'Vessel',
  29.     itemOperations: [
  30.         'get' => ['normalization_context' => ['groups' => 'vessel:item:get''enable_max_depth' => true]],
  31.         'put' => [
  32.             'normalization_context' => ['groups' => 'vessel:item:put''enable_max_depth' => true],
  33.             'denormalization_context' => ['groups' => 'vessel:item:put''enable_max_depth' => true],
  34.         ],
  35.         'delete' => [],
  36.     ],
  37.     collectionOperations: [
  38.         'get' => [
  39.             'normalization_context' => ['groups' => ['vessel:collection:get''createdAt'], 'enable_max_depth' => true],
  40.         ],
  41.         'post' => [
  42.             'normalization_context' => ['groups' => 'vessel:collection:post''enable_max_depth' => true],
  43.             'denormalization_context' => ['groups' => 'vessel:collection:post''enable_max_depth' => true],
  44.         ],
  45.     ],
  46. )]
  47. #[ApiFilter(
  48.     SearchFilter::class,
  49.     properties: [
  50.         'vesselName' => 'partial'
  51.         'imoNumber' => 'partial'
  52.         'vesselType' => 'exact',
  53.         'dwt' => 'partial',
  54.         'yearBuilt' => 'exact',
  55.         'imoClass' => 'partial',
  56.         'tankCoating' => 'exact',
  57.         'createdAt' => 'start'
  58.     ],
  59. )]
  60. #[ApiFilter(
  61.     OrderFilter::class,
  62.     properties: [
  63.         'vesselName'
  64.         'imoNumber'
  65.         'vesselType',
  66.         'dwt',
  67.         'yearBuilt',
  68.         'imoClass',
  69.         'nitrogenGenerator',
  70.         'boxShape',
  71.         'openHatch',
  72.         'tankCoating',
  73.         'createdAt'
  74.     ],
  75. )]
  76. #[ApiFilter(
  77.     BooleanFilter::class,
  78.     properties: [
  79.         'nitrogenGenerator',
  80.         'boxShape',
  81.         'openHatch',
  82.     ],
  83. )]
  84. #[ApiFilter(PropertyFilter::class)]
  85. class Vessel
  86. {
  87.     use TimestampableEntity;
  88.     public const VESSEL_TYPES = [
  89.         'Tanker',
  90.         'Bulker'
  91.     ];
  92.     public const TANKER_TYPES = [
  93.         'Chemical & Oil Carrier',
  94.         'Product Carrier',
  95.         'Chemical Bulk Tanker',
  96.         'Chemical Parcell Tanker',
  97.         'Asphalt & Bitumen Carrier',
  98.         'Methanol Carrier',
  99.         'Chemical Unknown Carrier',
  100.         'Tanker',
  101.         'Shuttle Tanker',
  102.         'Oil Bunkering Tanker',
  103.         'Products/Multi-Purpose',
  104.         'Cargo'
  105.     ];
  106.     public const BULKER_TYPES = [
  107.         'Aggregates Carrier',
  108.         'Bulk Carrier',
  109.         'Cement Carrier',
  110.         'Deck Cargo Carrier',
  111.         'General Cargo',
  112.         'Gypsum Carrier',
  113.         'Heavy Lift Cargo Vessel',
  114.         'Limestone Carrier',
  115.         'Livestock Carrier',
  116.         'Open Hatch Carrier',
  117.         'Ore & Sulphuric Acid Carrier',
  118.         'Ore Carrier',
  119.         'Ore/Oil Carrier',
  120.         'Salt Carrier',
  121.         'Urea Carrier',
  122.     ];
  123.     public const TANK_COATING = [
  124.         "Epoxy",
  125.         "Zinc",
  126.         "Stainless",
  127.         "Adv. Polymer"
  128.     ];
  129.     
  130.     #[ORM\Id]
  131.     #[ORM\GeneratedValue(strategy'NONE')]
  132.     #[ORM\Column(type'uuid'uniquetrue)]
  133.     #[ApiProperty(iri'https://schema.org/identifier')]
  134.     #[Groups(['vessel:collection:get''vessel:item:get'])]
  135.     private ?UuidInterface $id null;
  136.     #[ORM\Column(type'string'nullablefalse)]
  137.     #[Assert\NotNull]
  138.     #[Assert\Type('string')]
  139.     #[ApiProperty(iri'https://schema.org/vesselName')]
  140.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  141.     private ?string $vesselName null;
  142.     #[ORM\Column(type'string'nullablefalse)]
  143.     #[Assert\NotNull]
  144.     #[Assert\Type('string')]
  145.     #[ApiProperty(iri'https://schema.org/imoNumber')]
  146.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  147.     private ?string $imoNumber null;
  148.     #[ORM\Column(type'string'nullablefalse)]
  149.     #[Assert\NotNull]
  150.     #[Assert\Type('string')]
  151.     #[Assert\Choice(choicesself::VESSEL_TYPESmessage'The type is not valid.')]
  152.     #[ApiProperty(iri'https://schema.org/vesselType')]
  153.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  154.     private ?string $vesselType null;
  155.     #[ORM\Column(type'string'nullabletrue)]
  156.     #[Assert\Type('string')]
  157.     #[Assert\Choice(choicesself::TANKER_TYPESmessage'The type is not valid.')]
  158.     #[ApiProperty(iri'https://schema.org/tankerType')]
  159.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  160.     private ?string $tankerType null;
  161.     #[ORM\Column(type'string'nullabletrue)]
  162.     #[Assert\Type('string')]
  163.     #[Assert\Choice(choicesself::BULKER_TYPESmessage'The type is not valid.')]
  164.     #[ApiProperty(iri'https://schema.org/bulkerType')]
  165.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  166.     private ?string $bulkerType null;
  167.     #[ORM\Column(type'string'nullabletrue)]
  168.     #[ApiProperty(iri'https://schema.org/tankCoating')]
  169.     #[Assert\Type('string')]
  170.     #[Assert\Choice(choicesself::TANK_COATINGmessage'The option is not valid.')]
  171.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  172.     private ?string $tankCoating null;
  173.     #[ORM\Column(type'string'nullablefalse)]
  174.     #[Assert\NotNull]
  175.     #[Assert\Type('string')]
  176.     #[ApiProperty(iri'https://schema.org/dwt')]
  177.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  178.     private ?string $dwt null;
  179.     #[ORM\Column(type'integer'nullablefalse)]
  180.     #[Assert\NotNull]
  181.     #[Assert\Type('integer')]
  182.     #[ApiProperty(iri'https://schema.org/yearBuilt')]
  183.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  184.     private ?int $yearBuilt null;
  185.     // #[ORM\ManyToMany(targetEntity: 'App\Entity\Document')]
  186.     // #[ORM\InverseJoinColumn(unique: true)]
  187.     // #[ApiProperty(iri: 'https://schema.org/Document')]
  188.     // #[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
  189.     // private Collection $documents;
  190.     #[ORM\ManyToOne(targetEntity'App\Entity\Owner'inversedBy'vessels')]
  191.     #[ORM\JoinColumn(nullabletrue)]
  192.     #[ApiProperty(iri'https://schema.org/Owner')]
  193.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  194.     #[MaxDepth(1)]
  195.     private ?Owner $owner null;
  196.     #[ORM\Column(type'text'nullabletrue)]
  197.     #[ApiProperty(iri'https://schema.org/observations')]
  198.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  199.     private ?string $observations null;
  200.     #[ORM\Column(type'boolean'nullabletrue)]
  201.     #[ApiProperty(iri'https://schema.org/BoxShape')]
  202.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  203.     private ?bool $boxShape null;
  204.     #[ORM\Column(type'boolean'nullabletrue)]
  205.     #[ApiProperty(iri'https://schema.org/OpenHatch')]
  206.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  207.     private ?bool $openHatch null;
  208.     #[ORM\Column(type'boolean'nullabletrue)]
  209.     #[ApiProperty(iri'https://schema.org/NitrogenGenerator')]
  210.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  211.     private ?bool $nitrogenGenerator null;
  212.     #[ORM\Column(type'integer'nullabletrue)]
  213.     #[ApiProperty(iri'https://schema.org/imoClass')]
  214.     #[Assert\Type('integer')]
  215.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  216.     private ?int $imoClass null;
  217.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'vessel')]
  218.     #[ApiProperty(iri'https://schema.org/Contract')]
  219.     #[Groups(['vessel:collection:get''vessel:collection:post''vessel:item:get''vessel:item:put'])]
  220.     #[MaxDepth(1)]
  221.     private ?Collection $contracts null;
  222.     // #[ORM\OneToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'vessel')]
  223.     // #[ApiProperty(iri: 'https://schema.org/Lifting')]
  224.     // #[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
  225.     // #[MaxDepth(1)]
  226.     // private ?Collection $liftings = null;
  227.     public function __construct()
  228.     {
  229.         $this->id Uuid::uuid4();
  230.         // $this->documents = new ArrayCollection();
  231.         $this->contracts = new ArrayCollection();
  232.         // $this->liftings = new ArrayCollection();
  233.     }
  234.     public function getId(): ?UuidInterface
  235.     {
  236.         return $this->id;
  237.     }
  238.     public function setVesselName(?string $vesselName): void
  239.     {
  240.         $this->vesselName $vesselName;
  241.     }
  242.     public function getVesselName(): ?string
  243.     {
  244.         return $this->vesselName;
  245.     }
  246.     public function setImoNumber(?string $imoNumber): void
  247.     {
  248.         $this->imoNumber $imoNumber;
  249.     }
  250.     public function getImoNumber(): ?string
  251.     {
  252.         return $this->imoNumber;
  253.     }
  254.     public function setVesselType(?string $vesselType): void
  255.     {
  256.         $this->vesselType $vesselType;
  257.     }
  258.     public function getVesselType(): ?string
  259.     {
  260.         return $this->vesselType;
  261.     }
  262.     public function setDwt(?string $dwt): void
  263.     {
  264.         $this->dwt $dwt;
  265.     }
  266.     public function getDwt(): ?string
  267.     {
  268.         return $this->dwt;
  269.     }
  270.     public function setYearBuilt(?int $yearBuilt): void
  271.     {
  272.         $this->yearBuilt $yearBuilt;
  273.     }
  274.     public function getYearBuilt(): ?int
  275.     {
  276.         return $this->yearBuilt;
  277.     }
  278.     public function setTankerType(?string $tankerType): void
  279.     {
  280.         $this->tankerType $tankerType;
  281.     }
  282.     public function getTankerType(): ?string
  283.     {
  284.         return $this->tankerType;
  285.     }
  286.     public function setBulkerType(?string $bulkerType): void
  287.     {
  288.         $this->bulkerType $bulkerType;
  289.     }
  290.     public function getBulkerType(): ?string
  291.     {
  292.         return $this->bulkerType;
  293.     }
  294.     // public function addDocument(Document $document): void
  295.     // {
  296.     //     $this->documents[] = $document;
  297.     // }
  298.     // public function removeDocument(Document $document): void
  299.     // {
  300.     //     $this->documents->removeElement($document);
  301.     // }
  302.     // public function getDocuments(): Collection
  303.     // {
  304.     //     return $this->documents;
  305.     // }
  306.     public function setOwner(?Owner $owner): void
  307.     {
  308.         $this->owner $owner;
  309.     }
  310.     public function getOwner(): ?Owner
  311.     {
  312.         return $this->owner;
  313.     }
  314.     public function setObservations(?string $observations): void
  315.     {
  316.         $this->observations $observations;
  317.     }
  318.     public function getObservations(): ?string
  319.     {
  320.         return $this->observations;
  321.     }
  322.     public function setBoxShape(?bool $boxShape): void
  323.     {
  324.         $this->boxShape $boxShape;
  325.     }
  326.     public function getBoxShape(): ?bool
  327.     {
  328.         return $this->boxShape;
  329.     }
  330.     public function setOpenHatch(?bool $openHatch): void
  331.     {
  332.         $this->openHatch $openHatch;
  333.     }
  334.     public function getOpenHatch(): ?bool
  335.     {
  336.         return $this->openHatch;
  337.     }
  338.     public function setNitrogenGenerator(?bool $nitrogenGenerator): void
  339.     {
  340.         $this->nitrogenGenerator $nitrogenGenerator;
  341.     }
  342.     public function getNitrogenGenerator(): ?bool
  343.     {
  344.         return $this->nitrogenGenerator;
  345.     }
  346.     public function setImoClass(?int $imoClass): void
  347.     {
  348.         $this->imoClass $imoClass;
  349.     }
  350.     public function getImoClass(): ?int
  351.     {
  352.         return $this->imoClass;
  353.     }
  354.     public function setTankCoating(?string $tankCoating): void
  355.     {
  356.         $this->tankCoating $tankCoating;
  357.     }
  358.     public function getTankCoating(): ?string
  359.     {
  360.         return $this->tankCoating;
  361.     }
  362.     public function getContracts(): Collection
  363.     {
  364.         return $this->contracts;
  365.     }
  366.     public function addContract(Contract $contract): self
  367.     {
  368.         if (!$this->contracts->contains($contract)) {
  369.             $this->contracts[] = $contract;
  370.             $contract->setVessel($this);
  371.         }
  372.         return $this;
  373.     }
  374.     public function removeContract(Contract $contract): self
  375.     {
  376.         if ($this->contracts->removeElement($contract)) {
  377.             if ($contract->getVessel() === $this) {
  378.                 $contract->setVessel(null);
  379.             }
  380.         }
  381.         
  382.         return $this;
  383.     }
  384.     // public function getLiftings(): Collection
  385.     // {
  386.     //     return $this->liftings;
  387.     // }
  388.     // public function addLifting(Lifting $lifting): self
  389.     // {
  390.     //     if (!$this->liftings->contains($lifting)) {
  391.     //         $this->liftings[] = $lifting;
  392.     //         $lifting->setVessel($this);
  393.     //     }
  394.     //     return $this;
  395.     // }
  396.     // public function removeLifting(Lifting $lifting): self
  397.     // {
  398.     //     if ($this->liftings->removeElement($lifting)) {
  399.     //         if ($lifting->getVessel() === $this) {
  400.     //             $lifting->setVessel(null);
  401.     //         }
  402.     //     }
  403.         
  404.     //     return $this;
  405.     // }
  406. }