Back to PhocacartTag class

Method getAllTags

public static mixed
getAllTags
(mixed $ordering = 1, mixed $onlyAvailableProducts = 0, mixed $type = 0, mixed $lang = '', mixed $filterProducts = array(), mixed $limitCount = -1)
Parameters
  • int $ordering
  • int $onlyAvailableProducts
  • int $type 0 ... tag, 1 ... label
  • string $lang
Returns
  • mixed

Method getAllTags - Source code

/**
 * @param int $ordering
 * @param int $onlyAvailableProducts
 * @param int $type 0 ... tag, 1 ... label
 * @param string $lang
 * @return mixed
 */
public static function getAllTags($ordering = 1, $onlyAvailableProducts = 0, $type = 0, $lang = '', $filterProducts = array(), $limitCount = -1)
{
    /*	$db 			= JFactory::getDBO();
    		$orderingText 	= PhocacartOrdering::getOrderingText($ordering, 3);
    
    		$query = 'SELECT t.id, t.title, t.alias FROM #__phocacart_tags AS t WHERE t.published = 1 ORDER BY '.$orderingText;
    		$db->setQuery($query);
    		$tags = $db->loadObjectList();
    
    		return $tags;*/
    $wheres = array();
    $lefts = array();
    switch ($type) {
        case 1:
            $wheres[] = ' t.type = 1';
            $related = '#__phocacart_taglabels_related';
            break;
        case 0:
        default:
            $wheres[] = ' t.type = 0';
            $related = '#__phocacart_tags_related';
            break;
    }
    $db = Factory::getDBO();
    $orderingText = PhocacartOrdering::getOrderingText($ordering, 3);
    $columns = 't.id, t.title, t.alias, t.type, t.count_products';
    /*$groupsFull		= $columns;
    		$groupsFast		= 'm.id';
    		$groups			= PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;*/
    $wheres[] = ' t.published = 1';
    $productTableAdded = 0;
    if ($onlyAvailableProducts == 1) {
        if ($lang != '' && $lang != '*') {
            $wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
        }
        $lefts[] = ' ' . $related . ' AS tr ON tr.tag_id = t.id';
        $lefts[] = ' #__phocacart_products AS p ON tr.item_id = p.id';
        $productTableAdded = 1;
        $rules = PhocacartProduct::getOnlyAvailableProductRules();
        $wheres = array_merge($wheres, $rules['wheres']);
        $lefts = array_merge($lefts, $rules['lefts']);
    } else {
        if ($lang != '' && $lang != '*') {
            $wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
            $lefts[] = ' ' . $related . ' AS tr ON tr.tag_id = t.id';
            $lefts[] = ' #__phocacart_products AS p ON tr.item_id = p.id';
            $productTableAdded = 1;
        }
    }
    if (!empty($filterProducts)) {
        $productIds = implode(',', $filterProducts);
        $wheres[] = 'p.id IN (' . $productIds . ')';
        if ($productTableAdded == 0) {
            $lefts[] = ' ' . $related . ' AS tr ON tr.tag_id = t.id';
            $lefts[] = ' #__phocacart_products AS p ON tr.item_id = p.id';
        }
    }
    if ((int) $limitCount > -1) {
        $wheres[] = " t.count_products > " . (int) $limitCount;
    }
    $q = ' SELECT DISTINCT ' . $columns . ' FROM  #__phocacart_tags AS t' . (!empty($lefts) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $lefts) : '') . (!empty($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '') . ' ORDER BY ' . $orderingText;
    $db->setQuery($q);
    $items = $db->loadObjectList();
    return $items;
}