aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-10-20 15:36:59 +0200
committerpolo <ordipolo@gmx.fr>2025-10-20 15:36:59 +0200
commit6535db259081b02e9db59b905ae922a37d03eddc (patch)
treeccd2d4d06e1128f28bfb512c1db66f9a138c6f05
parent1e2cee519264f9ab2660540723915aec72bc2116 (diff)
downloadcms-6535db259081b02e9db59b905ae922a37d03eddc.zip
méthodes dans Page pour les fichiers CSS/JS, CCS/JS par défaut supprimé de la BDD, nettoyage quand le dernier bloc est supprimé
-rw-r--r--src/controller/PageManagementController.php43
-rw-r--r--src/installation.php2
-rw-r--r--src/model/Menu.php2
-rw-r--r--src/model/entities/Page.php36
4 files changed, 49 insertions, 34 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
diff --git a/src/installation.php b/src/installation.php
index df0f851..5a56f6b 100644
--- a/src/installation.php
+++ b/src/installation.php
@@ -87,7 +87,7 @@ HTACCESS;
87// création d'un site minimal avec une page d'accueil à la toute 1ère visite du site 87// création d'un site minimal avec une page d'accueil à la toute 1ère visite du site
88// fonctiona appelée après la première requête envoyée en BDD, 88// fonctiona appelée après la première requête envoyée en BDD,
89// en l'occurence dans Menu parce que count($bulk_data) === 0 89// en l'occurence dans Menu parce que count($bulk_data) === 0
90function makeStartPage(EntityManager $entityManager){ 90function fillStartingDatabase(EntityManager $entityManager){
91 /* -- table page -- */ 91 /* -- table page -- */
92 // paramètres: name_page, end_of_path, reachable, in_menu, hidden, position, parent 92 // paramètres: name_page, end_of_path, reachable, in_menu, hidden, position, parent
93 $accueil = new Page('Accueil', 'accueil', "Page d'accueil", true, true, false, 1, NULL); 93 $accueil = new Page('Accueil', 'accueil', "Page d'accueil", true, true, false, 1, NULL);
diff --git a/src/model/Menu.php b/src/model/Menu.php
index 9fb8562..4817b93 100644
--- a/src/model/Menu.php
+++ b/src/model/Menu.php
@@ -20,7 +20,7 @@ class Menu extends Page
20 ->getResult(); // :array de Page 20 ->getResult(); // :array de Page
21 21
22 if(count($bulk_data) === 0){ 22 if(count($bulk_data) === 0){
23 makeStartPage($entityManager); // => installation.php 23 fillStartingDatabase($entityManager); // => installation.php
24 } 24 }
25 25
26 foreach($bulk_data as $first_level_entries){ 26 foreach($bulk_data as $first_level_entries){
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php
index 3e90dbc..8d3dd40 100644
--- a/src/model/entities/Page.php
+++ b/src/model/entities/Page.php
@@ -40,14 +40,6 @@ class Page
40 static private array $default_css = ['body', 'head', 'nav', 'foot']; 40 static private array $default_css = ['body', 'head', 'nav', 'foot'];
41 static private array $default_js = ['main']; 41 static private array $default_js = ['main'];
42 42
43 /* remplissage
44 UPDATE nb_page
45 JOIN nb_node ON nb_node.page_id = nb_page.id_page
46 SET nb_page.css = JSON_EXTRACT(nb_node.attributes, '$.css_array');
47 UPDATE nb_page
48 JOIN nb_node ON nb_node.page_id = nb_page.id_page
49 SET nb_page.js = JSON_EXTRACT(nb_node.attributes, '$.js_array'); */
50
51 #[ORM\Column(type: "boolean")] 43 #[ORM\Column(type: "boolean")]
52 private bool $reachable; 44 private bool $reachable;
53 45
@@ -120,30 +112,38 @@ class Page
120 { 112 {
121 $this->description = $description; 113 $this->description = $description;
122 } 114 }
115
123 public function getCSS(): array 116 public function getCSS(): array
124 { 117 {
125 return $this->css; 118 return array_merge(self::$default_css, $this->css ?? []);
126 } 119 }
127 public function useDefaultCSS(): void 120 public function addCSS(string $css): void
128 { 121 {
129 $this->css = self::$default_css; 122 if(!in_array($css, $this->css ?? [])){
123 $this->css[] = $css;
124 }
130 } 125 }
131 public function setCSS(array $css): void 126 public function removeCSS(string $css): void
132 { 127 {
133 $this->css = $css; 128 // array_diff renvoie une copie du 1er tableau alégée des élements existants aussi dans le 2è, array_values réindexe
129 $this->css = array_values(array_diff($this->css, [$css]));
134 } 130 }
135 public function getJS(): array 131 public function getJS(): array
136 { 132 {
137 return $this->js; 133 return array_merge(self::$default_js, $this->js ?? []);
134 //UPDATE `nb_page` SET `js` = NULL WHERE JSON_EQUALS(`js`, '["main"]');
138 } 135 }
139 public function useDefaultJS(): void 136 public function addJS(string $js): void
140 { 137 {
141 $this->js = self::$default_js; 138 if(!in_array($js, $this->js ?? [])){
139 $this->js[] = $js;
140 }
142 } 141 }
143 public function setJS(array $js): void 142 public function removeJS(string $js): void
144 { 143 {
145 $this->js = $js; 144 $this->js = array_values(array_diff($this->js, [$js]));
146 } 145 }
146
147 public function isReachable(): bool 147 public function isReachable(): bool
148 { 148 {
149 return $this->reachable; 149 return $this->reachable;