diff options
Diffstat (limited to 'src/controller/ajax.php')
-rw-r--r-- | src/controller/ajax.php | 46 |
1 files changed, 34 insertions, 12 deletions
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; |