Exemplo n.º 1
0
 public function updateFacet(QueryBuilder $constrainedQuery, Facet $facet)
 {
     $qb = $constrainedQuery->merge($this->getBaseQueryBuilder()->innerJoin($this->qb->table("feature_value_lang")->alias("fvl"), $this->qb->both($this->qb->equal($this->qb->field("fvl", "id_feature_value"), $this->qb->field("fp", "id_feature_value")), $this->qb->equal($this->qb->field("fvl", "id_lang"), $this->qb->value($this->context->getIdLang()))))->where($this->qb->equal($this->qb->field("fl", "name"), $this->qb->value($facet->getLabel())))->groupBy($this->qb->field("fvl", "value"))->select($this->qb->field("fvl", "value")->alias("label"))->select($this->qb->count($this->qb->distinct($this->qb->field("p", "id_product")->noSuffix()))->alias("magnitude")));
     $newFacet = (new Facet())->setLabel($facet->getLabel());
     foreach ($this->db->executeS($qb->getSQL()) as $row) {
         $newFacet->addFilter((new Filter())->setType("feature")->setLabel($row["label"])->setMagnitude((int) $row["magnitude"])->setActive($this->isFilterActive($facet, $row["label"])));
     }
     return $newFacet;
 }
 /**
  * Converts a Facet to an array with all necessary
  * information for templating.
  *
  * @param Facet $facet
  *
  * @return array ready for templating
  */
 protected function prepareFacetForTemplate(Facet $facet)
 {
     $facetsArray = $facet->toArray();
     foreach ($facetsArray['filters'] as &$filter) {
         $filter['facetLabel'] = $facet->getLabel();
         if ($filter['nextEncodedFacets']) {
             $filter['nextEncodedFacetsURL'] = $this->updateQueryString(array('q' => $filter['nextEncodedFacets'], 'page' => null));
         } else {
             $filter['nextEncodedFacetsURL'] = $this->updateQueryString(array('q' => null));
         }
     }
     unset($filter);
     return $facetsArray;
 }
 private function getFilterByLabel(Facet $facet, $label)
 {
     foreach ($facet->getFilters() as $filter) {
         if ($filter->getLabel() === $label) {
             return $filter;
         }
     }
     throw new Exception(sprintf('Could not find a filter labelled `%1$s` in the `%2$s` facet containing `%3$s` filters (%4$s).', $label, $facet->getLabel(), count($facet->getFilters()), implode(", ", array_map(function (Filter $f) {
         return $f->getLabel();
     }, $facet->getFilters()))));
 }