You are here

public function UcAddressesAddressBook::setAddressName in Ubercart Addresses 6.2

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

Sets the name of the address.

@access public

Parameters

UcAddressesAddress $address: The address to set a name for.

string $name: The nickname the address will get.

Return value

boolean TRUE if the name was changed. FALSE otherwise.

File

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

Class

UcAddressesAddressBook
The address book class

Code

public function setAddressName($address, $name) {
  if (!$this->allLoaded) {
    $this
      ->loadAll();
  }

  // Check to make sure this is one of our addresses.
  if ($address
    ->getAddressBook() !== $this) {
    return FALSE;
  }

  // Check if an other address already has the same name.
  // We don't allow two addresses having the same name.
  // One exception: multiple addresses having an empty name is allowed.
  if ($name !== '') {
    foreach ($this->addresses as $aid => $addr) {
      if ($address !== $addr && $addr
        ->getName() == $name) {
        return FALSE;
      }
    }
  }
  $address
    ->privSetUcAddressField('name', $name);
  return TRUE;
}