src/Entity/TranslatorEntry.php line 56

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Serializer\Annotation\Groups,
  7.     Symfony\Component\Validator\Constraints as Assert;
  8. use ApiPlatform\Metadata\ApiResource,
  9.     ApiPlatform\Metadata\ApiProperty,
  10.     ApiPlatform\Metadata\Get,
  11.     ApiPlatform\Metadata\GetCollection,
  12.     ApiPlatform\Metadata\Post,
  13.     ApiPlatform\Metadata\Put,
  14.     ApiPlatform\Metadata\Delete,
  15.     ApiPlatform\Metadata\ApiFilter,
  16.     ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  18. use App\Entity\Trait\IdTrait,
  19.     App\Entity\Trait\UuidTrait,
  20.     App\Entity\Trait\OrdTrait,
  21.     App\Entity\Trait\TimestampableTrait,
  22.     App\Entity\Trait\TranslatableTrait,
  23.     App\Entity\Interface\TranslatableInterface,
  24.     App\Entity\Interface\OrderableInterface,
  25.     App\Enum\Language,
  26.     App\Repository\TranslatorEntryRepository;
  27. use App\StateProcessor\TranslatorEntryProcessor;
  28. #[ApiResource(
  29.     description'Translator entries',
  30.     normalizationContext: ['groups' => [
  31.         'read',
  32.         'read:' self::class,
  33.         'read:' self::class . 'Translation'
  34.     ]],
  35.     denormalizationContext: ['groups' => ['write']],
  36.     security'is_granted("' self::class . '")',
  37.     order: ['ord' => 'desc'],
  38.     operations: [
  39.         new GetCollection(),
  40.         new Post(processorTranslatorEntryProcessor::class),
  41.         new Get(),
  42.         new Put(processorTranslatorEntryProcessor::class),
  43.         new Delete(processorTranslatorEntryProcessor::class),
  44.     ],
  45.     extraProperties: ['standard_put' => false],
  46. )]
  47. #[ApiFilter(SearchFilter::class, properties: ['translations.title' => 'partial''code' => 'partial'])]
  48. #[ApiFilter(OrderFilter::class, properties: ['code''ord'])]
  49. #[ORM\Entity(repositoryClassTranslatorEntryRepository::class)]
  50. class TranslatorEntry implements TranslatableInterfaceOrderableInterface
  51. {
  52.     use IdTrait,
  53.         UuidTrait,
  54.         OrdTrait,
  55.         TimestampableTrait,
  56.         TranslatableTrait;
  57.     #[ApiProperty(description'Code of entry')]
  58.     #[Groups(['read''write'])]
  59.     #[Assert\NotBlank]
  60.     #[ORM\Column(typeTypes::STRINGlength191uniquetrue)]
  61.     private string $code;
  62.     public function __construct(string $code)
  63.     {
  64.         $this->setUuid();
  65.         $this->code $code;
  66.         $this->translations = new ArrayCollection();
  67.         foreach (Language::DEFAULT_SITE as $lang) {
  68.             new TranslatorEntryTranslation($this$lang);
  69.         }
  70.         $this->createdAt = new \DateTimeImmutable();
  71.         $this->updatedAt = new \DateTimeImmutable();
  72.     }
  73.     public function getCode(): ?string
  74.     {
  75.         return $this->code;
  76.     }
  77.     public function setCode(string $code): self
  78.     {
  79.         $this->code $code;
  80.         return $this;
  81.     }
  82. }