src/Entity/ClassificationType.php line 50

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\Collection,
  6.     Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Serializer\Annotation\Groups,
  8.     Symfony\Component\Validator\Constraints as Assert;
  9. use ApiPlatform\Metadata\ApiResource,
  10.     ApiPlatform\Metadata\ApiProperty,
  11.     ApiPlatform\Metadata\Get,
  12.     ApiPlatform\Metadata\GetCollection,
  13.     ApiPlatform\Metadata\Post,
  14.     ApiPlatform\Metadata\Put,
  15.     ApiPlatform\Metadata\Delete,
  16.     ApiPlatform\Metadata\ApiFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
  18.     ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
  19.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  20. use App\Entity\Trait\IdTrait,
  21.     App\Entity\Trait\UuidTrait,
  22.     App\Entity\Trait\OrdStatTrait,
  23.     App\Entity\Trait\TimestampableTrait,
  24.     App\Entity\Interface\OrdStatableInterface,
  25.     App\Repository\ClassificationTypeRepository;
  26. #[ApiResource(
  27.     description'Classification types',
  28.     normalizationContext: ['groups' => ['read''read:' self::class]],
  29.     denormalizationContext: ['groups' => ['write']],
  30.     security'is_granted("' self::class . '")',
  31.     order: ['ord' => 'desc'],
  32.     operations: [
  33.         new GetCollection(),
  34.         new Post(),
  35.         new Get(),
  36.         new Put(),
  37.         new Delete(),
  38.     ],
  39.     extraProperties: ['standard_put' => false],
  40. )]
  41. #[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])]
  42. #[ApiFilter(BooleanFilter::class, properties: ['stat'])]
  43. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  44. #[ORM\Entity(repositoryClassClassificationTypeRepository::class)]
  45. class ClassificationType implements OrdStatableInterface
  46. {
  47.     use IdTrait,
  48.         UuidTrait,
  49.         OrdStatTrait,
  50.         TimestampableTrait;
  51.     #[ApiProperty(description'Title')]
  52.     #[Groups(['read''write'])]
  53.     #[Assert\NotBlank]
  54.     #[ORM\Column(typeTypes::STRINGlength511uniquetrue)]
  55.     private string $title;
  56.     #[ApiProperty(description'Entries')]
  57.     #[Groups(['read:' self::class])]
  58.     #[ORM\OneToMany(targetEntityClassificationTypeEntry::class, mappedBy'type')]
  59.     #[ORM\OrderBy(['ord' => 'desc'])]
  60.     private Collection $entries;
  61.     public function __construct(string $title)
  62.     {
  63.         $this->setUuid();
  64.         $this->title $title;
  65.         $this->entries = new ArrayCollection();
  66.         $this->createdAt = new \DateTimeImmutable();
  67.         $this->updatedAt = new \DateTimeImmutable();
  68.     }
  69.     public function getTitle(): string
  70.     {
  71.         return $this->title;
  72.     }
  73.     public function setTitle(string $title): self
  74.     {
  75.         $this->title $title;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return Collection<int, ClassificationTypeEntry>
  80.      */
  81.     public function getEntries(): Collection
  82.     {
  83.         return $this->entries;
  84.     }
  85.     public function addEntry(ClassificationTypeEntry $entry): self
  86.     {
  87.         if ($this->entries->contains($entry)) {
  88.             return $this;
  89.         }
  90.         $this->entries[] = $entry;
  91.         return $this;
  92.     }
  93.     public function removeEntry(ClassificationTypeEntry $entry): self
  94.     {
  95.         $this->entries->removeElement($entry);
  96.         return $this;
  97.     }
  98. }