<?php
namespace App\Controller\Pages;
use App\Controller\Utils\ContentController;
use App\Entity\Collection;
use App\Entity\Project;
use App\Entity\SeoPage;
use App\Service\DocumentFileUploader;
use App\Service\FilePathAndUrlService;
use App\Traits\AttachmentUrls;
use Liip\ImagineBundle\Service\FilterService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CollectionController extends ContentController
{
use AttachmentUrls;
private $projectDir;
private $localeService;
protected $documentFileUploader;
private $filePathAndUrlService;
public const COLLECTION_BASE_BREADCRUMB = [
HomeController::HOME_BREADCRUMB,
['route' => 'pages_collections_overview', 'name' => 'Collections overview']
];
/**
* @var FilterService
*/
private $liip;
public function __construct(EventDispatcherInterface $dispatcher,FilterService $liip,
DocumentFileUploader $documentFileUploader, FilePathAndUrlService $filePathAndUrlService)
{
$this->documentFileUploader = $documentFileUploader;
$this->filePathAndUrlService = $filePathAndUrlService;
parent::__construct($dispatcher, self::class);
$this->liip = $liip;
}
/**
* @Route({
* "ja": "/collection-overview",
* "en": "/collection-overview"
* }, name="pages_collections_overview")
* @param Request $request
* @return Response
*/
public function index(Request $request): Response
{
$projects = $this->getDoctrine()->getRepository(Project::class)->findAll();
return $this->render('pages/collection/base.html.twig', [
'breadCrumbs' => self::COLLECTION_BASE_BREADCRUMB,
'pictures' => $this->getPicturesToShow($projects, $this->filePathAndUrlService, $this->liip),
'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(5)
], null, $request);
}
/**
* @Route({
* "ja": "/collection-overview/{slug}-{id}",
* "en": "/collection-overview/{slug}-{id}"
* }, name="pages_collection_details", requirements={"slug": "[a-zA-Z1-9\-_\/]+", "id": "[0-9]+"}, priority=2)
* @param Collection $collection
* @param string $slug
* @param Request $request
* @return Response
*/
public function show(Collection $collection, string $slug, Request $request): Response
{
if ($collection->getSlug() !== $slug) {
return $this->redirectToRoute('pages_collection_details', [
'id' => $collection->getId(),
'slug' => $collection->getSlug()
], 301);
}
$products = $collection->getProducts()->getValues();
$this->setAttachmentUrls($products, $this->filePathAndUrlService);
foreach ($products as $product) {
$product->urlProduct = $this->generateUrl('pages_product_details', [
'collectionSlug' => $product->getCollection()->getSlug(),
'slug' => $product->getSlug(),
'id' => $product->getId(),
'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(6)
]);
}
$firstLineProducts = array_slice($products, 0, ceil(count($products) / 3));
$secondLineProducts = array_slice($products, ceil(count($products) / 3), ceil(count($products) / 3));
$thirdLineProducts = array_slice($products,2 * ceil(count($products) / 3),count($products));
$this->setAttachmentUrls($collection, $this->filePathAndUrlService);
$projects = $this->getProjectsFromEntities([$collection], $this->getDoctrine()->getManager());
return $this->render('pages/collection/base.html.twig', [
'title' => ['collectionName' => $collection->getName()],
'collection' => $collection,
'downloads' => $this->documentFileUploader->getGenericPDF($collection->getProducts(), $request),
'firstLineProducts' => $firstLineProducts,
'secondLineProducts' => $secondLineProducts,
'thirdLineProducts' => $thirdLineProducts,
'breadCrumbs' => array_merge(self::COLLECTION_BASE_BREADCRUMB,
[['name' => $collection->getName()]]
),
'filter' => 'collection',
'filterValue' => $collection->getSlug(),
'pictures' => $this->getPicturesToShow(count($projects) > 0 ? $projects : [$collection], $this->filePathAndUrlService, $this->liip),
// 'threeDSimulationUrl' => $request->getSchemeAndHttpHost() . $this->generateUrl('pages_3d_simulation_index')
'threeDSimulationUrl' => "https://www.2tec2.com/3d-simulation"
. '?lang=' . $request->getLocale() . '&material=' . $product->getSlug() . '?lang=' . $request->getLocale(),
'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(6)
], null, $request);
}
}