function _uc_addresses_db_get_address in Ubercart Addresses 5
Same name and namespace in other branches
- 5.2 uc_addresses.module \_uc_addresses_db_get_address()
- 6 uc_addresses.module \_uc_addresses_db_get_address()
Get an address or list of addresses from the database.
Parameters
$uid The id of the user who "owns" the address.:
$aid The id of the address to fetch. If NULL, fetch: all addresses owned by the user.
Return value
FALSE on error. An object if $aid was not NULL. An array of objects if $aid was NULL.
4 calls to _uc_addresses_db_get_address()
- uc_addresses_delete_address_confirm in ./
uc_addresses.module - Display a confirmation page before deleting an address.
- uc_addresses_form_alter in ./
uc_addresses.module - Implementation of hook_form_alter().
- uc_addresses_get_address_form in ./
uc_addresses.module - Create a form used to add a new address or edit an existing address.
- uc_addresses_list_addresses in ./
uc_addresses.module - Generate a list of one or all addresses defined by one user and then theme the list for display.
File
- ./
uc_addresses.module, line 1482
Code
function _uc_addresses_db_get_address($uid, $aid = NULL) {
// If $aid is present, return just the one address
if ($aid) {
$result = db_query("SELECT * FROM {uc_addresses} WHERE aid = %d ", $aid);
// Check to make sure there is data
if (db_num_rows($result) == 0) {
return FALSE;
}
$address = db_fetch_object($result);
// Check to make sure it's from the right user
if ($address->uid != $uid) {
return FALSE;
}
// Find out if this is the default address
$address->is_default = 0;
$def = db_query("SELECT aid FROM {uc_addresses_defaults} WHERE uid = %d", $uid);
if (db_num_rows($def) == 1) {
$default_aid = db_fetch_object($def);
$address->is_default = $default_aid->aid == $address->aid;
}
// All OK
return $address;
}
// If $aid is NULL, return all addresses for that user
$result = db_query("SELECT * FROM {uc_addresses} WHERE uid = %d ORDER BY created", $uid);
// Check to make sure there is data
if (db_num_rows($result) == 0) {
return FALSE;
}
$default_aid = _uc_addresses_get_default_address_id($uid);
// Gather up everything
while ($address = db_fetch_object($result)) {
$address->is_default = $default_aid == $address->aid;
$addresses[] = $address;
}
return $addresses;
}