You are here

function flot_handler_field_datapoint::query in Flot 6

Same name and namespace in other branches
  1. 7 flot_views/views/flot_handler_field_datapoint.inc \flot_handler_field_datapoint::query()

Query method.

File

views/flot_handler_field_datapoint.inc, line 115

Class

flot_handler_field_datapoint

Code

function query() {

  // Killswitch
  if (empty($this->options['series']['field']) || empty($this->options['value']['field'])) {
    return;
  }

  // Yank off the base field & any other groupby's / having's. They will screw up our results.
  unset($this->query->fields[$this->view->base_field]);
  $this->query->groupby = array();
  $this->query->having = array();

  // Add in series field
  list($series_table, $series_field) = explode('.', $this->options['series']['field']);
  $alias = $this->query
    ->ensure_table($series_table);

  // Determine whether we are using a date field.
  $handler = get_class(views_get_handler($series_table, $series_field, 'field'));
  $this->use_date = strpos($handler, '_date') !== FALSE;
  $field_alias = $this->query
    ->add_field($series_table, $series_field);
  $this->query
    ->add_groupby($field_alias);
  $this->series_table = $alias;
  $this->series_field = $field_alias;

  // Add in value field
  list($value_table, $value_field) = explode('.', $this->options['value']['field']);
  $alias = $this->query
    ->ensure_table($value_table);
  if ($this->use_date) {
    $field_alias = $this->query
      ->add_field($value_table, $value_field);
  }
  else {
    switch ($this->options['value']['format']) {
      case 'count':
        $field_alias = $this->query
          ->add_field(NULL, "COUNT({$alias}.{$value_field})", "{$value_table}_{$value_field}", array(
          'aggregate' => TRUE,
        ));
        break;
      default:
        $field_alias = $this->query
          ->add_field($value_table, $value_field);
        break;
    }
  }
  $this->value_table = $alias;
  $this->value_field = $field_alias;
  $this->query
    ->set_count_field($alias, $value_field, $field_alias);
}