You are here

function image_gallery_handler_relationship_gallery_cover::left_query in Image 7

Same name and namespace in other branches
  1. 6 contrib/image_gallery/views/image_gallery_handler_relationship_gallery_cover.inc \image_gallery_handler_relationship_gallery_cover::left_query()

Return the subquery to use for the left side of the relationship join clause.

1 call to image_gallery_handler_relationship_gallery_cover::left_query()
image_gallery_handler_relationship_gallery_cover::query in contrib/image_gallery/views/image_gallery_handler_relationship_gallery_cover.inc
Called to implement a relationship in a query.

File

contrib/image_gallery/views/image_gallery_handler_relationship_gallery_cover.inc, line 85

Class

image_gallery_handler_relationship_gallery_cover
Relationship handler for image gallery cover node.

Code

function left_query() {
  $order = $this->definition['subquery order'];
  $field = $this->definition['correlated field'];
  $where_tid = $this->table_alias . '.' . $field;
  $subquery = "\nSELECT gallery_cover_node.nid FROM " . "{term_node} gallery_cover_term_node INNER JOIN {node} gallery_cover_node \n" . "ON gallery_cover_term_node.nid = gallery_cover_node.nid ";
  $where = "  WHERE gallery_cover_node.status = 1 AND " . "gallery_cover_term_node.tid = {$where_tid} ";

  // Depth: this is shamelessly ripped from views_handler_argument_term_node_tid_depth
  if ($this->options['depth'] > 0) {
    $subquery .= "    LEFT JOIN {term_hierarchy} th ON th.tid = gallery_cover_term_node.tid\n";
    $last = "th";
    foreach (range(1, abs($this->options['depth'])) as $count) {
      $subquery .= "    LEFT JOIN {term_hierarchy} th{$count} ON {$last}.parent = th{$count}.tid\n";
      $where .= "\n OR th{$count}.tid = {$where_tid}\n";
      $last = "th{$count}";
    }
  }
  else {
    if ($this->options['depth'] < 0) {
      $last = "tn";
      foreach (range(1, abs($this->options['depth'])) as $count) {
        $subquery .= "    LEFT JOIN {term_hierarchy} th{$count} ON {$last}.tid = th{$count}.parent\n";
        $where .= "\n OR th{$count}.tid = {$where_tid}\n";
        $last = "th{$count}";
      }
    }
  }
  $subquery = "{$subquery} {$where} ORDER BY {$order} LIMIT 1";
  return $subquery;
}