<?php
namespace App\Entity\Page;
use App\Repository\Page\MenuRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
#[ORM\Entity(repositoryClass: MenuRepository::class)]
class Menu implements TranslatableInterface
{
use TranslatableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $children;
#[ORM\OneToMany(mappedBy: 'menu', targetEntity: Page::class)]
private Collection $pages;
public function __construct()
{
$this->pages = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Page>
*/
public function getPages(): Collection
{
return $this->pages;
}
public function addPage(Page $page): static
{
if (!$this->pages->contains($page)) {
$this->pages->add($page);
$page->setMenu($this);
}
return $this;
}
public function removePage(Page $page): static
{
if ($this->pages->removeElement($page)) {
// set the owning side to null (unless already changed)
if ($page->getMenu() === $this) {
$page->setMenu(null);
}
}
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): static
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, Menu>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Menu $child): static
{
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}
return $this;
}
public function removeChild(Menu $child): static
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function __toString()
{
if($this->translate()->getNom()) {
return $this->translate()->getNom();
}
return '';
}
//On triche pour ne pas repasser sur le front et dev en cours
public function getNom()
{
if($this->translate()->getNom()) {
return $this->translate()->getNom();
}
return '';
}
public function getNomLangue($lang): ?string
{
if($this->translate($lang)->getNom()) {
return $this->translate($lang)->getNom();
}
return '';
}
public function getDescription()
{
if($this->translate()->getDescription()) {
return $this->translate()->getDescription();
}
return '';
}
public function getDescriptionLangue($lang): ?string
{
if($this->translate($lang)->getDescription()) {
return $this->translate($lang)->getDescription();
}
return '';
}
}