You are here

function menu_node_views_argument_nid::query in Menu Node Views 7

Same name and namespace in other branches
  1. 6 includes/menu_node_views_argument_nid.inc \menu_node_views_argument_nid::query()
  2. 7.2 includes/menu_node_views_argument_nid.inc \menu_node_views_argument_nid::query()

Set up the query for this argument.

The argument sent may be found at $this->argument.

Parameters

bool $group_by: Whether the query uses a group-by.

Overrides views_handler_argument_numeric::query

File

includes/menu_node_views_argument_nid.inc, line 26

Class

menu_node_views_argument_nid
Argument handler to accept a node id that is menu-sensitive.

Code

function query($group_by = FALSE) {
  $this
    ->ensure_my_table();
  $nid = $this->argument;
  $depth = $this->options['depth'];
  $pid_list = db_query("SELECT mlid FROM {menu_node} WHERE nid = :nid", array(
    ':nid' => $nid,
  ));
  $conditions = array();
  foreach ($pid_list as $pid) {
    $item = db_query("SELECT * FROM {menu_links} WHERE mlid = :pid", array(
      ':pid' => $pid->mlid,
    ))
      ->fetchObject();
    if ($item) {
      $max_depth = menu_link_children_relative_depth((array) $item);
      if ($max_depth < $this->options['depth']) {
        $depth = $max_depth;
      }
      $i = (int) $item->depth;
      $depth = (int) ($i + $depth);
      $expression = "({$this->table_alias}.p{$i} = " . (int) $item->mlid;
      $expression .= " AND {$this->table_alias}.depth > {$i}";
      $expression .= " AND {$this->table_alias}.depth <= {$depth})";
      $conditions[] = $expression;
    }
  }
  $snippet = '(' . implode(' OR ', $conditions) . ')';
  $this->query
    ->add_where_expression(0, $snippet);
}