You are here

function uc_addresses_address_book in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.pages.inc \uc_addresses_address_book()

Generates a list of all addresses owned by a single user.

This address list is themed for display.

If the current user is allowed to edit the addresses, then an edit link for each address will be provided.

Parameters

object $address_user: The user whose address book we want to display.

Return value

string The themed address book.

3 string references to 'uc_addresses_address_book'
UcAddressesViewsTestCase::testDefaultView in tests/uc_addresses.views.test
Tests if the default view works as expected.
uc_addresses_menu in ./uc_addresses.module
Implements hook_menu().
uc_addresses_views_default_views in views/uc_addresses.views_default.inc
Implements hook_views_default_views().

File

./uc_addresses.pages.inc, line 25
Page callbacks for viewing, adding, editing, and deleting addresses.

Code

function uc_addresses_address_book($address_user) {
  drupal_add_css(drupal_get_path('module', 'uc_addresses') . '/uc_addresses.css');
  drupal_set_title(t('Address book'));

  // Initialize addresses array used for in the template.
  $addresses = array();
  try {

    // Get all addresses for address user.
    $address_book = UcAddressesAddressBook::get($address_user);
    $all_addresses = $address_book
      ->getAddresses();
    if (count($all_addresses) > 0) {

      // Check for each address if the user may view it.
      foreach ($all_addresses as $address) {
        $address_output = uc_addresses_list_one_address($address_user, $address);
        if ($address_output) {
          $addresses[$address
            ->getId()] = $address_output;
        }
      }
    }
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
  }
  $options = array();

  // Check if user may add addresses.
  if (UcAddressesPermissions::canEditAddress($address_user)) {

    // Show add link.
    $options['add_link'] = TRUE;
  }
  return theme('uc_addresses_address_book', array(
    'addresses' => $addresses,
    'address_book' => $address_book,
    'options' => $options,
  ));
}