definition['table_to_query']) { $this->aliases['current_table'] = $this->definition['table_to_query']; } else { drupal_set_message(t("The field definition ( in hook_views_data() ) needs to specify the 'table_to_query' in order for this fields to work. Field:%field in the %table table definition"), array('%field' => $this->field, '%table' => $this->table), 'error'); } // set aliases $this->aliases['primary_id'] = $this->table . '_id'; $this->aliases['foreign_key'] = $this->table . '_id'; } //Needed to ensure that the name of this field is not added to the query function query() { $this->add_additional_fields(); } 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; } } function render($values) { return $values->{$this->field}; } }