You are here

class views_handler_field_amazon_participant in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 includes/views_handler_field_amazon_participant.inc \views_handler_field_amazon_participant
  2. 7 includes/views_handler_field_amazon_participant.inc \views_handler_field_amazon_participant

Hierarchy

Expanded class hierarchy of views_handler_field_amazon_participant

2 string references to 'views_handler_field_amazon_participant'
amazon_views_data in includes/amazon.views.inc
amazon_views_handlers in includes/amazon.views.inc
Implementation of hook_views_handlers()

File

includes/views_handler_field_amazon_participant.inc, line 3

View source
class views_handler_field_amazon_participant extends views_handler_field_prerender_list {
  function construct() {
    parent::construct();
    $this->additional_fields['asin'] = array(
      'table' => 'amazon_item',
      'field' => 'asin',
    );
  }

  /**
   * Provide meaningful defaults
   */
  function options(&$options) {
    parent::options($options);
    $options['participant_type'] = '**ALL**';
  }

  /**
   * Provide "link to term" option.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['participant_type'] = array(
      '#type' => 'select',
      '#title' => t('Participant restriction'),
      '#options' => array(
        '**ALL**' => t('Show all particpants'),
        'author' => 'Author',
        'artist' => 'Artist',
        'actor' => 'Actor',
        'director' => 'Director',
        'creator' => 'Creator',
      ),
      '#default_value' => $this->options['participant_type'],
    );
  }
  function query() {
    $this
      ->add_additional_fields();
  }
  function pre_render($values) {
    $this->field_alias = $this->aliases['asin'];
    $this->items = array();
    $asins = array();
    foreach ($values as $result) {
      if (!empty($result->{$this->aliases['asin']})) {
        $asins[] = $result->{$this->aliases['asin']};
      }
    }
    $sql = "SELECT aip.participant, aip.asin FROM {amazon_item_participant} aip WHERE aip.asin IN ('" . implode("', '", $asins) . "') ";
    if ($this->options['participant_type'] != '**ALL**') {
      $sql .= " AND aip.type = '%s'";
    }
    $results = db_query($sql, $this->options['participant_type']);
    while ($result = db_fetch_array($results)) {
      $this->items[$result['asin']][] = check_plain($result['participant']);
    }
  }

}

Members