From 6535db259081b02e9db59b905ae922a37d03eddc Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 20 Oct 2025 15:36:59 +0200 Subject: =?UTF-8?q?m=C3=A9thodes=20dans=20Page=20pour=20les=20fichiers=20C?= =?UTF-8?q?SS/JS,=20CCS/JS=20par=20d=C3=A9faut=20supprim=C3=A9=20de=20la?= =?UTF-8?q?=20BDD,=20nettoyage=20quand=20le=20dernier=20bloc=20est=20suppr?= =?UTF-8?q?im=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/PageManagementController.php | 43 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src/controller/PageManagementController.php') diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index c45f3f3..ca1f887 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -68,8 +68,6 @@ class PageManagementController true, true, false, $previous_page->getPosition(), $parent); // peut et DOIT être null si on est au 1er niveau - $page->useDefaultCSS(); - $page->useDefaultJS(); // on a donné à la nouvelle entrée la même position qu'à la précédente, // addChild l'ajoute à la fin du tableau "children" puis on trie @@ -126,11 +124,10 @@ class PageManagementController die; } - if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ - $page->setCSS(array_merge($page->getCSS(), [$_POST["bloc_select"]])); - + if(in_array($_POST["bloc_select"], ['calendar', 'form'])){ + $page->addCSS($_POST["bloc_select"]); if($_POST["bloc_select"] === 'form'){ - $page->setJS(array_merge($page->getJS(), [$_POST["bloc_select"]])); + $page->addJS($_POST["bloc_select"]); } $entityManager->persist($page); } @@ -146,7 +143,7 @@ class PageManagementController $data->setPresentation('grid'); } elseif($_POST["bloc_select"] === 'galery'){ - $data->setPresentation('mosaic'); // mieux que carousel pour commencer + $data->setPresentation('mosaic'); // un jour on mettra carousel } // else = null par défaut @@ -163,19 +160,37 @@ class PageManagementController $model->makeMenuAndPaths(); $model->findUniqueNodeByName('main'); $model->findItsChildren(); - //$model->findNodeById((int)$_POST['delete_bloc_id']); $main = $model->getNode(); - $bloc = null; + + $block = null; + $type = ''; + $nb_same_type = 0; foreach($main->getChildren() as $child){ if($child->getId() === (int)$_POST['delete_bloc_id']){ - $bloc = $child; - break; + $block = $child; + $type = $block->getName(); + } + if($child->getName() === $type){ + $nb_same_type++; } } - if(!empty($bloc)){ // si $bloc est null c'est que le HTML a été modifié volontairement - $main->removeChild($bloc); // réindex le tableau $children au passage + + // nettoyage fichiers CSS et JS si on retire le derner bloc de ce type + if($nb_same_type === 1 && in_array($block->getName(), ['calendar', 'form'])){ + $page = $block->getPage(); + $page->removeCSS($block->getName()); + if($block->getName() === 'form'){ + $page->removeJS($block->getName()); + } + } + + if(!empty($block)){ // si $block est null c'est que le HTML a été modifié volontairement + $main->removeChild($block); // réindex le tableau $children au passage $main->reindexPositions(); - $entityManager->remove($bloc); // suppression en BDD + if(isset($page)){ + $entityManager->persist($page); + } + $entityManager->remove($block); $entityManager->flush(); } -- cgit v1.2.3