You are here

function views_filters_selective_views_query_alter in Views Hacks 6

Implements hook_views_query_alter().

File

views_filters_selective/views_filters_selective.module, line 15

Code

function views_filters_selective_views_query_alter(&$view, &$query) {
  if (!empty($view->selective_all_results)) {

    // Selective view is the view that selects objects across all pages of original view.
    // Add the base_field explicitly.
    $query
      ->add_field($view->base_table, $view->base_field);
  }
  if (!empty($view->selective_query)) {

    // Selective query is the query that selects the possible filter values given the objects above.
    // Make the fields distinct. There's actually just one field.
    foreach ($query->fields as &$field) {
      $field['distinct'] = TRUE;
    }
  }
}