You are here

function _views_build_query in Views (for Drupal 7) 5

1 call to _views_build_query()
_views_get_query in ./views_cache.inc

File

./views_query.inc, line 6

Code

function _views_build_query(&$view, $args = array(), $filters = array()) {
  $query = new _views_query('node', 'nid', !empty($view->use_alias_prefix) ? $view->use_alias_prefix : '');

  // Process static filters and exposed filters
  _views_view_build_filters($query, $view, $filters);

  // Process arguments.
  $view->args = $args;

  // we'll need these later.
  foreach ($view->argument as $i => $argument) {
    if ($args[$i] != NULL && $args[$i] != '' && $args[$i] != '$arg') {
      _views_view_build_arg($query, $args[$i], $argument);
    }
    else {

      // This is what we do if we expected an arg but we didn't get it.
      switch ($argument['argdefault']) {
        case 1:
          $info['fail'] = TRUE;
          return $info;
        case 3:
        case 4:
          $self_sort = "ASC";
        case 5:

          // the if is a kind of a hack to make this case fall-thru fluid
          if (!$self_sort) {
            $self_sort = "DESC";
          }
        case 6:
          $level = $i;
          _views_build_summary($query, $argument['type'], $argument['options'], $self_sort);
          $summary = true;
          if (!$self_sort) {
            $sort = true;
          }
          break 2;

        // switch and for
        case 7:

          // to trigger empty text, send back an empty query
          $info['query'] = NULL;
          return $info;
      }
    }
  }
  if (!$summary || $sort) {
    _views_view_build_sorts($query, $view);
    $plugins = _views_get_style_plugins();
    if ($view->page && $plugins[$view->page_type]['needs_fields'] || $view->block && $plugins[$view->block_type]['needs_fields']) {
      _views_view_build_fields($query, $view);
    }
  }
  foreach (module_implements('views_query_alter') as $module) {
    $function = $module . '_views_query_alter';
    $results = $function($query, $view, $summary, $level);
  }
  $info['query'] = $query
    ->query();
  $info['countquery'] = $query
    ->query(true);
  $info['summary'] = $summary;
  $info['level'] = $level;
  $info['args'] = $query->where_args;
  return $info;
}