summaryrefslogtreecommitdiff
path: root/src/controller/post.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/post.php')
-rw-r--r--src/controller/post.php65
1 files changed, 61 insertions, 4 deletions
diff --git a/src/controller/post.php b/src/controller/post.php
index 631c4ad..6fac796 100644
--- a/src/controller/post.php
+++ b/src/controller/post.php
@@ -12,14 +12,70 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
12 /* -- formulaires HTML classiques -- */ 12 /* -- formulaires HTML classiques -- */
13 if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') 13 if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded')
14 { 14 {
15 /* -- nouvelle page -- */
16 if(isset($_POST['page_name']) && $_POST['page_name'] !== null
17 && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null
18 && isset($_POST['page_location']) && $_POST['page_location'] !== null
19 && isset($_POST['page_description']) && $_POST['page_description'] !== null
20 && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '')
21 {
22 // titre et chemin
23 $director = new Director($entityManager, true);
24 //Director::$menu_data = new Menu($entityManager);
25 $previous_page = Director::$menu_data->findPageById((int)$_POST["page_location"]); // (int) à cause de declare(strict_types=1);
26 $parent = $previous_page->getParent();
27
28 $page = new Page(
29 trim(htmlspecialchars($_POST["page_name"])),
30 trim(htmlspecialchars($_POST["page_name_path"])),
31 true, true, false,
32 $previous_page->getPosition(),
33 $parent); // peut et DOIT être null si on est au 1er niveau
34
35 // on a donné à la nouvelle entrée la même position qu'à la précédente,
36 // addChild l'ajoute à la fin du tableau "children" puis on trie
37 // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position
38 if($parent == null){
39 $parent = Director::$menu_data;
40 }
41 $parent->addChild($page);
42 $parent->reindexPositions();
43
44 $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/'));
45
46 // noeud "head"
47 $node = new Node(
48 'head',
49 null, [],
50 1, // position d'un head = 1
51 null, // pas de parent
52 $page);
53 $node->useDefaultAttributes(); // fichiers CSS et JS
54
55 $data = new NodeData([
56 'title' => trim(htmlspecialchars($_POST["page_name"])),
57 'description' => trim(htmlspecialchars($_POST["page_description"]))],
58 $node);
59
60 $entityManager->persist($page);
61 $entityManager->persist($node);
62 $entityManager->persist($data);
63 $entityManager->flush();
64
65 // page créée, direction la page en mode modification pour ajouter des blocs
66 header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page']));
67 die;
68 }
69
15 /* -- mode Modification d'une page -- */ 70 /* -- mode Modification d'une page -- */
16 if(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null 71
72 // modification des titres, chemins et descriptions
73 elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null
17 && isset($_POST['page_id']) && $_POST['page_id'] !== null 74 && isset($_POST['page_id']) && $_POST['page_id'] !== null
18 && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') 75 && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '')
19 { 76 {
20 $director = new Director($entityManager, true); 77 $director = new Director($entityManager, true);
21 $page = Director::$page_path->getLast(); 78 $page = Director::$page_path->getLast();
22 //$page = $entityManager->find('App\Entity\Page', $_POST['page_id']);
23 $path = htmlspecialchars($_POST['page_menu_path']); 79 $path = htmlspecialchars($_POST['page_menu_path']);
24 80
25 // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores 81 // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores
@@ -101,9 +157,10 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true)
101 filter_var($_POST["url_input"], FILTER_VALIDATE_URL), 157 filter_var($_POST["url_input"], FILTER_VALIDATE_URL),
102 true, true, false, 158 true, true, false,
103 $previous_page->getPosition(), 159 $previous_page->getPosition(),
104 $parent); 160 $parent); // peut et DOIT être null si on est au 1er niveau
105 161
106 // on indique pour la nouvelle entrée la même position que la précédente, puis addChild l'ajoute à la fin du tableau "children" avant de déclencher un tri 162 // on a donné à la nouvelle entrée la même position qu'à la précédente,
163 // addChild l'ajoute à la fin du tableau "children" puis on trie
107 // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position 164 // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position
108 if($parent == null){ 165 if($parent == null){
109 $parent = Director::$menu_data; 166 $parent = Director::$menu_data;