src/Controller/Pages/CollectionController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages;
  3. use App\Controller\Utils\ContentController;
  4. use App\Entity\Collection;
  5. use App\Entity\Project;
  6. use App\Entity\SeoPage;
  7. use App\Service\DocumentFileUploader;
  8. use App\Service\FilePathAndUrlService;
  9. use App\Traits\AttachmentUrls;
  10. use Liip\ImagineBundle\Service\FilterService;
  11. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class CollectionController extends ContentController
  16. {
  17.     use AttachmentUrls;
  18.     private $projectDir;
  19.     private $localeService;
  20.     protected $documentFileUploader;
  21.     private $filePathAndUrlService;
  22.     public const COLLECTION_BASE_BREADCRUMB = [
  23.         HomeController::HOME_BREADCRUMB,
  24.         ['route' => 'pages_collections_overview''name' => 'Collections overview']
  25.     ];
  26.     /**
  27.      * @var FilterService
  28.      */
  29.     private $liip;
  30.     public function __construct(EventDispatcherInterface $dispatcher,FilterService $liip,
  31.                                 DocumentFileUploader $documentFileUploaderFilePathAndUrlService $filePathAndUrlService)
  32.     {
  33.         $this->documentFileUploader $documentFileUploader;
  34.         $this->filePathAndUrlService $filePathAndUrlService;
  35.         parent::__construct($dispatcherself::class);
  36.         $this->liip $liip;
  37.     }
  38.     /**
  39.      * @Route({
  40.      *     "ja": "/collection-overview",
  41.      *     "en": "/collection-overview"
  42.      * }, name="pages_collections_overview")
  43.      * @param Request $request
  44.      * @return Response
  45.      */
  46.     public function index(Request $request): Response
  47.     {
  48.         $projects $this->getDoctrine()->getRepository(Project::class)->findAll();
  49.         return $this->render('pages/collection/base.html.twig', [
  50.             'breadCrumbs' => self::COLLECTION_BASE_BREADCRUMB,
  51.             'pictures' => $this->getPicturesToShow($projects$this->filePathAndUrlService$this->liip),
  52.             'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(5)
  53.         ], null$request);
  54.     }
  55.     /**
  56.      * @Route({
  57.      *     "ja": "/collection-overview/{slug}-{id}",
  58.      *     "en": "/collection-overview/{slug}-{id}"
  59.      * }, name="pages_collection_details", requirements={"slug": "[a-zA-Z1-9\-_\/]+", "id": "[0-9]+"}, priority=2)
  60.      * @param Collection $collection
  61.      * @param string $slug
  62.      * @param Request $request
  63.      * @return Response
  64.      */
  65.     public function show(Collection $collectionstring $slugRequest $request): Response
  66.     {
  67.         if ($collection->getSlug() !== $slug) {
  68.             return $this->redirectToRoute('pages_collection_details', [
  69.                 'id' => $collection->getId(),
  70.                 'slug' => $collection->getSlug()
  71.             ], 301);
  72.         }
  73.         $products $collection->getProducts()->getValues();
  74.         $this->setAttachmentUrls($products$this->filePathAndUrlService);
  75.         foreach ($products as $product) {
  76.             $product->urlProduct $this->generateUrl('pages_product_details', [
  77.                 'collectionSlug' => $product->getCollection()->getSlug(),
  78.                 'slug' => $product->getSlug(),
  79.                 'id' => $product->getId(),
  80.                 'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(6)
  81.             ]);
  82.         }
  83.         $firstLineProducts array_slice($products0ceil(count($products) / 3));
  84.         $secondLineProducts array_slice($productsceil(count($products) / 3), ceil(count($products) / 3));
  85.         $thirdLineProducts array_slice($products,ceil(count($products) / 3),count($products));
  86.         $this->setAttachmentUrls($collection$this->filePathAndUrlService);
  87.         $projects $this->getProjectsFromEntities([$collection], $this->getDoctrine()->getManager());
  88.         return $this->render('pages/collection/base.html.twig', [
  89.             'title' => ['collectionName' => $collection->getName()],
  90.             'collection' => $collection,
  91.             'downloads' => $this->documentFileUploader->getGenericPDF($collection->getProducts(), $request),
  92.             'firstLineProducts' => $firstLineProducts,
  93.             'secondLineProducts' => $secondLineProducts,
  94.             'thirdLineProducts' => $thirdLineProducts,
  95.             'breadCrumbs' => array_merge(self::COLLECTION_BASE_BREADCRUMB,
  96.                 [['name' => $collection->getName()]]
  97.             ),
  98.             'filter' => 'collection',
  99.             'filterValue' => $collection->getSlug(),
  100.             'pictures' => $this->getPicturesToShow(count($projects) > 0  $projects : [$collection], $this->filePathAndUrlService$this->liip),
  101.             // 'threeDSimulationUrl' => $request->getSchemeAndHttpHost() .  $this->generateUrl('pages_3d_simulation_index')
  102.             'threeDSimulationUrl' => "https://www.2tec2.com/3d-simulation"
  103.                 '?lang=' $request->getLocale() . '&material=' $product->getSlug() . '?lang=' $request->getLocale(),
  104.             'seoPage' => $this->getDoctrine()->getRepository(SeoPage::class)->find(6)
  105.         ], null$request);
  106.     }
  107. }