function uc_attribute_load_multiple in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_load_multiple()
- 6.2 uc_attribute/uc_attribute.module \uc_attribute_load_multiple()
Loads attribute objects from the database.
@todo If we feel it necessary, we could optimize this, by inverting the logic; that is, we could make uc_attribute load call this function and allow this function to minimize the number of queries necessary. -cha0s
Parameters
array $aids: Attribute IDs to load.
string $type: The type of attribute. 'product', or 'class'. Any other type will fetch a base attribute.
int $id: The ID of the product/class this attribute belongs to.
Return value
array An array of loaded attributes.
3 calls to uc_attribute_load_multiple()
- UbercartAttributeTestCase::testAttributeAPI in uc_attribute/
tests/ uc_attribute.test - Tests the basic attribute API.
- UbercartCartLinksTestCase::createCartLinksProduct in uc_cart_links/
tests/ uc_cart_links.test - Creates a product with all attribute types and options.
- uc_attribute_load_product_attributes in uc_attribute/
uc_attribute.module - Fetches an array of attribute objects that belong to a product.
File
- uc_attribute/
uc_attribute.module, line 615 - Ubercart Attribute module.
Code
function uc_attribute_load_multiple(array $aids = array(), $type = '', $id = NULL) {
$sql = uc_attribute_type_info($type);
// Product/class attributes.
if (!empty($type)) {
// Seems like a big query to get attribute IDs, but it's all about the sort.
// (I'm not sure if the default ordering is propagating down correctly here.
// It appears that product/class attributes with no ordering won't let the
// attribute's propagate down, as it does when loading. -cha0s)
$query = db_select($sql['attr_table'], 'uca')
->fields('uca', array(
'aid',
))
->condition("uca.{$sql['id']}", $id);
$query
->leftJoin('uc_attributes', 'ua', 'uca.aid = ua.aid');
$query
->orderBy('uca.ordering')
->orderBy('ua.name');
}
else {
$query = db_select('uc_attributes', 'ua')
->fields('ua', array(
'aid',
))
->orderBy('ordering')
->orderBy('name');
}
// Filter by the attribute IDs requested.
if (!empty($aids)) {
// Sanity check - filter out non-numeric attribute IDs.
$aids = array_filter($aids, 'is_numeric');
$query
->condition('ua.aid', $aids, 'IN');
}
$aids = $query
->execute()
->fetchCol();
// Load the attributes.
$attributes = array();
foreach ($aids as $aid) {
$attributes[$aid] = uc_attribute_load($aid, $id, $type);
}
return $attributes;
}