You are here

function uc_option_image_objects in Ubercart Option Images 7

Retrieve the image id for a given object

Parameters

$type = '': uc_attribute, uc_option, uc_product or uc_class If this is an empty string, all objects will be returned, keyed by type

$ids = NULL: The instance ids of the object, since each row contains multiple ids, according to the specificity of the data If this is NULL, all objects of the given type will be returned

Return value

Depending on the parameters, an array, a keyed array, or an object

$type and $ids are empty: a keyed array where the keys are type names and the values are arrays of objects only $ids is empty: an array of objects neither are empty: a single object

In all cases, if no data is present, NULL will be returned

3 calls to uc_option_image_objects()
uc_option_image_form in ./uc_option_image.module
Add a form element to allow the admin to insert a default image which applies to all options, unless an option is overridden.
uc_option_image_form_uc_object_options_form_alter in ./uc_option_image.module
Implements hook_uc_object_options_form_alter()
uc_option_image_save_form_data in ./uc_option_image.module

File

./uc_option_image.module, line 505
Allow store administrators to add images to attribute options.

Code

function uc_option_image_objects($type = '', $ids = NULL) {
  $query = db_select('uc_option_image', 'uoi');
  $query
    ->fields('uoi');
  if ($type) {
    $query
      ->condition('type', $type);
  }
  if ($ids) {
    $ids += array(
      'aid' => NULL,
      'oid' => NULL,
      'pid' => NULL,
      'cid' => NULL,
    );
    foreach ($ids as $field => $id) {
      if ($id) {
        $query
          ->condition($field, $id);
      }
      else {
        $query
          ->condition($field, 0);
      }
    }
  }
  $result = $query
    ->execute();
  $objects = array();
  foreach ($result as $row) {
    $objects[$row->type][] = $row;
  }
  if (!$objects) {
    return NULL;
  }
  if ($type && $ids) {
    return empty($objects[$type]) ? NULL : $objects[$type][0];
  }
  if ($type && !$ids) {
    return empty($objects[$type]) ? NULL : $objects[$type];
  }
  return $objects;
}