<?php
namespace App\Controller;
use App\Services\Api\Campaign\CampaignService;
use App\Services\Api\Category\CategoryService;
use App\Services\FakeDataService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class HomeController extends AbstractController
{
private $fakeDataService;
private CategoryService $categoryService;
private CampaignService $campaignService;
public function __construct(FakeDataService $fakeDataService, CategoryService $categoryService, CampaignService $campaignService){
$this->fakeDataService = $fakeDataService;
$this->categoryService = $categoryService;
$this->campaignService = $campaignService;
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws \Exception
*/
#[Route('/', name: 'app_home')]
public function index(): Response
{
$data = $this->fakeDataService->get();
$categories = $this->categoryService->getParentCategoriesWithAttractions();
$campaigns = $this->campaignService->getCampaign()->toArray()['hydra:member'];
$publicity = [];
foreach ($campaigns as $campaign){
$publicity= array_merge($publicity, $campaign['publicities']);
}
shuffle($publicity);
return $this->render('frontend/home/home.html.twig', [
'categories' => $categories,
'publicity' => $publicity
]);
}
}