src/Controller/ProductForkliftController.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller;
  7. use App\Twig\ConfigHelper;
  8. use Pimcore\Model\DataObject\Forklift;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. class ProductForkliftController extends AbstractController
  13. {
  14.     public function overviewAction(Request $requestConfigHelper $configHelper): JsonResponse|Response
  15.     {
  16.         $siteConfig $configHelper->getSiteConfig();
  17.         $products = new Forklift\Listing();
  18.         $products->addConditionParam("intNumber != '' AND intNumber IS NOT NULL");
  19.         if ($siteConfig) {
  20.             $products->addConditionParam('config LIKE :config', ['config' => '%,' $siteConfig->getId() . ',%']);
  21.         }
  22.         $countries = [];
  23.         $engineTypes = [];
  24.         $workingHourMin 1000000000;
  25.         $workingHourMax 1;
  26.         $yearOfManufactureMin 1950;
  27.         $yearOfManufactureMax 1;
  28.         $capacityMin 1000000000;
  29.         $capacityMax 1;
  30.         foreach ($products as $product) {
  31.             $countries[] = $product->getCountry();
  32.             $engineTypes[$product->getEngineType()] = $product->getEngineType();
  33.             if ($product->getHours() < $workingHourMin) {
  34.                 $workingHourMin $product->getHours();
  35.             }
  36.             if ($product->getHours() > $workingHourMax) {
  37.                 $workingHourMax $product->getHours();
  38.             }
  39.             if ($product->getYoc() < $yearOfManufactureMin) {
  40.                 $yearOfManufactureMin $product->getYoc();
  41.             }
  42.             if ($product->getYoc() > $yearOfManufactureMax) {
  43.                 $yearOfManufactureMax $product->getYoc();
  44.             }
  45.             if ($product->getCapacity() < $capacityMin) {
  46.                 $capacityMin $product->getCapacity();
  47.             }
  48.             if ($product->getCapacity() > $capacityMax) {
  49.                 $capacityMax $product->getCapacity();
  50.             }
  51.         }
  52.         if ($yearOfManufactureMin == $yearOfManufactureMax) {
  53.             $yearOfManufactureMin $yearOfManufactureMin 1;
  54.         }
  55.         if ($workingHourMin == $workingHourMax) {
  56.             $workingHourMin $workingHourMin 1;
  57.         }
  58.         if ($capacityMin == $capacityMax) {
  59.             $capacityMin $capacityMin 1;
  60.         }
  61.         asort($countries);
  62.         asort($engineTypes);
  63.         $returnArray = [
  64.             'products' => $products,
  65.             'countries' => array_unique($countries),
  66.             'engineTypes' => $engineTypes,
  67.             'workingHourMin' => $workingHourMin,
  68.             'workingHourMax' => $workingHourMax,
  69.             'yearOfManufactureMin' => $yearOfManufactureMin,
  70.             'yearOfManufactureMax' => $yearOfManufactureMax,
  71.             'capacityMin' => $capacityMin,
  72.             'capacityMax' => $capacityMax,
  73.         ];
  74.         if ($request->get('countries', [])) {
  75.             $products->addConditionParam('country LIKE :country', ['country' => '%' implode(','$request->get('countries', [])) . '%']);
  76.         }
  77.         if ($request->get('engineType')) {
  78.             $products->addConditionParam('engineType = :engineType', ['engineType' => $request->get('engineType')]);
  79.         }
  80.         if (!is_null($request->get('workingHoursMin'))) {
  81.             $products->addConditionParam('cast(hours as signed) >= :workingHoursMin OR hours IS NULL', ['workingHoursMin' => $request->get('workingHoursMin')]);
  82.         }
  83.         if (!is_null($request->get('workingHoursMax'))) {
  84.             $products->addConditionParam('cast(hours as signed) <= :workingHoursMax OR hours IS NULL', ['workingHoursMax' => $request->get('workingHoursMax')]);
  85.         }
  86.         if (!is_null($request->get('yearOfManufactureMin'))) {
  87.             $products->addConditionParam('yoc >= :yearOfManufactureMin OR yoc IS NULL', ['yearOfManufactureMin' => $request->get('yearOfManufactureMin')]);
  88.         }
  89.         if (!is_null($request->get('yearOfManufactureMax'))) {
  90.             $products->addConditionParam('yoc <= :yearOfManufactureMax OR yoc IS NULL', ['yearOfManufactureMax' => $request->get('yearOfManufactureMax')]);
  91.         }
  92.         if (!is_null($request->get('capacityMin'))) {
  93.             $products->addConditionParam('capacity >= :capacityMin OR capacity IS NULL', ['capacityMin' => $request->get('capacityMin')]);
  94.         }
  95.         if (!is_null($request->get('yearOfManufactureMax'))) {
  96.             $products->addConditionParam('capacity <= :capacityMax OR capacity IS NULL', ['capacityMax' => $request->get('capacityMax')]);
  97.         }
  98.         if ($request->get('search')) {
  99.             $products->addConditionParam('manufacturer LIKE :search OR model LIKE :search OR engine LIKE :search', ['search' => '%' $request->get('search') . '%']);
  100.         }
  101.         if ($request->isXmlHttpRequest() && $request->get('ajax')) {
  102.             return $this->json([
  103.                 'success' => true,
  104.                 'html' => $this->render('includes/product/product-content.html.twig'$returnArray)->getContent(),
  105.             ]);
  106.         }
  107.         return $this->renderTemplate('productForklift/overview.html.twig'$returnArray);
  108.     }
  109.     public function detailAction(Request $requestForklift $id): Response
  110.     {
  111.         $product $id;
  112.         return $this->renderTemplate('productForklift/detail.html.twig', [
  113.             'product' => $product,
  114.         ]);
  115.     }
  116. }