You are here

public static function UCXF_Value::load in Extra Fields Checkout Pane 7

Same name and namespace in other branches
  1. 6.2 class/UCXF_Value.class.php \UCXF_Value::load()

Loads value from database.

@access public

Parameters

int $element_id: id of element, order_id or uc_addresses id.

int $element_type: type of element: order or address.

int $field_id: id of field as known in uc_extra_fields.

Return value

UCXF_Value

3 calls to UCXF_Value::load()
UCXFApiTestCase::testUCXF_Value in ./uc_extra_fields_pane.test
Test if UCXF_Value behaves as excepted.
uc_extra_fields_pane_value_load in ./uc_extra_fields_pane.module
uc_extra_fields_pane_value_load() Loads value from database
uc_extra_fields_pane_value_save in ./uc_extra_fields_pane.module
uc_extra_fields_pane_value_save() Saves data to database

File

class/UCXF_Value.class.php, line 244
Contains the UCXF_Value class.

Class

UCXF_Value
This class is used to keep track of all field values currently loaded.

Code

public static function load($element_id, $element_type, $field_id) {

  // Check if value has already been loaded
  if (isset(self::$loaded_values[$element_id][$element_type][$field_id])) {
    return self::$loaded_values[$element_id][$element_type][$field_id];
  }
  $query = db_select('uc_extra_fields_values', 'ucxf_values');
  $query
    ->innerJoin('uc_extra_fields', 'ucxf_fields', 'ucxf_values.field_id = ucxf_fields.field_id');
  $result = $query
    ->condition('ucxf_values.element_id', $element_id)
    ->condition('ucxf_values.element_type', $element_type)
    ->condition('ucxf_values.field_id', $field_id)
    ->fields('ucxf_values', array(
    'element_id',
    'element_type',
    'field_id',
    'value',
  ))
    ->fields('ucxf_fields', array(
    'db_name',
  ))
    ->execute();
  if ($result) {
    self::dbResultToValue($result);
  }

  // Check if we have a result now
  if (isset(self::$loaded_values[$element_id][$element_type][$field_id])) {
    return self::$loaded_values[$element_id][$element_type][$field_id];
  }

  // Create new UCXF_Value
  $oValue = new self();
  $oValue->element_id = $element_id;
  $oValue->element_type = $element_type;
  $oValue->field_id = $field_id;

  // Save this UCXF_Value in the list
  self::$loaded_values[$element_id][$element_type][$field_id] = $oValue;

  // Return the UCXF_Value
  return $oValue;
}