function tripal_views_views_data_alter
2.x tripal_views.views.inc | tripal_views_views_data_alter(&$data) |
1.x tripal_views.views.inc | tripal_views_views_data_alter(&$data) |
File
- tripal_views/
tripal_views.views.inc, line 551 - Tripal Views Integration
Code
function tripal_views_views_data_alter(&$data) {
$tvi_query = db_query('SELECT * FROM {tripal_views}');
// iterate through the views that we manage
while ($tvi_row = db_fetch_object($tvi_query)) {
//ids we'll use for queries
$mview_id = $tvi_row->mview_id;
$setup_id = $tvi_row->setup_id;
// iterate through the columns and alter the existing data array for
// joins to other tables
$sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
$joins = db_query($sql, $setup_id);
while ($join = db_fetch_object($joins)) {
$left_table = $join->left_table;
$left_field = $join->left_field;
$base_field = $join->base_field;
$base_table = $join->base_table;
// add the recipricol join entries for each column
if (array_key_exists($left_table, $data) and $base_table != 'node') {
$data[$left_table]['table']['join'][$base_table] = array(
'left_field' => $base_field,
'field' => $left_field,
);
}
}
// add in joins to the node tables if the Chado schema is local
if (tripal_core_chado_schema_exists()) {
$base_table = $tvi_row->table_name;
$linker_table = 'chado_' . $base_table;
// if a node linking table exists then add in the joins
if (db_table_exists($linker_table)) {
$data['node']['table']['join'][$linker_table] = array(
'left_field' => 'nid',
'field' => 'nid',
);
$data['node']['table']['join'][$base_table] = array(
'left_table' => $linker_table,
'left_field' => 'nid',
'field' => 'nid',
);
}
}
}
return $data;
}