diff options
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/ArticleController.php | 30 | ||||
-rw-r--r-- | src/controller/Director.php | 6 | ||||
-rw-r--r-- | src/controller/PageManagementController.php | 11 |
3 files changed, 19 insertions, 28 deletions
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index 5cebad6..cb132cf 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php | |||
@@ -15,6 +15,10 @@ class ArticleController | |||
15 | if(json_last_error() === JSON_ERROR_NONE) | 15 | if(json_last_error() === JSON_ERROR_NONE) |
16 | { | 16 | { |
17 | $id = $json['id']; | 17 | $id = $json['id']; |
18 | if(in_array($id[0], ['t', 'p', 'i', 'd'])){ | ||
19 | $id = substr($id, 1); | ||
20 | } | ||
21 | |||
18 | $director = new Director($entityManager); | 22 | $director = new Director($entityManager); |
19 | $content = $json['content']; | 23 | $content = $json['content']; |
20 | 24 | ||
@@ -29,7 +33,7 @@ class ArticleController | |||
29 | } | 33 | } |
30 | 34 | ||
31 | // nouvel article | 35 | // nouvel article |
32 | if($id[0] === 'n') | 36 | if($json['id'][0] === 'n') // ici $id est un bloc |
33 | { | 37 | { |
34 | $section_id = (int)substr($id, 1); // id du bloc <section> | 38 | $section_id = (int)substr($id, 1); // id du bloc <section> |
35 | if(!$director->findNodeById($section_id)){ | 39 | if(!$director->findNodeById($section_id)){ |
@@ -40,9 +44,9 @@ class ArticleController | |||
40 | $node = $director->getNode(); // = <section> | 44 | $node = $director->getNode(); // = <section> |
41 | 45 | ||
42 | if(is_array($content)){ // cas d'une nouvelle "news" | 46 | if(is_array($content)){ // cas d'une nouvelle "news" |
43 | $date = new \DateTime($content['d']); | 47 | $date = new \DateTime($content['d'] . ':' . (new \DateTime)->format('s')); // l'input type="datetime-local" ne donne pas les secondes, on les ajoute: 'hh:mm' . ':ss' |
44 | $article = new Article($content['i'], $date, $content['t'], $content['p']); | 48 | $article = new Article($content['i'], $date, $content['t'], $content['p']); |
45 | $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); | 49 | $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); |
46 | } | 50 | } |
47 | else{ // autres cas | 51 | else{ // autres cas |
48 | $timestamp = time(); | 52 | $timestamp = time(); |
@@ -50,9 +54,8 @@ class ArticleController | |||
50 | $date->setTimestamp($timestamp); | 54 | $date->setTimestamp($timestamp); |
51 | 55 | ||
52 | $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD | 56 | $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD |
53 | |||
54 | $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; // | 57 | $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; // |
55 | $article_node = new Node('post', 'i' . (string)$timestamp, [], $placement, $node, $node->getPage(), $article); | 58 | $article_node = new Node('post', [], $placement, $node, $node->getPage(), $article); |
56 | 59 | ||
57 | if($json['placement'] === 'first'){ | 60 | if($json['placement'] === 'first'){ |
58 | $node->addChild($article_node); | 61 | $node->addChild($article_node); |
@@ -63,13 +66,11 @@ class ArticleController | |||
63 | $entityManager->persist($article_node); | 66 | $entityManager->persist($article_node); |
64 | $entityManager->flush(); | 67 | $entityManager->flush(); |
65 | 68 | ||
66 | echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); | 69 | echo json_encode(['success' => true, 'article_id' => $article_node->getId()]); |
67 | die; | 70 | die; |
68 | } | 71 | } |
69 | // modification article | 72 | // modification article |
70 | else{ | 73 | //else{} |
71 | $id[0] = 'i'; // id de l'article node | ||
72 | } | ||
73 | 74 | ||
74 | if($director->makeArticleNode($id)) // une entrée est trouvée | 75 | if($director->makeArticleNode($id)) // une entrée est trouvée |
75 | { | 76 | { |
@@ -87,9 +88,8 @@ class ArticleController | |||
87 | case 'd': | 88 | case 'd': |
88 | echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); | 89 | echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); |
89 | die; | 90 | die; |
90 | default: | 91 | default: // modif article simple (id sans lettre devant) |
91 | echo json_encode(['success' => false, 'message' => 'identifiant non utilisable']); | 92 | $node->getArticle()->setContent($content); |
92 | die; | ||
93 | } | 93 | } |
94 | $entityManager->flush(); | 94 | $entityManager->flush(); |
95 | echo json_encode(['success' => true]); | 95 | echo json_encode(['success' => true]); |
@@ -141,10 +141,9 @@ class ArticleController | |||
141 | $section = $director->getNode(); | 141 | $section = $director->getNode(); |
142 | 142 | ||
143 | $section->sortChildren(true); // régénère les positions avant inversion | 143 | $section->sortChildren(true); // régénère les positions avant inversion |
144 | |||
145 | $article2 = null; | 144 | $article2 = null; |
146 | foreach($section->getChildren() as $child){ | 145 | foreach($section->getChildren() as $child){ |
147 | if($child->getArticleTimestamp() === $json['id2']) // type string | 146 | if((string)$child->getId() === $json['id2']) // type string |
148 | { | 147 | { |
149 | $article2 = $child; | 148 | $article2 = $child; |
150 | break; | 149 | break; |
@@ -163,8 +162,7 @@ class ArticleController | |||
163 | 162 | ||
164 | static public function dateSubmit(EntityManager $entityManager, array $json): void | 163 | static public function dateSubmit(EntityManager $entityManager, array $json): void |
165 | { | 164 | { |
166 | $id = $json['id']; | 165 | $id = substr($json['id'], 1); |
167 | $id[0] = 'i'; | ||
168 | $date = new DateTime($json['date']); | 166 | $date = new DateTime($json['date']); |
169 | 167 | ||
170 | $director = new Director($entityManager); | 168 | $director = new Director($entityManager); |
diff --git a/src/controller/Director.php b/src/controller/Director.php index 6ee0993..8be9b59 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php | |||
@@ -50,7 +50,7 @@ class Director | |||
50 | } | 50 | } |
51 | else // avec $_GET['id'] dans l'URL | 51 | else // avec $_GET['id'] dans l'URL |
52 | { | 52 | { |
53 | $dql .= ' OR n.article_timestamp = :id'; | 53 | $dql .= ' OR n.id_node = :id'; |
54 | $bulk_data = $this->entityManager | 54 | $bulk_data = $this->entityManager |
55 | ->createQuery($dql) | 55 | ->createQuery($dql) |
56 | ->setParameter('page', $this->page) | 56 | ->setParameter('page', $this->page) |
@@ -105,10 +105,10 @@ class Director | |||
105 | public function makeArticleNode(string $id = '', bool $get_section = false): bool | 105 | public function makeArticleNode(string $id = '', bool $get_section = false): bool |
106 | { | 106 | { |
107 | if($get_section){ | 107 | if($get_section){ |
108 | $dql = 'SELECT n, p FROM App\Entity\Node n LEFT JOIN n.parent p WHERE n.article_timestamp = :id'; | 108 | $dql = 'SELECT n, p FROM App\Entity\Node n LEFT JOIN n.parent p WHERE n.id_node = :id'; |
109 | } | 109 | } |
110 | else{ | 110 | else{ |
111 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.article_timestamp = :id'; | 111 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.id_node = :id'; |
112 | } | 112 | } |
113 | // n est l'article et p son $parent | 113 | // n est l'article et p son $parent |
114 | $bulk_data = $this->entityManager | 114 | $bulk_data = $this->entityManager |
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index 75967eb..3d7edde 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
@@ -79,9 +79,7 @@ class PageManagementController | |||
79 | $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); | 79 | $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); |
80 | 80 | ||
81 | // noeud "head" | 81 | // noeud "head" |
82 | $node = new Node( | 82 | $node = new Node('head', [], |
83 | 'head', | ||
84 | null, [], | ||
85 | 1, // position d'un head = 1 | 83 | 1, // position d'un head = 1 |
86 | null, // pas de parent | 84 | null, // pas de parent |
87 | $page); | 85 | $page); |
@@ -163,12 +161,7 @@ class PageManagementController | |||
163 | $entityManager->persist($bulk_data[0]); | 161 | $entityManager->persist($bulk_data[0]); |
164 | } | 162 | } |
165 | 163 | ||
166 | $block = new Node( | 164 | $block = new Node($_POST["bloc_select"], [], $position, $main, $page); |
167 | $_POST["bloc_select"], | ||
168 | null, [], | ||
169 | $position, | ||
170 | $main, | ||
171 | $page); | ||
172 | $data = new NodeData( | 165 | $data = new NodeData( |
173 | ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], | 166 | ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], |
174 | $block); | 167 | $block); |