function uc_attribute_load in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_load()
- 5 uc_attribute/uc_attribute.module \uc_attribute_load()
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_load()
Loads an attribute from the database.
Parameters
$aid: The ID of the attribute.
$type: The type of attribute. 'product', or 'class'. Any other type will fetch a base attribute.
$id: The ID of the product/class this attribute belongs to.
Return value
The attribute object, or FALSE if it doesn't exist.
13 calls to uc_attribute_load()
- UbercartAttributeTestCase::testAttributeAPI in uc_attribute/
uc_attribute.test - Tests the basic attribute API.
- UbercartAttributeTestCase::testAttributeUIAddAttribute in uc_attribute/
uc_attribute.test - Tests the "add attribute" user interface.
- UbercartAttributeTestCase::testAttributeUIClassAttributeOverview in uc_attribute/
uc_attribute.test - Tests the product class attribute user interface.
- UbercartAttributeTestCase::testAttributeUIEditAttribute in uc_attribute/
uc_attribute.test - Tests the "edit attribute" user interface.
- UbercartAttributeTestCase::testAttributeUIProductAttributeOverview in uc_attribute/
uc_attribute.test - Tests the product node attribute user interface.
File
- uc_attribute/
uc_attribute.module, line 719
Code
function uc_attribute_load($aid, $id = NULL, $type = '') {
$sql = uc_attribute_type_info($type);
switch ($type) {
case 'product':
case 'class':
// Read attribute data.
$attribute = db_fetch_object(db_query("\n SELECT a.aid, a.name, a.label AS default_label, a.ordering AS default_ordering,\n a.required AS default_required, a.display AS default_display,\n a.description, pa.label, pa.default_option, pa.required, pa.ordering,\n pa.display, pa.{$sql['id']}\n FROM {uc_attributes} AS a\n LEFT JOIN {$sql['attr_table']} AS pa ON a.aid = pa.aid AND\n pa.{$sql['id']} = {$sql['placeholder']}\n WHERE a.aid = %d", $id, $aid));
// Don't try to build it further if it failed already.
if (!$attribute) {
return FALSE;
}
// Set any missing defaults.
foreach (array(
'ordering',
'required',
'display',
'label',
) as $field) {
if (isset($attribute->{"default_{$field}"}) && is_null($attribute->{$field})) {
$attribute->{$field} = $attribute->{"default_{$field}"};
}
}
if (empty($attribute->label)) {
$attribute->label = $attribute->name;
}
// Read option data.
$result = db_query("\n SELECT po.{$sql['id']}, po.oid, po.cost, po.price, po.weight, po.ordering, ao.name,\n ao.aid\n FROM {$sql['opt_table']} AS po\n LEFT JOIN {uc_attribute_options} AS ao ON po.oid = ao.oid AND\n po.{$sql['id']} = {$sql['placeholder']}\n WHERE aid = %d ORDER BY po.ordering, ao.name", $id, $aid);
break;
default:
// Read attribute and option data.
$attribute = db_fetch_object(db_query("SELECT * FROM {uc_attributes} WHERE aid = %d", $aid));
$result = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering, name", $aid);
// Don't try to build it further if it failed already.
if (!$attribute) {
return FALSE;
}
break;
}
// Got an attribute?
if ($attribute) {
// Get its options, too.
$attribute->options = array();
while ($option = db_fetch_object($result)) {
$attribute->options[$option->oid] = $option;
}
uc_attribute_translate($attribute);
}
return $attribute;
}