You are here

public function bat_event_handler_duration_field::query in Booking and Availability Management Tools for Drupal 7

Called to add the field to a query.

Overrides views_handler_field::query

File

modules/bat_event/views/bat_event_handler_duration_field.inc, line 30

Class

bat_event_handler_duration_field

Code

public function query() {
  $this
    ->ensure_my_table();
  $this->field_alias = $this->table_alias . '_duration';
  $alias = $this->field_alias;
  $counter = 0;
  while (!empty($this->query->fields[$this->field_alias])) {
    $this->field_alias = $alias . '_' . ++$counter;
  }

  // Add the field.
  $params = $this->options['group_type'] != 'group' ? array(
    'function' => $this->options['group_type'],
  ) : array();
  $this->query
    ->add_field(NULL, 'TIMESTAMPDIFF(SECOND, ' . $this->table_alias . '.start_date, ' . $this->table_alias . '.end_date)', $this->field_alias, $params);
  $this
    ->add_additional_fields();
}