<?php
namespace App\Controller;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class actualiteController extends AbstractController
{
private $client;
public function __construct(HttpClientInterface $client)
{
$this->client = $client;
}
/**
* @Route("/actualite-de-l-audition")
*/
public function renderActualitePage()
{
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles"
);
$content = $response->toArray()["articles"];
//dd($content);
return $this->render('./actualite/actualite.html.twig', array(
"articles" => json_encode($content),
"pro" => "false",
"base" => "base.html.twig"
));
}
/**
* @Route("/pro/actualite")
*/
public function renderActualiteProPage()
{
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles/pro"
);
$content = $response->toArray()["articles"];
return $this->render('./actualite/actualite.html.twig', array(
"articles" => json_encode($content),
"pro" => "true",
"base" => "/pro/base.html.twig"
));
}
/**
* @Route("/actualite-de-l-audition/{slug}")
*/
public function renderArticlePage(string $slug)
{
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}article/".$slug
);
$content = $response->toArray();
$category = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles/categories/withArticle"
);
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles?limit=4"
);
$articles = $response->toArray()["articles"];
return $this->render('./actualite/article.html.twig', array(
"article" => $content,
"category" => $category->toArray()['content'],
"articles" => $articles,
"id" => $slug,
"pro" => "false",
"base" => "base.html.twig"
));
}
/**
* @Route("pro/actualite-de-l-audition/{slug}")
*/
public function renderArticleProPage(string $slug)
{
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}article/".$slug
);
$content = $response->toArray();
$category = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles/pro/categories/withArticle"
);
$response = $this->client->request(
'GET',
"{$_ENV['BASE_API']}articles/pro?limit=4"
);
$articles = $response->toArray()["articles"];
return $this->render('./actualite/article.html.twig', array(
"article" => $content,
"category" => $category->toArray()['content'],
"articles" => $articles,
"id" => $slug,
"pro" => "true",
"base" => "/pro/base.html.twig"
));
}
}
?>