function _uc_addresses_db_get_address in Ubercart Addresses 6
Same name and namespace in other branches
- 5.2 uc_addresses.module \_uc_addresses_db_get_address()
- 5 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.
3 calls to _uc_addresses_db_get_address()
- uc_addresses_address_load in ./
uc_addresses.module - Given a wildcard of %uc_addresses_address in path, replace it with the corresponding address object.
- uc_addresses_form_uc_cart_checkout_form_alter in ./
uc_addresses.module - Implementation of hook_form_alter().
- 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 1555
Code
function _uc_addresses_db_get_address($uid, $aid = NULL) {
if ($aid === 0) {
return FALSE;
}
// 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 (($address = db_fetch_object($result)) == FALSE) {
return FALSE;
}
// 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 ($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);
$default_aid = _uc_addresses_get_default_address_id($uid);
// Gather up everything
$num_rows = 0;
while ($address = db_fetch_object($result)) {
$num_rows++;
$address->is_default = $default_aid == $address->aid;
$addresses[] = $address;
}
if ($num_rows == 0) {
return FALSE;
}
return $addresses;
}