/** * 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; } } }
/** * Generate a limit form */ protected function generateLimit() { $this->Template->hasLimit = false; if ($this->iso_enableLimit) { $arrOptions = array(); $arrLimit = array_map('intval', trimsplit(',', $this->iso_perPage)); $objLimit = Isotope::getRequestCache()->getFirstLimitForModules(array($this->id)); $arrLimit = array_unique($arrLimit); sort($arrLimit); if ($this->blnUpdateCache && in_array(\Input::post('limit'), $arrLimit)) { // Cache new request value Isotope::getRequestCache()->setLimitForModule(Limit::to(\Input::post('limit')), $this->id); } elseif ($objLimit->notIn($arrLimit)) { // Request cache contains wrong value, delete it! $this->blnUpdateCache = true; Isotope::getRequestCache()->setLimitForModule(Limit::to($arrLimit[0]), $this->id); RequestCache::deleteById(\Input::get('isorc')); } elseif (!$this->blnUpdateCache) { // No need to generate options if we reload anyway foreach ($arrLimit as $limit) { $arrOptions[] = array('label' => $limit, 'value' => $limit, 'default' => $objLimit->equals($limit) ? '1' : ''); } $this->Template->hasLimit = true; $this->Template->limitLabel = $GLOBALS['TL_LANG']['MSC']['perPageLabel']; $this->Template->limitOptions = $arrOptions; } } }