Back to PhocacartFilter class

Method getActiveFilterValues

public
getActiveFilterValues
()

Method getActiveFilterValues - Source code

public function getActiveFilterValues()
{
    $app = Factory::getApplication();
    $paramsC = PhocacartUtils::getComponentParameters();
    $manufacturer_alias = $paramsC->get('manufacturer_alias', 'manufacturer');
    $manufacturer_alias = $manufacturer_alias != '' ? trim(PhocacartText::filterValue($manufacturer_alias, 'alphanumeric')) : 'manufacturer';
    $parameters = PhocacartParameter::getAllParameters();
    $option = $app->input->get('option', '', 'string');
    $view = $app->input->get('view', '', 'string');
    $id = 0;
    if ($option == 'com_phocacart' && $view == 'item') {
        $id = $app->input->get('catid', '', 'int');
        // Category ID (Active Category)
    } else {
        if ($option == 'com_phocacart' && ($view == 'items' && $view == 'category')) {
            $id = $app->input->get('id', '', 'int');
            // Category ID (Active Category)
        }
    }
    $c = $app->input->get('c', '', 'string');
    // Category More (All Categories)
    $tags = $app->input->get('tag', '', 'string');
    $labels = $app->input->get('label', '', 'string');
    $manufacturers = $app->input->get($manufacturer_alias, '', 'string');
    $price_from = $app->input->get('price_from', '', 'float');
    $price_to = $app->input->get('price_to', '', 'float');
    $a = $app->input->get('a', '', 'array');
    // Attributes
    $s = $app->input->get('s', '', 'array');
    // Specifications
    // CATEGORY id
    $cIdIN = '';
    //- $cIdIK = '';
    if ($id > 0) {
        $cIdIN = (int) $id;
        //- $cIdIK = (int)$cIdIN > 0 ? ':cid:' . $cIdIN : '';
    }
    // CATEGORY
    $cIN = '';
    //- $cIK = '';
    if ($c != '') {
        $cA = explode(',', $c);
        $cAN = array_unique(array_map('intval', $cA));
        $cIN = implode(',', $cAN);
        //- $cIK = (int)$cIN > 0 ? ':c:' . $cIN : '';
    }
    // TAGS
    $tIN = '';
    //- $tIK = '';
    if ($tags != '') {
        $tA = explode(',', $tags);
        $tAN = array_unique(array_map('intval', $tA));
        $tIN = implode(',', $tAN);
        //- $tIK = (int)$tIN > 0 ? ':t:' . $tIN : '';
    }
    // LABELS
    $lIN = '';
    //- $lIK = '';
    if ($labels != '') {
        $lA = explode(',', $labels);
        $lAN = array_unique(array_map('intval', $lA));
        $lIN = implode(',', $lAN);
        //- $lIK = (int)$lIN > 0 ? ':l:' . $lIN : '';
    }
    // MANUFACTURERS
    $mIN = '';
    //- $mIK = '';
    if ($manufacturers != '') {
        $mA = explode(',', $manufacturers);
        $mAN = array_unique(array_map('intval', $mA));
        $mIN = implode(',', $mAN);
        //- $mIK = (int)$mIN > 0 ? ':m:' . $mIN : '';
    }
    // PRICE
    $pfIN = $pfIK = '';
    if ($price_from !== '') {
        $pfIN = $price_from;
        //- $pfIK = $pfIN > 0 ? ':pf:' . $pfIN : '';
    }
    $ptIN = $ptIK = '';
    if ($price_to !== '') {
        $ptIN = $price_to;
        //- $ptIK = $ptIN > 0 ? ':pt:' . $ptIN : '';
    }
    // PARAMETERS
    $pA = array();
    //- $pIK = '';
    if (!empty($parameters)) {
        foreach ($parameters as $k => $v) {
            $alias = trim(PhocacartText::filterValue($v->alias, 'alphanumeric'));
            $parameter = $app->input->get($alias, '', 'string');
            if ($parameter != '') {
                $pIN = implode(',', array_unique(array_map('intval', explode(',', $parameter))));
                if ((int) $pIN > 0) {
                    //- $pIK .= ':' . $alias . ':' . $pIN;
                    $pA[$alias] = $pIN;
                }
            }
        }
    }
    // ATTRIBUTES
    $aA = array();
    //- $aIK = '';
    if (!empty($a)) {
        foreach ($a as $k => $v) {
            $alias = strip_tags($k);
            $parameter = strip_tags($v);
            $alias = trim(PhocacartText::filterValue($alias, 'alphanumeric'));
            if ($parameter != '') {
                $aINA = explode(',', $parameter);
                $aINA = array_map(function ($item) {
                    return PhocacartText::filterValue($item, 'alphanumeric');
                }, $aINA);
                $aINA = array_unique($aINA);
                $aIN = implode(',', $aINA);
                if ($aIN != '') {
                    //- $aIK .= ':' . $alias . ':' . $aIN;
                    $aA[$alias] = "'" . implode("','", $aINA) . "'";
                }
            }
        }
    }
    // SPECIFICATIONS
    $sA = array();
    //- $sIK = '';
    if (!empty($s)) {
        foreach ($s as $k => $v) {
            $alias = strip_tags($k);
            $parameter = strip_tags($v);
            $alias = trim(PhocacartText::filterValue($alias, 'alphanumeric'));
            if ($parameter != '') {
                $sINA = explode(',', $parameter);
                $sINA = array_map(function ($item) {
                    return PhocacartText::filterValue($item, 'alphanumeric');
                }, $sINA);
                $sINA = array_unique($sINA);
                $sIN = implode(',', $sINA);
                if ($sIN != '') {
                    //- $sIK .= ':' . $alias . ':' . $sIN;
                    $sA[$alias] = "'" . implode("','", $sINA) . "'";
                }
            }
        }
    }
    //- $key = 'k' . $cIdIK . $cIK . $tIK . $lIK . $mIK . $pfIK . $ptIK . $pIK . $aIK . $sIK;
    //- $key = base64_encode(serialize($key));
    // Get all items
    $f = array();
    if ($cIN != '') {
        $f['c'] = PhocacartCategory::getActiveCategories($cIN, $this->ordering_category);
    } else {
        if ((int) $cIdIN > 0) {
            $f['c'] = PhocacartCategory::getActiveCategories((int) $cIdIN, $this->ordering_category);
        }
    }
    $f['t'] = PhocacartTag::getActiveTags($tIN, $this->ordering_tag);
    $f['l'] = PhocacartTag::getActiveLabels($lIN, $this->ordering_label);
    $f['m'] = PhocacartManufacturer::getActiveManufacturers($mIN, $this->ordering_manufacturer, $manufacturer_alias);
    $f['price'] = array();
    $f['price']['from'] = '';
    $f['price']['to'] = '';
    if ($pfIN !== '') {
        $f['price']['from'] = $pfIN;
    }
    if ($ptIN !== '') {
        $f['price']['to'] = $ptIN;
    }
    $f['p'] = PhocacartParameter::getActiveParameterValues($pA, $this->ordering_parameter);
    $f['a'] = PhocacartAttribute::getActiveAttributeValues($aA, $this->ordering_attribute);
    $f['s'] = PhocacartSpecification::getActiveSpecificationValues($aA, $this->ordering_specification);
    return $f;
}