/** * Override of UcAddressesSchemaAddress::setField(). * * Prevents setting some schema fields directly. * * @param string $fieldName * The name of the field whose value we will set. * @param mixed $value * The value to which to set the field. * * @access public * @return void * @throws UcAddressInvalidFieldException */ public function setField($fieldName, $value) { switch ($fieldName) { case 'aid': // Don't set. // @todo Throw an Exception here? break; case 'uid': // Only set if the address is unowned. Else, ignore it. // @todo Throw an Exception here? if (!$this->isOwned()) { $this->setOwner($value); } break; case 'address_name': $this->setName($value); break; case 'default_shipping': if ($value) { $this->setAsDefault('shipping'); } break; case 'default_billing': if ($value) { $this->setAsDefault('billing'); } break; default: parent::setField($fieldName, $value); break; } }
/** * Checks if the schema address of the given address * is equal to the schema address of this. * * @param UcAddressesSchemaAddress $address * The address to compare against. * * @access public * @return boolean * TRUE if the addresses are considered equal. * FALSE otherwise. */ public function compareAddress(UcAddressesSchemaAddress $address) { $fields_to_compare =& drupal_static('UcAddressesSchemaAddress::compareAddress', array()); if ($address === $this) { // No comparison needed. Given address object is exactly the same. return TRUE; } $fieldsDataThisAddress = $this->getRawFieldData(); $fieldsDataOtherAddress = $address->getRawFieldData(); // Find out which field to compare. if (count($fields_to_compare) < 1) { $fields_data = self::getDefinedFields(); foreach ($fields_data as $fieldName => $field_data) { if ($field_data['compare']) { $fields_to_compare[] = $fieldName; } } } foreach ($fields_to_compare as $fieldName) { if ($fieldsDataThisAddress[$fieldName] != $fieldsDataOtherAddress[$fieldName]) { return FALSE; } } return TRUE; }