function chado_get_token_value
2.x tripal_core.chado_nodes.title_and_path.api.inc | chado_get_token_value($token_info, $node, $options = array()) |
3.x tripal_core.chado_nodes.title_and_path.inc | chado_get_token_value($token_info, $node, $options = array()) |
Retrieve the value of the token from the node based on the $token_info['location']
Parameters
$token_info: An array of information about the token including: -table: the name of the chado table -field: the name of the field in the above table -token: the token string (ie: [stock.stock_id]) -description: a very short description of the token (displayed when tokens are listed) -location: the location of the value in a chado node variable with each level separated by an arrow (>) symbol. For example, the location for $node->feature->type_id->name is feature>type_id>name @param $node The node to get the value of the token
Return value
The value of the token
Related topics
4 calls to chado_get_token_value()
- chado_get_node_title in legacy/
tripal_core/ api/ tripal_core.chado_nodes.title_and_path.inc - Get the title of a node based on the Title Format set in the admin section of the module. If the format has not yet been set than the the unique constrain and name fields will be used to generate a default format
- chado_get_node_url in legacy/
tripal_core/ api/ tripal_core.chado_nodes.title_and_path.inc - Get the url of a node based on the url Format set in the admin section of the module. If the format has not yet been set than the the unique constrain and name fields will be used to generate a default format
- tripal_core_get_token_value_for_property in legacy/
tripal_core/ includes/ tripal_core.search.inc - Retrieve values for all tokens for an entity property getter function.
- tripal_core_node_view_build_toc in legacy/
tripal_core/ includes/ tripal_core.toc.inc - To be called by tripal_core_node_view_alter() to generate the TOC.
File
- legacy/
tripal_core/ api/ tripal_core.chado_nodes.title_and_path.inc, line 1329 - Contains API functions to set titles and paths for all chado nodes
Code
function chado_get_token_value($token_info, $node, $options = array()) {
$token = $token_info['token'];
$table = $token_info['table'];
$var = $node;
$supress_errors = (isset($options['supress_errors'])) ? $options['supress_errors'] : FALSE;
// Iterate through each portion of the location string. An example string
// might be: stock > type_id > name.
$location = explode('>', $token_info['location']);
foreach ($location as $index) {
$index = trim($index);
// if $var is an object then it is the $node object or a table
// that has been expanded.
if (is_object($var)) {
// check to see if the index is a member of the object. If so,
// then reset the $var to this value.
if (property_exists($var, $index)) {
$var = $var->$index;
}
else {
if (!$supress_errors) {
tripal_report_error('chado_node_api', TRIPAL_WARNING,
'Tokens: Unable to determine the value of %token. Things went awry when trying ' .
'to access \'%index\' for the following: \'%var\'.',
array('%token' => $token, '%index' => $index, '%var' => print_r($var, TRUE))
);
}
return '';
}
}
// if the $var is an array then there are multiple instances of the same
// table in a FK relationship (e.g. relationship tables)
elseif (is_array($var)) {
$var = $var[$index];
}
else {
if (!$supress_errors) {
tripal_report_error('chado_node_api', TRIPAL_WARNING,
'Tokens: Unable to determine the value of %token. Things went awry when trying ' .
'to access \'%index\' for the following: \'%var\'.',
array('%token' => $token, '%index' => $index, '%var' => print_r($var, TRUE))
);
}
return '';
}
}
return $var;
}