You are here

private static function UcAddressesAddressBook::loadStatic in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 class/UcAddressesAddressBook.class.php \UcAddressesAddressBook::loadStatic()

Loads a single address from the database if not already loaded.

@access private

Parameters

int $aid: The id of the address.

Return value

boolean TRUE if the address has been loaded or found. FALSE otherwise.

1 call to UcAddressesAddressBook::loadStatic()
UcAddressesAddressBook::loadAddress in class/UcAddressesAddressBook.class.php
Looks up a single address.

File

class/UcAddressesAddressBook.class.php, line 917
Contains the UcAddressesAddressBook class.

Class

UcAddressesAddressBook
The address book class

Code

private static function loadStatic($aid) {

  // Reasons to skip out early.
  // Lookup in all address books if the address is already loaded.
  foreach (self::$singleton as $addressbook) {
    if ($addressbook
      ->addressExists($aid)) {
      return TRUE;
    }
  }
  $result = db_query("SELECT * FROM {uc_addresses} WHERE aid = %d", $aid);
  if ($result === FALSE) {
    throw new UcAddressesDbException(t('Failed to read from database table uc_addresses'));
  }

  // Create an object from the database record.
  $obj = db_fetch_object($result);
  if (!$obj) {

    // If there is no such address record, then abort.
    return FALSE;
  }

  // Get address book for loaded user.
  $addressbook = self::get($obj->uid);

  // Create UcAddressesAddress object.
  $address = new UcAddressesAddress($addressbook, $obj);

  // Give other modules a chance to add their fields.
  module_invoke_all('uc_addresses_address_load', $address, $obj);
  return TRUE;
}