src/Entity/Page/Menu.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Page;
  3. use App\Repository\Page\MenuRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  8. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  9. #[ORM\Entity(repositoryClassMenuRepository::class)]
  10. class Menu implements TranslatableInterface
  11. {
  12.     use TranslatableTrait;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'children')]
  18.     private ?self $parent null;
  19.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  20.     private Collection $children;
  21.     #[ORM\OneToMany(mappedBy'menu'targetEntityPage::class)]
  22.     private Collection $pages;
  23.     public function __construct()
  24.     {
  25.         $this->pages = new ArrayCollection();
  26.         $this->children = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     /**
  33.      * @return Collection<int, Page>
  34.      */
  35.     public function getPages(): Collection
  36.     {
  37.         return $this->pages;
  38.     }
  39.     public function addPage(Page $page): static
  40.     {
  41.         if (!$this->pages->contains($page)) {
  42.             $this->pages->add($page);
  43.             $page->setMenu($this);
  44.         }
  45.         return $this;
  46.     }
  47.     public function removePage(Page $page): static
  48.     {
  49.         if ($this->pages->removeElement($page)) {
  50.             // set the owning side to null (unless already changed)
  51.             if ($page->getMenu() === $this) {
  52.                 $page->setMenu(null);
  53.             }
  54.         }
  55.         return $this;
  56.     }
  57.     public function getParent(): ?self
  58.     {
  59.         return $this->parent;
  60.     }
  61.     public function setParent(?self $parent): static
  62.     {
  63.         $this->parent $parent;
  64.         return $this;
  65.     }
  66.     /**
  67.      * @return Collection<int, Menu>
  68.      */
  69.     public function getChildren(): Collection
  70.     {
  71.         return $this->children;
  72.     }
  73.     public function addChild(Menu $child): static
  74.     {
  75.         if (!$this->children->contains($child)) {
  76.             $this->children->add($child);
  77.             $child->setParent($this);
  78.         }
  79.         return $this;
  80.     }
  81.     public function removeChild(Menu $child): static
  82.     {
  83.         if ($this->children->removeElement($child)) {
  84.             // set the owning side to null (unless already changed)
  85.             if ($child->getParent() === $this) {
  86.                 $child->setParent(null);
  87.             }
  88.         }
  89.         return $this;
  90.     }
  91.     public function __toString()
  92.     {
  93.         if($this->translate()->getNom()) {
  94.             return $this->translate()->getNom();
  95.         }
  96.         return '';
  97.     }
  98.     //On triche pour ne pas repasser sur le front et dev en cours
  99.     public function getNom()
  100.     {
  101.         if($this->translate()->getNom()) {
  102.             return $this->translate()->getNom();
  103.         }
  104.         return '';
  105.     }
  106.     public function getNomLangue($lang): ?string
  107.     {
  108.         if($this->translate($lang)->getNom()) {
  109.             return $this->translate($lang)->getNom();
  110.         }
  111.         return '';
  112.     }
  113.     public function getDescription()
  114.     {
  115.         if($this->translate()->getDescription()) {
  116.             return $this->translate()->getDescription();
  117.         }
  118.         return '';
  119.     }
  120.     public function getDescriptionLangue($lang): ?string
  121.     {
  122.         if($this->translate($lang)->getDescription()) {
  123.             return $this->translate($lang)->getDescription();
  124.         }
  125.         return '';
  126.     }
  127. }