function views_calc_views_tables in Views Calc 5
Implementation of hook_views_tables.
Add calc fields to views field list.
File
- ./
views_calc.module, line 396 - This module will allow you to add calculated fields to views tables and compute (SUM, COUNT, AVG, etc) columns of numeric data in a views table.
Code
function views_calc_views_tables() {
$tables['views_calc'] = array(
'name' => 'node',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'nid',
),
),
);
// insert all available views_calc fields into field list as placeholders
// using NULL for table name so views doesn't try to prepend the calc with a tablename
$results = _views_calc_fields();
while ($field = db_fetch_array($results)) {
$tables[NULL]['fields']['cid' . $field['cid']] = array(
'name' => t($field['label']),
'notafield' => true,
'sortable' => true,
'query_handler' => 'views_calc_query_handler',
'handler' => 'views_calc_field_handler',
'cid' => $field['cid'],
'format' => $field['format'],
'custom' => $field['custom'],
);
}
return $tables;
}