src/Entity/LandingFooterItem.php line 63

  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.     Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  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\Trait\TranslatableTrait,
  25.     App\Entity\Trait\Languages\LanguageableChildTrait,
  26.     App\Entity\Interface\TranslatableInterface,
  27.     App\Entity\Interface\OrdStatableInterface,
  28.     App\Entity\Interface\LanguageableChildInterface,
  29.     App\Filter\IriFilter;
  30. use App\Repository\LandingFooterItemRepository;
  31. #[ApiResource(
  32.     description'Landing footer items',
  33.     normalizationContext: ['groups' => [
  34.         'read',
  35.         'read:' self::class,
  36.         'read:' self::class . 'Translation'
  37.     ]],
  38.     denormalizationContext: ['groups' => ['write']],
  39.     security'is_granted("' Landing::class . '")',
  40.     order: ['ord' => 'desc'],
  41.     operations: [
  42.         new GetCollection(),
  43.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  44.         new Get(),
  45.         new Put(),
  46.         new Delete(),
  47.     ],
  48.     extraProperties: ['standard_put' => false],
  49. )]
  50. #[ApiFilter(SearchFilter::class, properties: ['translations.title' => 'partial''workingTitle' => 'partial'])]
  51. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  52. #[ApiFilter(BooleanFilter::class, properties: ['stat'])]
  53. #[ApiFilter(OrderFilter::class, properties: ['workingTitle''ord'])]
  54. #[UniqueEntity(fields: ['workingTitle''parent'], message'This working title already exists.')]
  55. #[ORM\UniqueConstraint(fields: ['parent''workingTitle'])]
  56. #[ORM\Entity(repositoryClassLandingFooterItemRepository::class)]
  57. class LandingFooterItem implements TranslatableInterfaceOrdStatableInterfaceLanguageableChildInterface
  58. {
  59.     use IdTrait,
  60.         UuidTrait,
  61.         OrdStatTrait,
  62.         TimestampableTrait,
  63.         TranslatableTrait,
  64.         LanguageableChildTrait;
  65.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  66.     #[Groups(['read''post'])]
  67.     #[Assert\NotNull]
  68.     #[ORM\ManyToOne(targetEntityLanding::class, inversedBy'footerItems')]
  69.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  70.     private Landing $parent;
  71.     #[ApiProperty(description'Working title')]
  72.     #[Groups(['read''write'])]
  73.     #[Assert\NotBlank]
  74.     #[ORM\Column(typeTypes::STRINGlength511)]
  75.     private string $workingTitle;
  76.     #[ApiProperty(description'Is target blank')]
  77.     #[Groups(['read:' self::class, 'write'])]
  78.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  79.     private bool $isTargetBlank false;
  80.     public function __construct(Landing $parentstring $workingTitle)
  81.     {
  82.         $this->setUuid();
  83.         $this->parent $parent;
  84.         $this->workingTitle $workingTitle;
  85.         $this->translations = new ArrayCollection();
  86.         $this->createdAt = new \DateTimeImmutable();
  87.         $this->updatedAt = new \DateTimeImmutable();
  88.         foreach ($this->getParentLanguages() as $lang) {
  89.             new LandingFooterItemTranslation($this$lang);
  90.         }
  91.         $parent->addFooterItem($this);
  92.     }
  93.     public function getParent(): Landing
  94.     {
  95.         return $this->parent;
  96.     }
  97.     public function getWorkingTitle(): string
  98.     {
  99.         return $this->workingTitle;
  100.     }
  101.     public function setWorkingTitle(string $workingTitle): self
  102.     {
  103.         $this->workingTitle $workingTitle;
  104.         return $this;
  105.     }
  106.     public function getIsTargetBlank(): bool
  107.     {
  108.         return $this->isTargetBlank;
  109.     }
  110.     public function setIsTargetBlank(bool $isTargetBlank): self
  111.     {
  112.         $this->isTargetBlank $isTargetBlank;
  113.         return $this;
  114.     }
  115. }