You are here

class image_field_caption_handler_join in Image Field Caption 7.2

@file Image field caption views join handler.

Hierarchy

Expanded class hierarchy of image_field_caption_handler_join

1 string reference to 'image_field_caption_handler_join'
image_field_caption_views_data in views/image_field_caption.views.inc
Implements of hook_views_data().

File

views/image_field_caption_handler_join.inc, line 8
Image field caption views join handler.

View source
class image_field_caption_handler_join extends views_join {

  /**
   * This is basically a copy of views_join::build_join
   * excepts that it also adds delta as this module always relates
   * to a delta
   *
   * Build the SQL for the join this object represents.
   *
   * When possible, try to use table alias instead of table names.
   *
   * @param $select_query
   *   An implementation of SelectQueryInterface.
   * @param $table
   *   The base table to join.
   * @param $view_query
   *   The source query, implementation of views_plugin_query.
   */
  function build_join($select_query, $table, $view_query) {
    if (empty($this->definition['table formula'])) {
      $right_table = $this->table;
    }
    else {
      $right_table = $this->definition['table formula'];
    }
    if ($this->left_table) {
      $left = $view_query
        ->get_table_info($this->left_table);
      $left_field = "{$left['alias']}.{$this->left_field}";
      $left_field_delta = "{$left['alias']}.delta";
    }
    else {

      // This can be used if left_field is a formula or something. It should be used only *very* rarely.
      $left_field = $this->left_field;
      $left_field_delta = "delta";
    }
    $condition = "{$left_field} = {$table['alias']}.{$this->field}";

    // Add delta
    $condition .= " AND {$left_field_delta} = {$table['alias']}.delta";
    $arguments = array();

    // Tack on the extra.
    if (isset($this->extra)) {
      if (is_array($this->extra)) {
        $extras = array();
        foreach ($this->extra as $info) {
          $extra = '';

          // Figure out the table name. Remember, only use aliases provided
          // if at all possible.
          $join_table = '';
          if (!array_key_exists('table', $info)) {
            $join_table = $table['alias'] . '.';
          }
          elseif (isset($info['table'])) {

            // If we're aware of a table alias for this table, use the table
            // alias instead of the table name.
            if (isset($left) && $left['table'] == $info['table']) {
              $join_table = $left['alias'] . '.';
            }
            else {
              $join_table = $info['table'] . '.';
            }
          }

          // Convert a single-valued array of values to the single-value case,
          // and transform from IN() notation to = notation
          if (is_array($info['value']) && count($info['value']) == 1) {
            if (empty($info['operator'])) {
              $operator = '=';
            }
            else {
              $operator = $info['operator'] == 'NOT IN' ? '!=' : '=';
            }
            $info['value'] = array_shift($info['value']);
          }
          if (is_array($info['value'])) {

            // With an array of values, we need multiple placeholders and the
            // 'IN' operator is implicit.
            foreach ($info['value'] as $value) {
              $placeholder_i = $view_query
                ->placeholder('views_join_condition_');
              $arguments[$placeholder_i] = $value;
            }
            $operator = !empty($info['operator']) ? $info['operator'] : 'IN';
            $placeholder = '( ' . implode(', ', array_keys($arguments)) . ' )';
          }
          else {

            // With a single value, the '=' operator is implicit.
            $operator = !empty($info['operator']) ? $info['operator'] : '=';
            $placeholder = $view_query
              ->placeholder('views_join_condition_');
            $arguments[$placeholder] = $info['value'];
          }
          $extras[] = "{$join_table}{$info['field']} {$operator} {$placeholder}";
        }
        if ($extras) {
          if (count($extras) == 1) {
            $condition .= ' AND ' . array_shift($extras);
          }
          else {
            $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
          }
        }
      }
      elseif ($this->extra && is_string($this->extra)) {
        $condition .= " AND ({$this->extra})";
      }
    }
    $select_query
      ->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
image_field_caption_handler_join::build_join function This is basically a copy of views_join::build_join excepts that it also adds delta as this module always relates to a delta Overrides views_join::build_join
views_join::$definition public property
views_join::$extra public property
views_join::$field public property
views_join::$left_field public property
views_join::$left_table public property
views_join::$table public property
views_join::$type public property
views_join::construct public function Construct the views_join object. 1