You are here

public function SingleDateFilter::query in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/views/filter/SingleDateFilter.php \Drupal\rng\Plugin\views\filter\SingleDateFilter::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides NumericFilter::query

File

src/Plugin/views/filter/SingleDateFilter.php, line 57

Class

SingleDateFilter
Plugin annotation @ViewsFilter("single_date_filter");

Namespace

Drupal\rng\Plugin\views\filter

Code

public function query() {
  return parent::query();
  $alias = 'date_filter_single';
  $subquery = $this->database
    ->select($this->table, $alias);
  $subquery
    ->addField($alias, 'entity_id');
  $subquery
    ->addExpression('MIN(' . $alias . '.' . $this->realField . ')', 'filter_min_date');
  $subquery
    ->groupBy($alias . '.entity_id');
  $join_table = $this->options['entity_type'] . '_field_data';
  $id_field = $this->entityTypeManager
    ->getDefinition($this->options['entity_type'])
    ->getKey('id');
  $definition = [
    'table formula' => $subquery,
    'field' => 'entity_id',
    'left_table' => $join_table,
    'left_field' => $id_field,
    'adjust' => TRUE,
  ];
  $join = $this->joinManager
    ->createInstance('standard', $definition);
  $this->query
    ->addRelationship('filter_min_date_table', $join, $join_table);
  $field = 'filter_min_date_table.filter_min_date';
  $info = $this
    ->operators();
  if (!empty($info[$this->operator]['method'])) {
    $this
      ->{$info[$this->operator]['method']}($field);
  }
}