summaryrefslogtreecommitdiff
path: root/src/controller/ajax.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-04-27 23:58:46 +0200
committerpolo <ordipolo@gmx.fr>2025-04-27 23:58:46 +0200
commit962d315ec0c99974df3dc2261bf94c54ca8cdbdd (patch)
tree7463f74a722e759067daf8c3ef43202a60352759 /src/controller/ajax.php
parenta3ba7dde60dc1c94b7170ec28266a966e5004d33 (diff)
downloadcms-962d315ec0c99974df3dc2261bf94c54ca8cdbdd.zip
page menu et chemins, partie3
Diffstat (limited to 'src/controller/ajax.php')
-rw-r--r--src/controller/ajax.php87
1 files changed, 86 insertions, 1 deletions
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index 9d1cc42..a20bd87 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -170,7 +170,8 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action']))
170} 170}
171 171
172// détection des requêtes d'upload d'image de tinymce 172// détection des requêtes d'upload d'image de tinymce
173if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image'){ 173if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image')
174{
174 if (isset($_FILES['file'])) { 175 if (isset($_FILES['file'])) {
175 $file = $_FILES['file']; 176 $file = $_FILES['file'];
176 $dest = 'images/'; 177 $dest = 'images/';
@@ -211,6 +212,90 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
211 $json = json_decode($data, true); 212 $json = json_decode($data, true);
212 Director::$menu_data = new Menu($entityManager); 213 Director::$menu_data = new Menu($entityManager);
213 214
215 // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions
216 if($_GET['menu_edit'] === 'move_one_level_up' && isset($json['id'])){
217 $id = $json['id'];
218 $page = Director::$menu_data->findPageById((int)$id);
219
220 $parent = $page->getParent(); // peut être null
221 if($parent === null){
222 // 1er niveau: ne rien faire
223 echo json_encode(['success' => false]);
224 die;
225 }
226 // BDD
227 else{
228 $page->setPosition($parent->getPosition() + 1); // nouvelle position
229
230 // 2ème niveau: le parent devient $menu_data, puis null après tri
231 if($parent->getParent() === null){
232 // connexion dans les deux sens
233 $page->setParent(Director::$menu_data); // => pour la persistance
234
235 //Director::$menu_data->addChild($page); // => pour sortChildren
236 $page->getParent()->addChild($page); // => pour sortChildren
237 //Director::$menu_data->sortChildren(true); // positions décaléees des nouveaux petits frères
238 $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères
239 $page->setParent(null);
240
241 // affichage
242 $page->setPagePath($page->getEndOfPath());
243 $page->fillChildrenPagePath();
244 }
245 // 3ème niveau et plus
246 else{
247 $page->setParent($parent->getParent()); // nouveau parent
248 $page->getParent()->addChild($page); // => pour sortChildren
249 $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères
250 $page->fillChildrenPagePath($page->getParent()->getPagePath());
251 }
252 //$parent->sortChildren(true); // positions des enfants restants, inutile si la fonction est récursive?
253 $entityManager->flush();
254
255 // affichage
256 $parent->removeChild($page);
257 $nav_builder = new NavBuilder();
258 $menu_builder = new MenuBuilder(null, false);
259 echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]);
260 die;
261 }
262 }
263
264 // flèche droite =>: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent
265 if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){
266 $id = $json['id'];
267 $page = Director::$menu_data->findPageById((int)$id);
268
269 $parent = $page->getParent(); // peut être null
270 if($parent == null){
271 $parent = Director::$menu_data;
272 }
273
274 // BDD
275 $parent->sortChildren(true); // trie et réindexe par sécurité: 1, 2, 3...
276 if($page->getPosition() > 1){
277 foreach($parent->getChildren() as $child){
278 //echo $child->getPageName();
279 if($child->getPosition() === $page->getPosition() - 1){
280 $page->setParent($child);
281 break;
282 }
283 }
284 $page->setPosition(count($page->getParent()->getChildren()) + 1);
285 }
286 $entityManager->flush();
287
288 // affichage
289 $parent->removeChild($page);
290 $page->getParent()->addChild($page);
291 $page->fillChildrenPagePath($page->getParent()->getPagePath()); // variable non mappée $page_path
292 $nav_builder = new NavBuilder();
293 $menu_builder = new MenuBuilder(null, false);
294
295 echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]);
296 die;
297 }
298
214 if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) 299 if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2']))
215 { 300 {
216 $id1 = $json['id1']; 301 $id1 = $json['id1'];