function chado_get_tokens
3.x tripal_chado.api.inc | chado_get_tokens($base_table) |
Returns an array of tokens based on Tripal Entity Fields.
Parameters
$base_table: The name of a base table in Chado.
Return value
An array of tokens where the key is the machine_name of the token.
Related topics
3 calls to chado_get_tokens()
- chado_replace_tokens in tripal_chado/
api/ tripal_chado.api.inc - Replace all Chado Tokens in a given string.
- obi__organism::instanceSettingsForm in tripal_chado/
includes/ TripalFields/ obi__organism/ obi__organism.inc - tripal_get_chado_tokens in tripal_chado/
api/ tripal_chado.DEPRECATED.api.inc - Returns an array of tokens based on Tripal Entity Fields.
File
- tripal_chado/
api/ tripal_chado.api.inc, line 276 - This file contains miscellaneous API functions specific to working with records in Chado that do not have a home in any other sub category of API functions.
Code
function chado_get_tokens($base_table) {
$tokens = array();
$table_descrip = chado_get_schema($base_table);
foreach ($table_descrip['fields'] as $field_name => $field_details) {
$token = '[' . $base_table . '.' . $field_name . ']';
$location = implode(' > ', array($base_table, $field_name));
$tokens[$token] = array(
'name' => ucwords(str_replace('_', ' ', $base_table)) . ': ' . ucwords(str_replace('_', ' ', $field_name)),
'table' => $base_table,
'field' => $field_name,
'token' => $token,
'description' => array_key_exists('description', $field_details) ? $field_details['description'] : '',
'location' => $location
);
if (!array_key_exists('description', $field_details) or preg_match('/TODO/', $field_details['description'])) {
$tokens[$token]['description'] = 'The ' . $field_name . ' field of the ' . $base_table . ' table.';
}
}
// RECURSION:
// Follow the foreign key relationships recursively
if (array_key_exists('foreign keys', $table_descrip)) {
foreach ($table_descrip['foreign keys'] as $table => $details) {
foreach ($details['columns'] as $left_field => $right_field) {
$sub_token_prefix = $base_table . '.' . $left_field;
$sub_location_prefix = implode(' > ', array($base_table, $left_field));
$sub_tokens = chado_get_tokens($table);
if (is_array($sub_tokens)) {
$tokens = array_merge($tokens, $sub_tokens);
}
}
}
}
return $tokens;
}