/** * Output a field's value. * * @param mixed $value * The value to output. * @param string $format * The format in which the value should be outputted. * Possible formats are declared by field handlers: getOutputFormats(). * * @access public * @return string * The field's value safe for output. * @see getOutputFormats() */ public function outputValue($value = '', $format = '') { if ($value === '') { $value = $this->address->getField($this->name); } return check_plain($value); }
/** * Removes an address from this address book. * * This method is called when an address is deleted * or when the owner of an address is set. * * @param UcAddressesAddress $address * The address to remove from the address book. * * @access private * @return void */ private function removeAddressFromAddressBook($address) { $aid = $address->getId(); if (isset($this->addresses[$aid])) { unset($this->addresses[$address->getId()]); } // Check default addresses array foreach ($this->defaultAddresses as $address_type => $defaultAddress) { if ($defaultAddress->getId() == $aid) { unset($this->defaultAddresses[$address_type]); } } }
/** * Restore variables when the address is unserialized. * * @access public * @return void */ public function __wakeup() { parent::__wakeup(); $this->addressBook = UcAddressesAddressBook::get($this->getSchemaAddress()->uid); if ($this->getId() <= self::$nextNewAid) { self::$nextNewAid = $this->getId() - 1; } try { $this->addressBook->addAddress($this); } catch (UcAddressesException $e) { // Ignore any exceptions. } }
/** * Check if the user can delete addresses of this user. * Default addresses can never be deleted. * * @param object $address_user * The owner of the address. * @param UcAddressesAddress * (optional) The address object. * @param object $account * (optional) The account to check access for. * Defaults to the current active user. * * @access public * @static * @return boolean * TRUE if the given user has permission to delete the address. * FALSE otherwise. */ public static function canDeleteAddress($address_user, UcAddressesAddress $address = NULL, $account = NULL) { $account = self::getAccount($account); if ($address instanceof UcAddressesAddress) { // Check if the address is a default address. If so, the address may not be deleted. if ($address->isDefault('shipping') || $address->isDefault('billing')) { return FALSE; } } if ($address_user->uid == $account->uid && self::canDeleteOwn($account)) { // Ask other modules if the address may be deleted. return self::invoke('uc_addresses_may_delete', $address_user, $address, $account); } if ($address_user->uid != $account->uid && self::canDeleteAll($account)) { // Ask other modules if the address may be deleted. return self::invoke('uc_addresses_may_delete', $address_user, $address, $account); } // No other cases are permitted. return FALSE; }
/** * This hook allows you to prevent a certain address from being edited. * * Don't use this hook if you want to prevent editing addresses for users * with a certain role. You can use the permission settings for that. * * If you want the address not to be edited return FALSE. * Return TRUE in all other cases. * WARNING: If you don't return TRUE, then no address may be edited. * * Note that this hook is only invoked when permissions are checked and not * when changes to an address are done programmatically. * * @param object $address_user * The owner of the address. * @param UcAddressesAddress $address * (optional) Address object. * @param object $account * The account to check access for. * * @return boolean * FALSE if the account may not edit the address or any address from * the address user if no address is passed. * TRUE otherwise. */ function hook_uc_addresses_may_edit($address_user, $address, $account) { // Example: don't allow editing of default addresses. if ($address instanceof UcAddressesAddress) { if ($address->isDefault('shipping') || $address->isDefault('billing')) { return FALSE; } } // In all other cases, the address may be edited. return TRUE; }