src/Entity/Vessel.php line 144

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 Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Serializer\Annotation\MaxDepth;
  18. use Ramsey\Uuid\Uuid;
  19. use Ramsey\Uuid\UuidInterface;
  20. #[ORM\Entity]
  21. #[ApiResource(
  22.     iri'Vessel',
  23.     itemOperations: [
  24.         'get' => [
  25.             'security' => "
  26.                 is_granted('ROLE_ADMIN') or 
  27.                 is_granted('ROLE_OPERATOR') or
  28.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  29.                 is_granted('ROLE_RESEARCH_ANALYST') or
  30.                 is_granted('ROLE_BROKER') or 
  31.                 is_granted('ROLE_INTERN')
  32.             ",
  33.             'normalization_context' => [
  34.                 'groups' => 'vessel:item:get'
  35.                 'enable_max_depth' => true
  36.             ]
  37.         ],
  38.         'put' => [
  39.             'security' => "
  40.                 is_granted('ROLE_ADMIN') or 
  41.                 is_granted('ROLE_OPERATOR') or
  42.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  43.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  44.                 is_granted('ROLE_BROKER')
  45.             ",
  46.             'normalization_context' => [
  47.                 'groups' => 'vessel:item:put'
  48.                 'enable_max_depth' => true
  49.             ],
  50.             'denormalization_context' => [
  51.                 'groups' => 'vessel:item:put'
  52.                 'enable_max_depth' => true
  53.             ],
  54.         ],
  55.         'delete' => [
  56.             'security' => "
  57.                 is_granted('ROLE_ADMIN') or 
  58.                 is_granted('ROLE_OPERATOR') or
  59.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  60.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  61.                 is_granted('ROLE_BROKER')
  62.             ",
  63.         ],
  64.     ],
  65.     collectionOperations: [
  66.         'get' => [
  67.             'security' => "
  68.                 is_granted('ROLE_ADMIN') or 
  69.                 is_granted('ROLE_OPERATOR') or
  70.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  71.                 is_granted('ROLE_RESEARCH_ANALYST') or
  72.                 is_granted('ROLE_BROKER') or 
  73.                 is_granted('ROLE_INTERN')
  74.             ",
  75.             'normalization_context' => [
  76.                 'groups' => [
  77.                     'vessel:collection:get'
  78.                     'createdAt'
  79.                 ], 
  80.                 'enable_max_depth' => true
  81.             ],
  82.         ],
  83.         'post' => [
  84.             'security' => "
  85.                 is_granted('ROLE_ADMIN') or 
  86.                 is_granted('ROLE_OPERATOR') or
  87.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  88.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  89.                 is_granted('ROLE_BROKER')
  90.             ",
  91.             'normalization_context' => [
  92.                 'groups' => 'vessel:collection:post'
  93.                 'enable_max_depth' => true
  94.             ],
  95.             'denormalization_context' => [
  96.                 'groups' => 'vessel:collection:post'
  97.                 'enable_max_depth' => true
  98.             ],
  99.         ],
  100.     ],
  101. )]
  102. #[ApiFilter(
  103.     SearchFilter::class,
  104.     properties: [
  105.         'vesselName' => 'partial'
  106.         'imoNumber' => 'partial'
  107.         'vesselType' => 'exact',
  108.         'dwt' => 'partial',
  109.         'yearBuilt' => 'exact',
  110.         'imoClass' => 'partial',
  111.         'tankCoating' => 'exact',
  112.         'createdAt' => 'start'
  113.     ],
  114. )]
  115. #[ApiFilter(
  116.     OrderFilter::class,
  117.     properties: [
  118.         'vesselName'
  119.         'imoNumber'
  120.         'vesselType',
  121.         'dwt',
  122.         'yearBuilt',
  123.         'imoClass',
  124.         'nitrogenGenerator',
  125.         'boxShape',
  126.         'openHatch',
  127.         'tankCoating',
  128.         'createdAt'
  129.     ],
  130. )]
  131. #[ApiFilter(
  132.     BooleanFilter::class,
  133.     properties: [
  134.         'nitrogenGenerator',
  135.         'boxShape',
  136.         'openHatch',
  137.     ],
  138. )]
  139. #[ApiFilter(PropertyFilter::class)]
  140. class Vessel
  141. {
  142.     use TimestampableEntity;
  143.     public const VESSEL_TYPE_TANKER 'Tanker';
  144.     public const VESSEL_TYPE_BULKER 'Bulker';
  145.     public const VESSEL_TYPES = [
  146.         self::VESSEL_TYPE_TANKER,
  147.         self::VESSEL_TYPE_BULKER,
  148.     ];
  149.     public const TANKER_TYPE_CHEMICAL 'Chemical & Oil Carrier';
  150.     public const TANKER_TYPE_PRODUCT 'Product Carrier';
  151.     public const TANKER_TYPE_CHEMICAL_BULK 'Chemical Bulk Tanker';
  152.     public const TANKER_TYPE_CHEMICAL_PARCEL 'Chemical Parcell Tanker';
  153.     public const TANKER_TYPE_ASPHALT_BITUMEN 'Asphalt & Bitumen Carrier';
  154.     public const TANKER_TYPE_METHANOL 'Methanol Carrier';
  155.     public const TANKER_TYPE_CHEMICAL_UNKNOWN 'Chemical Unknown Carrier';
  156.     public const TANKER_TYPE_TANKER 'Tanker';
  157.     public const TANKER_TYPE_SHUTTLE 'Shuttle Tanker';
  158.     public const TANKER_TYPE_OIL_BUNKERING 'Oil Bunkering Tanker';
  159.     public const TANKER_TYPE_PRODUCTS_MULTI_PURPOSE 'Products/Multi-Purpose';
  160.     public const TANKER_TYPE_CARGO 'Cargo';
  161.     public const TANKER_TYPES = [
  162.         self::TANKER_TYPE_CHEMICAL,
  163.         self::TANKER_TYPE_PRODUCT,
  164.         self::TANKER_TYPE_CHEMICAL_BULK,
  165.         self::TANKER_TYPE_CHEMICAL_PARCEL,
  166.         self::TANKER_TYPE_ASPHALT_BITUMEN,
  167.         self::TANKER_TYPE_METHANOL,
  168.         self::TANKER_TYPE_CHEMICAL_UNKNOWN,
  169.         self::TANKER_TYPE_TANKER,
  170.         self::TANKER_TYPE_SHUTTLE,
  171.         self::TANKER_TYPE_OIL_BUNKERING,
  172.         self::TANKER_TYPE_PRODUCTS_MULTI_PURPOSE,
  173.         self::TANKER_TYPE_CARGO,
  174.     ];
  175.     public const BULKER_TYPE_AGGREGATES 'Aggregates Carrier';
  176.     public const BULKER_TYPE_BULK 'Bulk Carrier';
  177.     public const BULKER_TYPE_CEMENT 'Cement Carrier';
  178.     public const BULKER_TYPE_DECK 'Deck Cargo Carrier';
  179.     public const BULKER_TYPE_GENERAL 'General Cargo';
  180.     public const BULKER_TYPE_GYPSUM 'Gypsum Carrier';
  181.     public const BULKER_TYPE_HEAVY_LIFT 'Heavy Lift Cargo Vessel';
  182.     public const BULKER_TYPE_LIMESTONE 'Limestone Carrier';
  183.     public const BULKER_TYPE_LIVESTOCK 'Livestock Carrier';
  184.     public const BULKER_TYPE_OPEN_HATCH 'Open Hatch Carrier';
  185.     public const BULKER_TYPE_ORE_SULPHURIC_ACID 'Ore & Sulphuric Acid Carrier';
  186.     public const BULKER_TYPE_ORE 'Ore Carrier';
  187.     public const BULKER_TYPE_ORE_OIL 'Ore/Oil Carrier';
  188.     public const BULKER_TYPE_SALT 'Salt Carrier';
  189.     public const BULKER_TYPE_UREA 'Urea Carrier';
  190.     public const BULKER_TYPES = [
  191.         self::BULKER_TYPE_AGGREGATES,
  192.         self::BULKER_TYPE_BULK,
  193.         self::BULKER_TYPE_CEMENT,
  194.         self::BULKER_TYPE_DECK,
  195.         self::BULKER_TYPE_GENERAL,
  196.         self::BULKER_TYPE_GYPSUM,
  197.         self::BULKER_TYPE_HEAVY_LIFT,
  198.         self::BULKER_TYPE_LIMESTONE,
  199.         self::BULKER_TYPE_LIVESTOCK,
  200.         self::BULKER_TYPE_OPEN_HATCH,
  201.         self::BULKER_TYPE_ORE_SULPHURIC_ACID,
  202.         self::BULKER_TYPE_ORE,
  203.         self::BULKER_TYPE_ORE_OIL,
  204.         self::BULKER_TYPE_SALT,
  205.         self::BULKER_TYPE_UREA,
  206.     ];
  207.     public const TANK_COATING_EPOXY 'Epoxy';
  208.     public const TANK_COATING_ZINC 'Zinc';
  209.     public const TANK_COATING_STAINLESS 'Stainless';
  210.     public const TANK_COATING_ADV_POLYMER 'Adv. Polymer';
  211.     public const TANK_COATING = [
  212.         self::TANK_COATING_EPOXY,
  213.         self::TANK_COATING_ZINC,
  214.         self::TANK_COATING_STAINLESS,
  215.         self::TANK_COATING_ADV_POLYMER,
  216.     ];
  217.     
  218.     #[ORM\Id]
  219.     #[ORM\GeneratedValue(strategy'NONE')]
  220.     #[ORM\Column(type'uuid'uniquetrue)]
  221.     private ?UuidInterface $id null;
  222.     #[ORM\Column(type'string'nullablefalse)]
  223.     #[Assert\NotNull]
  224.     #[Assert\Type('string')]
  225.     #[ApiProperty()]
  226.     #[Groups([
  227.         'vessel:collection:get'
  228.         'vessel:collection:post'
  229.         'vessel:item:get'
  230.         'vessel:item:put'
  231.         'contract:item:get'
  232.         'contract:item:put'
  233.         'contract:collection:get'
  234.         'contract:collection:post',
  235.         'market_rumor:item:get'
  236.         'market_rumor:item:put'
  237.         'market_rumor:collection:get'
  238.         'market_rumor:collection:post'
  239.     ])]
  240.     private ?string $vesselName null;
  241.     #[ORM\Column(type'string'nullabletrue)]
  242.     ##[Assert\NotNull]
  243.     ##[Assert\Type('string')]
  244.     #[ApiProperty()]
  245.     #[Groups([
  246.         'vessel:collection:get'
  247.         'vessel:collection:post'
  248.         'vessel:item:get'
  249.         'vessel:item:put'
  250.     ])]
  251.     private ?string $imoNumber null;
  252.     #[ORM\Column(type'string'nullablefalse)]
  253.     #[Assert\NotNull]
  254.     #[Assert\Type('string')]
  255.     #[Assert\Choice(
  256.         choicesself::VESSEL_TYPES
  257.         message'The type is not valid.'
  258.     )]
  259.     #[ApiProperty()]
  260.     #[Groups([
  261.         'vessel:collection:get'
  262.         'vessel:collection:post'
  263.         'vessel:item:get'
  264.         'vessel:item:put'
  265.     ])]
  266.     private ?string $vesselType null;
  267.     #[ORM\Column(type'string'nullabletrue)]
  268.     ##[Assert\Type('string')]
  269.     #[Assert\Choice(
  270.         choicesself::TANKER_TYPES
  271.         message'The type is not valid.'
  272.     )]
  273.     #[ApiProperty()]
  274.     #[Groups([
  275.         // 'vessel:collection:get', 
  276.         'vessel:collection:post'
  277.         'vessel:item:get'
  278.         'vessel:item:put'
  279.     ])]
  280.     private ?string $tankerType null;
  281.     #[ORM\Column(type'string'nullabletrue)]
  282.     ##[Assert\Type('string')]
  283.     #[Assert\Choice(
  284.         choicesself::BULKER_TYPES
  285.         message'The type is not valid.'
  286.     )]
  287.     #[ApiProperty()]
  288.     #[Groups([
  289.         // 'vessel:collection:get', 
  290.         'vessel:collection:post'
  291.         'vessel:item:get'
  292.         'vessel:item:put'
  293.     ])]
  294.     private ?string $bulkerType null;
  295.     #[ORM\Column(type'string'nullabletrue)]
  296.     #[ApiProperty()]
  297.     ##[Assert\Type('string')]
  298.     #[Assert\Choice(
  299.         choicesself::TANK_COATING
  300.         message'The option is not valid.'
  301.     )]
  302.     #[Groups([
  303.         'vessel:collection:get'
  304.         'vessel:collection:post'
  305.         'vessel:item:get'
  306.         'vessel:item:put'
  307.     ])]
  308.     private ?string $tankCoating null;
  309.     #[ORM\Column(type'string'nullabletrue)]
  310.     ##[Assert\NotNull]
  311.     ##[Assert\Type('string')]
  312.     #[ApiProperty()]
  313.     #[Groups([
  314.         'vessel:collection:get'
  315.         'vessel:collection:post'
  316.         'vessel:item:get'
  317.         'vessel:item:put'
  318.     ])]
  319.     private ?string $dwt null;
  320.     #[ORM\Column(type'integer'nullabletrue)]
  321.     ##[Assert\NotNull]
  322.     ##[Assert\Type('integer')]
  323.     #[ApiProperty()]
  324.     #[Groups([
  325.         'vessel:collection:get'
  326.         'vessel:collection:post'
  327.         'vessel:item:get'
  328.         'vessel:item:put'
  329.     ])]
  330.     private ?int $yearBuilt null;
  331.     #[ORM\ManyToOne(
  332.         targetEntityOwner::class, 
  333.         inversedBy'vessels'
  334.     )]
  335.     #[ORM\JoinColumn(nullabletrue)]
  336.     #[ApiProperty()]
  337.     #[Groups([
  338.         // 'vessel:collection:get', 
  339.         'vessel:collection:post'
  340.         'vessel:item:get'
  341.         'vessel:item:put'
  342.     ])]
  343.     #[MaxDepth(1)]
  344.     private ?Owner $owner null;
  345.     #[ORM\Column(type'text'nullabletrue)]
  346.     #[ApiProperty()]
  347.     #[Groups([
  348.         // 'vessel:collection:get', 
  349.         'vessel:collection:post'
  350.         'vessel:item:get'
  351.         'vessel:item:put'
  352.     ])]
  353.     private ?string $observations null;
  354.     #[ORM\Column(type'boolean'nullabletrue)]
  355.     #[ApiProperty()]
  356.     #[Groups([
  357.         'vessel:collection:get'
  358.         'vessel:collection:post'
  359.         'vessel:item:get'
  360.         'vessel:item:put'
  361.     ])]
  362.     private ?bool $boxShape false;
  363.     #[ORM\Column(type'boolean'nullabletrue)]
  364.     #[ApiProperty()]
  365.     #[Groups([
  366.         'vessel:collection:get'
  367.         'vessel:collection:post'
  368.         'vessel:item:get'
  369.         'vessel:item:put'
  370.     ])]
  371.     private ?bool $openHatch false;
  372.     #[ORM\Column(type'boolean'nullabletrue)]
  373.     #[ApiProperty()]
  374.     #[Groups([
  375.         'vessel:collection:get'
  376.         'vessel:collection:post'
  377.         'vessel:item:get'
  378.         'vessel:item:put'
  379.     ])]
  380.     private ?bool $nitrogenGenerator false;
  381.     #[ORM\Column(type'integer'nullabletrue)]
  382.     #[ApiProperty()]
  383.     ##[Assert\Type('integer')]
  384.     #[Groups([
  385.         'vessel:collection:get'
  386.         'vessel:collection:post'
  387.         'vessel:item:get'
  388.         'vessel:item:put'
  389.     ])]
  390.     private ?int $imoClass null;
  391.     #[ORM\OneToMany(
  392.         targetEntityContract::class, 
  393.         mappedBy'vessel'
  394.     )]
  395.     private ?Collection $contracts null;
  396.     #[ORM\OneToMany(
  397.         targetEntityMarketRumor::class, 
  398.         mappedBy'vessel'
  399.     )]
  400.     private ?Collection $marketRumors null;
  401.     public function __construct()
  402.     {
  403.         $this->id Uuid::uuid4();
  404.         $this->contracts = new ArrayCollection();
  405.         $this->marketRumors = new ArrayCollection();
  406.     }
  407.     public function getId(): ?UuidInterface
  408.     {
  409.         return $this->id;
  410.     }
  411.     public function setVesselName(?string $vesselName): void
  412.     {
  413.         $this->vesselName $vesselName;
  414.     }
  415.     public function getVesselName(): ?string
  416.     {
  417.         return $this->vesselName;
  418.     }
  419.     public function setImoNumber(?string $imoNumber): void
  420.     {
  421.         $this->imoNumber $imoNumber;
  422.     }
  423.     public function getImoNumber(): ?string
  424.     {
  425.         return $this->imoNumber;
  426.     }
  427.     public function setVesselType(?string $vesselType): void
  428.     {
  429.         $this->vesselType $vesselType;
  430.     }
  431.     public function getVesselType(): ?string
  432.     {
  433.         return $this->vesselType;
  434.     }
  435.     public function setDwt(?string $dwt): void
  436.     {
  437.         $this->dwt $dwt;
  438.     }
  439.     public function getDwt(): ?string
  440.     {
  441.         return $this->dwt;
  442.     }
  443.     public function setYearBuilt(?int $yearBuilt): void
  444.     {
  445.         $this->yearBuilt $yearBuilt;
  446.     }
  447.     public function getYearBuilt(): ?int
  448.     {
  449.         return $this->yearBuilt;
  450.     }
  451.     public function setTankerType(?string $tankerType): void
  452.     {
  453.         $this->tankerType $tankerType;
  454.     }
  455.     public function getTankerType(): ?string
  456.     {
  457.         return $this->tankerType;
  458.     }
  459.     public function setBulkerType(?string $bulkerType): void
  460.     {
  461.         $this->bulkerType $bulkerType;
  462.     }
  463.     public function getBulkerType(): ?string
  464.     {
  465.         return $this->bulkerType;
  466.     }
  467.     public function setOwner(?Owner $owner): void
  468.     {
  469.         $this->owner $owner;
  470.     }
  471.     public function getOwner(): ?Owner
  472.     {
  473.         return $this->owner;
  474.     }
  475.     public function setObservations(?string $observations): void
  476.     {
  477.         $this->observations $observations;
  478.     }
  479.     public function getObservations(): ?string
  480.     {
  481.         return $this->observations;
  482.     }
  483.     public function setBoxShape(?bool $boxShape): void
  484.     {
  485.         $this->boxShape $boxShape;
  486.     }
  487.     public function getBoxShape(): ?bool
  488.     {
  489.         return $this->boxShape ?? false;
  490.     }
  491.     public function setOpenHatch(?bool $openHatch): void
  492.     {
  493.         $this->openHatch $openHatch;
  494.     }
  495.     public function getOpenHatch(): ?bool
  496.     {
  497.         return $this->openHatch ?? false;
  498.     }
  499.     public function setNitrogenGenerator(?bool $nitrogenGenerator): void
  500.     {
  501.         $this->nitrogenGenerator $nitrogenGenerator;
  502.     }
  503.     public function getNitrogenGenerator(): ?bool
  504.     {
  505.         return $this->nitrogenGenerator ?? false;
  506.     }
  507.     public function setImoClass(?int $imoClass): void
  508.     {
  509.         $this->imoClass $imoClass;
  510.     }
  511.     public function getImoClass(): ?int
  512.     {
  513.         return $this->imoClass;
  514.     }
  515.     public function setTankCoating(?string $tankCoating): void
  516.     {
  517.         $this->tankCoating $tankCoating;
  518.     }
  519.     public function getTankCoating(): ?string
  520.     {
  521.         return $this->tankCoating;
  522.     }
  523.     public function getContracts(): Collection
  524.     {
  525.         return $this->contracts;
  526.     }
  527.     public function addContract(Contract $contract): self
  528.     {
  529.         if (!$this->contracts->contains($contract)) {
  530.             $this->contracts[] = $contract;
  531.             $contract->setVessel($this);
  532.         }
  533.         return $this;
  534.     }
  535.     public function removeContract(Contract $contract): self
  536.     {
  537.         if ($this->contracts->removeElement($contract)) {
  538.             if ($contract->getVessel() === $this) {
  539.                 $contract->setVessel(null);
  540.             }
  541.         }
  542.         
  543.         return $this;
  544.     }
  545.     public function getMarketRumors(): Collection
  546.     {
  547.         return $this->marketRumors;
  548.     }
  549.     public function addMarketRumor(MarketRumor $marketRumor): self
  550.     {
  551.         if (!$this->marketRumors->contains($marketRumor)) {
  552.             $this->marketRumors[] = $marketRumor;
  553.             $marketRumor->setVessel($this);
  554.         }
  555.         return $this;
  556.     }
  557.     public function removeMarketRumor(MarketRumor $marketRumor): self
  558.     {
  559.         if ($this->marketRumors->removeElement($marketRumor)) {
  560.             if ($marketRumor->getVessel() === $this) {
  561.                 $marketRumor->setVessel(null);
  562.             }
  563.         }
  564.         
  565.         return $this;
  566.     }
  567. }