You are here

function draggableviews_views_query_alter in DraggableViews 7

Same name and namespace in other branches
  1. 8 draggableviews.module \draggableviews_views_query_alter()
  2. 6.3 views/draggableviews.views.inc \draggableviews_views_query_alter()

@todo Please document this function.

See also

http://drupal.org/node/1354

File

views/draggableviews.views.inc, line 95
Derives the view style plugin

Code

function draggableviews_views_query_alter(&$view, &$query) {
  $exists = FALSE;
  for ($i = 0; $i < 2; $i++) {
    if (isset($query->table_queue['draggableviews_structure_' . $view->base_table . $i])) {
      $exists = TRUE;
    }
  }
  if (!$exists) {

    // No "DraggableViews: Order/Parent" fields available.
    return;
  }

  // We look for a display of this view that uses arguments.
  // If any of the displays uses arguments we'll use arguments for this display too, except the
  // style plugin configuration of this display tells us explicitly something else.
  $use_args = FALSE;
  if (isset($view->style_plugin->options['draggableviews_arguments']['use_args'])) {
    $use_args = !empty($view->style_plugin->options['draggableviews_arguments']['use_args']);
  }
  else {
    foreach ($view->display as $display_id => $display) {
      if (isset($display->display_options['style_plugin'])) {
        $display_options = $display->display_options;

        // We don't care about the fact that displays probably don't contain
        // all their information because of inheritance of the default display.
        // We'll check the default display anyway.
        if ($display_options['style_plugin'] == 'draggabletable') {
          if (!empty($display_options['style_options']['draggableviews_arguments']['use_args'])) {
            $use_args = TRUE;
          }
        }
      }
    }
  }
  for ($i = 0; $i < 2; $i++) {
    if (isset($query->table_queue['draggableviews_structure_' . $view->base_table . $i])) {
      $query->table_queue['draggableviews_structure_' . $view->base_table . $i]['join']->extra[] = array(
        'field' => 'view_name',
        'operator' => '=',
        'value' => $view->name,
      );
      $args = '';
      if ($use_args) {
        if (!empty($view->args)) {
          $args = implode('/', $view->args);
        }
      }
      $query->table_queue['draggableviews_structure_' . $view->base_table . $i]['join']->extra[] = array(
        'field' => 'args',
        'operator' => '=',
        'value' => $args,
      );
    }
  }
}