From eb3e1eb8c8365d3b3d1d39f24314ba420255afc2 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 21 Apr 2025 20:36:10 +0200 Subject: page menu et chemin, partie1 --- src/model/entities/Page.php | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/model/entities/Page.php') diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index c40a297..c30305c 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php @@ -13,6 +13,8 @@ use Doctrine\Common\Collections\ArrayCollection; #[ORM\Table(name: TABLE_PREFIX . "page")] class Page { + use \Position; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: "integer")] @@ -56,11 +58,11 @@ class Page $this->children = new ArrayCollection(); } - // getters - /*public function getId(): int + // getters/setters + public function getId(): int { return $this->id_page; - }*/ + } public function getPageName(): string { return $this->name_page; @@ -85,6 +87,10 @@ class Page { return $this->position; } + public function setPosition(int $position): void + { + $this->position = $position; + } public function getParent(): ?Page { return $this->parent; @@ -105,25 +111,23 @@ class Page public function addChild(self $child): void { $this->children[] = $child; - $this->sortChildren(); + $this->sortChildren(false); } - // utiliser $position pour afficher les éléments dans l'ordre - private function sortChildren(): void + public function findPageById(int $id): ?Page { - $iteration = count($this->children); - while($iteration > 1) - { - for($i = 0; $i < $iteration - 1; $i++) - { - if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) - { - $tmp = $this->children[$i]; - $this->children[$i] = $this->children[$i + 1]; - $this->children[$i + 1] = $tmp; + $target = null; + foreach($this->children as $page){ + if($page->getId() === $id){ + return $page; + } + if(count($page->getChildren()) > 0){ + $target = $page->findPageById($id); + if($target !== null){ + return $target; } } - $iteration--; } + return $target; } } -- cgit v1.2.3