<?php
namespace App\Controller;
use App\Entity\Vinyl;
use App\Form\SearchType;
use App\Repository\ArtistRepository;
use App\Repository\LabelRepository;
use App\Repository\ParamsRepository;
use App\Repository\PromoteRepository;
use App\Services\Search;
use App\Repository\StyleRepository;
use App\Repository\VinylRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class PageController extends AbstractController
{
/**
* @Route("/maintenance", name="maintenance")
*/
public function maintenance(): Response
{
return $this->render('pages/maintenance.html.twig', [
'current' => 'maintenance',
]);
}
/**
* @Route("/", name="home")
*/
public function index(
VinylRepository $vinylRepository,
StyleRepository $styleRepository,
Request $request,
LabelRepository $labelRepository,
ArtistRepository $artistRepository,
PromoteRepository $promoteRepository,
ParamsRepository $paramsRepository,
SessionInterface $sessionInterface
): Response
{
// Recherche
$searchData = [
'labels' => $labelRepository->findBy([], ['name' => 'ASC']),
'artists' => $artistRepository->findBy([], ['name' => 'ASC']),
];
$search = new Search();
$form = $this->createForm(SearchType::class, $search)->handleRequest($request);
$new = $promoteRepository->find(1)->getProducts();
$neufs = [];
$occasions = [];
foreach ($new as $vinyl) {
/** @var Vinyl $vinyl */
if ($vinyl->getState() == "neuf") {
$neufs[] = $vinyl;
}
else {
$occasions[] = $vinyl;
}
}
$news = [
'neufs' => $neufs,
'occasions' => $occasions
];
$bestSeller = $promoteRepository->find(2)->getProducts();
$repress = $promoteRepository->find(3)->getProducts();
$restock = $promoteRepository->find(4)->getProducts();
//$promo = $vinylRepository->getPromo();
$homeProd = $promoteRepository->find(6)->getProducts();
$extras = [
'last' => $vinylRepository->getLast(),
'news' => $news,
'best' => $bestSeller,
'restock' => $restock,
'repress' => $repress,
'homeprod' => $homeProd,
//'promo' => $promo,
];
return $this->render('pages/index.html.twig', [
'current' => 'home',
'is_connected' => $this->getUser() ? true : false,
'params' => $paramsRepository->findAll(),
'search_form' => $form->createView(),
'search_data' => $searchData,
'styles' => $styleRepository->findBy([],["name" => "ASC"]),
'new_vinyls' => $new,
//'promo_vinyls' => $promo,
'extras' => $extras,
]);
}
/**
* @Route("/a-propos", name="about")
*/
public function about(ParamsRepository $paramsRepository): Response
{
return $this->render('pages/about.html.twig', [
'current' => 'page',
'params' => $paramsRepository->findAll(),
]);
}
/**
* @Route("/informations-livraison", name="shipping")
*/
public function shipping(ParamsRepository $paramsRepository): Response
{
return $this->render('pages/shipping.html.twig', [
'current' => 'page',
'params' => $paramsRepository->findAll(),
]);
}
/**
* @Route("/informations-paiement", name="paiement")
*/
public function paiement(ParamsRepository $paramsRepository): Response
{
return $this->render('pages/paiement.html.twig', [
'current' => 'page',
'params' => $paramsRepository->findAll(),
]);
}
/**
* @Route("/mentions-legales", name="mentions_legales")
*/
public function mentionslegales(ParamsRepository $paramsRepository): Response
{
return $this->render('pages/mentions-legales.html.twig', [
'current' => 'page',
'params' => $paramsRepository->findAll(),
]);
}
/**
* @Route("/cgv", name="cgv")
*/
public function cgv(ParamsRepository $paramsRepository): Response
{
return $this->render('pages/cgv.html.twig', [
'current' => 'page',
'params' => $paramsRepository->findAll(),
]);
}
}