function tripal_feature_add_cvterm
2.x tripal_feature.DEPRECATED.inc | tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) |
3.x tripal_feature.DEPRECATED.inc | tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) |
1.x tripal_feature.api.inc | tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) |
File
- tripal_feature/
api/ tripal_feature.api.inc, line 1089 - Provides an application programming interface (API) for working with features
Code
function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
// make sure the cv exists. If it doesn't, then add it
$values = array('name' => $cvname);
$options = array('statement_name' => 'sel_cv_na');
$cv = tripal_core_chado_select('cv', array('cv_id'), $values, $options);
if (!$cv or count($cv) == 0) {
$options = array('statement_name' => 'ins_cv_na');
$success = tripal_core_chado_insert('cv', $values, $options);
if (!$success) {
watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, ".
"could not be added because the CV, %cvname, does not exist and cannot be added.',
array('%feature_id' => $feature_id, '%cvname' => $cvname), WATCHDOG_WARNING);
return FALSE;
}
}
// first make sure that the record doesn't already exist
$values = array(
'cvterm_id' => array(
'name' => $cvterm,
'cv_id' => array(
'name' => $cvname
),
),
'feature_id' => $feature_id,
'pub_id' => 1,
);
$options = array('statement_name' => 'sel_featuredcvterm_cvfepu');
$xref = tripal_core_chado_select('feature_cvterm', array('feature_cvterm_id'), $values, $options);
if (count($xref) == 0) {
// if the record doesn't exist then add it.
$options = array('statement_name' => 'ins_featurecvterm_cvfepu');
$success = tripal_core_chado_insert('feature_cvterm', $values, $options);
if (!$success) {
watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, ' .
'could not be added: %cvterm.', array('%feature_id' => $feature_id, '%cvterm' => $cvterm), WATCHDOG_WARNING);
return FALSE;
}
}
return TRUE;
}