function tripal_views_add_node_relationship_to_chado_table_integration
1.x tripal_views.api.inc | tripal_views_add_node_relationship_to_chado_table_integration($defn_array) |
Adds the joins necessary to link a chado table to it's node counterpart
Parameters
$defn_array: The current definition array for a given table
Related topics
File
- tripal_views/
api/ tripal_views.api.inc, line 625 - API functions for Tripal Views Integration
Code
function tripal_views_add_node_relationship_to_chado_table_integration($defn_array) {
$integrations[$defn_array['table']] = $defn_array;
$primary_key = $defn_array['table'] . '_id';
$chado_linking = 'chado_' . $defn_array['table'];
if (empty($defn_array['table'])) {
watchdog('tripal_views', 'Tried to add a node=>chado relationship for an empty table defn: %defn',
array('%defn' => print_r($defn_array, TRUE)), WATCHDOG_WARNING);
return FALSE;
}
// Add table.primary_key => chado_table.primary key join to $defn_array
$integrations[$defn_array['table']]['fields'][$primary_key]['joins'][$chado_linking] = array(
'table' => $chado_linking,
'field' => $primary_key,
);
// Create chado_table defn_array
$integrations[$chado_linking] = array(
'table' => $chado_linking,
'type' => 'drupal',
'name' => 'Chado ' . $defn_array['table'] . ' Node',
'description' => 'Links chado content to its drupal node counterpart',
'priority' => $defn_array['priority'],
'base_table' => FALSE,
'fields' => array(
$primary_key => array(
'name' => $primary_key,
'title' => ucwords(str_replace('_', ' ', $primary_key)),
'type' => 'int',
'description' => 'The primary key of the chado ' . $defn_array['table'] . ' table',
'handlers' => array(),
'joins' => array(
$defn_array['table'] => array(
'table' => $defn_array['table'],
'field' => $primary_key,
)
),
),
'nid' => array(
'name' => 'nid',
'title' => 'Node ID',
'type' => 'int',
'description' => 'Link ' . ucfirst($defn_array['table']) . ' to it\'s node',
'handlers' => array(
'relationship' => array(
'name' => 'chado_views_handler_relationship_to_node',
'title' => ucfirst($defn_array['table']) . ' to Node',
'label' => ucfirst($defn_array['table']) . ' to Node',
'base table' => $defn_array['table'],
'base field' => $primary_key
)
),
'joins' => array(
'node' => array(
'table' => 'node',
'field' => 'nid',
),
),
)
),
);
// Create node defn_array
$integrations['node'] = array(
'table' => 'node',
'name' => 'Node',
'description' => 'Primary Drupal Content',
'priority' => $defn_array['priority'],
'additional_content' => TRUE, // Allows multiple modules to add to the node setup
'fields' => array(
'nid' => array(
'name' => 'nid',
'title' => 'Node ID',
'type' => 'int',
'description' => 'the primary key of the drupal node table',
'handlers' => array(),
'joins' => array(
$defn_array['table'] => array(
'table' => $defn_array['table'],
'field' => 'nid',
),
$chado_linking => array(
'table' => $chado_linking,
'field' => 'nid',
),
),
),
),
);
return $integrations;
}