From 09bea09c8157ff45279f0d06aa9d313448c0bec5 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 7 Apr 2025 07:46:27 +0200 Subject: nouvelle "news" --- src/controller/ajax.php | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'src/controller/ajax.php') 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'])) if(json_last_error() === JSON_ERROR_NONE) { $id = $json['id']; - $content = Security::secureString($json['content']); $director = new Director($entityManager); - // nouvel article - if($id[0] === 'n') - { + // cas d'une nouvelle "news" + if(is_array($json['content'])){ + foreach($json['content'] as $one_input){ + $one_input = Security::secureString($one_input); + } + $content = $json['content']; + } + else{ + $content = Security::secureString($json['content']); if($content === ''){ echo json_encode(['success' => false, 'message' => 'pas de données à sauvegarder']); die; } + } + + // nouvel article + if($id[0] === 'n') + { $section_id = (int)substr($id, 1); // id du bloc
$director->makeSectionNode($section_id); $node = $director->getNode(); // =
- $timestamp = time(); - $date = new \DateTime; - $date->setTimestamp($timestamp); + if(is_array($content)){ + // + //$timestamp = time(); // int + $date = new \DateTime($content['d']); + + //echo substr($content['i'], 1) . ' '; + //echo $article_id;die; + $article = new Article($content['i'], $date, $content['t'], $content['p']); + $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); - $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD - $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); + // id_node tout juste généré + //$article_node->getId(); + } + else{ + $timestamp = time(); + $date = new \DateTime; + $date->setTimestamp($timestamp); + + $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD + $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); + } $entityManager->persist($article_node); $entityManager->flush(); - - // id_node tout juste généré - //$article_node->getId(); echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); die; -- cgit v1.2.3