function uc_addresses_list_addresses in Ubercart Addresses 5
Same name and namespace in other branches
- 5.2 uc_addresses.module \uc_addresses_list_addresses()
- 6 uc_addresses.module \uc_addresses_list_addresses()
Generate a list of one or all addresses defined by one user and then theme the list for display.
If the current user can edit the addresses, then provide an edit link for each address.
Parameters
$uid The id of the user whose list we want to display.:
$aid The id of the address to display or null to display all.:
Return value
The themed list (as a string).
1 string reference to 'uc_addresses_list_addresses'
- uc_addresses_menu in ./
uc_addresses.module - Implementation of hook_menu().
File
- ./
uc_addresses.module, line 614
Code
function uc_addresses_list_addresses($uid, $aid = NULL) {
global $user;
// Save this for later use
$saved_aid = $aid;
// Determine if the user can view all addresses or just the default address
$can_view_all_addresses = $user->uid == $uid || user_access(UC_ADDRESSES_ACCESS_VIEW_ALL) || user_access(UC_ADDRESSES_ACCESS_ADD_EDIT);
// Flag to determine error message
$allowed_to_view_address = true;
// If they can view all addresses, fetch the addresses
if ($can_view_all_addresses) {
$addresses = _uc_addresses_db_get_address($uid, $aid);
}
else {
if ($aid === NULL) {
$aid = _uc_addresses_get_default_address_id($uid);
if ($aid === NULL) {
$aid = 0;
}
// NULL would mean read all addresses
}
$addresses = _uc_addresses_db_get_address($uid, $aid);
if (is_object($addresses) && $addresses->is_default === false) {
$addresses = FALSE;
$allowed_to_view_address = FALSE;
}
}
$output = '';
// We have multiple addresses
if (is_array($addresses)) {
foreach ($addresses as $address) {
$output .= _uc_addresses_list_one_address($uid, $address);
}
}
elseif (is_object($addresses)) {
$output .= _uc_addresses_list_one_address($uid, $addresses);
}
else {
// If they asked for all addresses and got nothing, it's because
// there is nothing
if ($saved_aid === NULL) {
$output .= t('No addresses have been saved.<br />');
}
elseif ($allowed_to_view_address) {
$output .= t('This address does not exist.<br />');
}
else {
$output .= t('You are not allowed to view this address.<br />');
}
}
// Decide whether to include a link for adding a new address based
// on whether the current user can edit the addresses
if (user_access(UC_ADDRESSES_ACCESS_ADD_EDIT) || $user->uid == $uid) {
$link = l(t('Add a new address'), 'user/' . $uid . '/addresses/add');
$output .= $link;
}
return $output;
}