diff options
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/Director.php | 26 | ||||
-rw-r--r-- | src/controller/ajax.php | 39 | ||||
-rw-r--r-- | src/controller/post.php | 34 |
3 files changed, 83 insertions, 16 deletions
diff --git a/src/controller/Director.php b/src/controller/Director.php index 56a90cb..b154432 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php | |||
@@ -36,6 +36,7 @@ class Director | |||
36 | return $this->article; | 36 | return $this->article; |
37 | } | 37 | } |
38 | 38 | ||
39 | // affichage d'une page ordinaire | ||
39 | public function makeRootNode(string $id = ''): void | 40 | public function makeRootNode(string $id = ''): void |
40 | { | 41 | { |
41 | // on récupère toutes les entrées | 42 | // on récupère toutes les entrées |
@@ -91,6 +92,12 @@ class Director | |||
91 | } | 92 | } |
92 | } | 93 | } |
93 | 94 | ||
95 | // le basique | ||
96 | public function findNodeById(int $id): void | ||
97 | { | ||
98 | $this->node = $this->entityManager->find('App\Entity\Node', $id); | ||
99 | } | ||
100 | |||
94 | // récupération d'un article pour modification | 101 | // récupération d'un article pour modification |
95 | public function makeArticleNode(string $id = '', bool $get_section = false): bool | 102 | public function makeArticleNode(string $id = '', bool $get_section = false): bool |
96 | { | 103 | { |
@@ -112,7 +119,8 @@ class Director | |||
112 | 119 | ||
113 | if($get_section){ | 120 | if($get_section){ |
114 | $this->article = $bulk_data[0]; | 121 | $this->article = $bulk_data[0]; |
115 | $this->makeSectionNode($bulk_data[0]->getParent()->getId()); | 122 | $this->findNodeById($bulk_data[0]->getParent()->getId()); |
123 | $this->makeSectionNode(); | ||
116 | } | 124 | } |
117 | else{ | 125 | else{ |
118 | $this->article = $bulk_data[0]; | 126 | $this->article = $bulk_data[0]; |
@@ -122,31 +130,30 @@ class Director | |||
122 | } | 130 | } |
123 | 131 | ||
124 | // récupération des articles d'un bloc <section> à la création d'un article | 132 | // récupération des articles d'un bloc <section> à la création d'un article |
125 | public function makeSectionNode(int $section_id): bool | 133 | public function makeSectionNode(): bool |
126 | { | 134 | { |
127 | $section = $this->entityManager->find('App\Entity\Node', (string)$section_id); | ||
128 | |||
129 | $bulk_data = $this->entityManager | 135 | $bulk_data = $this->entityManager |
130 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') | 136 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') |
131 | ->setParameter('parent', $section) | 137 | ->setParameter('parent', $this->node) |
132 | ->getResult(); | 138 | ->getResult(); |
133 | 139 | ||
134 | foreach($bulk_data as $article){ | 140 | foreach($bulk_data as $article){ |
135 | $section->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page | 141 | $this->node->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page |
136 | } | 142 | } |
137 | $this->node = $section; | ||
138 | return true; | 143 | return true; |
139 | } | 144 | } |
140 | 145 | ||
141 | public function findNodeByName(string $name): void | 146 | public function findUniqueNodeByName(string $name): void // = unique en BDD, donc sans "page" associée |
142 | { | 147 | { |
143 | $bulk_data = $this->entityManager | 148 | $bulk_data = $this->entityManager |
144 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') | 149 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') |
145 | ->setParameter('name', $name) | 150 | ->setParameter('name', $name) |
146 | ->getResult(); | 151 | ->getResult(); |
147 | $this->node = $bulk_data[0]; | 152 | $this->node = $bulk_data[0]; |
148 | echo $this->page->getPageName() . ' '; | 153 | } |
149 | 154 | ||
155 | public function findItsChildren(): void | ||
156 | { | ||
150 | $bulk_data = $this->entityManager | 157 | $bulk_data = $this->entityManager |
151 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') | 158 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') |
152 | ->setParameter('parent', $this->node) | 159 | ->setParameter('parent', $this->node) |
@@ -154,7 +161,6 @@ class Director | |||
154 | ->getResult(); | 161 | ->getResult(); |
155 | foreach($bulk_data as $child){ | 162 | foreach($bulk_data as $child){ |
156 | $this->node->addChild($child); | 163 | $this->node->addChild($child); |
157 | echo $child->getName() . ' '; | ||
158 | } | 164 | } |
159 | } | 165 | } |
160 | } | 166 | } |
diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a20bd87..a6786d9 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php | |||
@@ -35,7 +35,8 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) | |||
35 | if($id[0] === 'n') | 35 | if($id[0] === 'n') |
36 | { | 36 | { |
37 | $section_id = (int)substr($id, 1); // id du bloc <section> | 37 | $section_id = (int)substr($id, 1); // id du bloc <section> |
38 | $director->makeSectionNode($section_id); | 38 | $director->findNodeById($section_id); |
39 | $director->makeSectionNode(); | ||
39 | $node = $director->getNode(); // = <section> | 40 | $node = $director->getNode(); // = <section> |
40 | 41 | ||
41 | if(is_array($content)){ | 42 | if(is_array($content)){ |
@@ -205,6 +206,8 @@ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_ | |||
205 | die; | 206 | die; |
206 | } | 207 | } |
207 | 208 | ||
209 | |||
210 | /* -- page Menu et chemins -- */ | ||
208 | if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) | 211 | if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) |
209 | { | 212 | { |
210 | // récupération des données | 213 | // récupération des données |
@@ -347,7 +350,39 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) | |||
347 | } | 350 | } |
348 | } | 351 | } |
349 | 352 | ||
350 | // détection des requêtes de type XHR?, pas d'utilité pour l'instant | 353 | |
354 | /* -- mode Modification d'une page -- */ | ||
355 | if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['bloc_edit'])) | ||
356 | { | ||
357 | // récupération des données | ||
358 | $data = file_get_contents('php://input'); | ||
359 | $json = json_decode($data, true); | ||
360 | |||
361 | // renommage d'un bloc | ||
362 | if($_GET['bloc_edit'] === 'rename_page_bloc') | ||
363 | { | ||
364 | if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ | ||
365 | $director = new Director($entityManager); | ||
366 | $director->findNodeById($json['bloc_id']); | ||
367 | |||
368 | // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé | ||
369 | $data = $director->getNode()->getNodeData()->getData(); | ||
370 | $data['title'] = htmlspecialchars($json['bloc_title']); | ||
371 | $director->getNode()->getNodeData()->setData($data); | ||
372 | |||
373 | $entityManager->flush(); | ||
374 | echo json_encode(['success' => true, 'title' => $data['title']]); | ||
375 | } | ||
376 | else{ | ||
377 | echo json_encode(['success' => false]); | ||
378 | } | ||
379 | die; | ||
380 | } | ||
381 | |||
382 | } | ||
383 | |||
384 | |||
385 | // détection des requêtes de type XHR?, pas d'utilité à priori | ||
351 | /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ | 386 | /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ |
352 | echo "requête XHR reçue par le serveur"; | 387 | echo "requête XHR reçue par le serveur"; |
353 | die; | 388 | die; |
diff --git a/src/controller/post.php b/src/controller/post.php index 76ac72b..d437423 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
@@ -15,10 +15,13 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
15 | /* -- mode Modification d'une page -- */ | 15 | /* -- mode Modification d'une page -- */ |
16 | 16 | ||
17 | // ajout d'un bloc dans une page | 17 | // ajout d'un bloc dans une page |
18 | if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ | 18 | if(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null |
19 | && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden | ||
20 | { | ||
19 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data | 21 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data |
20 | $page = Director::$page_path->getLast(); | 22 | $page = Director::$page_path->getLast(); |
21 | $director->findNodeByName('main'); | 23 | $director->findUniqueNodeByName('main'); |
24 | $director->findItsChildren(); | ||
22 | $main = $director->getNode(); | 25 | $main = $director->getNode(); |
23 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 26 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
24 | 27 | ||
@@ -37,7 +40,30 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
37 | $entityManager->flush(); | 40 | $entityManager->flush(); |
38 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | 41 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); |
39 | } | 42 | } |
43 | // suppression d'un bloc de page | ||
44 | elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null | ||
45 | && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden | ||
46 | { | ||
47 | $director = new Director($entityManager, true); | ||
48 | $director->findUniqueNodeByName('main'); | ||
49 | $director->findItsChildren(); | ||
50 | //$director->findNodeById((int)$_POST['delete_bloc_id']); | ||
51 | $main = $director->getNode(); | ||
52 | $bloc; | ||
53 | foreach($main->getChildren() as $child){ | ||
54 | if($child->getId() === (int)$_POST['delete_bloc_id']){ | ||
55 | $bloc = $child; | ||
56 | break; | ||
57 | } | ||
58 | } | ||
59 | $main->removeChild($bloc); // réindex le tableau $children au passage | ||
60 | $main->reindexPositions(); | ||
40 | 61 | ||
62 | $entityManager->remove($bloc); // suppression en BDD | ||
63 | $entityManager->flush(); | ||
64 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | ||
65 | } | ||
66 | |||
41 | 67 | ||
42 | /* -- page Menu et chemins -- */ | 68 | /* -- page Menu et chemins -- */ |
43 | 69 | ||
@@ -60,7 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
60 | $parent = Director::$menu_data; | 86 | $parent = Director::$menu_data; |
61 | } | 87 | } |
62 | $parent->addChild($page); // true pour réindexer les positions en BDD | 88 | $parent->addChild($page); // true pour réindexer les positions en BDD |
63 | $parent->reindex(); | 89 | $parent->reindexPositions(); |
64 | 90 | ||
65 | $entityManager->persist($page); | 91 | $entityManager->persist($page); |
66 | $entityManager->flush(); | 92 | $entityManager->flush(); |
@@ -76,7 +102,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
76 | } | 102 | } |
77 | 103 | ||
78 | $parent->removeChild($page); // suppression de $children avant de trier | 104 | $parent->removeChild($page); // suppression de $children avant de trier |
79 | $parent->reindex(); | 105 | $parent->reindexPositions(); |
80 | 106 | ||
81 | $entityManager->remove($page); // suppression en BDD | 107 | $entityManager->remove($page); // suppression en BDD |
82 | $entityManager->flush(); | 108 | $entityManager->flush(); |