Back to PhocacartGroup class

Method getGroupsById

public static
getGroupsById
(mixed $id, mixed $type, mixed $returnArray = 0, mixed $productId = 0)

Method getGroupsById - Source code

/*
 * id ... user id
 * type ... see header comment in this class
 *
 */
public static function getGroupsById($id, $type, $returnArray = 0, $productId = 0)
{
    $key = base64_encode(serialize((int) $id . ':' . (int) $type . (int) $returnArray . ':' . (int) $productId));
    if (!array_key_exists((string) $key, self::$group)) {
        if ((int) $id > 0) {
            $db = Factory::getDBO();
            $query = 'SELECT a.id, a.title, a.alias, a.type, a.published, a.display_price, a.display_addtocart, a.display_attributes' . ' FROM #__phocacart_groups AS a' . ' LEFT JOIN #__phocacart_item_groups AS g ON g.group_id = a.id' . ' WHERE g.item_id = ' . (int) $id . ' AND g.type = ' . (int) $type;
            if ($productId > 0) {
                $query .= ' AND g.product_id = ' . (int) $productId;
            }
            $query .= ' ORDER BY a.id';
            $db->setQuery($query);
            if ($returnArray == 1) {
                $items = $db->loadColumn();
                if (empty($items)) {
                    $items = array(0 => 1);
                    // Default is default for all
                }
            } else {
                if ($returnArray == 2) {
                    $items = $db->loadAssocList();
                    if (empty($items)) {
                        $items[0]['id'] = 1;
                        $items[0]['title'] = 'COM_PHOCACART_DEFAULT';
                        $items[0]['alias'] = 'com-phocacart-default';
                        $items[0]['type'] = 1;
                        $items[0]['display_price'] = 1;
                        $items[0]['display_addtocart'] = 1;
                        $items[0]['display_attributes'] = 1;
                        $items[0]['published'] = 1;
                    }
                } else {
                    $items = $db->loadObjectList();
                    if (empty($items)) {
                        $items[0]->id = 1;
                        $items[0]->title = 'COM_PHOCACART_DEFAULT';
                        $items[0]->alias = 'com-phocacart-default';
                        $items[0]->type = 1;
                        $items[0]->display_price = 1;
                        $items[0]->display_addtocart = 1;
                        $items[0]->display_attributes = 1;
                        $items[0]->published = 1;
                    }
                }
            }
            self::$group[$key] = $items;
        } else {
            self::$group[$key] = array(0 => 1);
        }
    }
    if (!empty(self::$group[$key])) {
        return self::$group[$key];
    } else {
        return array(0 => 1);
    }
}