src/Entity/FooterMenuGroup.php line 60
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\Collection,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\Languages\SiteLanguagesTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableInterface;
use App\Enum\Language,
App\Repository\FooterMenuGroupRepository;
#[ApiResource(
description: 'Footer menu groups',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation'
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(SearchFilter::class, properties: ['translations.title' => 'partial', 'workingTitle' => 'partial'])]
#[ApiFilter(BooleanFilter::class, properties: ['stat'])]
#[ApiFilter(OrderFilter::class, properties: ['workingTitle', 'ord'])]
#[ORM\Entity(repositoryClass: FooterMenuGroupRepository::class)]
class FooterMenuGroup implements TranslatableInterface, OrdStatableInterface, LanguageableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
SiteLanguagesTrait;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 511, unique: true)]
private string $workingTitle;
#[ApiProperty(description: 'Is target blank')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isTargetBlank = false;
#[ApiProperty(description: 'Items')]
#[Groups(['read:' . self::class])]
#[ORM\OneToMany(targetEntity: FooterMenuGroupItem::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['ord' => 'desc'])]
private Collection $items;
public function __construct(?array $languages)
{
$this->setUuid();
$this->translations = new ArrayCollection();
$this->setLanguages($languages ?? Language::DEFAULT_SITE);
$this->items = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getWorkingTitle(): string
{
return $this->workingTitle;
}
public function setWorkingTitle(string $workingTitle): self
{
$this->workingTitle = $workingTitle;
return $this;
}
public function getIsTargetBlank(): bool
{
return $this->isTargetBlank;
}
public function setIsTargetBlank(bool $isTargetBlank): self
{
$this->isTargetBlank = $isTargetBlank;
return $this;
}
/**
* @return Collection|FooterMenuGroupItem[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(FooterMenuGroupItem $item): self
{
if ($this->items->contains($item)) {
return $this;
}
$this->items[] = $item;
return $this;
}
public function removeItem(FooterMenuGroupItem $item): self
{
$this->items->removeElement($item);
return $this;
}
#[Groups(['read:' . self::class])]
public function getDepth(): int
{
return 1;
}
}