custom/src/EshopBundle/DependencyInjection/Shopping/Assistant.php line 545

Open in your IDE?
  1. <?php
  2. namespace EshopBundle\DependencyInjection\Shopping;
  3. use EshopBundle\Interfaces\ProductListInterface;
  4. use EshopBundle\Entity\Category;
  5. use EshopBundle\Entity\ActionOffer;
  6. use EshopBundle\Entity\Feature;
  7. use EshopBundle\Entity\Parameters;
  8. use EshopBundle\Entity\ParametersValues;
  9. use EshopBundle\Entity\Product;
  10. use EshopBundle\Entity\ProductTypeFeature;
  11. use EshopBundle\Model\ProductList;
  12. use Symfony\Component\DependencyInjection\Container;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use EshopBundle\Interfaces\SeoFieldsInterface;
  15. use Doctrine\ORM\Query\ResultSetMapping;
  16. /**
  17.  * Nakupni asistent eshopu
  18.  * @author DJ
  19.  */
  20. class Assistant implements ProductListInterface
  21. {
  22.     const DEFAULT_VISIBLE_BRANDS 111;
  23.     use Traits\AssistantTrait {
  24.         #Traits\AssistantTrait::getLink AS private tGetLink;
  25.         Traits\AssistantTrait::initByRequest AS private tInitByRequest;
  26.         Traits\AssistantTrait::getActualParams AS private tGetActualParams;
  27.         Traits\AssistantTrait::getParams AS private tGetParams;
  28.     }
  29.     /**
  30.      * @var SeoFieldsInterface
  31.      */
  32.     private $customPageEntity;
  33.     /**
  34.      * @return SeoFieldsInterface
  35.      */
  36.     public function getCustomPageEntity()
  37.     {
  38.         return $this->customPageEntity;
  39.     }
  40.     /**
  41.      * @param SeoFieldsInterface $customPageEntity
  42.      *
  43.      * @return self
  44.      */
  45.     public function setCustomPageEntity(SeoFieldsInterface $customPageEntity)
  46.     {
  47.         $this->customPageEntity $customPageEntity;
  48.         return $this;
  49.     }
  50.     /**
  51.      * @param string $sortType
  52.      *
  53.      * @return self
  54.      */
  55.     public function setSortType($sortType)
  56.     {
  57.         $this->sortType $sortType;
  58.         return $this;
  59.     }
  60.     /**
  61.      * Vraci seznam stitku akce, novinka, vyprodej, top a baraz a pocty.
  62.      *
  63.      * @return array
  64.      */
  65.     public function getProductTags()
  66.     {
  67.         $freeDeliveryWithVat $this->getCurrencyOptions() ? $this->getCurrencyOptions()->freeDeliveryLimit false;
  68.         $freeDelivery $this->getFreeDeliveryVat($freeDeliveryWithVat);
  69.         $slot $this->productList->getPriceSlot();
  70.         $builder $this->productList
  71.             ->build(array('allTags' => true))
  72.             ->select(
  73.                 'SUM(case when p.tagAction = \'t\' then 1 else 0 end) / COUNT(p.id), ' .
  74.                     'SUM(case when p.tagNew = \'t\' then 1 else 0 end) / COUNT(p.id), ' .
  75.                     'SUM(case when p.tagSale = \'t\' then 1 else 0 end) / COUNT(p.id), ' .
  76.                     'SUM(case when p.tagFreeDelivery = \'t\' then 1 else ' .
  77.                     ($freeDelivery 'CASE WHEN p.' $slot 'Min > ' $freeDelivery ' THEN 1 ELSE 0 END' '0') .
  78.                     ' end) / COUNT(p.id), ' .
  79.                     'SUM(case when p.tagTop = \'t\' then 1 else 0 end) / COUNT(p.id), ' .
  80.                     'SUM(case when p.tagBazaar = \'t\' then 1 else 0 end) / COUNT(p.id)'
  81.             )
  82.             ->groupBy('p.id');
  83.         $sql //vypnuti... (docasne?)
  84.             /*. 'SUM(sclr_3) AS tagFreeDelivery, '*/ 'SELECT SUM(sclr_0) AS tagAction, ' .
  85.             'SUM(sclr_1) AS tagNew, ' .
  86.             'SUM(sclr_2) AS tagSale, ' .
  87.             'IF(SUM(sclr_3)>0, -1 , 0) AS tagFreeDelivery, ' .
  88.             'SUM(sclr_4) AS tagTop, ' .
  89.             'SUM(sclr_5) AS tagBazaar ' .
  90.             'FROM (' .
  91.             $builder->getQuery()->getSQL() .
  92.             ') AS tmp';
  93.         $em $this->container->get('doctrine')->getManager();
  94.         $rsm = new ResultSetMapping();
  95.         $rsm->addScalarResult('tagAction''tagAction');
  96.         $rsm->addScalarResult('tagNew''tagNew');
  97.         $rsm->addScalarResult('tagSale''tagSale');
  98.         $rsm->addScalarResult('tagFreeDelivery''tagFreeDelivery');
  99.         $rsm->addScalarResult('tagTop''tagTop');
  100.         $rsm->addScalarResult('tagBazaar''tagBazaar');
  101.         $query $em->createNativeQuery($sql$rsm);
  102.         $parameters $builder->getParameters();
  103.         foreach ($parameters as $i => $param) {
  104.             $query->setParameter($i$param->getValue());
  105.         }
  106.         if ($this->cacheTtl) {
  107.             $query->useResultCache(true$this->cacheTtl);
  108.         }
  109.         $tags = array();
  110.         $catLink $this->category->getLink();
  111.         if ($result $query->getSingleResult()) {
  112.             $translator $this->container->get('eshop_config.translator');
  113.             $indexes = array(
  114.                 'tagAction' => $translator->getValue('ASS_ACTION'),
  115.                 'tagNew' => $translator->getValue('ASS_NEW'),
  116.                 'tagSale' => $translator->getValue('ASS_SALE'),
  117.                 'tagTop' => $translator->getValue('BESTSELLING'),
  118.                 // 'tagFreeDelivery' => $translator->getValue('FREE_DELIVERY'),
  119.                 'tagBazaar' => $translator->getValue('ASS_BAZAAR'),
  120.             );
  121.             foreach ($indexes as $index => $name) {
  122.                 $tmp = new \stdClass();
  123.                 $tmp->id $index;
  124.                 $tmp->name $name;
  125.                 $tmp->checked $this->productList->getTag($index);
  126.                 $tmp->cnt intval($result[$index]);
  127.                 $tmp->link $catLink '?' $index '=1';
  128.                 $tags[] = $tmp;
  129.             }
  130.         }
  131.         return $tags;
  132.     }
  133.     /**
  134.      * Vraci aktualni nastaveni filtru
  135.      * Box s aktuálně vybranými parametry nad výpisem
  136.      *
  137.      * @return array
  138.      */
  139.     public function getActualParams()
  140.     {
  141.         $translator $this->container->get('eshop_config.translator');
  142.         $items $this->tGetActualParams();
  143.         if ($items && empty(end($items)['id'])) {
  144.             array_pop($items);
  145.         }
  146.         if ($parameters $this->productList->getSelectedParameters()) {
  147.             foreach ($parameters as $parameterId => $values) {
  148.                 $p $this->container
  149.                     ->get('doctrine')
  150.                     ->getManager()
  151.                     ->getRepository('EshopBundle:Parameters')
  152.                     ->findOneById($parameterId);
  153.                 // pokud náhodou příjde neexistující parametr tak aby to nespadlo do 500
  154.                 if ($p === null) {
  155.                     continue;
  156.                 }
  157.                 if ($p->isNumericParameter()) {
  158.                     if ($p->getFilterMethod() === "range") {
  159.                         if ($values['rMin'] == $values['min'] && $values['rMax'] == $values['max']) {
  160.                             continue;
  161.                         }
  162.                         $items[] = array(
  163.                             'id' => 'p-' $parameterId,
  164.                             'name' => $this->getParametersRangeName($p$values),
  165.                             'link' => $this->getLink($this->getSortType(), $this->getListType(), 'p-' $parameterId),
  166.                         );
  167.                     } else {
  168.                         foreach ($values as $val) {
  169.                             $items[] = array(
  170.                                 'id' => 'p-' $parameterId '-' $val,
  171.                                 'name' => $val,
  172.                                 'link' => $this->getLink($this->getSortType(), $this->getListType(), 'p-' $parameterId$val),
  173.                             );
  174.                         }
  175.                     }
  176.                 } else {
  177.                     foreach ($values as $val) {
  178.                         $items[] = array(
  179.                             'id' => 'p-' $parameterId '-' $val,
  180.                             'name' => $this->getParameterValueNameById($val),
  181.                             'link' => $this->getLink($this->getSortType(), $this->getListType(), 'p-' $parameterId$val),
  182.                         );
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.         # Reset all btn - na začátek
  188.         if (count($items) > && $this->category) {
  189.             array_unshift($items, [
  190.                 'id' => '',
  191.                 'name' => $translator->getValue('ASSISTANT_FILTER_RESET'),
  192.                 'link' => $this->category->getLink(),
  193.             ]);
  194.         }
  195.         return $items;
  196.     }
  197.     /**
  198.      * Inicializace parametru nakupniho pomocnika na zaklade requestu.
  199.      *
  200.      * @param Request $request
  201.      *
  202.      * @return self
  203.      */
  204.     public function initCustomPageListByRequest(Request $request)
  205.     {
  206.         $this->productList
  207.             ->setInStock($request->get('inStock'false))
  208.             ->setTagAction($request->get('tagAction'false))
  209.             ->setTagNew($request->get('tagNew'false))
  210.             ->setTagSale($request->get('tagSale'false))
  211.             ->setTagTop($request->get('tagTop'false))
  212.             ->setTagBazaar($request->get('tagBazaar'false))
  213.             ->setTagFreeDelivery($request->get('tagFreeDelivery'false))
  214.             ->setCustom($request->get('custom'));
  215.         if ($brand $request->get('brand'0)) {
  216.             $this->productList->addBrand($brand);
  217.         }
  218.         if (($brands $request->get('brands'0)) && is_array($brands)) {
  219.             foreach ($brands as $brand) {
  220.                 $this->productList->addBrand($brand);
  221.             }
  222.         }
  223.         $this->allBrands $request->get('allBrands'0);
  224.         $config $this->container->get('eshop_config.client_config');
  225.         if ($config->isTrue('PROD_COMPARABLE_FEATURES')) {
  226.             $features $request->get('f');
  227.             if (is_array($features)) {
  228.                 $this->productList->setFeatures($features);
  229.             }
  230.         }
  231.         if ($config->isTrue('PRODUCT_CATALOG_TYPES')) {
  232.             $types $request->get('t');
  233.             if (is_array($types)) {
  234.                 $this->productList->setTypes($types);
  235.             }
  236.         }
  237.         $this->closed $request->get('closed');
  238.         if ($listType $request->get('list')) {
  239.             $this->setListType($listType);
  240.         }
  241.         if ($sortType $request->get('sort')) {
  242.             $this->setSortType($sortType);
  243.         }
  244.         $parameters $request->get('p');
  245.         if (is_array($parameters)) {
  246.             $this->productList->setSelectedParameters($parameters);
  247.         }
  248.         return $this;
  249.     }
  250.     /**
  251.      * Inicializace parametru nakupniho pomocnika na zaklade requestu.
  252.      *
  253.      * @param Request $request
  254.      *
  255.      * @return self
  256.      */
  257.     public function initByRequest(Request $request)
  258.     {
  259.         $this->tInitByRequest($request);
  260.         $parameters $request->get('p');
  261.         if (is_array($parameters)) {
  262.             $this->productList->setSelectedParameters($parameters);
  263.         }
  264.         return $this;
  265.     }
  266.     /**
  267.      * Vraci aktualni link dle aktualnich parametru asistenta.
  268.      *
  269.      * @param string $sortType
  270.      * @param string $listType
  271.      *
  272.      * @return string
  273.      */
  274.     public function getLink($sortType null$listType null$exclude null$excludeId null)
  275.     {
  276.         if ($this->customPageEntity) {
  277.             $link $this->customPageEntity->getLink();
  278.         } elseif ($this->category) {
  279.             $link $this->category->getLink();
  280.         } elseif ($this->actionOffer) {
  281.             $link $this->actionOffer->getLink();
  282.         } elseif ($this->brand instanceof Brand) {
  283.             $link $this->brand->getLink();
  284.         } else {
  285.             $link '';
  286.         }
  287.         $params = array();
  288.         // znacka
  289.         $brands $this->productList->getBrands();
  290.         $brandsCnt count($brands);
  291.         if ($brandsCnt == 1) {
  292.             if ($exclude != 'brands' || $excludeId != $brands[0]) {
  293.                 $brand $this->container
  294.                     ->get('doctrine')
  295.                     ->getRepository('EshopBundle:Brand')
  296.                     ->find($brands[0]);
  297.                 if ($this->brand instanceof Brand && $this->brand->getId() === $brands[0]) {
  298.                     // Aby se pro brand nepřidával tag do url už je v klasické url obsazen
  299.                 } elseif ($this->category === null || !$this->linkExists($this->category->getId(), $brands[0])) {
  300.                     $tmp[] = $brands[0];
  301.                 } elseif (!is_null($brand) && $this->linkExists($this->category->getId(), $brands[0])) {
  302.                     $link $this->getCategoryBrandLink($this->category->getId(), $brands[0])->getUri();
  303.                 } elseif (!is_null($brand)) {
  304.                     $link .= '/' $brand->getSlug();
  305.                 }
  306.             }
  307.         } elseif ($brandsCnt 1) {
  308.             $tmp = array();
  309.             foreach ($brands as $brand) {
  310.                 if ($exclude != 'brands' || $excludeId != $brand) {
  311.                     $tmp[] = $brand;
  312.                 }
  313.             }
  314.         }
  315.         if (!empty($tmp)) {
  316.             $params['brands'] = $tmp;
  317.         }
  318.         // stitky
  319.         if (empty($this->actionOffer)) {
  320.             if ($exclude != 'inStock' && $this->productList->getInStock()) {
  321.                 $params['inStock'] = 1;
  322.             }
  323.             if ($exclude != 'tagAction' && $this->productList->getTagAction()) {
  324.                 $params['tagAction'] = 1;
  325.             }
  326.             if ($exclude != 'tagNew' && $this->productList->getTagNew()) {
  327.                 $params['tagNew'] = 1;
  328.             }
  329.             if ($exclude != 'tagSale' && $this->productList->getTagSale()) {
  330.                 $params['tagSale'] = 1;
  331.             }
  332.             if ($exclude != 'tagTop' && $this->productList->getTagTop()) {
  333.                 $params['tagTop'] = 1;
  334.             }
  335.             if ($exclude != 'tagBazaar' && $this->productList->getTagBazaar()) {
  336.                 $params['tagBazaar'] = 1;
  337.             }
  338.             if ($exclude != 'tagFreeDelivery' && $this->productList->getTagFreeDelivery()) {
  339.                 $params['tagFreeDelivery'] = 1;
  340.             }
  341.         }
  342.         // hodnoceni
  343.         if ($exclude != 'rating' && ($rating $this->productList->getRating())) {
  344.             $params['rating'] = $rating;
  345.         }
  346.         // cena min
  347.         if ($exclude != 'priceMin' && ($priceMin $this->productList->getPriceMin())) {
  348.             $params['priceMin'] = $priceMin;
  349.         }
  350.         // cena max
  351.         if ($exclude != 'priceMax' && ($priceMax $this->productList->getPriceMax())) {
  352.             $params['priceMax'] = $priceMax;
  353.         }
  354.         // parametry
  355.         if ($features $this->productList->getFeatures()) {
  356.             $tmp = array();
  357.             foreach ($features as $feature => $values) {
  358.                 if ($exclude != 'f-' $feature || $excludeId !== null) {
  359.                     foreach ($values as $key => $val) {
  360.                         if ($exclude != 'f-' $feature || $excludeId != $val) {
  361.                             $tmp[$feature][$key] = $val;
  362.                         }
  363.                     }
  364.                 }
  365.             }
  366.             if (!empty($tmp)) {
  367.                 $params['f'] = $tmp;
  368.             }
  369.         }
  370.         // vlastnosti typu
  371.         if ($types $this->productList->getTypes()) {
  372.             $tmp = array();
  373.             foreach ($types as $type => $values) {
  374.                 foreach ($values as $val) {
  375.                     if ($exclude != 't-' $type || $excludeId != $val) {
  376.                         $tmp[$type][] = $val;
  377.                     }
  378.                 }
  379.             }
  380.             if (!empty($tmp)) {
  381.                 $params['t'] = $tmp;
  382.             }
  383.         }
  384.         // custom filtr
  385.         if ($custom $this->productList->getCustom()) {
  386.             if (is_array($custom)) {
  387.                 $tmp = array();
  388.                 foreach ($custom as $c) {
  389.                     if ($exclude != 'custom' || $excludeId != $c) {
  390.                         $tmp[] = $c;
  391.                     }
  392.                 }
  393.                 if (!empty($tmp)) {
  394.                     $params['custom'] = $tmp;
  395.                 }
  396.             } elseif ($exclude != 'custom') {
  397.                 $params['custom'] = $custom;
  398.             }
  399.         }
  400.         // zpusob razeni
  401.         if ($sortType) {
  402.             if ($sortType != $this->defaultSortType) {
  403.                 $params['sort'] = $sortType;
  404.             }
  405.         } elseif ($this->sortType && $this->sortType != $this->defaultSortType) {
  406.             $params['sort'] = $this->sortType;
  407.         }
  408.         // typ vypisu
  409.         if ($listType) {
  410.             if ($listType != $this->defaultListType) {
  411.                 $params['list'] = $listType;
  412.             }
  413.         } elseif ($this->listType && $this->listType != $this->defaultListType) {
  414.             $params['list'] = $this->listType;
  415.         }
  416.         // parametry
  417.         if ($parameters $this->productList->getSelectedParameters()) {
  418.             $tmp = array();
  419.             foreach ($parameters as $parameterId => $values) {
  420.                 if ($exclude != 'p-' $parameterId || $excludeId !== null) {
  421.                     foreach ($values as $key => $val) {
  422.                         if ($exclude != 'p-' $parameterId || $excludeId != $val) {
  423.                             $tmp[$parameterId][$key] = $val;
  424.                         }
  425.                     }
  426.                 }
  427.             }
  428.             if (!empty($tmp)) {
  429.                 $params['p'] = $tmp;
  430.             }
  431.         }
  432.         if (!empty($params)) {
  433.             $link .= '?' str_replace(array('%5B''%5D'), array('['']'), http_build_query($params));
  434.         }
  435.         return $link;
  436.     }
  437.     /**
  438.      * Vraci aktualni nastaveni filtru.
  439.      *
  440.      * @return array
  441.      */
  442.     public function getParams()
  443.     {
  444.         $params $this->tGetParams();
  445.         $params['p'] = $this->productList->getSelectedParameters();
  446.         return $params;
  447.     }
  448.     /**
  449.      * Vraci seznam custom parametrů pro filtraci v asistentovi
  450.      *
  451.      * @return array
  452.      */
  453.     public function getParameters()
  454.     {
  455.         $em $this->container->get('doctrine')->getManager();
  456.         $catLink $this->category->getLink();
  457.         # Nacteni vsech dostupnych filtračních parametrů v rámci dané kategorie
  458.         $builder $em
  459.             ->getRepository('EshopBundle:ProductParameters')
  460.             ->createQueryBuilder('ppar')
  461.             ->join('EshopBundle:Parameters''par''WITH''par.id = ppar.parameterId')
  462.             ->join('EshopBundle:Product''p''WITH''p.id = ppar.product');
  463.         $builder $this->productList->build([], $buildertrue);
  464.         $builder->andWhere($builder->expr()->isNotNull('par.filterMethod'));
  465.         $builder->orderBy('par.sequence''ASC');
  466.         $query $builder->getQuery();
  467.         if ($this->cacheTtl) {
  468.             $query->useResultCache(true$this->cacheTtl);
  469.         }
  470.         $result $query->getResult();
  471.         #dump($query->getSQL());die;
  472.         # Výstupní pole parametrů
  473.         $parameters = [];
  474.         $collator = new \Collator('cs_CZ'); // české locale
  475.         foreach ($result as $productParameter) {
  476.             $parameterId $productParameter->getParameterId();
  477.             if (!isset($parameters[$parameterId])) {
  478.                 $parameterEntity $productParameter->getParameter();
  479.                 $tmp = new \stdClass();
  480.                 $tmp->id        $parameterId;
  481.                 $tmp->name      $parameterEntity->getName();
  482.                 $tmp->isNumeric $parameterEntity->isNumericParameter();
  483.                 $tmp->filter    $parameterEntity->getFilterMethod();
  484.                 $tmp->unit      $parameterEntity->getUnit() ? $parameterEntity->getUnit()->getName() : null;
  485.                 $tmp->values    = [];
  486.                 $parameters[$parameterId] = $tmp;
  487.             }
  488.             # Naplnění všemi values pro tuto kategorii
  489.             if ($value $productParameter->getValue()) {
  490.                 $tmp            = new \stdClass();
  491.                 $tmp->id        $value->getId();
  492.                 $tmp->name      $value->getName();
  493.                 $tmp->sequence  $value->getSequence();
  494.                 $tmp->image     $value->imageExists() ? $value->getImageTnUri() : null;
  495.                 $tmp->checked   false;
  496.                 $tmp->disabled  true;
  497.                 $tmp->link      $catLink '?p[' $parameterId '][]=' $value->getId();
  498.                 $parameters[$parameterId]->values[$value->getId()] = $tmp;
  499.             } else {
  500.                 $parameters[$parameterId]->values[] = $productParameter->getFloatValue();
  501.             }
  502.         }
  503.         foreach ($parameters as $parameterId => $parameterEnvelope) {
  504.             # Seřadíme values
  505.             usort($parameterEnvelope->values, function($a$b) use ($collator) {
  506.                 if ($a instanceof \stdClass) {
  507.                     return $collator->compare($a->name$b->name);
  508.                 } else {
  509.                     return $a $b;
  510.                 }
  511.             });
  512.             # Omezíme všechny values dle aktuálních podmínek filtru
  513.             if ($parameterEnvelope->isNumeric && $parameterEnvelope->filter === "range") {
  514.                 $values $this->getCurrentParameterRange($parameterEnvelope->id);
  515.                 $values['overallMin'] = min($parameterEnvelope->values);
  516.                 $values['overallMax'] = max($parameterEnvelope->values);
  517.                 $parameterEnvelope->values $values
  518.             } elseif ($parameterEnvelope->isNumeric) {
  519.                 # Ošetření pro stav kdy numerické zobrazujeme jako checkboxy
  520.                 $normalizedValues = [];
  521.                 foreach ($parameterEnvelope->values as $value) {
  522.                     $tmp            = new \stdClass();
  523.                     $tmp->id        $value;
  524.                     $tmp->name      $value;
  525.                     $tmp->image     null;
  526.                     $tmp->checked   false;
  527.                     $tmp->disabled  true;
  528.                     $tmp->link      $catLink '?p[' $parameterId '][]=' $value;
  529.                     $normalizedValues[] = $tmp;   
  530.                 }
  531.                 $parameterEnvelope->values $normalizedValues;
  532.                 $values $this->getCurrentParameterFloatValues($parameterEnvelope->id);
  533.                 $activeValues $this->productList->getSelectedValuesByParameterId($parameterEnvelope->id);
  534.                 array_walk(
  535.                     $parameterEnvelope->values
  536.                     function($value) use ($values$activeValues) {
  537.                     $value->disabled = !in_array($value->id$values);
  538.                     $value->checked  in_array($value->id$activeValues);
  539.                 });
  540.             } else {
  541.                 $values $this->getCurrentParameterValues($parameterEnvelope->id);
  542.                 $activeValues $this->productList->getSelectedValuesByParameterId($parameterEnvelope->id);
  543.                 array_walk(
  544.                     $parameterEnvelope->values
  545.                     function($value) use ($values$activeValues) {
  546.                     $value->disabled = !array_key_exists($value->id$values);
  547.                     $value->checked  in_array($value->id$activeValues);
  548.                 });
  549.             }
  550.         }
  551.         return $parameters;
  552.     }
  553.     /**
  554.      * Načte aktuální numrické hodnoty na výběr daného parametru
  555.      */
  556.     protected function getCurrentParameterRange($parameterId)
  557.     {
  558.         $em $this->container->get('doctrine')->getManager();
  559.         $builder $em
  560.             ->getRepository('EshopBundle:ProductParameters')
  561.             ->createQueryBuilder('ppar')
  562.             ->join('EshopBundle:Product''p''WITH''p.id = ppar.product');
  563.         $builder $this->productList->build(['parameter_'.$parameterId => true], $builder);
  564.         $builder->andWhere($builder->expr()->isNotNull('ppar.floatValue'));
  565.         $builder->select('(MIN(ppar.floatValue) + 0)  AS rangeMin, (MAX(ppar.floatValue) + 0) AS rangeMax');
  566.         $query $builder->getQuery();
  567.         if ($this->cacheTtl) {
  568.             $query->useResultCache(true$this->cacheTtl);
  569.         }
  570.         $result $query->getSingleResult();
  571.         $values $this->productList->getSelectedValuesByParameterId($parameterId);
  572.         if (isset($values['min']) && $values['min'] > $result['rangeMin'] && $values['min'] < $result['rangeMax']) {
  573.             $result['selectedMin'] = (float) $values['min'];
  574.         } else {
  575.             $result['selectedMin'] = (float) $result['rangeMin'];
  576.         }
  577.         if (isset($values['max']) && $values['max'] > $result['rangeMin'] && $values['max'] < $result['rangeMax']) {
  578.             $result['selectedMax'] = (float) $values['max'];
  579.         } else {
  580.             $result['selectedMax'] = (float) $result['rangeMax'];
  581.         }
  582.         return $result;
  583.     }
  584.     
  585.     /**
  586.      * Načte aktuální možnosti daného parametru
  587.      */
  588.     protected function getCurrentParameterValues($parameterId)
  589.     {
  590.         $em $this->container->get('doctrine')->getManager();
  591.         $builder $em
  592.             ->getRepository('EshopBundle:ProductParameters')
  593.             ->createQueryBuilder('ppar')
  594.             ->join('EshopBundle:Product''p''WITH''p.id = ppar.product');
  595.         $builder $this->productList->build(['parameter_'.$parameterId => true], $builder);
  596.         $builder->andWhere($builder->expr()->eq('ppar.parameterId'$parameterId));
  597.         $builder->andWhere($builder->expr()->isNotNull('ppar.valueId'));
  598.         $result $builder->getQuery()->getResult();
  599.         $values = [];
  600.         foreach ($result as $result) {
  601.             $valueEntity $result->getValue();
  602.             $values[$valueEntity->getId()] = $valueEntity;
  603.         }
  604.         return $values;
  605.     }
  606.     /**
  607.      * Načte aktuální možnosti daného parametru float hodnot
  608.      */
  609.     protected function getCurrentParameterFloatValues($parameterId)
  610.     {
  611.         $em $this->container->get('doctrine')->getManager();
  612.         $builder $em
  613.             ->getRepository('EshopBundle:ProductParameters')
  614.             ->createQueryBuilder('ppar')
  615.             ->join('EshopBundle:Product''p''WITH''p.id = ppar.product');
  616.         $builder $this->productList->build(['parameter_'.$parameterId => true], $builder);
  617.         $builder->andWhere($builder->expr()->eq('ppar.parameterId'$parameterId));
  618.         $builder->andWhere($builder->expr()->isNotNull('ppar.floatValue'));
  619.         $result $builder->getQuery()->getResult();
  620.         $values = [];
  621.         foreach ($result as $result) {
  622.             $values[] = $result->getFloatValue();
  623.         }
  624.         return $values;
  625.     }
  626.     /**
  627.      * Helpers
  628.      */
  629.     protected function getParametersRangeName(Parameters $feature, array $values)
  630.     {
  631.         $translator $this->container->get('eshop_config.translator');
  632.         $text[] = "{$feature->getName()}:";
  633.         if ($values['rMin'] < $values['min']) {
  634.             $text[] =
  635.                 $translator->getValue('OD''od') .
  636.                 ' ' .
  637.                 $values['min'] .
  638.                 (!empty($feature->getUnit()) ? {$feature->getUnit()}'');
  639.         }
  640.         if ($values['rMax'] > $values['max']) {
  641.             $text[] =
  642.                 $translator->getValue('Do''do') .
  643.                 ' ' .
  644.                 $values['max'] .
  645.                 (!empty($feature->getUnit()) ? {$feature->getUnit()}'');
  646.         }
  647.         return implode(' '$text);
  648.     }
  649.     private function getParameterValueNameById($id)
  650.     {
  651.         $value $this->container
  652.             ->get('doctrine')
  653.             ->getRepository('EshopBundle:ParametersValues')
  654.             ->find($id);
  655.         if ($value) {
  656.             return $value->getName();
  657.         } else {
  658.             return $id;
  659.         }
  660.     }
  661. }