You are here

public function UcAddressesSchemaAddress::setField in Ubercart Addresses 6.2

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

Set a field's value.

@access public

Parameters

string $fieldName: The name of the field whose value we will set.

mixed $value: The value to which to set the field.

Return value

void

Throws

UcAddressInvalidFieldException

3 calls to UcAddressesSchemaAddress::setField()
UcAddressesAddress::setField in class/UcAddressesAddress.class.php
Override of UcAddressesSchemaAddress::setField().
UcAddressesSchemaAddress::setMultipleFields in class/UcAddressesSchemaAddress.class.php
Set multiple fields at once.
UcAddressesSchemaAddress::__set in class/UcAddressesSchemaAddress.class.php
Magic setter.
1 method overrides UcAddressesSchemaAddress::setField()
UcAddressesAddress::setField in class/UcAddressesAddress.class.php
Override of UcAddressesSchemaAddress::setField().

File

class/UcAddressesSchemaAddress.class.php, line 254
Contains the UcAddressesSchemaAddress class.

Class

UcAddressesSchemaAddress
The schema address class.

Code

public function setField($fieldName, $value) {
  self::fieldMustExist($fieldName);

  // Convert value to the right data type.
  $fields_data = self::getDefinedFields();
  switch ($fields_data[$fieldName]['type']) {
    case 'text':
    case 'string':
      $value = (string) $value;
      break;
    case 'int':
    case 'integer':
    case 'date':
      $value = (int) $value;
      break;
    case 'decimal':
    case 'duration':
    case 'float':
    case 'numeric':
      $value = (double) $value;
      break;
    case 'boolean':
      $value = (bool) $value;
      break;
    default:

      // In all other cases the setted value is left untouched.
      break;
  }
  if ($this->schemaAddress->{$fieldName} !== $value) {
    $this->schemaAddress->{$fieldName} = $value;
    $this
      ->setDirty();
  }
}