Back to PhocacartManufacturer class

Method getAllManufacturers

public static
getAllManufacturers
(mixed $ordering = 1, mixed $onlyAvailableProducts = 0, mixed $lang = '', mixed $filterProducts = array(), mixed $limitCount = -1)

Method getAllManufacturers - Source code

public static function getAllManufacturers($ordering = 1, $onlyAvailableProducts = 0, $lang = '', $filterProducts = array(), $limitCount = -1)
{
    $db = Factory::getDBO();
    $orderingText = PhocacartOrdering::getOrderingText($ordering, 4);
    $wheres = array();
    $lefts = array();
    $columns = 'm.id, m.title, m.image, m.alias, m.description, m.count_products';
    /*$groupsFull		= $columns;
    		$groupsFast		= 'm.id';
    		$groups			= PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;*/
    $wheres[] = ' m.published = 1';
    if ($lang != '' && $lang != '*') {
        $wheres[] = PhocacartUtilsSettings::getLangQuery('m.language', $lang);
    }
    if ($onlyAvailableProducts == 1) {
        if ($lang != '' && $lang != '*') {
            $wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
        }
        $lefts[] = ' #__phocacart_products AS p ON m.id = p.manufacturer_id';
        $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[] = ' #__phocacart_products AS p ON m.id = p.manufacturer_id';
        }
    }
    if (!empty($filterProducts)) {
        $productIds = implode(',', $filterProducts);
        $wheres[] = 'p.id IN (' . $productIds . ')';
    }
    if ((int) $limitCount > -1) {
        $wheres[] = " m.count_products > " . (int) $limitCount;
    }
    $q = ' SELECT DISTINCT ' . $columns . ' FROM  #__phocacart_manufacturers AS m' . (!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;
}