You are here

function tmgmt_handler_field_tmgmt_job_item_count::query in Translation Management Tool 7

Called to add the field to a query.

Overrides views_handler_field::query

File

views/handlers/tmgmt_handler_field_tmgmt_job_item_count.inc, line 43
Contains the tmgmt_handler_field_tmgmt_job_item_count field handler.

Class

tmgmt_handler_field_tmgmt_job_item_count
Field handler to show the amount of job items per job.

Code

function query() {
  $this
    ->ensure_my_table();

  // Therefore construct the join.
  $join = new views_join();
  $join->definition['left_table'] = $this->table_alias;
  $join->definition['left_field'] = $this->real_field;
  $join->definition['table'] = 'tmgmt_job_item';
  $join->definition['field'] = 'tjid';
  $join->definition['type'] = 'LEFT';
  if (!empty($this->options['state'])) {
    $join->extra = array(
      array(
        'field' => 'state',
        'value' => $this->options['state'],
      ),
    );
  }
  $join
    ->construct();

  // Add the join to the tmgmt_job_item table.
  $this->table_alias = $this->query
    ->add_table('tmgmt_job_item', $this->relationship, $join);

  // And finally add the count of the job items field.
  $params = array(
    'function' => 'count',
  );
  $this->field_alias = $this->query
    ->add_field($this->table_alias, 'tjiid', NULL, $params);
  $this
    ->add_additional_fields();
}