Back to PhocacartCategory class

Method filterCategory

public static
filterCategory
(mixed $query, mixed $active = NULL, mixed $frontend = NULL, mixed $onChange = TRUE, mixed $fullTree = NULL)

Method filterCategory - Source code

public static function filterCategory($query, $active = NULL, $frontend = NULL, $onChange = TRUE, $fullTree = NULL)
{
    $db = Factory::getDBO();
    $form = 'adminForm';
    if ($frontend == 1) {
        $form = 'phocacartproductsform';
    }
    if ($onChange) {
        $onChO = 'class="form-control" size="1" onchange="document.' . $form . '.submit( );"';
    } else {
        $onChO = 'class="form-control" size="1"';
    }
    $categories[] = HTMLHelper::_('select.option', '0', '- ' . Text::_('COM_PHOCACART_SELECT_CATEGORY') . ' -');
    $db->setQuery($query);
    $catData = $db->loadObjectList();
    if ($fullTree) {
        // Start - remove in case there is a memory problem
        $tree = array();
        $text = '';
        $queryAll = ' SELECT cc.id AS value, cc.title AS text, cc.parent_id as parentid' . ' FROM #__phocacart_categories AS cc' . ' ORDER BY cc.ordering';
        $db->setQuery($queryAll);
        $catDataAll = $db->loadObjectList();
        $catDataTree = PhocacartCategory::CategoryTreeOption($catDataAll, $tree, 0, $text, -1);
        $catDataTreeRights = array();
        /*foreach ($catData as $k => $v) {
        			foreach ($catDataTree as $k2 => $v2) {
        				if ($v->value == $v2->value) {
        					$catDataTreeRights[$k]->text 	= $v2->text;
        					$catDataTreeRights[$k]->value = $v2->value;
        				}
        			}
        		}*/
        foreach ($catDataTree as $k => $v) {
            foreach ($catData as $k2 => $v2) {
                if ($v->value == $v2->value) {
                    $catDataTreeRights[$k] = new StdClass();
                    $catDataTreeRights[$k]->text = $v->text;
                    $catDataTreeRights[$k]->value = $v->value;
                }
            }
        }
        $catDataTree = array();
        $catDataTree = $catDataTreeRights;
        // End - remove in case there is a memory problem
        // Uncomment in case there is a memory problem
        //$catDataTree	= $catData;
    } else {
        $catDataTree = $catData;
    }
    $categories = array_merge($categories, $catDataTree);
    $category = HTMLHelper::_('select.genericlist', $categories, 'catid', $onChO, 'value', 'text', $active);
    return $category;
}