<?php
namespace App\Controller;
use App\Instagram\Feed;
use App\Service\DataFetcher;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class IndexController extends Controller
{
public function index(DataFetcher $dataFetcher, Feed $feed): Response
{
// ig id nomo: 45908777985
$instagramPosts = $feed->getPosts();
$configuration = $this->dataFetcher->getConfig();
$results = $dataFetcher->getBlogPosts(1);
$realisations = $dataFetcher->getRealisationsByCategories();
return $this->render('main.html.twig',
[
'configuration' => $configuration,
'realisations' => $realisations,
'instagramPosts' => $instagramPosts,
'blogPosts' => $results,
]
);
}
public function about(DataFetcher $dataFetcher): Response
{
$page = $dataFetcher->getPage('o-nomo');
$realisations = $dataFetcher->getRealisationsByCategories();
return $this->render(
'about.html.twig',
[
'page' => $page,
'realisations' => $realisations,
]
);
}
public function offer(DataFetcher $dataFetcher): Response
{
$page = $dataFetcher->getPage('oferta');
$realisations = $dataFetcher->getRealisationsByCategories();
return $this->render(
'offer.html.twig',
[
'page' => $page,
'realisations' => $realisations,
]
);
}
public function blog(DataFetcher $dataFetcher, Request $request, UrlGeneratorInterface $generator): Response
{
if (null === $request->query->get('sort')) {
return new RedirectResponse($generator->generate('blog') . '?sort=asc');
}
$filters = $this->parseFilters($request);
$page = max((int) $request->get('page', 1), 1);
$results = $dataFetcher->getBlogPostsFiltered($filters, $page, 9);
$pages = $dataFetcher->getBlogPostsPagesNumberFiltered($filters, 9);
$blogPostsCount = $dataFetcher->getBlogPostsCountFiltered($filters);
return $this->render(
'blog.html.twig',
[
'pages' => $pages,
'blogPosts' => $results,
'blogPosts_count' => $blogPostsCount,
'categoriesList' => $dataFetcher->categoryList('blog_post', 'b'),
'archivesList' => $dataFetcher->getArchiveYears('blog_post', 'b'),
]
);
}
public function portfolio(DataFetcher $dataFetcher, Request $request, UrlGeneratorInterface $generator): Response
{
if (null === $request->query->get('sort')) {
return new RedirectResponse($generator->generate('portfolio') . '?sort=ord');
}
$filters = $this->parseFilters($request);
$page = max((int) $request->get('page', 1), 1);
$results = $dataFetcher->getRealisationsFiltered($filters, $page, 9);
$pages = $dataFetcher->getRealisationsPagesNumberFiltered($filters, 9);
$realisationsCount = $dataFetcher->getRealisationsCountFiltered($filters);
return $this->render(
'portfolios.html.twig',
[
'pages' => $pages,
'realisations' => $results,
'realisation_count' => $realisationsCount,
'categoriesList' => $dataFetcher->categoryList('article', 'a'),
'archivesList' => $dataFetcher->getArchiveYears('article', 'a'),
]
);
}
}