src/Entity/Berth.php line 56

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 App\Trait\TimestampableEntity;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Serializer\Annotation\MaxDepth;
  16. use Ramsey\Uuid\Uuid;
  17. use Ramsey\Uuid\UuidInterface;
  18. /**
  19.  * @see https://schema.org/Thing
  20.  *
  21.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  22.  */
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     iri'Berth',
  26.     itemOperations: [
  27.         'get' => ['normalization_context' => ['groups' => 'berth:item:get''enable_max_depth' => true]],
  28.         'put' => [
  29.             'normalization_context' => ['groups' => 'berth:item:put''enable_max_depth' => true],
  30.             'denormalization_context' => ['groups' => 'berth:item:put''enable_max_depth' => true],
  31.         ],
  32.         'delete' => [],
  33.     ],
  34.     collectionOperations: [
  35.         'get' => [
  36.             'normalization_context' => ['groups' => ['berth:collection:get''createdAt'], 'enable_max_depth' => true],
  37.         ],
  38.         'post' => [
  39.             'normalization_context' => ['groups' => 'berth:collection:post''enable_max_depth' => true],
  40.             'denormalization_context' => ['groups' => 'berth:collection:post''enable_max_depth' => true],
  41.         ],
  42.     ],
  43. )]
  44. #[ApiFilter(
  45.     SearchFilter::class,
  46.     properties: ['port' => 'exact''berthName' => 'partial''createdAt' => 'start'],
  47. )]
  48. #[ApiFilter(
  49.     OrderFilter::class,
  50.     properties: ['berthName''createdAt'],
  51. )]
  52. class Berth
  53. {
  54.     use TimestampableEntity;
  55.     
  56.     #[ORM\Id]
  57.     #[ORM\GeneratedValue(strategy'NONE')]
  58.     #[ORM\Column(type'uuid'uniquetrue)]
  59.     private ?UuidInterface $id null;
  60.     #[ORM\Column(type'string'nullablefalse)]
  61.     #[ApiProperty(iri'https://schema.org/name')]
  62.     #[Assert\NotBlank]
  63.     #[Groups(['berth:collection:get''berth:collection:post''berth:item:get''berth:item:put''port:item:get'])]
  64.     private ?string $berthName null;
  65.     // @deprecated
  66.     // #[ORM\ManyToMany(targetEntity: 'App\Entity\CargoType')]
  67.     // #[ApiProperty(iri: 'https://schema.org/CargoType')]
  68.     // #[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put'])]
  69.     // private Collection $cargoType;
  70.     #[ORM\ManyToMany(targetEntity'App\Entity\DockingRestriction')]
  71.     #[ApiProperty(iri'https://schema.org/DockeringRestriction')]
  72.     #[Groups(['berth:collection:get''berth:collection:post''berth:item:get''berth:item:put'])]
  73.     private Collection $dockingRestrictions;
  74.     #[ORM\Column(type'string'nullablefalse)]
  75.     #[ApiProperty(iri'https://schema.org/restrictionInfoSource')]
  76.     #[Assert\NotBlank]
  77.     #[Groups(['berth:collection:get''berth:collection:post''berth:item:get''berth:item:put'])]
  78.     private ?string $restrictionInfoSource null;
  79.     #[ORM\Column(type'text'nullabletrue)]
  80.     #[ApiProperty(iri'https://schema.org/observations')]
  81.     #[Groups(['berth:collection:get''berth:collection:post''berth:item:get''berth:item:put'])]
  82.     private ?string $observations null;
  83.     #[ORM\ManyToOne(targetEntity'App\Entity\Port'inversedBy'berths')]
  84.     #[ORM\JoinColumn(nullabletrue)]
  85.     #[ApiProperty(iri'https://schema.org/Port')]
  86.     #[Groups(['berth:item:get''berth:item:put''berth:collection:get''berth:collection:post'])]
  87.     #[MaxDepth(1)]
  88.     private ?Port $port null;
  89.     public function __construct()
  90.     {
  91.         $this->id Uuid::uuid4();
  92.         // $this->cargoType = new ArrayCollection();
  93.         $this->dockingRestrictions = new ArrayCollection();
  94.     }
  95.     public function getId(): ?UuidInterface
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function setBerthName(?string $berthName): void
  100.     {
  101.         $this->berthName $berthName;
  102.     }
  103.     public function getBerthName(): ?string
  104.     {
  105.         return $this->berthName;
  106.     }
  107.     // public function addCargoType(CargoType $cargoType): void
  108.     // {
  109.     //     if (!$this->cargoType->contains($cargoType)) {
  110.     //         $this->cargoType[] = $cargoType;
  111.     //     }
  112.     // }
  113.     // public function removeCargoType(CargoType $cargoType): void
  114.     // {
  115.     //     $this->cargoType->removeElement($cargoType);
  116.     // }
  117.     // public function getCargoType(): Collection
  118.     // {
  119.     //     return $this->cargoType;
  120.     // }
  121.     public function addDockingRestriction(DockingRestriction $dockingRestriction): void
  122.     {
  123.         if (!$this->dockingRestrictions->contains($dockingRestriction)) {
  124.             $this->dockingRestrictions[] = $dockingRestriction;
  125.         }
  126.     }
  127.     public function removeDockingRestriction(DockingRestriction $dockingRestriction): void
  128.     {
  129.         $this->dockingRestrictions->removeElement($dockingRestriction);
  130.     }
  131.     public function getDockingRestrictions(): Collection
  132.     {
  133.         return $this->dockingRestrictions;
  134.     }
  135.     public function setRestrictionInfoSource(?string $restrictionInfoSource): void
  136.     {
  137.         $this->restrictionInfoSource $restrictionInfoSource;
  138.     }
  139.     public function getRestrictionInfoSource(): ?string
  140.     {
  141.         return $this->restrictionInfoSource;
  142.     }
  143.     public function setObservations(?string $observations): void
  144.     {
  145.         $this->observations $observations;
  146.     }
  147.     public function getObservations(): ?string
  148.     {
  149.         return $this->observations;
  150.     }
  151.     public function setPort(?Port $port): void
  152.     {
  153.         $this->port $port;
  154.     }
  155.     public function getPort(): ?Port
  156.     {
  157.         return $this->port;
  158.     }
  159. }