summaryrefslogtreecommitdiff
path: root/src/model/entities/Page.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/entities/Page.php')
-rw-r--r--src/model/entities/Page.php38
1 files changed, 21 insertions, 17 deletions
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;
13#[ORM\Table(name: TABLE_PREFIX . "page")] 13#[ORM\Table(name: TABLE_PREFIX . "page")]
14class Page 14class Page
15{ 15{
16 use \Position;
17
16 #[ORM\Id] 18 #[ORM\Id]
17 #[ORM\GeneratedValue] 19 #[ORM\GeneratedValue]
18 #[ORM\Column(type: "integer")] 20 #[ORM\Column(type: "integer")]
@@ -56,11 +58,11 @@ class Page
56 $this->children = new ArrayCollection(); 58 $this->children = new ArrayCollection();
57 } 59 }
58 60
59 // getters 61 // getters/setters
60 /*public function getId(): int 62 public function getId(): int
61 { 63 {
62 return $this->id_page; 64 return $this->id_page;
63 }*/ 65 }
64 public function getPageName(): string 66 public function getPageName(): string
65 { 67 {
66 return $this->name_page; 68 return $this->name_page;
@@ -85,6 +87,10 @@ class Page
85 { 87 {
86 return $this->position; 88 return $this->position;
87 } 89 }
90 public function setPosition(int $position): void
91 {
92 $this->position = $position;
93 }
88 public function getParent(): ?Page 94 public function getParent(): ?Page
89 { 95 {
90 return $this->parent; 96 return $this->parent;
@@ -105,25 +111,23 @@ class Page
105 public function addChild(self $child): void 111 public function addChild(self $child): void
106 { 112 {
107 $this->children[] = $child; 113 $this->children[] = $child;
108 $this->sortChildren(); 114 $this->sortChildren(false);
109 } 115 }
110 116
111 // utiliser $position pour afficher les éléments dans l'ordre 117 public function findPageById(int $id): ?Page
112 private function sortChildren(): void
113 { 118 {
114 $iteration = count($this->children); 119 $target = null;
115 while($iteration > 1) 120 foreach($this->children as $page){
116 { 121 if($page->getId() === $id){
117 for($i = 0; $i < $iteration - 1; $i++) 122 return $page;
118 { 123 }
119 if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) 124 if(count($page->getChildren()) > 0){
120 { 125 $target = $page->findPageById($id);
121 $tmp = $this->children[$i]; 126 if($target !== null){
122 $this->children[$i] = $this->children[$i + 1]; 127 return $target;
123 $this->children[$i + 1] = $tmp;
124 } 128 }
125 } 129 }
126 $iteration--;
127 } 130 }
131 return $target;
128 } 132 }
129} 133}