From e4a325c9d5c07f09bc18b7e366ffb82b82c43502 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 2 Apr 2025 00:00:35 +0200 Subject: =?UTF-8?q?modification=20des=20titres,=20aper=C3=A7us=20et=20date?= =?UTF-8?q?s=20des=20news?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ajax.php | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'src/controller/ajax.php') diff --git a/src/controller/ajax.php b/src/controller/ajax.php index bcba3f2..86acd39 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -14,16 +14,32 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) { if(json_last_error() === JSON_ERROR_NONE) { - $articleId = $json['id']; + $id = $json['id']; + $id[0] = 'i'; $content = Security::secureString($json['content']); $director = new Director($entityManager); - if($director->makeArticleNode($articleId)) // une entrée est trouvée + if($director->makeArticleNode($id)) // une entrée est trouvée { $node = $director->getRootNode(); - $node->getArticle()->setContent($content); + switch($json['id'][0]){ + case 'i': + $node->getArticle()->setContent($content); + break; + case 'p': + $node->getArticle()->setPreview($content); // html de l'éditeur + break; + case 't': + $node->getArticle()->setTitle($content); // html de l'éditeur + break; + case 'd': + echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); + die; + default: + echo json_encode(['success' => false, 'message' => 'identifiant non utilisable']); + die; + } $entityManager->flush(); - echo json_encode(['success' => true]); } else{ @@ -37,16 +53,16 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) } elseif($_GET['action'] === 'delete_article' && isset($json['id'])) { - $articleId = $json['id']; + $id = $json['id']; $director = new Director($entityManager); - $director->makeArticleNode($articleId); + $director->makeArticleNode($id); $node = $director->getRootNode(); $entityManager->remove($node); $entityManager->flush(); // test avec une nouvelle requête qui ne devrait rien trouver - if(!$director->makeArticleNode($articleId)) + if(!$director->makeArticleNode($id)) { echo json_encode(['success' => true]); @@ -72,6 +88,21 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) $node2->setPosition($tmp); $entityManager->flush(); + echo json_encode(['success' => true]); + die; + } + elseif($_GET['action'] === 'date_submit' && isset($json['id']) && isset($json['date'])) + { + $id = $json['id']; + $id[0] = 'i'; + $date = new DateTime($json['date']); + + $director = new Director($entityManager); + $director->makeArticleNode($id); + $node = $director->getRootNode(); + $node->getArticle()->setDateTime($date); + $entityManager->flush(); + echo json_encode(['success' => true]); die; } -- cgit v1.2.3