You are here

public function references_plugin_display::query in References 7.2

Query.

Overrides views_plugin_display::query

File

views/references_plugin_display.inc, line 81
Handler for references_plugin_display.

Class

references_plugin_display
Default class.

Code

public function query() {
  $options = $this
    ->get_option('references_options');

  // Play nice with View UI 'preview' : if the view is not executed through
  // _*_reference_potential_references_views(), don't alter the query.
  if (empty($options)) {
    return;
  }

  // Make sure the id field is included in the results, and save its alias
  // so that references_plugin_style can retrieve it.
  $this->id_field_alias = $this->view->query
    ->add_field($this->view->base_table, $this->view->base_field);

  // Restrict on the incoming string, or incoming ids.
  if ($options['string'] !== '') {
    switch ($options['match']) {
      case 'equals':
        $operator = '=';
        $value = $options['string'];
        break;
      case 'starts_with':
        $operator = 'LIKE';
        $value = db_like($options['string']) . '%';
        break;
      case 'contains':
      default:
        $operator = 'LIKE';
        $value = '%' . db_like($options['string']) . '%';
        break;
    }
    $table_alias = $this->view->query
      ->ensure_table($this->view->base_table);
    $this->view->query
      ->add_where(NULL, $table_alias . '.' . $options['title_field'], $value, $operator);
  }
  elseif ($options['ids']) {
    $table_alias = $this->view->query
      ->ensure_table($this->view->base_table);
    $this->view->query
      ->add_where(NULL, $table_alias . '.' . $this->view->base_field, $options['ids'], 'IN');
  }
}