function chado_node_get_location_from_token
2.x tripal_core.chado_nodes.title_and_path.api.inc | chado_node_get_location_from_token($token) |
3.x tripal_core.chado_nodes.title_and_path.inc | chado_node_get_location_from_token($token) |
Returns the "location" as specified in the token information based on the token.
1 call to chado_node_get_location_from_token()
- tripal_core_get_token_value_for_property in tripal_core/
includes/ tripal_core.search.inc - Retrieve values for all tokens for an entity property getter function.
File
- tripal_core/
api/ tripal_core.chado_nodes.title_and_path.api.inc, line 1454 - Contains API functions to set titles and paths for all chado nodes
Code
function chado_node_get_location_from_token($token) {
if (is_array($token) and isset($token['location'])) {
return $token['location'];
}
// If we have been given the token as a string, we can still determine the location
// but it takes more work...
// First, lets clarify what the location is: the location shows which keys in which
// order need to be travelled in order to access the value. For example, the token
// [feature.organism_id>organism.genus] would have a location of
// feature > organism_id > genus to show that the value is at
// $node->feature->organism->genus.
elseif (is_string($token)) {
// First, lets break down the token into it's parts.
// 1. Remove containing brackets.
$parts = str_replace(array('[', ']'), '', $token);
// 2. Break into table clauses.
$parts = explode('>', $parts);
// 3. Break each table clause into table & field.
foreach ($parts as $k => $v) {
$parts[$k] = explode('.', $v);
if (sizeof($parts[$k]) == 1) {
$parts[$k] = explode(':', $v);
}
}
// This is a base level field that is not a foreign key.
if (sizeof($parts) == 1 AND sizeof($parts[0]) == 2) {
return $parts[0][0] . ' > ' . $parts[0][1];
}
// Darn, we have at least one foreign key...
elseif (sizeof($parts) > 1 AND sizeof($parts[0]) == 2) {
$location = $parts[0][0] . ' > ' . $parts[0][1];
foreach ($parts as $k => $p) {
if ($k != 0 AND isset($p[1])) {
$location .= ' > ' . $p[1];
}
}
return $location;
}
else {
return FALSE;
}
}
}