aboutsummaryrefslogtreecommitdiff
path: root/src/controller/PageManagementController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/PageManagementController.php')
-rw-r--r--src/controller/PageManagementController.php43
1 files changed, 29 insertions, 14 deletions
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
68 true, true, false, 68 true, true, false,
69 $previous_page->getPosition(), 69 $previous_page->getPosition(),
70 $parent); // peut et DOIT être null si on est au 1er niveau 70 $parent); // peut et DOIT être null si on est au 1er niveau
71 $page->useDefaultCSS();
72 $page->useDefaultJS();
73 71
74 // on a donné à la nouvelle entrée la même position qu'à la précédente, 72 // on a donné à la nouvelle entrée la même position qu'à la précédente,
75 // addChild l'ajoute à la fin du tableau "children" puis on trie 73 // addChild l'ajoute à la fin du tableau "children" puis on trie
@@ -126,11 +124,10 @@ class PageManagementController
126 die; 124 die;
127 } 125 }
128 126
129 if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ 127 if(in_array($_POST["bloc_select"], ['calendar', 'form'])){
130 $page->setCSS(array_merge($page->getCSS(), [$_POST["bloc_select"]])); 128 $page->addCSS($_POST["bloc_select"]);
131
132 if($_POST["bloc_select"] === 'form'){ 129 if($_POST["bloc_select"] === 'form'){
133 $page->setJS(array_merge($page->getJS(), [$_POST["bloc_select"]])); 130 $page->addJS($_POST["bloc_select"]);
134 } 131 }
135 $entityManager->persist($page); 132 $entityManager->persist($page);
136 } 133 }
@@ -146,7 +143,7 @@ class PageManagementController
146 $data->setPresentation('grid'); 143 $data->setPresentation('grid');
147 } 144 }
148 elseif($_POST["bloc_select"] === 'galery'){ 145 elseif($_POST["bloc_select"] === 'galery'){
149 $data->setPresentation('mosaic'); // mieux que carousel pour commencer 146 $data->setPresentation('mosaic'); // un jour on mettra carousel
150 } 147 }
151 // else = null par défaut 148 // else = null par défaut
152 149
@@ -163,19 +160,37 @@ class PageManagementController
163 $model->makeMenuAndPaths(); 160 $model->makeMenuAndPaths();
164 $model->findUniqueNodeByName('main'); 161 $model->findUniqueNodeByName('main');
165 $model->findItsChildren(); 162 $model->findItsChildren();
166 //$model->findNodeById((int)$_POST['delete_bloc_id']);
167 $main = $model->getNode(); 163 $main = $model->getNode();
168 $bloc = null; 164
165 $block = null;
166 $type = '';
167 $nb_same_type = 0;
169 foreach($main->getChildren() as $child){ 168 foreach($main->getChildren() as $child){
170 if($child->getId() === (int)$_POST['delete_bloc_id']){ 169 if($child->getId() === (int)$_POST['delete_bloc_id']){
171 $bloc = $child; 170 $block = $child;
172 break; 171 $type = $block->getName();
172 }
173 if($child->getName() === $type){
174 $nb_same_type++;
173 } 175 }
174 } 176 }
175 if(!empty($bloc)){ // si $bloc est null c'est que le HTML a été modifié volontairement 177
176 $main->removeChild($bloc); // réindex le tableau $children au passage 178 // nettoyage fichiers CSS et JS si on retire le derner bloc de ce type
179 if($nb_same_type === 1 && in_array($block->getName(), ['calendar', 'form'])){
180 $page = $block->getPage();
181 $page->removeCSS($block->getName());
182 if($block->getName() === 'form'){
183 $page->removeJS($block->getName());
184 }
185 }
186
187 if(!empty($block)){ // si $block est null c'est que le HTML a été modifié volontairement
188 $main->removeChild($block); // réindex le tableau $children au passage
177 $main->reindexPositions(); 189 $main->reindexPositions();
178 $entityManager->remove($bloc); // suppression en BDD 190 if(isset($page)){
191 $entityManager->persist($page);
192 }
193 $entityManager->remove($block);
179 $entityManager->flush(); 194 $entityManager->flush();
180 } 195 }
181 196