src/Controller/HomeController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\Api\Campaign\CampaignService;
  4. use App\Services\Api\Category\CategoryService;
  5. use App\Services\FakeDataService;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  10. use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
  11. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  12. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  13. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  14. class HomeController extends AbstractController
  15. {
  16.     private $fakeDataService;
  17.     private CategoryService $categoryService;
  18.     private CampaignService $campaignService;
  19.     public function __construct(FakeDataService $fakeDataServiceCategoryService $categoryServiceCampaignService $campaignService){
  20.         $this->fakeDataService $fakeDataService;
  21.         $this->categoryService $categoryService;
  22.         $this->campaignService $campaignService;
  23.     }
  24.     /**
  25.      * @throws TransportExceptionInterface
  26.      * @throws ServerExceptionInterface
  27.      * @throws RedirectionExceptionInterface
  28.      * @throws DecodingExceptionInterface
  29.      * @throws ClientExceptionInterface
  30.      * @throws \Exception
  31.      */
  32.     #[Route('/'name'app_home')]
  33.     public function index(): Response
  34.     {
  35.         $data $this->fakeDataService->get();
  36.         $categories =  $this->categoryService->getParentCategoriesWithAttractions();
  37.         $campaigns $this->campaignService->getCampaign()->toArray()['hydra:member'];
  38.         $publicity = [];
  39.         foreach ($campaigns as $campaign){
  40.             $publicityarray_merge($publicity$campaign['publicities']);
  41.         }
  42.         shuffle($publicity);
  43.         return $this->render('frontend/home/home.html.twig', [
  44.             'categories' => $categories,
  45.             'publicity' => $publicity
  46.         ]);
  47.     }
  48. }