You are here

function views_handler_field_amazon_image::render in Amazon Product Advertisement API 7.2

Same name and namespace in other branches
  1. 6 includes/views_handler_field_amazon_image.inc \views_handler_field_amazon_image::render()
  2. 7 includes/views_handler_field_amazon_image.inc \views_handler_field_amazon_image::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

includes/views_handler_field_amazon_image.inc, line 88
Provide views handler so that Amazon Image can be displayed in the various ways that are available.

Class

views_handler_field_amazon_image
@file Provide views handler so that Amazon Image can be displayed in the various ways that are available.

Code

function render($values) {
  $url = $this
    ->get_value($values, 'url');
  $asin = $this
    ->get_value($values, 'asin');

  // We may not have a URL. It's not guaranteed that Amazon will give us one.
  if (empty($url)) {
    return;
  }
  $attributes = array(
    'height' => $this
      ->get_value($values, 'height'),
    'width' => $this
      ->get_value($values, 'width'),
  );

  // Choose presentation style
  if ($this->options['presentation_format'] == 'markup') {
    $image = theme('image', array(
      'path' => $url,
      'alt' => NULL,
      'title' => NULL,
      'attributes' => $attributes,
      'getsize' => FALSE,
    ));
  }
  else {
    $image = $url;
  }
  switch ($this->options['link_format']) {
    case 'plain':
      return $image;
      break;
    case 'amazon':
      if ($detailpageurl = $this
        ->get_value($values, 'detailpageurl')) {
        return l($image, $detailpageurl, array(
          'html' => TRUE,
        ));
      }
      else {
        return $image;
      }
      break;
    case 'amazon_store':
      $path = function_exists('amazon_store_get_amazon_store_path') ? amazon_store_get_amazon_store_path() : 'amazon_store';
      return l($image, $path . '/item/' . $asin, array(
        'html' => TRUE,
      ));
      break;
  }
}