src/Entity/HomeSlide.php line 57

  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\OrderFilter;
  17. use App\Entity\Trait\IdTrait,
  18.     App\Entity\Trait\UuidTrait,
  19.     App\Entity\Trait\OrdStatTrait,
  20.     App\Entity\Trait\TimestampableTrait,
  21.     App\Entity\Trait\TranslatableTrait,
  22.     App\Entity\Trait\Languages\SiteLanguagesTrait,
  23.     App\Entity\Interface\TranslatableInterface,
  24.     App\Entity\Interface\OrdStatableInterface,
  25.     App\Entity\Interface\LanguageableInterface,
  26.     App\Repository\HomeSlideRepository;
  27. use App\Entity\AbstractThumb,
  28.     App\Enum\Language;
  29. #[ApiResource(
  30.     description'Home slides',
  31.     normalizationContext: ['groups' => [
  32.         'read',
  33.         'read:' self::class,
  34.         'read:' self::class . 'Translation',
  35.         'read:' AbstractThumb::class
  36.     ]],
  37.     denormalizationContext: ['groups' => ['write']],
  38.     security'is_granted("' self::class . '")',
  39.     order: ['ord' => 'desc'],
  40.     operations: [
  41.         new GetCollection(),
  42.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  43.         new Get(),
  44.         new Put(),
  45.         new Delete(),
  46.     ],
  47.     extraProperties: ['standard_put' => false],
  48. )]
  49. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  50. #[ORM\Entity(repositoryClassHomeSlideRepository::class)]
  51. class HomeSlide implements TranslatableInterfaceOrdStatableInterfaceLanguageableInterface
  52. {
  53.     use IdTrait,
  54.         UuidTrait,
  55.         OrdStatTrait,
  56.         TimestampableTrait,
  57.         TranslatableTrait,
  58.         SiteLanguagesTrait;
  59.     #[ApiProperty(description'Working title')]
  60.     #[Groups(['read''write'])]
  61.     #[Assert\NotBlank]
  62.     #[ORM\Column(typeTypes::STRINGlength511)]
  63.     private string $workingTitle;
  64.     public function __construct(string $workingTitle, ?array $languages)
  65.     {
  66.         $this->setUuid();
  67.         $this->workingTitle $workingTitle;
  68.         $this->translations = new ArrayCollection();
  69.         $this->setLanguages($languages ?? Language::DEFAULT_SITE);
  70.         $this->createdAt = new \DateTimeImmutable();
  71.         $this->updatedAt = new \DateTimeImmutable();
  72.     }
  73.     public function getWorkingTitle(): string
  74.     {
  75.         return $this->workingTitle;
  76.     }
  77.     public function setWorkingTitle(string $workingTitle): self
  78.     {
  79.         $this->workingTitle $workingTitle;
  80.         return $this;
  81.     }
  82. }