summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controller/Director.php2
-rw-r--r--src/controller/ajax.php46
-rw-r--r--src/model/Path.php6
-rw-r--r--src/model/entities/Node.php10
-rw-r--r--src/view/GridBuilder.php4
-rw-r--r--src/view/MainBuilder.php18
-rw-r--r--src/view/NewBuilder.php63
7 files changed, 96 insertions, 53 deletions
diff --git a/src/controller/Director.php b/src/controller/Director.php
index db84661..b7be9b8 100644
--- a/src/controller/Director.php
+++ b/src/controller/Director.php
@@ -87,7 +87,7 @@ class Director
87 } 87 }
88 } 88 }
89 if(isset($new)){ 89 if(isset($new)){
90 $main->setTempChild($new); 90 $main->setAdoptedChild($new);
91 } 91 }
92 } 92 }
93 93
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index b5c2e51..4863681 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -18,32 +18,54 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action']))
18 if(json_last_error() === JSON_ERROR_NONE) 18 if(json_last_error() === JSON_ERROR_NONE)
19 { 19 {
20 $id = $json['id']; 20 $id = $json['id'];
21 $content = Security::secureString($json['content']);
22 $director = new Director($entityManager); 21 $director = new Director($entityManager);
23 22
24 // nouvel article 23 // cas d'une nouvelle "news"
25 if($id[0] === 'n') 24 if(is_array($json['content'])){
26 { 25 foreach($json['content'] as $one_input){
26 $one_input = Security::secureString($one_input);
27 }
28 $content = $json['content'];
29 }
30 else{
31 $content = Security::secureString($json['content']);
27 if($content === ''){ 32 if($content === ''){
28 echo json_encode(['success' => false, 'message' => 'pas de données à sauvegarder']); 33 echo json_encode(['success' => false, 'message' => 'pas de données à sauvegarder']);
29 die; 34 die;
30 } 35 }
36 }
37
38 // nouvel article
39 if($id[0] === 'n')
40 {
31 $section_id = (int)substr($id, 1); // id du bloc <section> 41 $section_id = (int)substr($id, 1); // id du bloc <section>
32 $director->makeSectionNode($section_id); 42 $director->makeSectionNode($section_id);
33 $node = $director->getNode(); // = <section> 43 $node = $director->getNode(); // = <section>
34 44
35 $timestamp = time(); 45 if(is_array($content)){
36 $date = new \DateTime; 46 //
37 $date->setTimestamp($timestamp); 47 //$timestamp = time(); // int
48 $date = new \DateTime($content['d']);
49
50 //echo substr($content['i'], 1) . ' ';
51 //echo $article_id;die;
52 $article = new Article($content['i'], $date, $content['t'], $content['p']);
53 $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article);
38 54
39 $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD 55 // id_node tout juste généré
40 $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); 56 //$article_node->getId();
57 }
58 else{
59 $timestamp = time();
60 $date = new \DateTime;
61 $date->setTimestamp($timestamp);
62
63 $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD
64 $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article);
65 }
41 66
42 $entityManager->persist($article_node); 67 $entityManager->persist($article_node);
43 $entityManager->flush(); 68 $entityManager->flush();
44
45 // id_node tout juste généré
46 //$article_node->getId();
47 69
48 echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); 70 echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]);
49 die; 71 die;
diff --git a/src/model/Path.php b/src/model/Path.php
index 6faadfd..11be6fe 100644
--- a/src/model/Path.php
+++ b/src/model/Path.php
@@ -17,12 +17,6 @@ class Path extends Page
17 $this->findPage(Director::$menu_data, $path_array); // remplit $this->current_page 17 $this->findPage(Director::$menu_data, $path_array); // remplit $this->current_page
18 } 18 }
19 catch(Exception $e){} 19 catch(Exception $e){}
20 /*echo "nb d'autres pages: " . count(Director::$menu_data->getOtherPages()) . '<br>';
21 echo 'longueur du chemin: ' . count($this->current_page) . '<br>';
22 foreach($this->current_page as $current){
23 echo $current->getEndOfPath() . ' ';
24 }
25 die;*/
26 } 20 }
27 21
28 // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu 22 // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index c9b310a..a52a7e6 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -52,7 +52,7 @@ class Node
52 // -- fin des attributs destinés à doctrine, début du code utilisateur -- 52 // -- fin des attributs destinés à doctrine, début du code utilisateur --
53 53
54 private array $children = []; // tableau de Node 54 private array $children = []; // tableau de Node
55 private ?self $temp_child = null; // = "new" est l'enfant de "main" lorsque la page est "article" 55 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
56 56
57 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) 57 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null)
58 { 58 {
@@ -176,12 +176,12 @@ class Node
176 $this->children = array_values($this->children); // réindexer pour supprimer la case vide 176 $this->children = array_values($this->children); // réindexer pour supprimer la case vide
177 } 177 }
178 178
179 public function getTempChild(): ?self // peut renvoyer null 179 public function getAdoptedChild(): ?self // peut renvoyer null
180 { 180 {
181 return $this->temp_child; 181 return $this->adopted;
182 } 182 }
183 public function setTempChild(self $child): void 183 public function setAdoptedChild(self $child): void
184 { 184 {
185 $this->temp_child = $child; 185 $this->adopted = $child;
186 } 186 }
187} 187}
diff --git a/src/view/GridBuilder.php b/src/view/GridBuilder.php
index e183e6f..fdc5426 100644
--- a/src/view/GridBuilder.php
+++ b/src/view/GridBuilder.php
@@ -27,9 +27,9 @@ class GridBuilder extends AbstractBuilder
27 $share_button = '<p class="share hidden"><img class="action_icon" src="assets/share.svg"></p>'; 27 $share_button = '<p class="share hidden"><img class="action_icon" src="assets/share.svg"></p>';
28 $html = ''; 28 $html = '';
29 29
30 if(CURRENT_PAGE === 'accueil'){ 30 if(Director::$page_path->getLast()->getEndOfPath() === 'accueil'){
31 $new_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'article', 'id' => $id]) . '"> 31 $new_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'article', 'id' => $id]) . '">
32 <button><img class="action_icon" src="assets/book-open.svg">Nouvel article</button></a></p>'; 32 <button><img class="action_icon" src="assets/edit.svg">Nouvel article</button></a></p>';
33 } 33 }
34 else{ 34 else{
35 $new_button = '<p id="new-' . $id . '">' . "\n" . 35 $new_button = '<p id="new-' . $id . '">' . "\n" .
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php
index a44570b..ea7b8c3 100644
--- a/src/view/MainBuilder.php
+++ b/src/view/MainBuilder.php
@@ -1,6 +1,7 @@
1<?php 1<?php
2// src/view/MainBuilder.php 2// src/view/MainBuilder.php
3 3
4use App\Entity\Article;
4use App\Entity\Node; 5use App\Entity\Node;
5 6
6class MainBuilder extends AbstractBuilder 7class MainBuilder extends AbstractBuilder
@@ -10,11 +11,22 @@ class MainBuilder extends AbstractBuilder
10 $this->html .= "<main>\n"; 11 $this->html .= "<main>\n";
11 12
12 if(Director::$page_path->getLast()->getEndOfPath() === 'article'){ 13 if(Director::$page_path->getLast()->getEndOfPath() === 'article'){
13 if($node->getTempChild() == null){ 14 // pas censé arriver
14 $new = new Node; 15 if(!isset($_GET['id'])){
16 header('Location: ' . new URL);
17 die;
18 }
19
20 if($node->getAdoptedChild() == null){
21 // on pourrait raccourcir ça
22 $timestamp = time(); // int
23 $date = new \DateTime;
24 $date->setTimestamp($timestamp); // \DateTime
25 $article = new Article('', $date);
26 $new = new Node('new', 'i' . (string)$timestamp, [], 0, null, null, $article);
15 } 27 }
16 else{ 28 else{
17 $new = $node->getTempChild(); 29 $new = $node->getAdoptedChild();
18 } 30 }
19 //$builder_name = $this->snakeToPascalCase($new->getName()) . 'Builder'; 31 //$builder_name = $this->snakeToPascalCase($new->getName()) . 'Builder';
20 $builder_name = 'NewBuilder'; 32 $builder_name = 'NewBuilder';
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php
index acde8b4..a862a08 100644
--- a/src/view/NewBuilder.php
+++ b/src/view/NewBuilder.php
@@ -5,7 +5,7 @@ use App\Entity\Node;
5 5
6class NewBuilder extends AbstractBuilder 6class NewBuilder extends AbstractBuilder
7{ 7{
8 public function __construct(Node $node) 8 public function __construct(Node $node, )
9 { 9 {
10 $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; 10 $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
11 11
@@ -50,10 +50,15 @@ class NewBuilder extends AbstractBuilder
50 //$date = str_replace(':', 'h', $date_object->format('d-m-Y à H:i')); 50 //$date = str_replace(':', 'h', $date_object->format('d-m-Y à H:i'));
51 51
52 // partage 52 // partage
53 $share_link = new URL(['page' => CURRENT_PAGE], $id); 53 $share_link = new URL(['page' => 'article', 'id' => $id]);
54 isset($_GET['id']) ? $share_link->addParams(['id' => $_GET['id']]) : '';
55 $share_js = 'onclick="copyInClipBoard(\'' . $share_link . '\')"'; 54 $share_js = 'onclick="copyInClipBoard(\'' . $share_link . '\')"';
56 $share_button = '<a class="share" href="' . $share_link . '" ' . $share_js . '><img class="action_icon" src="assets/share.svg"></a>' . "\n"; 55 if(isset($_GET['id']) && $_GET['id'][0] === 'n'){
56 $class = 'class="share hidden"';
57 }
58 else{
59 $class = 'class="share"';
60 }
61 $share_button = '<p ' . $class . ' ' . $share_js . '><img class="action_icon" src="assets/share.svg"></p>' . "\n";
57 62
58 // modifier un article 63 // modifier un article
59 $title_buttons = ''; 64 $title_buttons = '';
@@ -65,53 +70,64 @@ class NewBuilder extends AbstractBuilder
65 { 70 {
66 if(Director::$page_path->getLast()->getEndOfPath() === 'article'){ 71 if(Director::$page_path->getLast()->getEndOfPath() === 'article'){
67 $title_js = 'onclick="openEditor(\'' . $id_title . '\', \'article\')"'; 72 $title_js = 'onclick="openEditor(\'' . $id_title . '\', \'article\')"';
68 $modify_title = '<p id="edit-' . $id_title . '"><a href="#"><button ' . $title_js . '><img class="action_icon" src="assets/edit.svg">Titre</button></a></p>' . "\n"; 73 $modify_title = '<p id="edit-' . $id_title . '"><button ' . $title_js . '><img class="action_icon" src="assets/edit.svg">Titre</button></p>' . "\n";
69 $close_js_title = 'onclick="closeEditor(\'' . $id_title . '\', \'article\', \'preview\')"'; 74 $close_js_title = 'onclick="closeEditor(\'' . $id_title . '\', \'article\', \'preview\')"';
70 $close_editor_title = '<p id="cancel-' . $id_title . '" class="hidden"><a href="#"><button ' . $close_js_title . '>Annuler</button></a></p>'; 75 $close_editor_title = '<p id="cancel-' . $id_title . '" class="hidden"><button ' . $close_js_title . '>Annuler</button></p>';
71 $submit_js_title = 'onclick="submitArticle(\'' . $id_title . '\', \'article\')"'; 76 $submit_js_title = 'onclick="submitArticle(\'' . $id_title . '\', \'article\')"';
72 $submit_title = '<p id="submit-' . $id_title . '" class="hidden"><a href="#"><button ' . $submit_js_title . '>Valider</button></a></p>'; 77 $submit_title = '<p id="submit-' . $id_title . '" class="hidden"><button ' . $submit_js_title . '>Valider</button></p>';
73 $title_buttons = '<div class="button_zone">' . $modify_title . $close_editor_title . $submit_title . '</div>'; 78 $title_buttons = '<div class="button_zone">' . $modify_title . $close_editor_title . $submit_title . '</div>';
74 79
75 $preview_js = 'onclick="openEditor(\'' . $id_preview . '\', \'article\')"'; 80 $preview_js = 'onclick="openEditor(\'' . $id_preview . '\', \'article\')"';
76 $modify_preview = '<p id="edit-' . $id_preview . '"><a href="#"><button ' . $preview_js . '><img class="action_icon" src="assets/edit.svg">Aperçu</button></a></p>' . "\n"; 81 $modify_preview = '<p id="edit-' . $id_preview . '"><button ' . $preview_js . '><img class="action_icon" src="assets/edit.svg">Aperçu</button></a></p>' . "\n";
77 $close_js_preview = 'onclick="closeEditor(\'' . $id_preview . '\', \'article\', \'preview\')"'; 82 $close_js_preview = 'onclick="closeEditor(\'' . $id_preview . '\', \'article\', \'preview\')"';
78 $close_editor_preview = '<p id="cancel-' . $id_preview . '" class="hidden"><a href="#"><button ' . $close_js_preview . '>Annuler</button></a></p>'; 83 $close_editor_preview = '<p id="cancel-' . $id_preview . '" class="hidden"><button ' . $close_js_preview . '>Annuler</button></p>';
79 $submit_js_preview = 'onclick="submitArticle(\'' . $id_preview . '\', \'article\')"'; 84 $submit_js_preview = 'onclick="submitArticle(\'' . $id_preview . '\', \'article\')"';
80 $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><a href="#"><button ' . $submit_js_preview . '>Valider</button></a></p>'; 85 $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><button ' . $submit_js_preview . '>Valider</button></p>';
81 $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>'; 86 $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>';
82 87
83 $article_js = 'onclick="openEditor(\'' . $id . '\', \'article\')"'; 88 $article_js = 'onclick="openEditor(\'' . $id . '\', \'article\')"';
84 $modify_article = '<p id="edit-' . $id . '"><a href="#"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></a></p>' . "\n"; 89 $modify_article = '<p id="edit-' . $id . '"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></p>' . "\n";
85 $close_js_article = 'onclick="closeEditor(\'' . $id . '\', \'article\')"'; 90 $close_js_article = 'onclick="closeEditor(\'' . $id . '\', \'article\')"';
86 $close_editor_article = '<p id="cancel-' . $id . '" class="hidden"><a href="#"><button ' . $close_js_article . '>Annuler</button></a></p>'; 91 $close_editor_article = '<p id="cancel-' . $id . '" class="hidden"><button ' . $close_js_article . '>Annuler</button></p>';
87 $submit_js_article = 'onclick="submitArticle(\'' . $id . '\', \'article\')"'; 92 $submit_js_article = 'onclick="submitArticle(\'' . $id . '\', \'article\')"';
88 $submit_article = '<p id="submit-' . $id . '" class="hidden"><a href="#"><button ' . $submit_js_article . '>Valider</button></a></p>'; 93 $submit_article = '<p id="submit-' . $id . '" class="hidden"><button ' . $submit_js_article . '>Valider</button></p>';
89 $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>'; 94 $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>';
90 95
91 $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');'; 96 $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');';
92 $modify_date = '<p id="edit-' . $id_date . '"><a href="#"><button ' . $date_js . '"><img class="action_icon" src="assets/edit.svg">Date</button></a></p>' . "\n"; 97 $modify_date = '<p id="edit-' . $id_date . '"><button ' . $date_js . '"><img class="action_icon" src="assets/edit.svg">Date</button></p>' . "\n";
93 $close_js_date = 'onclick="closeInput(\'' . $id_date . '\')"'; 98 $close_js_date = 'onclick="closeInput(\'' . $id_date . '\')"';
94 $close_editor_date = '<p id="cancel-' . $id_date . '" class="hidden"><a href="#"><button ' . $close_js_date . '>Annuler</button></a></p>'; 99 $close_editor_date = '<p id="cancel-' . $id_date . '" class="hidden"><button ' . $close_js_date . '>Annuler</button></p>';
95 $submit_js_date = 'onclick="submitDate(\'' . $id_date . '\')"'; 100 $submit_js_date = 'onclick="submitDate(\'' . $id_date . '\')"';
96 $submit_date = '<p id="submit-' . $id_date . '" class="hidden"><a href="#"><button ' . $submit_js_date . '>Valider</button></a></p>'; 101 $submit_date = '<p id="submit-' . $id_date . '" class="hidden"><button ' . $submit_js_date . '>Valider</button></p>';
97 $date_buttons = '<div class="button_zone">' . $modify_date . $close_editor_date . $submit_date . '</div>'; 102 $date_buttons = '<div class="button_zone">' . $modify_date . $close_editor_date . $submit_date . '</div>';
98 103
99 $delete_js = 'onclick="deleteArticle(\'' . $id . '\', \'' . CURRENT_PAGE . '\')"'; 104 $delete_article = '';
100 $delete_article = '<p id="delete-' . $id . '"><a href="#"><button ' . $delete_js . '"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '>Retirer<br>la publication</button></a></p>' . "\n"; 105 $submit_article = '';
101 106 // modification: bouton "supprimer"
102 $admin_buttons = $delete_article; 107 if($_GET['id'][0] === 'i'){
108 $delete_js = 'onclick="deleteArticle(\'' . $id . '\', \'' . Director::$page_path->getLast()->getEndOfPath() . '\')"';
109 $delete_article = '<p id="delete-' . $id . '"><button ' . $delete_js . '><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '>Retirer<br>la publication</button></p>' . "\n";
110 }
111 // nouvel article: bouton pour valider la création d'un nouvel article
112 else{
113 $submit_js = 'onclick="submitArticle(\'' . $_GET['id'] . '\', \'' . Director::$page_path->getLast()->getEndOfPath() . '\')"';
114 $submit_article = '<p id="submit-' . $id . '"><button ' . $submit_js . '><img class="action_icon" src="assets/edit.svg">Tout<br>enregistrer</button></p>' . "\n";
115 }
116
117 $admin_buttons = $delete_article . $submit_article;
103 } 118 }
119 // page d'accueil
104 else{ 120 else{
105 $modify_article = '<p id="edit-' . $id . '"></p>' . "\n"; 121 $modify_article = '<p id="edit-' . $id . '"></p>' . "\n";
106 122
107 $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; 123 $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"';
108 $up_button = '<p id="position_up-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-up.svg" ' . $up_js . '></a></p>' . "\n"; 124 $up_button = '<p id="position_up-' . $id . '"><img class="action_icon" src="assets/arrow-up.svg" ' . $up_js . '></p>' . "\n";
109 125
110 $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; 126 $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"';
111 $down_button = '<p id="position_down-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-down.svg" ' . $down_js . '></a></p>' . "\n"; 127 $down_button = '<p id="position_down-' . $id . '"><img class="action_icon" src="assets/arrow-down.svg" ' . $down_js . '></p>' . "\n";
112 128
113 $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; 129 $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"';
114 $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; 130 $delete_article = '<p id="delete-' . $id . '"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></p>' . "\n";
115 131
116 $close_editor = '<p id="cancel-' . $id . '" class="hidden"></p>'; 132 $close_editor = '<p id="cancel-' . $id . '" class="hidden"></p>';
117 $submit_article = '<p id="submit-' . $id . '" class="hidden"></p>'; 133 $submit_article = '<p id="submit-' . $id . '" class="hidden"></p>';
@@ -120,7 +136,6 @@ class NewBuilder extends AbstractBuilder
120 136
121 $admin_buttons = $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; 137 $admin_buttons = $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article;
122 } 138 }
123
124 } 139 }
125 140
126 ob_start(); 141 ob_start();