diff options
Diffstat (limited to 'src/controller/ArticleController.php')
| -rw-r--r-- | src/controller/ArticleController.php | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index b8af290..5cebad6 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php | |||
| @@ -16,15 +16,15 @@ class ArticleController | |||
| 16 | { | 16 | { |
| 17 | $id = $json['id']; | 17 | $id = $json['id']; |
| 18 | $director = new Director($entityManager); | 18 | $director = new Director($entityManager); |
| 19 | $content = $json['content']; | ||
| 19 | 20 | ||
| 20 | // cas d'une nouvelle "news" | 21 | // nettoyage |
| 21 | if(is_array($json['content'])){ | 22 | if(is_array($content)){ // cas d'une nouvelle "news" |
| 22 | foreach($json['content'] as $one_input){ | 23 | foreach($content as $one_input){ |
| 23 | $one_input = Security::secureHTML($one_input); | 24 | $one_input = Security::secureHTML($one_input); |
| 24 | } | 25 | } |
| 25 | $content = $json['content']; | ||
| 26 | } | 26 | } |
| 27 | else{ | 27 | else{ // autres cas |
| 28 | $content = Security::secureHTML($json['content']); | 28 | $content = Security::secureHTML($json['content']); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| @@ -39,21 +39,25 @@ class ArticleController | |||
| 39 | $director->makeSectionNode(); | 39 | $director->makeSectionNode(); |
| 40 | $node = $director->getNode(); // = <section> | 40 | $node = $director->getNode(); // = <section> |
| 41 | 41 | ||
| 42 | if(is_array($content)){ | 42 | if(is_array($content)){ // cas d'une nouvelle "news" |
| 43 | $date = new \DateTime($content['d']); | 43 | $date = new \DateTime($content['d']); |
| 44 | $article = new Article($content['i'], $date, $content['t'], $content['p']); | 44 | $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); | 45 | $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); |
| 46 | |||
| 47 | // id_node tout juste généré | ||
| 48 | //$article_node->getId(); | ||
| 49 | } | 46 | } |
| 50 | else{ | 47 | else{ // autres cas |
| 51 | $timestamp = time(); | 48 | $timestamp = time(); |
| 52 | $date = new \DateTime; | 49 | $date = new \DateTime; |
| 53 | $date->setTimestamp($timestamp); | 50 | $date->setTimestamp($timestamp); |
| 54 | 51 | ||
| 55 | $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD | 52 | $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD |
| 56 | $article_node = new Node('post', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); | 53 | |
| 54 | $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; // | ||
| 55 | $article_node = new Node('post', 'i' . (string)$timestamp, [], $placement, $node, $node->getPage(), $article); | ||
| 56 | |||
| 57 | if($json['placement'] === 'first'){ | ||
| 58 | $node->addChild($article_node); | ||
| 59 | $node->reindexPositions(); // régénère les positions (0 devient 1, 1 devient 2...) | ||
| 60 | } | ||
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | $entityManager->persist($article_node); | 63 | $entityManager->persist($article_node); |
