You are here

function amazon_component_lookup_gallery_from_db in Amazon Product Advertisement API 7.2

Look up ASINs in database and return arrays of information keyed by ASIN.

Parameters

$item_ids: An array of string ASINs.

$size: Image Gallery Size Filter. Reference define(AMAZON_IMAGE_SIZES) in amazon Module.

Return value

array Array of Amazon 'cleaned' data structures keyed by ASIN.

1 call to amazon_component_lookup_gallery_from_db()
amazon_component_gallery_lookup in amazon_component/amazon_component.module
Look up an item using database or web. The default is to look in the database for existing data, and then to do the web search if that fails. $force_lookup==TRUE forces going to Amazon's API.

File

amazon_component/amazon_component.module, line 199

Code

function amazon_component_lookup_gallery_from_db($item_ids = array(), $size = NULL) {
  if (!empty($item_ids)) {

    // Function Variables
    $items = array();
    $i = 0;

    // IF :: Return all image gallery sizes: smallimage, mediumimage, etc.
    if (!$size) {

      // Query :: ASIN Image Gallery WITHOUT $size
      $query = 'SELECT * FROM {amazon_item_image_gallery} WHERE asin IN (:asins)';
      $args = array(
        ':asins' => $item_ids,
      );
      $options = array(
        'fetch' => PDO::FETCH_ASSOC,
      );

      // Result :: Image Gallery Sizes
      $result = db_query($query, $args, $options);

      // ELSE :: Return single image gallery size.
    }
    else {

      // Query :: ASIN Image Gallery WITH $size
      $query = 'SELECT * FROM {amazon_item_image_gallery} WHERE asin IN (:asins) AND size IN (:size)';
      $args = array(
        ':asins' => $item_ids,
        ':size' => $size,
      );
      $options = array(
        'fetch' => PDO::FETCH_ASSOC,
      );

      // Result :: Image Gallery Sizes
      $result = db_query($query, $args, $options);
    }

    // Loop :: Query Result into $items varkables
    foreach ($result as $image) {
      $items[$image['asin']]['imagesets_gallery'][$image['size']][$image['image_order']] = $image;
    }

    // Return :: (array) $items
    return $items;
  }
  return array();
}