function tripal_get_node_variables

2.x tripal_core.tripal_variables.api.inc tripal_get_node_variables($nid, $name = '', $rank = '')
3.x tripal_core.tripal_variables.api.inc tripal_get_node_variables($nid, $name = '', $rank = '')

Returns one or more variables assigned to a node.

An array is returned containing an object for each variable assigned to a term that matches the criteria. If a name and rank are provided then the variables returned must match.

Parameters

$nid: The node ID

$name: Optional. The name of the variable.

$rank: Optional. The rank of the variable to retreive.

Return value

An array of variable objects.

2 calls to tripal_get_node_variables()
chado_phylotree_load in tripal_phylogeny/includes/tripal_phylogeny.chado_node.inc
Implements hook_load().
tripal_add_node_variable in tripal_core/api/tripal_core.tripal_variables.api.inc
Associates a variable and it's value to a node.

File

tripal_core/api/tripal_core.tripal_variables.api.inc, line 168
Provides an application programming interface (API) for managing variables associated with Tripal managed Drupal nodes/

Code

function tripal_get_node_variables($nid, $name = '', $rank = '') {
  $variables = array();
  if (!$nid) {
    return $variables;
  }
  $query = db_select('tripal_node_variables', 'tnv')
    ->fields('tnv')
    ->condition('nid', $nid, '=');
  if ($name) {
    $variable = tripal_get_variable($name);
    $query->condition('variable_id', $variable->variable_id, '=');
  }
  if ($rank) {
    $query->condition('rank', $rank, '=');
  }
  $results = $query->execute();

  // Build the  variables array and return it.
  while ($variable = $results->fetchObject()) {
    $variables[] = $variable;
  }
  return $variables;
}