예제 #1
0
 /**
  * Compile the module
  */
 protected function compile()
 {
     $arrFilter = explode(';', base64_decode(\Input::get('cumulativefilter', true)), 4);
     if ($arrFilter[0] == $this->id && in_array($arrFilter[2], $this->iso_filterFields)) {
         // Unique filter key is necessary to unset the filter
         $strFilterKey = $arrFilter[2] . '=' . $arrFilter[3];
         if ($arrFilter[1] == 'add') {
             Isotope::getRequestCache()->setFilterForModule($strFilterKey, Filter::attribute($arrFilter[2])->isEqualTo($arrFilter[3]), $this->id);
         } else {
             Isotope::getRequestCache()->removeFilterForModule($strFilterKey, $this->id);
         }
         $objCache = Isotope::getRequestCache()->saveNewConfiguration();
         // Include \Environment::base or the URL would not work on the index page
         \Controller::redirect(\Environment::get('base') . Url::addQueryString('isorc=' . $objCache->id, Url::removeQueryString(array('cumulativefilter'))));
     } else {
         $this->generateFilter();
         $this->Template->linkClearAll = ampersand(preg_replace('/\\?.*/', '', \Environment::get('request')));
         $this->Template->labelClearAll = $GLOBALS['TL_LANG']['MSC']['clearFiltersLabel'];
     }
 }
 /**
  * Generate a filter form
  */
 protected function generateFilters()
 {
     $this->Template->hasFilters = false;
     if (is_array($this->iso_filterFields) && count($this->iso_filterFields)) {
         $time = time();
         $arrFilters = array();
         $arrInput = \Input::post('filter');
         $arrCategories = $this->findCategories();
         foreach ($this->iso_filterFields as $strField) {
             $arrValues = array();
             $objValues = \Database::getInstance()->execute("\n                    SELECT DISTINCT p1.{$strField} FROM tl_iso_product p1\n                    LEFT OUTER JOIN tl_iso_product p2 ON p1.pid=p2.id\n                    WHERE\n                        p1.language=''\n                        " . (BE_USER_LOGGED_IN === true ? '' : "AND p1.published='1' AND (p1.start='' OR p1.start<{$time}) AND (p1.stop='' OR p1.stop>{$time}) ") . "\n                        AND (\n                            p1.id IN (\n                                SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n                            )\n                            OR p1.pid IN (\n                                SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n                            )\n                        )\n                        " . (BE_USER_LOGGED_IN === true ? '' : " AND (p1.pid=0 OR (p2.published='1' AND (p2.start='' OR p2.start<{$time}) AND (p2.stop='' OR p2.stop>{$time})))") . "\n                        " . ($this->iso_list_where == '' ? '' : " AND " . Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where)));
             while ($objValues->next()) {
                 $arrValues[] = deserialize($objValues->{$strField}, false);
             }
             if ($this->blnUpdateCache && in_array($arrInput[$strField], $arrValues)) {
                 Isotope::getRequestCache()->setFilterForModule($strField, Filter::attribute($strField)->isEqualTo($arrInput[$strField]), $this->id);
             } elseif ($this->blnUpdateCache && $arrInput[$strField] == '') {
                 Isotope::getRequestCache()->removeFilterForModule($strField, $this->id);
             } elseif (($objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id)) !== null && $objFilter->valueNotIn($arrValues)) {
                 // Request cache contains wrong value, delete it!
                 $this->blnUpdateCache = true;
                 Isotope::getRequestCache()->removeFilterForModule($strField, $this->id);
                 RequestCache::deleteById(\Input::get('isorc'));
             } elseif (!$this->blnUpdateCache) {
                 // Only generate options if we do not reload anyway
                 if (empty($arrValues)) {
                     continue;
                 }
                 $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField];
                 if (is_array($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback']) && !empty($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'])) {
                     foreach ($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'] as $callback) {
                         $objCallback = \System::importStatic($callback[0]);
                         $arrData = $objCallback->{$callback[1]}($strField, $arrData, $this);
                     }
                 }
                 // Use the default routine to initialize options data
                 $arrWidget = \Widget::getAttributesFromDca($arrData, $strField);
                 $objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id);
                 if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strField]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) {
                     $objAttribute->optionsSource = 'attribute';
                     $arrWidget['options'] = $objAttribute->getOptionsForProductFilter($arrValues);
                 }
                 foreach ($arrValues as $value) {
                     $arrWidget['options'][] = array('value' => $value, 'label' => $value == '' ? ' ' : 'text');
                 }
                 // Must have options to apply the filter
                 if (!is_array($arrWidget['options'])) {
                     continue;
                 }
                 foreach ($arrWidget['options'] as $k => $option) {
                     if ($option['value'] == '') {
                         $arrWidget['blankOptionLabel'] = $option['label'];
                         unset($arrWidget['options'][$k]);
                         continue;
                     } elseif (!in_array($option['value'], $arrValues) || $option['value'] == '-') {
                         // @deprecated IsotopeAttributeWithOptions::getOptionsForProductFilter already checks this
                         unset($arrWidget['options'][$k]);
                         continue;
                     }
                     $arrWidget['options'][$k]['default'] = null !== $objFilter && $objFilter->valueEquals($option['value']) ? '1' : '';
                 }
                 // Hide fields with just one option (if enabled)
                 if ($this->iso_filterHideSingle && count($arrWidget['options']) < 2) {
                     continue;
                 }
                 $arrFilters[$strField] = $arrWidget;
             }
         }
         // !HOOK: alter the filters
         if (isset($GLOBALS['ISO_HOOKS']['generateFilters']) && is_array($GLOBALS['ISO_HOOKS']['generateFilters'])) {
             foreach ($GLOBALS['ISO_HOOKS']['generateFilters'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 $arrFilters = $objCallback->{$callback}[1]($arrFilters);
             }
         }
         if (!empty($arrFilters)) {
             $this->Template->hasFilters = true;
             $this->Template->filterOptions = $arrFilters;
         }
     }
 }
 /**
  * @param Filter[] $filters
  * @param string   $attribute
  * @param string   $value
  *
  * @return Filter[]
  */
 private function addFilter(array $filters, $attribute, $value)
 {
     if ($this->isCsv($attribute)) {
         $filter = CsvFilter::attribute($attribute)->contains($value);
     } else {
         $filter = Filter::attribute($attribute)->isEqualTo($value);
     }
     if (!$this->isMultiple($attribute) || self::QUERY_OR === $this->iso_cumulativeFields[$attribute]['queryType']) {
         $group = 'cumulative_' . $attribute;
         $filter->groupBy($group);
         if (self::QUERY_AND === $this->iso_cumulativeFields[$attribute]['queryType']) {
             foreach ($filters as $k => $oldFilter) {
                 if ($oldFilter->getGroup() == $group) {
                     unset($filters[$k]);
                 }
             }
         }
     }
     $filters[$this->generateFilterKey($attribute, $value)] = $filter;
     return $filters;
 }
예제 #4
0
 /**
  * Generate a filter form
  */
 protected function generateFilters()
 {
     $this->Template->hasFilters = false;
     if (!empty($this->iso_filterFields)) {
         $arrFilters = array();
         $arrInput = \Input::post('filter');
         $arrCategories = $this->findCategories();
         foreach ($this->iso_filterFields as $strField) {
             $arrValues = $this->getUsedValuesForAttribute($strField, $arrCategories, $this->iso_newFilter, $this->iso_list_where);
             if ($this->blnUpdateCache && in_array($arrInput[$strField], $arrValues)) {
                 Isotope::getRequestCache()->setFilterForModule($strField, Filter::attribute($strField)->isEqualTo($arrInput[$strField]), $this->id);
             } elseif ($this->blnUpdateCache && $arrInput[$strField] == '') {
                 Isotope::getRequestCache()->removeFilterForModule($strField, $this->id);
             } elseif (($objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id)) !== null && $objFilter->valueNotIn($arrValues)) {
                 // Request cache contains wrong value, delete it!
                 $this->blnUpdateCache = true;
                 Isotope::getRequestCache()->removeFilterForModule($strField, $this->id);
                 RequestCache::deleteById(\Input::get('isorc'));
             } elseif (!$this->blnUpdateCache) {
                 // Only generate options if we do not reload anyway
                 if (empty($arrValues)) {
                     continue;
                 }
                 $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField];
                 // Use the default routine to initialize options data
                 $arrWidget = \Widget::getAttributesFromDca($arrData, $strField);
                 $objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id);
                 if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strField]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) {
                     $arrWidget['options'] = $objAttribute->getOptionsForProductFilter($arrValues);
                 }
                 // Must have options to apply the filter
                 if (!is_array($arrWidget['options'])) {
                     continue;
                 }
                 foreach ($arrWidget['options'] as $k => $option) {
                     if ($option['value'] == '') {
                         $arrWidget['blankOptionLabel'] = $option['label'];
                         unset($arrWidget['options'][$k]);
                         continue;
                     } elseif (!in_array($option['value'], $arrValues) || $option['value'] == '-') {
                         // @deprecated IsotopeAttributeWithOptions::getOptionsForProductFilter already checks this
                         unset($arrWidget['options'][$k]);
                         continue;
                     }
                     $arrWidget['options'][$k]['default'] = null !== $objFilter && $objFilter->valueEquals($option['value']) ? '1' : '';
                 }
                 // Hide fields with just one option (if enabled)
                 if ($this->iso_filterHideSingle && count($arrWidget['options']) < 2) {
                     continue;
                 }
                 $arrFilters[$strField] = $arrWidget;
             }
         }
         // !HOOK: alter the filters
         if (isset($GLOBALS['ISO_HOOKS']['generateFilters']) && is_array($GLOBALS['ISO_HOOKS']['generateFilters'])) {
             foreach ($GLOBALS['ISO_HOOKS']['generateFilters'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 $arrFilters = $objCallback->{$callback}[1]($arrFilters);
             }
         }
         if (!empty($arrFilters)) {
             $this->Template->hasFilters = true;
             $this->Template->filterOptions = $arrFilters;
         }
     }
 }