function views_handler_field_chado_count::pre_render

1.x views_handler_field_chado_count.inc views_handler_field_chado_count::pre_render(&$values)

Run before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

$values: An array of all objects returned from the query.

Overrides views_handler_field::pre_render

File

tripal_views/views/handlers/deprecated/views_handler_field_chado_count.inc, line 38
Purpose: Provide a field that counts the number of records in the current table are connected to the base table. For example, this field could be used to count the number of features connected to a given organism -base table=organism, current…

Class

views_handler_field_chado_count
@file Purpose: Provide a field that counts the number of records in the current table are connected to the base table. For example, this field could be used to count the number of features connected to a given organism -base table=organism, current…

Code

function pre_render(&$values) {
  // Render nothing if the current table wasn't set in the field definition
  if (!$this->aliases['current_table']) {
    return '';
  }

  foreach ($values as $key => $record) {
    $primary_id = $record->{$this->aliases['primary_id']};

    //Select count from database
    $sql = 'SELECT count(*) as count FROM %s WHERE %s=%d';
    $result = db_fetch_object(chado_query(
    $sql, 
    $this->aliases['current_table'], 
    $this->aliases['foreign_key'], 
    $primary_id
    ));

    //Add to view results
    $this->view->result[$key]->{$this->field} = $result->count;
  }
}