src/Entity/ReportedIncident.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'ReportedIncident',
  21.     itemOperations: [
  22.         'get' => ['normalization_context' => ['groups' => 'reported_incident:item:get''enable_max_depth' => true]],
  23.         'put' => [
  24.             'normalization_context' => ['groups' => 'reported_incident:item:put''enable_max_depth' => true],
  25.             'denormalization_context' => ['groups' => 'reported_incident:item:put''enable_max_depth' => true],
  26.         ],
  27.         'delete' => [],
  28.     ],
  29.     collectionOperations: [
  30.         'get' => [
  31.             'normalization_context' => [
  32.                 'groups' => ['reported_incident:collection:get''createdAt'],
  33.                 'enable_max_depth' => true,
  34.             ],
  35.         ],
  36.         'post' => [
  37.             'normalization_context' => ['groups' => 'reported_incident:collection:post''enable_max_depth' => true],
  38.             'denormalization_context' => ['groups' => 'reported_incident:collection:post''enable_max_depth' => true],
  39.         ],
  40.     ],
  41. )]
  42. class ReportedIncident
  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/category')]
  56.     #[Assert\NotBlank]
  57.     #[Assert\Type('string')]
  58.     // #[Assert\Choice(choices: self::PORT_CALL_TYPES, message: 'The type is not valid.')]
  59.     #[Groups(['reported_incident:item:get''reported_incident:item:put''reported_incident:collection:get''reported_incident:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  60.     private ?string $category null;
  61.     #[ORM\Column(type'string'nullablefalse)]
  62.     #[ApiProperty(iri'https://schema.org/subcategory')]
  63.     #[Assert\NotBlank]
  64.     #[Assert\Type('string')]
  65.     // #[Assert\Choice(choices: self::PORT_CALL_TYPES, message: 'The type is not valid.')]
  66.     #[Groups(['reported_incident:item:get''reported_incident:item:put''reported_incident:collection:get''reported_incident:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  67.     private ?string $subcategory null;
  68.     #[ORM\ManyToOne(targetEntity'App\Entity\Contract'inversedBy'reportedIncidents')]
  69.     #[ORM\JoinColumn(nullabletrue)]
  70.     #[ApiProperty(iri'https://schema.org/Contract')]
  71.     #[Groups(['reported_incident:collection:get''reported_incident:collection:post''reported_incident:item:get''reported_incident:item:put'])]
  72.     #[MaxDepth(1)]
  73.     private ?Contract $contract null;
  74.     public function __construct()
  75.     {
  76.         $this->id Uuid::uuid4();
  77.     }
  78.     public function getId(): ?UuidInterface
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function setCategory(?string $category): void
  83.     {
  84.         $this->category $category;
  85.     }
  86.     public function getCategory(): ?string
  87.     {
  88.         return $this->category;
  89.     }
  90.     public function setSubcategory(?string $subcategory): void
  91.     {
  92.         $this->subcategory $subcategory;
  93.     }
  94.     public function getSubcategory(): ?string
  95.     {
  96.         return $this->subcategory;
  97.     }
  98.     public function setContract(?Contract $contract): void
  99.     {
  100.         $this->contract $contract;
  101.     }
  102.     public function getContract(): ?Contract
  103.     {
  104.         return $this->contract;
  105.     }
  106. }