You are here

private function UcAddressesAddressBook::deleteOne in Ubercart Addresses 6.2

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

Deletes one address.

@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

boolean TRUE if the address was deleted. FALSE otherwise.

Throws

UcAddressesDbException

3 calls to UcAddressesAddressBook::deleteOne()
UcAddressesAddressBook::deleteAddress in class/UcAddressesAddressBook.class.php
Deletes an addres by giving the addres object.
UcAddressesAddressBook::deleteAddressById in class/UcAddressesAddressBook.class.php
Deletes an address by ID.
UcAddressesAddressBook::deleteAddressByName in class/UcAddressesAddressBook.class.php
Deletes an address by name.

File

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

Class

UcAddressesAddressBook
The address book class

Code

private function deleteOne($type, $arg) {

  // Reasons to skip out early
  if (!$this
    ->isOwned()) {
    return FALSE;
  }

  // We can't delete an address that is a default address, so
  // we'll need to make sure this address is loaded.
  $this
    ->loadOne($type, $arg);
  if ($type == self::BY_AID) {
    $address = $this
      ->getAddressById($arg);
  }
  if ($type == self::BY_NAME) {
    $address = $this
      ->getAddressByName($arg);
  }
  if (!$address) {
    return FALSE;
  }
  if ($address
    ->isDefault('shipping') || $address
    ->isDefault('billing')) {
    return FALSE;
  }

  // Delete the address from the database only if it is not new (else it won't exist in the db).
  if (!$address
    ->isNew()) {
    $result = db_query("DELETE FROM {uc_addresses} WHERE aid = %d", $address
      ->getId());
    if ($result === FALSE || db_affected_rows() == 0) {
      throw new UcAddressesDbException(t('Failed to delete an address from database table uc_addresses'));
    }
  }

  // Remove from address book object.
  $this
    ->removeAddressFromAddressBook($address);

  // Give other modules a chance to react on this.
  module_invoke_all('uc_addresses_address_delete', $address);
  return TRUE;
}