function tripal_insert_variable
2.x tripal_core.tripal_variables.api.inc | tripal_insert_variable($name, $description) |
3.x tripal.variables.api.inc | tripal_insert_variable($name, $description) |
Adds a new variable name.
Parameters
$name: The name of the variable
$description: The description for the variable
Return value
A record object containg the variable that was added if successful.
2 calls to tripal_insert_variable()
- tripal_add_node_variable in tripal_core/
api/ tripal_core.tripal_variables.api.inc - Associates a variable and it's value to a node.
- tripal_phylogeny_install in tripal_phylogeny/
tripal_phylogeny.install - Implements hook_install().
File
- tripal_core/
api/ tripal_core.tripal_variables.api.inc, line 35 - Provides an application programming interface (API) for managing variables associated with Tripal managed Drupal nodes/
Code
function tripal_insert_variable($name, $description) {
$name = trim($name);
if (!$name) {
tripal_report_error('tripal_core', TRIPAL_ERROR,
'Must have a variable name when adding a new Tripal Variable.', array());
return NULL;
}
if (!$description) {
tripal_report_error('tripal_core', TRIPAL_ERROR,
'Must have a description when adding a new Tripal Variable.', array());
return NULL;
}
// Make sure the variable is not a duplicate. If so, then just select
// it and return the variable_id
$variable = tripal_get_variable($name);
if ($variable) {
return $variable;
}
else {
db_insert('tripal_variables')
->fields(array(
'name' => $name,
'description' => $description,
))
->execute();
return tripal_get_variable($name);
}
}