You are here

private function UcAddressesAddressBook::loadOne in Ubercart Addresses 6.2

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

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

No database call is done in these cases:

  • Address is already loaded;
  • All addresses are already loaded.

@access private

Parameters

int $type: Type of the argument given, can be the address id (BY_AID) or the address nickname (BY_NAME).

mixed $arg: Either the address id or the address nickname.

Return value

void

Throws

UcAddressesDbException

3 calls to UcAddressesAddressBook::loadOne()
UcAddressesAddressBook::deleteOne in class/UcAddressesAddressBook.class.php
Deletes one address.
UcAddressesAddressBook::getAddressById in class/UcAddressesAddressBook.class.php
Get an address by ID.
UcAddressesAddressBook::getAddressByName in class/UcAddressesAddressBook.class.php
Get an address by it's nickname.

File

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

Class

UcAddressesAddressBook
The address book class

Code

private function loadOne($type, $arg) {

  // Reasons to skip out early.
  if ($this->allLoaded) {
    return;
  }
  if (!$this
    ->isOwned()) {
    return;
  }
  if ($type == self::BY_AID && isset($this->addresses[$arg])) {
    return;
  }
  if ($type == self::BY_NAME && $this
    ->findByName($arg)) {
    return;
  }

  // If we're going to save an address, we'll need to know about
  // possible name collisions and what the current default
  // addresses are.
  if ($this->performanceHint == self::PERF_HINT_LOAD_ALL) {
    $this
      ->loadAll();
    return;
  }

  // Read the database. Note that we ensure that this requested
  // address is in this address book by including $uid in the
  // query.
  if ($type == self::BY_AID) {
    $result = db_query("SELECT * FROM {uc_addresses} WHERE uid = %d AND aid = %d", $this->uid, $arg);
  }
  else {
    $result = db_query("SELECT * FROM {uc_addresses} WHERE uid = %d AND address_name = '%s'", $this->uid, $arg);
  }
  if ($result === FALSE) {
    throw new UcAddressesDbException(t('Failed to read from database table uc_addresses'));
  }
  $this
    ->dbResultToAddresses($result);
}