src/Entity/IncidentSubcategory.php line 44

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 Symfony\Component\Serializer\Annotation\Groups;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Ramsey\Uuid\Uuid;
  11. use Ramsey\Uuid\UuidInterface;
  12. /**
  13.  * The most generic type of item.
  14.  *
  15.  * @see https://schema.org/Thing
  16.  *
  17.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  18.  */
  19. #[ORM\Entity]
  20. #[ApiResource(
  21.     iri'IncidentSubcategory',
  22.     itemOperations: [
  23.         'get' => ['normalization_context' => ['groups' => 'incident_subcategory:item:get']],
  24.         'put' => [
  25.             'normalization_context' => ['groups' => 'incident_subcategory:item:put'],
  26.             'denormalization_context' => ['groups' => 'incident_subcategory:item:put'],
  27.         ],
  28.         'delete' => [],
  29.     ],
  30.     collectionOperations: [
  31.         'get' => [
  32.             'normalization_context' => ['groups' => 'incident_subcategory:collection:get'],
  33.         ],
  34.         'post' => [
  35.             'normalization_context' => ['groups' => 'incident_subcategory:collection:post'],
  36.             'denormalization_context' => ['groups' => 'incident_subcategory:collection:post'],
  37.         ],
  38.     ],
  39. )]
  40. class IncidentSubcategory
  41. {
  42.     use TimestampableEntity;
  43.     
  44.     #[ORM\Id]
  45.     #[ORM\GeneratedValue(strategy'NONE')]
  46.     #[ORM\Column(type'uuid'uniquetrue)]
  47.     #[ApiProperty(iri'https://schema.org/identifier')]
  48.     #[Groups(['incident_subcategory:item:get''incident_subcategory:collection:get'])]
  49.     private ?UuidInterface $id null;
  50.     /**
  51.      * @var string|null the name of the item
  52.      *
  53.      * @see https://schema.org/name
  54.      */
  55.     #[ORM\Column(type'string'nullablefalse)]
  56.     #[ApiProperty(iri'https://schema.org/name')]
  57.     #[Groups(['incident_subcategory:item:get''incident_subcategory:collection:get''incident_subcategory:collection:post'])]
  58.     #[Assert\NotBlank// Asegura que el nombre no esté vacío
  59.     #[Assert\Length(min2max255)] // Longitud mínima y máxima
  60.     private ?string $name null;
  61.     /** @see _:parentCategory */
  62.     #[ORM\OneToOne(targetEntity'App\Entity\IncidentCategory')]
  63.     #[ORM\JoinColumn(nullablefalse)]
  64.     #[Groups(['incident_subcategory:item:get''incident_subcategory:collection:get''incident_subcategory:collection:post'])]
  65.     private ?IncidentCategory $parentCategory null;
  66.     public function __construct()
  67.     {
  68.         $this->id Uuid::uuid4();
  69.     }
  70.     public function getId(): ?UuidInterface
  71.     {
  72.         return $this->id;
  73.     }
  74.     /**
  75.      * @param string|null $name
  76.      */
  77.     public function setName(?string $name): void
  78.     {
  79.         $this->name $name;
  80.     }
  81.     /**
  82.      * @return string|null
  83.      */
  84.     public function getName(): ?string
  85.     {
  86.         return $this->name;
  87.     }
  88.     public function setParentCategory(?IncidentCategory $parentCategory): void
  89.     {
  90.         $this->parentCategory $parentCategory;
  91.     }
  92.     public function getParentCategory(): ?IncidentCategory
  93.     {
  94.         return $this->parentCategory;
  95.     }
  96. }