diff options
Diffstat (limited to 'src/controller/PageManagementController.php')
-rw-r--r-- | src/controller/PageManagementController.php | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index e6886b1..9dce952 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
@@ -25,16 +25,16 @@ class PageManagementController | |||
25 | 25 | ||
26 | static public function updatePageMenuPath(EntityManager $entityManager): void | 26 | static public function updatePageMenuPath(EntityManager $entityManager): void |
27 | { | 27 | { |
28 | Director::$menu_data = new Menu($entityManager); | 28 | Model::$menu_data = new Menu($entityManager); |
29 | Director::$page_path = new Path(); | 29 | Model::$page_path = new Path(); |
30 | $page = Director::$page_path->getLast(); | 30 | $page = Model::$page_path->getLast(); |
31 | $path = htmlspecialchars($_POST['page_menu_path']); | 31 | $path = htmlspecialchars($_POST['page_menu_path']); |
32 | 32 | ||
33 | // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores | 33 | // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores |
34 | $path = trim(preg_replace('/_+/', '_', strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $path))), '_'); | 34 | $path = trim(preg_replace('/_+/', '_', strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $path))), '_'); |
35 | $page->setEndOfPath($path); | 35 | $page->setEndOfPath($path); |
36 | foreach(Director::$menu_data->getChildren() as $child){ | 36 | foreach(Model::$menu_data->getChildren() as $child){ |
37 | if($child->getEndOfPath() === Director::$page_path->getArray()[0]->getEndOfPath()){ | 37 | if($child->getEndOfPath() === Model::$page_path->getArray()[0]->getEndOfPath()){ |
38 | $child->fillChildrenPagePath(); // MAJ de $page_path | 38 | $child->fillChildrenPagePath(); // MAJ de $page_path |
39 | } | 39 | } |
40 | } | 40 | } |
@@ -55,10 +55,10 @@ class PageManagementController | |||
55 | static public function newPage(EntityManager $entityManager, array $post): void | 55 | static public function newPage(EntityManager $entityManager, array $post): void |
56 | { | 56 | { |
57 | // titre et chemin | 57 | // titre et chemin |
58 | $director = new Director($entityManager); | 58 | $model = new Model($entityManager); |
59 | $director->makeMenuAndPaths(); | 59 | $model->makeMenuAndPaths(); |
60 | //Director::$menu_data = new Menu($entityManager); | 60 | //Model::$menu_data = new Menu($entityManager); |
61 | $previous_page = Director::$menu_data->findPageById((int)$post["page_location"]); // (int) à cause de declare(strict_types=1); | 61 | $previous_page = Model::$menu_data->findPageById((int)$post["page_location"]); // (int) à cause de declare(strict_types=1); |
62 | $parent = $previous_page->getParent(); | 62 | $parent = $previous_page->getParent(); |
63 | 63 | ||
64 | $page = new Page( | 64 | $page = new Page( |
@@ -73,7 +73,7 @@ class PageManagementController | |||
73 | // addChild l'ajoute à la fin du tableau "children" puis on trie | 73 | // addChild l'ajoute à la fin du tableau "children" puis on trie |
74 | // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position | 74 | // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position |
75 | if($parent == null){ | 75 | if($parent == null){ |
76 | $parent = Director::$menu_data; | 76 | $parent = Model::$menu_data; |
77 | } | 77 | } |
78 | $parent->addChild($page); | 78 | $parent->addChild($page); |
79 | $parent->reindexPositions(); | 79 | $parent->reindexPositions(); |
@@ -127,12 +127,12 @@ class PageManagementController | |||
127 | /* partie "blocs" */ | 127 | /* partie "blocs" */ |
128 | static public function addBloc(EntityManager $entityManager): void | 128 | static public function addBloc(EntityManager $entityManager): void |
129 | { | 129 | { |
130 | $director = new Director($entityManager); | 130 | $model = new Model($entityManager); |
131 | $director->makeMenuAndPaths(); // on a besoin de page_path qui dépend de menu_data | 131 | $model->makeMenuAndPaths(); // on a besoin de page_path qui dépend de menu_data |
132 | $page = Director::$page_path->getLast(); | 132 | $page = Model::$page_path->getLast(); |
133 | $director->findUniqueNodeByName('main'); | 133 | $model->findUniqueNodeByName('main'); |
134 | $director->findItsChildren(); | 134 | $model->findItsChildren(); |
135 | $main = $director->getNode(); | 135 | $main = $model->getNode(); |
136 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 136 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
137 | 137 | ||
138 | if(!in_array($_POST["bloc_select"], array_keys(Blocks::$blocks), true)) // 3è param: contrôle du type | 138 | if(!in_array($_POST["bloc_select"], array_keys(Blocks::$blocks), true)) // 3è param: contrôle du type |
@@ -185,12 +185,12 @@ class PageManagementController | |||
185 | 185 | ||
186 | static public function deleteBloc(EntityManager $entityManager): void | 186 | static public function deleteBloc(EntityManager $entityManager): void |
187 | { | 187 | { |
188 | $director = new Director($entityManager); | 188 | $model = new Model($entityManager); |
189 | $director->makeMenuAndPaths(); | 189 | $model->makeMenuAndPaths(); |
190 | $director->findUniqueNodeByName('main'); | 190 | $model->findUniqueNodeByName('main'); |
191 | $director->findItsChildren(); | 191 | $model->findItsChildren(); |
192 | //$director->findNodeById((int)$_POST['delete_bloc_id']); | 192 | //$model->findNodeById((int)$_POST['delete_bloc_id']); |
193 | $main = $director->getNode(); | 193 | $main = $model->getNode(); |
194 | $bloc = null; | 194 | $bloc = null; |
195 | foreach($main->getChildren() as $child){ | 195 | foreach($main->getChildren() as $child){ |
196 | if($child->getId() === (int)$_POST['delete_bloc_id']){ | 196 | if($child->getId() === (int)$_POST['delete_bloc_id']){ |
@@ -212,13 +212,13 @@ class PageManagementController | |||
212 | static public function renameBloc(EntityManager $entityManager, array $json): void | 212 | static public function renameBloc(EntityManager $entityManager, array $json): void |
213 | { | 213 | { |
214 | if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ | 214 | if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ |
215 | $director = new Director($entityManager); | 215 | $model = new Model($entityManager); |
216 | $director->findNodeById($json['bloc_id']); | 216 | $model->findNodeById($json['bloc_id']); |
217 | 217 | ||
218 | // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé | 218 | // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé |
219 | $data = $director->getNode()->getNodeData()->getData(); | 219 | $data = $model->getNode()->getNodeData()->getData(); |
220 | $data['title'] = htmlspecialchars($json['bloc_title']); | 220 | $data['title'] = htmlspecialchars($json['bloc_title']); |
221 | $director->getNode()->getNodeData()->updateData('title', htmlspecialchars($json['bloc_title'])); | 221 | $model->getNode()->getNodeData()->updateData('title', htmlspecialchars($json['bloc_title'])); |
222 | 222 | ||
223 | $entityManager->flush(); | 223 | $entityManager->flush(); |
224 | echo json_encode(['success' => true, 'title' => $data['title']]); | 224 | echo json_encode(['success' => true, 'title' => $data['title']]); |
@@ -232,11 +232,11 @@ class PageManagementController | |||
232 | static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void | 232 | static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void |
233 | { | 233 | { |
234 | if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ | 234 | if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ |
235 | $director = new Director($entityManager); | 235 | $model = new Model($entityManager); |
236 | $director->makeMenuAndPaths(); // true pour $director->findItsChildren(); | 236 | $model->makeMenuAndPaths(); // true pour $model->findItsChildren(); |
237 | $director->findUniqueNodeByName('main'); | 237 | $model->findUniqueNodeByName('main'); |
238 | $director->findItsChildren(); | 238 | $model->findItsChildren(); |
239 | $main = $director->getNode(); | 239 | $main = $model->getNode(); |
240 | $main->sortChildren(true); // régénère les positions avant inversion | 240 | $main->sortChildren(true); // régénère les positions avant inversion |
241 | 241 | ||
242 | $bloc1 = null; | 242 | $bloc1 = null; |
@@ -271,8 +271,8 @@ class PageManagementController | |||
271 | static public function changeArticlesOrder(EntityManager $entityManager, array $json): void | 271 | static public function changeArticlesOrder(EntityManager $entityManager, array $json): void |
272 | { | 272 | { |
273 | if(isset($json['id']) && isset($json['chrono_order'])){ | 273 | if(isset($json['id']) && isset($json['chrono_order'])){ |
274 | $director = new Director($entityManager); | 274 | $model = new Model($entityManager); |
275 | $director->findNodeById($json['id']); | 275 | $model->findNodeById($json['id']); |
276 | 276 | ||
277 | if($json['chrono_order'] === 'chrono'){ | 277 | if($json['chrono_order'] === 'chrono'){ |
278 | $chrono_order = true; | 278 | $chrono_order = true; |
@@ -284,7 +284,7 @@ class PageManagementController | |||
284 | echo json_encode(['success' => false]); | 284 | echo json_encode(['success' => false]); |
285 | die; | 285 | die; |
286 | } | 286 | } |
287 | $director->getNode()->getNodeData()->setChronoOrder($chrono_order); | 287 | $model->getNode()->getNodeData()->setChronoOrder($chrono_order); |
288 | $entityManager->flush(); | 288 | $entityManager->flush(); |
289 | 289 | ||
290 | echo json_encode(['success' => true, 'chrono_order' => $json['chrono_order']]); | 290 | echo json_encode(['success' => true, 'chrono_order' => $json['chrono_order']]); |
@@ -298,16 +298,16 @@ class PageManagementController | |||
298 | static public function changePresentation(EntityManager $entityManager, array $json): void | 298 | static public function changePresentation(EntityManager $entityManager, array $json): void |
299 | { | 299 | { |
300 | if(isset($json['id']) && isset($json['presentation'])){ | 300 | if(isset($json['id']) && isset($json['presentation'])){ |
301 | $director = new Director($entityManager); | 301 | $model = new Model($entityManager); |
302 | $director->findNodeById($json['id']); | 302 | $model->findNodeById($json['id']); |
303 | 303 | ||
304 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ | 304 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ |
305 | $director->getNode()->getNodeData()->setPresentation($json['presentation']); | 305 | $model->getNode()->getNodeData()->setPresentation($json['presentation']); |
306 | $entityManager->flush(); | 306 | $entityManager->flush(); |
307 | 307 | ||
308 | $response_data = ['success' => true, 'presentation' => $json['presentation']]; | 308 | $response_data = ['success' => true, 'presentation' => $json['presentation']]; |
309 | if($json['presentation'] === 'grid'){ | 309 | if($json['presentation'] === 'grid'){ |
310 | $response_data['cols_min_width'] = $director->getNode()->getNodeData()->getColsMinWidth(); | 310 | $response_data['cols_min_width'] = $model->getNode()->getNodeData()->getColsMinWidth(); |
311 | } | 311 | } |
312 | echo json_encode($response_data); | 312 | echo json_encode($response_data); |
313 | } | 313 | } |
@@ -323,9 +323,9 @@ class PageManagementController | |||
323 | static public function changeColsMinWidth(EntityManager $entityManager, array $json): void | 323 | static public function changeColsMinWidth(EntityManager $entityManager, array $json): void |
324 | { | 324 | { |
325 | if(isset($json['id']) && isset($json['cols_min_width'])){ | 325 | if(isset($json['id']) && isset($json['cols_min_width'])){ |
326 | $director = new Director($entityManager); | 326 | $model = new Model($entityManager); |
327 | $director->findNodeById($json['id']); | 327 | $model->findNodeById($json['id']); |
328 | $director->getNode()->getNodeData()->setColsMinWidth((int)$json['cols_min_width']); // attention conversion? | 328 | $model->getNode()->getNodeData()->setColsMinWidth((int)$json['cols_min_width']); // attention conversion? |
329 | 329 | ||
330 | $entityManager->flush(); | 330 | $entityManager->flush(); |
331 | echo json_encode(['success' => true, 'cols_min_width' => $json['cols_min_width']]); | 331 | echo json_encode(['success' => true, 'cols_min_width' => $json['cols_min_width']]); |
@@ -338,10 +338,10 @@ class PageManagementController | |||
338 | static public function changePaginationLimit(EntityManager $entityManager, array $json): void | 338 | static public function changePaginationLimit(EntityManager $entityManager, array $json): void |
339 | { | 339 | { |
340 | if(isset($json['id']) && isset($json['pagination_limit'])){ | 340 | if(isset($json['id']) && isset($json['pagination_limit'])){ |
341 | $director = new Director($entityManager); | 341 | $model = new Model($entityManager); |
342 | $director->findNodeById($json['id']); | 342 | $model->findNodeById($json['id']); |
343 | $old_limit = $director->getNode()->getNodeData()->getPaginationLimit() ?? 12; | 343 | $old_limit = $model->getNode()->getNodeData()->getPaginationLimit() ?? 12; |
344 | $director->getNode()->getNodeData()->setPaginationLimit((int)$json['pagination_limit']); // attention conversion? | 344 | $model->getNode()->getNodeData()->setPaginationLimit((int)$json['pagination_limit']); // attention conversion? |
345 | 345 | ||
346 | $entityManager->flush(); | 346 | $entityManager->flush(); |
347 | 347 | ||