summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-05-08 22:58:04 +0200
committerpolo <ordipolo@gmx.fr>2025-05-08 22:58:04 +0200
commit0f497d215de8e16739263e2718bd39640a6cc4d8 (patch)
treed241a0f95e34ee6e20d0221a9e8cae0e46379c10 /src
parent28698982ff6dc67a331788c2637bce8689121769 (diff)
downloadcms-0f497d215de8e16739263e2718bd39640a6cc4d8.zip
modif page, renommage et suppression, du responsive design, modif dans Director, notif toast
Diffstat (limited to 'src')
-rw-r--r--src/controller/Director.php26
-rw-r--r--src/controller/ajax.php39
-rw-r--r--src/controller/post.php34
-rw-r--r--src/model/Position.php4
-rw-r--r--src/model/entities/NodeData.php4
-rw-r--r--src/view/FooterBuilder.php28
-rw-r--r--src/view/MainBuilder.php26
-rw-r--r--src/view/templates/footer.php3
8 files changed, 132 insertions, 32 deletions
diff --git a/src/controller/Director.php b/src/controller/Director.php
index 56a90cb..b154432 100644
--- a/src/controller/Director.php
+++ b/src/controller/Director.php
@@ -36,6 +36,7 @@ class Director
36 return $this->article; 36 return $this->article;
37 } 37 }
38 38
39 // affichage d'une page ordinaire
39 public function makeRootNode(string $id = ''): void 40 public function makeRootNode(string $id = ''): void
40 { 41 {
41 // on récupère toutes les entrées 42 // on récupère toutes les entrées
@@ -91,6 +92,12 @@ class Director
91 } 92 }
92 } 93 }
93 94
95 // le basique
96 public function findNodeById(int $id): void
97 {
98 $this->node = $this->entityManager->find('App\Entity\Node', $id);
99 }
100
94 // récupération d'un article pour modification 101 // récupération d'un article pour modification
95 public function makeArticleNode(string $id = '', bool $get_section = false): bool 102 public function makeArticleNode(string $id = '', bool $get_section = false): bool
96 { 103 {
@@ -112,7 +119,8 @@ class Director
112 119
113 if($get_section){ 120 if($get_section){
114 $this->article = $bulk_data[0]; 121 $this->article = $bulk_data[0];
115 $this->makeSectionNode($bulk_data[0]->getParent()->getId()); 122 $this->findNodeById($bulk_data[0]->getParent()->getId());
123 $this->makeSectionNode();
116 } 124 }
117 else{ 125 else{
118 $this->article = $bulk_data[0]; 126 $this->article = $bulk_data[0];
@@ -122,31 +130,30 @@ class Director
122 } 130 }
123 131
124 // récupération des articles d'un bloc <section> à la création d'un article 132 // récupération des articles d'un bloc <section> à la création d'un article
125 public function makeSectionNode(int $section_id): bool 133 public function makeSectionNode(): bool
126 { 134 {
127 $section = $this->entityManager->find('App\Entity\Node', (string)$section_id);
128
129 $bulk_data = $this->entityManager 135 $bulk_data = $this->entityManager
130 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') 136 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent')
131 ->setParameter('parent', $section) 137 ->setParameter('parent', $this->node)
132 ->getResult(); 138 ->getResult();
133 139
134 foreach($bulk_data as $article){ 140 foreach($bulk_data as $article){
135 $section->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page 141 $this->node->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page
136 } 142 }
137 $this->node = $section;
138 return true; 143 return true;
139 } 144 }
140 145
141 public function findNodeByName(string $name): void 146 public function findUniqueNodeByName(string $name): void // = unique en BDD, donc sans "page" associée
142 { 147 {
143 $bulk_data = $this->entityManager 148 $bulk_data = $this->entityManager
144 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') 149 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name')
145 ->setParameter('name', $name) 150 ->setParameter('name', $name)
146 ->getResult(); 151 ->getResult();
147 $this->node = $bulk_data[0]; 152 $this->node = $bulk_data[0];
148 echo $this->page->getPageName() . ' '; 153 }
149 154
155 public function findItsChildren(): void
156 {
150 $bulk_data = $this->entityManager 157 $bulk_data = $this->entityManager
151 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') 158 ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page')
152 ->setParameter('parent', $this->node) 159 ->setParameter('parent', $this->node)
@@ -154,7 +161,6 @@ class Director
154 ->getResult(); 161 ->getResult();
155 foreach($bulk_data as $child){ 162 foreach($bulk_data as $child){
156 $this->node->addChild($child); 163 $this->node->addChild($child);
157 echo $child->getName() . ' ';
158 } 164 }
159 } 165 }
160} 166}
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index a20bd87..a6786d9 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -35,7 +35,8 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action']))
35 if($id[0] === 'n') 35 if($id[0] === 'n')
36 { 36 {
37 $section_id = (int)substr($id, 1); // id du bloc <section> 37 $section_id = (int)substr($id, 1); // id du bloc <section>
38 $director->makeSectionNode($section_id); 38 $director->findNodeById($section_id);
39 $director->makeSectionNode();
39 $node = $director->getNode(); // = <section> 40 $node = $director->getNode(); // = <section>
40 41
41 if(is_array($content)){ 42 if(is_array($content)){
@@ -205,6 +206,8 @@ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_
205 die; 206 die;
206} 207}
207 208
209
210/* -- page Menu et chemins -- */
208if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) 211if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
209{ 212{
210 // récupération des données 213 // récupération des données
@@ -347,7 +350,39 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
347 } 350 }
348} 351}
349 352
350// détection des requêtes de type XHR?, pas d'utilité pour l'instant 353
354/* -- mode Modification d'une page -- */
355if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['bloc_edit']))
356{
357 // récupération des données
358 $data = file_get_contents('php://input');
359 $json = json_decode($data, true);
360
361 // renommage d'un bloc
362 if($_GET['bloc_edit'] === 'rename_page_bloc')
363 {
364 if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){
365 $director = new Director($entityManager);
366 $director->findNodeById($json['bloc_id']);
367
368 // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé
369 $data = $director->getNode()->getNodeData()->getData();
370 $data['title'] = htmlspecialchars($json['bloc_title']);
371 $director->getNode()->getNodeData()->setData($data);
372
373 $entityManager->flush();
374 echo json_encode(['success' => true, 'title' => $data['title']]);
375 }
376 else{
377 echo json_encode(['success' => false]);
378 }
379 die;
380 }
381
382}
383
384
385// détection des requêtes de type XHR?, pas d'utilité à priori
351/*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ 386/*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
352 echo "requête XHR reçue par le serveur"; 387 echo "requête XHR reçue par le serveur";
353 die; 388 die;
diff --git a/src/controller/post.php b/src/controller/post.php
index 76ac72b..d437423 100644
--- a/src/controller/post.php
+++ b/src/controller/post.php
@@ -15,10 +15,13 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
15 /* -- mode Modification d'une page -- */ 15 /* -- mode Modification d'une page -- */
16 16
17 // ajout d'un bloc dans une page 17 // ajout d'un bloc dans une page
18 if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ 18 if(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null
19 && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden
20 {
19 $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data 21 $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data
20 $page = Director::$page_path->getLast(); 22 $page = Director::$page_path->getLast();
21 $director->findNodeByName('main'); 23 $director->findUniqueNodeByName('main');
24 $director->findItsChildren();
22 $main = $director->getNode(); 25 $main = $director->getNode();
23 $position = count($main->getChildren()) + 1; // position dans la fraterie 26 $position = count($main->getChildren()) + 1; // position dans la fraterie
24 27
@@ -37,7 +40,30 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
37 $entityManager->flush(); 40 $entityManager->flush();
38 header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); 41 header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page']));
39 } 42 }
43 // suppression d'un bloc de page
44 elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null
45 && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden
46 {
47 $director = new Director($entityManager, true);
48 $director->findUniqueNodeByName('main');
49 $director->findItsChildren();
50 //$director->findNodeById((int)$_POST['delete_bloc_id']);
51 $main = $director->getNode();
52 $bloc;
53 foreach($main->getChildren() as $child){
54 if($child->getId() === (int)$_POST['delete_bloc_id']){
55 $bloc = $child;
56 break;
57 }
58 }
59 $main->removeChild($bloc); // réindex le tableau $children au passage
60 $main->reindexPositions();
40 61
62 $entityManager->remove($bloc); // suppression en BDD
63 $entityManager->flush();
64 header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page']));
65 }
66
41 67
42 /* -- page Menu et chemins -- */ 68 /* -- page Menu et chemins -- */
43 69
@@ -60,7 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
60 $parent = Director::$menu_data; 86 $parent = Director::$menu_data;
61 } 87 }
62 $parent->addChild($page); // true pour réindexer les positions en BDD 88 $parent->addChild($page); // true pour réindexer les positions en BDD
63 $parent->reindex(); 89 $parent->reindexPositions();
64 90
65 $entityManager->persist($page); 91 $entityManager->persist($page);
66 $entityManager->flush(); 92 $entityManager->flush();
@@ -76,7 +102,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
76 } 102 }
77 103
78 $parent->removeChild($page); // suppression de $children avant de trier 104 $parent->removeChild($page); // suppression de $children avant de trier
79 $parent->reindex(); 105 $parent->reindexPositions();
80 106
81 $entityManager->remove($page); // suppression en BDD 107 $entityManager->remove($page); // suppression en BDD
82 $entityManager->flush(); 108 $entityManager->flush();
diff --git a/src/model/Position.php b/src/model/Position.php
index b5040df..8035481 100644
--- a/src/model/Position.php
+++ b/src/model/Position.php
@@ -30,12 +30,12 @@ trait Position
30 } 30 }
31 31
32 if($reindexation){ 32 if($reindexation){
33 $this->reindex(); 33 $this->reindexPositions();
34 } 34 }
35 } 35 }
36 36
37 // nouvelles positions (tableau $children => BDD) 37 // nouvelles positions (tableau $children => BDD)
38 public function reindex(): void 38 public function reindexPositions(): void
39 { 39 {
40 $i = 1; 40 $i = 1;
41 foreach($this->children as $child){ 41 foreach($this->children as $child){
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index ddf6083..aaffb6a 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -47,11 +47,11 @@ class NodeData
47 { 47 {
48 return $this->data; 48 return $this->data;
49 } 49 }
50 /*public function setData(array $data): void 50 public function setData(array $data): void
51 { 51 {
52 $this->data = $data; 52 $this->data = $data;
53 } 53 }
54 public function setNode(Node $node): void 54 /*public function setNode(Node $node): void
55 { 55 {
56 $this->node = $node; 56 $this->node = $node;
57 }*/ 57 }*/
diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php
index 8678f56..084e122 100644
--- a/src/view/FooterBuilder.php
+++ b/src/view/FooterBuilder.php
@@ -27,9 +27,19 @@ class FooterBuilder extends AbstractBuilder
27 //$zone_admin = ''; 27 //$zone_admin = '';
28 if($_SESSION['admin']) 28 if($_SESSION['admin'])
29 { 29 {
30 $div_admin = 'logged_in';
31 $empty_admin_zone = 'empty_admin_zone'; 30 $empty_admin_zone = 'empty_admin_zone';
32 $link_edit_page = new URL(['page' => CURRENT_PAGE, 'action' => 'modif_page']); 31 if(MainBuilder::$modif_mode){
32 $mode = 'modification de page';
33 $div_admin = 'logged_in modif_mode';
34 $link_edit_page = new URL(['page' => CURRENT_PAGE]);
35 $link_edit_label = 'Sortir du mode modification';
36 }
37 else{
38 $mode = 'administrateur';
39 $div_admin = 'logged_in';
40 $link_edit_page = new URL(['page' => CURRENT_PAGE, 'action' => 'modif_page']);
41 $link_edit_label = 'Modifier la page';
42 }
33 $link_new_page = new URL(['page' => 'nouvelle_page']); 43 $link_new_page = new URL(['page' => 'nouvelle_page']);
34 $link_change_paths = new URL(['page' => 'menu_chemins']); 44 $link_change_paths = new URL(['page' => 'menu_chemins']);
35 45
@@ -39,12 +49,14 @@ class FooterBuilder extends AbstractBuilder
39 $link_logout = new URL(['page' => CURRENT_PAGE, 'action' => 'deconnexion']); 49 $link_logout = new URL(['page' => CURRENT_PAGE, 'action' => 'deconnexion']);
40 isset($_GET['id']) ? $link_logout->addParams(['id' => $_GET['id']]) : ''; 50 isset($_GET['id']) ? $link_logout->addParams(['id' => $_GET['id']]) : '';
41 51
42 $zone_admin = '<p>Vous êtes en mode administrateur.' . "\n" . 52 $zone_admin = '<div class="admin_buttons_zone">
43 '<a href="' . $link_edit_page . '"><button>Modifier la page</button></a>' . "\n" . 53 <p>Vous êtes en mode ' . $mode . ".</p>\n" .
44 '<a href="' . $link_new_page . '"><button>Nouvelle page</button></a>' . "\n" . 54 '<div><a href="' . $link_edit_page . '"><button>' . $link_edit_label . '</button></a></div>' . "\n" .
45 '<a href="' . $link_change_paths . '"><button>Menu et chemins</button></a>' . "\n" . 55 '<div><a href="' . $link_new_page . '"><button>Nouvelle page</button></a></div>' . "\n" .
46 '<a href="' . $link_change_password . '"><button>Changer de mot de passe</button></a>' . "\n" . 56 '<div><a href="' . $link_change_paths . '"><button>Menu et chemins</button></a></div>' . "\n" .
47 '<a href="' . $link_logout . '"><button>Déconnexion</button></a></p>' . "\n"; 57 '<div><a href="' . $link_change_password . '"><button>Changer de mot de passe</button></a></div>' . "\n" .
58 '<div><a href="' . $link_logout . '"><button>Déconnexion</button></a></div>' . "\n" .
59 '</div>' . "\n";
48 } 60 }
49 else 61 else
50 { 62 {
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php
index fbdfbdd..4664c17 100644
--- a/src/view/MainBuilder.php
+++ b/src/view/MainBuilder.php
@@ -69,8 +69,9 @@ class MainBuilder extends AbstractBuilder
69 </aside>' . "\n";*/ 69 </aside>' . "\n";*/
70 70
71 // ajout d'un nouveau bloc 71 // ajout d'un nouveau bloc
72 $this->html .= '<div class="new_bloc"> 72 $this->html .= '<div class="edit_bloc_zone">
73 <p>Ajouter un bloc dans la page:</p> 73 <div class="new_bloc">
74 <p>Ajouter un bloc de page</p>
74 <form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '"> 75 <form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '">
75 <p><label for="bloc_title">Titre</label> 76 <p><label for="bloc_title">Titre</label>
76 <input type="text" id="bloc_title" name="bloc_title" required></p> 77 <input type="text" id="bloc_title" name="bloc_title" required></p>
@@ -78,11 +79,30 @@ class MainBuilder extends AbstractBuilder
78 <select id="bloc_select" name="bloc_select" required>' 79 <select id="bloc_select" name="bloc_select" required>'
79 . $options . 80 . $options .
80 '</select> 81 '</select>
82 <input type="hidden" name="bloc_title_hidden">
81 <input type="submit" value="Valider"></p> 83 <input type="submit" value="Valider"></p>
82 </form> 84 </form>
83 </div>' . "\n"; 85 </div>' . "\n";
86 $this->html .= '<div class="modify_bloc">
87 <p>Modifier un bloc</p>';
84 foreach($node->getChildren() as $child_node){ 88 foreach($node->getChildren() as $child_node){
85 //$this->html .= 89 // renommage d'un bloc
90 $this->html .= '<div>
91 <p><label for="bloc_rename_title">Titre</label>
92 <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required>
93 <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n";
94 // déplacement d'un bloc
95 $this->html .= '<img class="action_icon" onclick="switchBlocPositions(' . $child_node->getId() . ', \'up\')" src="assets/arrow-up.svg">
96 <img class="action_icon" onclick="switchBlocPositions(' . $child_node->getId() . ', \'down\')" src="assets/arrow-down.svg">' . "\n";
97 // suppression d'un bloc
98 $this->html .= '<form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '">
99 <input type="hidden" name="delete_bloc_id" value="' . $child_node->getId() . '">
100 <input type="hidden" name="delete_bloc_hidden">
101 <input type="submit" value="Supprimer"></p>
102 </form>
103 </div>'. "\n";
86 } 104 }
105 $this->html .= "</div>
106 </div>\n";
87 } 107 }
88} 108}
diff --git a/src/view/templates/footer.php b/src/view/templates/footer.php
index 52cb1b5..8f6d465 100644
--- a/src/view/templates/footer.php
+++ b/src/view/templates/footer.php
@@ -7,11 +7,12 @@
7 <a href="mailto:<?= $e_mail ?>"><?= $e_mail ?></a></p> 7 <a href="mailto:<?= $e_mail ?>"><?= $e_mail ?></a></p>
8 <p class="footer_logo"><img src="<?= $logo_footer ?>" alt="logo"><p> 8 <p class="footer_logo"><img src="<?= $logo_footer ?>" alt="logo"><p>
9 </div> 9 </div>
10 </footer>
11 <div class="<?= $empty_admin_zone ?>"></div> 10 <div class="<?= $empty_admin_zone ?>"></div>
12 <div class="<?= $div_admin ?>"> 11 <div class="<?= $div_admin ?>">
13<?= $zone_admin ?> 12<?= $zone_admin ?>
14 </div> 13 </div>
14 <div id="toast"></div>
15 </footer>
15 </div> 16 </div>
16 </body> 17 </body>
17</html> \ No newline at end of file 18</html> \ No newline at end of file