<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\SiteHome\Slide;
use App\Entity\SiteHome\Imprime;
use App\Entity\SiteHome\SlideSaison;
use App\Entity\SiteHome\CoteBoutique;
use App\Entity\SiteHome\HomeProductVariant;
use App\Entity\SiteHome\HomeMainTaxon;
use App\Entity\SiteSacZipSelection;
use App\Services\InstagramBasicDisplayService;
use Twig\Environment;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use App\Controller\SiteCollectionController;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
class HomepageController extends AbstractController
{
public function indexAction(
Request $request,
LocaleContextInterface $localeContext
): Response
{
$em = $this->get('doctrine')->getManager();
// Selectionne la combinaison par défaut
$sacZipSelectionDefault = $em->getRepository(SiteSacZipSelection::class)
->createQueryBuilder('c')
->where('c.default = 1')
->getQuery()
->getOneOrNullResult();
// dump($sacZipSelectionDefault);
// Selectionne les slides
$slideRepository = $em->getRepository(Slide::class);
$slides = $slideRepository->createQueryBuilder('a')
->where('a.enabled = 1')
->where('a.dateDiffusion < :last')
->setParameter('last', new \DateTime('-5 second'))
->orderBy('a.position', 'ASC')
->getQuery()
->getResult();
// Selectionne les déclinaisons produits à afficher sur l'accueil
$homeProductVariantRepository = $em->getRepository(HomeProductVariant::class);
$homeProductsVariants = $homeProductVariantRepository->createQueryBuilder('a')
->innerJoin(
'a.productVariant',
'productVariant',
'WITH',
'productVariant.enabled = 1 AND productVariant.onHand >= 5'
)->orderBy('a.position', 'ASC')
->getQuery()
->getResult();
// Selectionne les "imprimés"
$imprimeRepository = $em->getRepository(Imprime::class);
$imprimes = $imprimeRepository->createQueryBuilder('a')
->where('a.enabled = 1')
->orderBy('a.position', 'ASC')
->getQuery()
->getResult();
foreach($imprimes as $imprime){
$imprime->slugLocale = SiteCollectionController::CATEGORIES[$localeContext->getLocaleCode()][$imprime->getCollection()->getCategory()];
}
// Selectionne les catégories pour "Vous les adorez"
$homeMainTaxonRepository = $em->getRepository(HomeMainTaxon::class);
$homeTaxons = $homeMainTaxonRepository->createQueryBuilder('a')
->where('a.enabled = 1')
->orderBy('a.position', 'ASC')
->getQuery()
->getResult();
// Selectionne les "slides saisons"
$saisonRepository = $em->getRepository(SlideSaison::class);
$saisons = $saisonRepository->createQueryBuilder('a')
->where('a.enabled = 1')
->orderBy('a.position', 'ASC')
->getQuery()
->getResult();
// Selectionne les informations sur "Côté boutique"
$coteBoutiqueRepository = $em->getRepository(CoteBoutique::class);
$coteboutique = $coteBoutiqueRepository->createQueryBuilder('a')
->where('a.enabled = 1')
->getQuery()
->getSingleResult();
return $this->render('index.html.twig', [
'slides' => $slides,
'homeProductsVariants' => $homeProductsVariants,
'imprimes' => $imprimes,
'homeTaxons' => $homeTaxons,
'saisons' => $saisons,
'coteboutique' => $coteboutique,
'sacZipSelectionDefault' => $sacZipSelectionDefault
]);
}
public function instagramBasicDisplayAPICallbackAction(InstagramBasicDisplayService $instagram, Request $request)
{
$code = $request->query->get('code');
$token = $instagram->generateNewToken($code);
return new Response($token);
}
}