src/Entity/MenuGroupItem.php line 63
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert,
Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
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\LanguageableChildTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableChildInterface,
App\Filter\IriFilter;
use App\Repository\MenuGroupItemRepository;
#[ApiResource(
description: 'Menu group items',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation'
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . MenuGroup::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(IriFilter::class, properties: ['parent'])]
#[ApiFilter(BooleanFilter::class, properties: ['stat'])]
#[ApiFilter(OrderFilter::class, properties: ['workingTitle', 'ord'])]
#[UniqueEntity(fields: ['workingTitle', 'parent'], message: 'This working title already exists.')]
#[ORM\UniqueConstraint(fields: ['parent', 'workingTitle'])]
#[ORM\Entity(repositoryClass: MenuGroupItemRepository::class)]
class MenuGroupItem implements TranslatableInterface, OrdStatableInterface, LanguageableChildInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
LanguageableChildTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: MenuGroup::class, inversedBy: 'items')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private MenuGroup $parent;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 511)]
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: 'Is small')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isSmall = false;
public function __construct(MenuGroup $parent, string $workingTitle)
{
$this->setUuid();
$this->parent = $parent;
$this->workingTitle = $workingTitle;
$this->translations = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
foreach ($this->getParentLanguages() as $lang) {
new MenuGroupItemTranslation($this, $lang);
}
$parent->addItem($this);
}
public function getParent(): MenuGroup
{
return $this->parent;
}
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;
}
public function getIsSmall(): bool
{
return $this->isSmall;
}
public function setIsSmall(bool $isSmall): self
{
$this->isSmall = $isSmall;
return $this;
}
}