public static
getAllAttributesAndOptions
(mixed $ordering = 1, mixed $onlyAvailableProducts = 0, mixed $lang = '', mixed $filterProducts = array())
public static function getAllAttributesAndOptions($ordering = 1, $onlyAvailableProducts = 0, $lang = '', $filterProducts = array())
{
$db = Factory::getDBO();
$orderingText = PhocacartOrdering::getOrderingText($ordering, 5);
$columns = 'v.id, v.title, v.alias, v.image, v.image_medium, v.image_small, v.download_folder, v.download_file, v.download_token, v.color, v.default_value, v.required, v.type, at.id AS attrid, at.title AS attrtitle, at.alias AS attralias, at.type as attrtype';
$groupsFull = 'v.id, v.title, v.alias, v.image, v.image_medium, v.image_small, v.download_folder, v.download_file, v.download_token, v.color, v.default_value, v.required, v.type attralias, at.id, at.title, at.alias, at.type';
$groupsFast = 'v.id';
$groups = PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;
$wheres = array();
$lefts = array();
$lefts[] = ' #__phocacart_attributes AS at ON at.id = v.attribute_id';
if ($onlyAvailableProducts == 1) {
if ($lang != '' && $lang != '*') {
$wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
}
$lefts[] = ' #__phocacart_products AS p ON at.product_id = p.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 at.product_id = p.id';
}
}
if (!empty($filterProducts)) {
$productIds = implode(',', $filterProducts);
$wheres[] = 'p.id IN (' . $productIds . ')';
}
$q = ' SELECT ' . $columns . ' FROM #__phocacart_attribute_values AS v' . (!empty($lefts) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $lefts) : '') . (!empty($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '') . ' GROUP BY ' . $groups . ' ORDER BY ' . $orderingText;
$db->setQuery($q);
$attributes = $db->loadObjectList();
$a = array();
if (!empty($attributes)) {
foreach ($attributes as $k => $v) {
if (isset($v->attrtitle) && $v->attrtitle != '' && isset($v->attrid) && $v->attrid != '' && isset($v->attralias) && $v->attralias != '') {
$a[$v->attralias]['title'] = $v->attrtitle;
$a[$v->attralias]['id'] = $v->attrid;
$a[$v->attralias]['alias'] = $v->attralias;
$a[$v->attralias]['type'] = $v->attrtype;
if (isset($v->title) && $v->title != '' && isset($v->id) && $v->id != '' && isset($v->alias) && $v->alias != '') {
$a[$v->attralias]['options'][$v->alias] = new stdClass();
$a[$v->attralias]['options'][$v->alias]->title = $v->title;
$a[$v->attralias]['options'][$v->alias]->id = $v->id;
$a[$v->attralias]['options'][$v->alias]->alias = $v->alias;
$a[$v->attralias]['options'][$v->alias]->image = $v->image;
$a[$v->attralias]['options'][$v->alias]->image_small = $v->image_small;
$a[$v->attralias]['options'][$v->alias]->download_folder = $v->download_folder;
$a[$v->attralias]['options'][$v->alias]->download_file = $v->download_file;
$a[$v->attralias]['options'][$v->alias]->download_token = $v->download_token;
$a[$v->attralias]['options'][$v->alias]->color = $v->color;
$a[$v->attralias]['options'][$v->alias]->default_value = $v->default_value;
$a[$v->attralias]['options'][$v->alias]->required = $v->required;
$a[$v->attralias]['options'][$v->alias]->type = $v->type;
} else {
$a[$v->attralias]['options'] = array();
}
}
}
}
return $a;
}