src/Entity/MenuGroup.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\MenuGroupRepository;
  31. #[ApiResource(
  32.     description'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(repositoryClassMenuGroupRepository::class)]
  54. class MenuGroup 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 visible in bar')]
  68.     #[Groups(['read:' self::class, 'write'])]
  69.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  70.     private bool $isVisibleInBar false;
  71.     #[ApiProperty(description'Is target blank')]
  72.     #[Groups(['read:' self::class, 'write'])]
  73.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  74.     private bool $isTargetBlank false;
  75.     #[ApiProperty(description'Is collapsed')]
  76.     #[Groups(['read:' self::class, 'write'])]
  77.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  78.     private bool $isCollapsed true;
  79.     #[ApiProperty(description'Is small')]
  80.     #[Groups(['read:' self::class, 'write'])]
  81.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  82.     private bool $isSmall false;
  83.     #[ApiProperty(description'Items')]
  84.     #[Groups(['read:' self::class])]
  85.     #[ORM\OneToMany(targetEntityMenuGroupItem::class, mappedBy'parent'cascade: ['persist''remove'])]
  86.     #[ORM\OrderBy(['ord' => 'desc'])]
  87.     private Collection $items;
  88.     public function __construct(?array $languages)
  89.     {
  90.         $this->setUuid();
  91.         $this->translations = new ArrayCollection();
  92.         $this->setLanguages($languages ?? Language::DEFAULT_SITE);
  93.         $this->items = new ArrayCollection();
  94.         $this->createdAt = new \DateTimeImmutable();
  95.         $this->updatedAt = new \DateTimeImmutable();
  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 getIsVisibleInBar(): bool
  107.     {
  108.         return $this->isVisibleInBar;
  109.     }
  110.     public function setIsVisibleInBar(bool $isVisibleInBar): self
  111.     {
  112.         $this->isVisibleInBar $isVisibleInBar;
  113.         return $this;
  114.     }
  115.     public function getIsTargetBlank(): bool
  116.     {
  117.         return $this->isTargetBlank;
  118.     }
  119.     public function setIsTargetBlank(bool $isTargetBlank): self
  120.     {
  121.         $this->isTargetBlank $isTargetBlank;
  122.         return $this;
  123.     }
  124.     public function getIsCollapsed(): bool
  125.     {
  126.         return $this->isCollapsed;
  127.     }
  128.     public function setIsCollapsed(bool $isCollapsed): self
  129.     {
  130.         $this->isCollapsed $isCollapsed;
  131.         return $this;
  132.     }
  133.     public function getIsSmall(): bool
  134.     {
  135.         return $this->isSmall;
  136.     }
  137.     public function setIsSmall(bool $isSmall): self
  138.     {
  139.         $this->isSmall $isSmall;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection|MenuGroupItem[]
  144.      */
  145.     public function getItems(): Collection
  146.     {
  147.         return $this->items;
  148.     }
  149.     public function addItem(MenuGroupItem $item): self
  150.     {
  151.         if ($this->items->contains($item)) {
  152.             return $this;
  153.         }
  154.         $this->items[] = $item;
  155.         return $this;
  156.     }
  157.     public function removeItem(MenuGroupItem $item): self
  158.     {
  159.         $this->items->removeElement($item);
  160.         return $this;
  161.     }
  162.     #[Groups(['read:' self::class])]
  163.     public function getDepth(): int
  164.     {
  165.         return 1;
  166.     }
  167. }