diff options
Diffstat (limited to 'src/controller/ArticleController.php')
| -rw-r--r-- | src/controller/ArticleController.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index 411c1dc..8bbef19 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php | |||
| @@ -6,10 +6,51 @@ declare(strict_types=1); | |||
| 6 | use App\Entity\Node; | 6 | use App\Entity\Node; |
| 7 | use App\Entity\Article; | 7 | use App\Entity\Article; |
| 8 | use Doctrine\ORM\EntityManager; | 8 | use Doctrine\ORM\EntityManager; |
| 9 | use Symfony\Component\HttpFoundation\Request; | ||
| 9 | use Symfony\Component\HttpFoundation\Response; | 10 | use Symfony\Component\HttpFoundation\Response; |
| 10 | 11 | ||
| 11 | class ArticleController | 12 | class ArticleController |
| 12 | { | 13 | { |
| 14 | static public function fetch(EntityManager $entityManager, Request $request): void | ||
| 15 | { | ||
| 16 | if($request->query->has('id') && !empty($request->query->get('id')) && $request->query->has('last_article')){ | ||
| 17 | //var_dump($request->query->get('last_article')); | ||
| 18 | $id = (int)$request->get('id'); // type et nettoie | ||
| 19 | $director = new Director($entityManager); | ||
| 20 | $director->findNodeById($id); | ||
| 21 | $parent_block = $director->getNode(); | ||
| 22 | |||
| 23 | if(Blocks::hasPresentation($parent_block->getName())){ | ||
| 24 | $get_articles_return = $director->getNextArticles($parent_block, $request); | ||
| 25 | $bulk_data = $get_articles_return[0]; | ||
| 26 | |||
| 27 | if($parent_block->getName() === 'post_block'){ | ||
| 28 | $builder_name = 'PostBuilder'; | ||
| 29 | } | ||
| 30 | elseif($parent_block->getName() === 'news_block'){ | ||
| 31 | $builder_name = 'NewBuilder'; | ||
| 32 | } | ||
| 33 | |||
| 34 | $html = ''; | ||
| 35 | foreach($bulk_data as $article){ | ||
| 36 | $builder = new $builder_name($article); | ||
| 37 | $html .= $builder->render(); | ||
| 38 | } | ||
| 39 | |||
| 40 | echo json_encode(['success' => true, 'html' => $html, 'truncated' => $get_articles_return[1]]); | ||
| 41 | die; | ||
| 42 | } | ||
| 43 | else{ | ||
| 44 | echo json_encode(['success' => false, 'error' => 'mauvais type de bloc']); | ||
| 45 | die; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | else{ | ||
| 49 | echo json_encode(['success' => false, 'error' => 'la requête ne comporte pas les paramètres attendus']); | ||
| 50 | die; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 13 | static public function editorSubmit(EntityManager $entityManager, array $json): void | 54 | static public function editorSubmit(EntityManager $entityManager, array $json): void |
| 14 | { | 55 | { |
| 15 | if(json_last_error() === JSON_ERROR_NONE) | 56 | if(json_last_error() === JSON_ERROR_NONE) |
