src/Entity/FooterMenuGroup.php line 60

  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\Trait\TranslatableTrait,
  25.     App\Entity\Trait\Languages\SiteLanguagesTrait,
  26.     App\Entity\Interface\TranslatableInterface,
  27.     App\Entity\Interface\OrdStatableInterface,
  28.     App\Entity\Interface\LanguageableInterface;
  29. use App\Enum\Language,
  30.     App\Repository\FooterMenuGroupRepository;
  31. #[ApiResource(
  32.     description'Footer menu groups',
  33.     normalizationContext: ['groups' => [
  34.         'read',
  35.         'read:' self::class,
  36.         'read:' self::class . 'Translation'
  37.     ]],
  38.     denormalizationContext: ['groups' => ['write']],
  39.     security'is_granted("' self::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(BooleanFilter::class, properties: ['stat'])]
  52. #[ApiFilter(OrderFilter::class, properties: ['workingTitle''ord'])]
  53. #[ORM\Entity(repositoryClassFooterMenuGroupRepository::class)]
  54. class FooterMenuGroup implements TranslatableInterfaceOrdStatableInterfaceLanguageableInterface
  55. {
  56.     use IdTrait,
  57.         UuidTrait,
  58.         OrdStatTrait,
  59.         TimestampableTrait,
  60.         TranslatableTrait,
  61.         SiteLanguagesTrait;
  62.     #[ApiProperty(description'Working title')]
  63.     #[Groups(['read''write'])]
  64.     #[Assert\NotBlank]
  65.     #[ORM\Column(typeTypes::STRINGlength511uniquetrue)]
  66.     private string $workingTitle;
  67.     #[ApiProperty(description'Is target blank')]
  68.     #[Groups(['read:' self::class, 'write'])]
  69.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  70.     private bool $isTargetBlank false;
  71.     #[ApiProperty(description'Items')]
  72.     #[Groups(['read:' self::class])]
  73.     #[ORM\OneToMany(targetEntityFooterMenuGroupItem::class, mappedBy'parent'cascade: ['persist''remove'])]
  74.     #[ORM\OrderBy(['ord' => 'desc'])]
  75.     private Collection $items;
  76.     public function __construct(?array $languages)
  77.     {
  78.         $this->setUuid();
  79.         $this->translations = new ArrayCollection();
  80.         $this->setLanguages($languages ?? Language::DEFAULT_SITE);
  81.         $this->items = new ArrayCollection();
  82.         $this->createdAt = new \DateTimeImmutable();
  83.         $this->updatedAt = new \DateTimeImmutable();
  84.     }
  85.     public function getWorkingTitle(): string
  86.     {
  87.         return $this->workingTitle;
  88.     }
  89.     public function setWorkingTitle(string $workingTitle): self
  90.     {
  91.         $this->workingTitle $workingTitle;
  92.         return $this;
  93.     }
  94.     public function getIsTargetBlank(): bool
  95.     {
  96.         return $this->isTargetBlank;
  97.     }
  98.     public function setIsTargetBlank(bool $isTargetBlank): self
  99.     {
  100.         $this->isTargetBlank $isTargetBlank;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection|FooterMenuGroupItem[]
  105.      */
  106.     public function getItems(): Collection
  107.     {
  108.         return $this->items;
  109.     }
  110.     public function addItem(FooterMenuGroupItem $item): self
  111.     {
  112.         if ($this->items->contains($item)) {
  113.             return $this;
  114.         }
  115.         $this->items[] = $item;
  116.         return $this;
  117.     }
  118.     public function removeItem(FooterMenuGroupItem $item): self
  119.     {
  120.         $this->items->removeElement($item);
  121.         return $this;
  122.     }
  123.     #[Groups(['read:' self::class])]
  124.     public function getDepth(): int
  125.     {
  126.         return 1;
  127.     }
  128. }