src/Entity/CitationType.php line 47

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups,
  6.     Symfony\Component\Validator\Constraints as Assert;
  7. use ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\Get,
  10.     ApiPlatform\Metadata\GetCollection,
  11.     ApiPlatform\Metadata\Put,
  12.     ApiPlatform\Metadata\ApiFilter,
  13.     ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
  14.     ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
  15.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use App\Entity\Trait\IdTrait,
  17.     App\Entity\Trait\UuidTrait,
  18.     App\Entity\Trait\OrdStatTrait,
  19.     App\Entity\Trait\TimestampableTrait,
  20.     App\Entity\Interface\OrdStatableInterface,
  21.     App\Repository\CitationTypeRepository;
  22. use App\Attribute\Sanitizeable;
  23. use App\Enum\PredefinedCitationType;
  24. #[ApiResource(
  25.     description'Citation types',
  26.     normalizationContext: ['groups' => ['read''read:' self::class]],
  27.     denormalizationContext: ['groups' => ['write']],
  28.     security'is_granted("' self::class . '")',
  29.     order: ['ord' => 'desc'],
  30.     operations: [
  31.         new GetCollection(),
  32.         new Get(),
  33.         new Put(),
  34.     ],
  35.     extraProperties: ['standard_put' => false],
  36. )]
  37. #[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])]
  38. #[ApiFilter(BooleanFilter::class, properties: ['stat'])]
  39. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  40. #[ORM\Entity(repositoryClassCitationTypeRepository::class)]
  41. class CitationType implements OrdStatableInterface
  42. {
  43.     use IdTrait,
  44.         UuidTrait,
  45.         OrdStatTrait,
  46.         TimestampableTrait;
  47.     #[ApiProperty(description'Title')]
  48.     #[Groups(['read''write'])]
  49.     #[Assert\NotBlank]
  50.     #[ORM\Column(typeTypes::STRINGlength255uniquetrue)]
  51.     private string $title;
  52.     #[ApiProperty(description'Example')]
  53.     #[Sanitizeable]
  54.     #[Groups(['read:' self::class, 'write'])]
  55.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  56.     private ?string $example null;
  57.     #[ApiProperty(description'Type')]
  58.     #[Groups(['read:' self::class])]
  59.     #[ORM\Column(
  60.         typeTypes::STRING,
  61.         enumTypePredefinedCitationType::class,
  62.         length255,
  63.         options: ['default' => PredefinedCitationType::APA],
  64.         uniquetrue
  65.     )]
  66.     private PredefinedCitationType $type PredefinedCitationType::APA;
  67.     public function __construct(string $titlePredefinedCitationType $type)
  68.     {
  69.         $this->setUuid();
  70.         $this->title $title;
  71.         $this->type $type;
  72.         $this->createdAt = new \DateTimeImmutable();
  73.         $this->updatedAt = new \DateTimeImmutable();
  74.     }
  75.     public function getTitle(): string
  76.     {
  77.         return $this->title;
  78.     }
  79.     public function setTitle(string $title): self
  80.     {
  81.         $this->title $title;
  82.         return $this;
  83.     }
  84.     public function getExample(): ?string
  85.     {
  86.         return $this->example;
  87.     }
  88.     public function setExample(?string $example): self
  89.     {
  90.         $this->example $example;
  91.         return $this;
  92.     }
  93.     public function getType(): PredefinedCitationType
  94.     {
  95.         return $this->type;
  96.     }
  97. }