Skip to content

Commit

Permalink
Fixed potential foreach warning in Cumulative Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Dec 9, 2013
1 parent 7d64795 commit 2e7af25
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
1 change: 1 addition & 0 deletions system/modules/isotope/docs/CHANGELOG-2.0.md
Expand Up @@ -14,6 +14,7 @@ Version 2.0.0 (????-??-??)
- Calling Product::setActive() when there's no product available
- Surcharges were not available in notifications
- PSP did not take order to check currency
- Potential foreach warning in Cumulative Filter


Version 2.0.rc2 (2013-11-22)
Expand Down
84 changes: 44 additions & 40 deletions system/modules/isotope/library/Isotope/Module/CumulativeFilter.php
Expand Up @@ -104,54 +104,58 @@ protected function generateFilter()
$blnShowClear = false;
$arrFilters = array();

foreach ($this->iso_filterFields as $strField) {
$blnTrail = false;
$arrItems = array();
$arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField); // Use the default routine to initialize options data

foreach ($arrWidget['options'] as $option) {
$varValue = $option['value'];

// skip zero values (includeBlankOption)
if ($varValue === '' || $varValue === '-') {
continue;
$this->iso_filterFields = deserialize($this->iso_filterFields);

if (is_array($this->iso_filterFields) && count($this->iso_filterFields)) { // Can't use empty() because its an object property (using __get)
foreach ($this->iso_filterFields as $strField) {
$blnTrail = false;
$arrItems = array();
$arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField); // Use the default routine to initialize options data

foreach ($arrWidget['options'] as $option) {
$varValue = $option['value'];

// skip zero values (includeBlankOption)
if ($varValue === '' || $varValue === '-') {
continue;
}

$strFilterKey = $strField . '=' . $varValue;
$blnActive = (Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null);
$blnTrail = $blnActive ? true : $blnTrail;

$arrItems[] = array
(
'href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)),
'class' => ($blnActive ? 'active' : ''),
'title' => specialchars($option['label']),
'link' => $option['label'],
);
}

$strFilterKey = $strField . '=' . $varValue;
$blnActive = (Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null);
$blnTrail = $blnActive ? true : $blnTrail;
if (!empty($arrItems) || ($this->iso_iso_filterHideSingle && count($arrItems) < 2)) {
$objClass = RowClass::withKey('class')->addFirstLast();

$arrItems[] = array
(
'href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)),
'class' => ($blnActive ? 'active' : ''),
'title' => specialchars($option['label']),
'link' => $option['label'],
);
}
if ($blnTrail) {
$objClass->addCustom('sibling');
}

if (!empty($arrItems) || ($this->iso_iso_filterHideSingle && count($arrItems) < 2)) {
$objClass = RowClass::withKey('class')->addFirstLast();
$objClass->applyTo($arrItems);

if ($blnTrail) {
$objClass->addCustom('sibling');
}
$objTemplate = new \Isotope\Template($this->navigationTpl);

$objClass->applyTo($arrItems);
$objTemplate->level = 'level_2';
$objTemplate->items = $arrItems;

$objTemplate = new \Isotope\Template($this->navigationTpl);
$arrFilters[$strField] = array
(
'label' => $arrWidget['label'],
'subitems' => $objTemplate->parse(),
'isActive' => $blnTrail,
);

$objTemplate->level = 'level_2';
$objTemplate->items = $arrItems;

$arrFilters[$strField] = array
(
'label' => $arrWidget['label'],
'subitems' => $objTemplate->parse(),
'isActive' => $blnTrail,
);

$blnShowClear = $blnTrail ? true : $blnShowClear;
$blnShowClear = $blnTrail ? true : $blnShowClear;
}
}
}

Expand Down

0 comments on commit 2e7af25

Please sign in to comment.