function tripal_insert_cv

2.x tripal_cv.api.inc tripal_insert_cv($name, $definition)
3.x tripal_chado.module.DEPRECATED.api.inc tripal_insert_cv($name, $definition)

Adds a controlled vocabular to the CV table of Chado.

Parameters

$name: The name of the controlled vocabulary. These are typically all lower case with no special characters other than an undrescore (for spaces).

$comment: A description or definition of the vocabulary.

Return value

An object populated with fields from the newly added database.

Related topics

23 calls to tripal_insert_cv()
tripal_analysis_add_cvterms in tripal_analysis/tripal_analysis.install
Adds controlled vocabulary terms needed by this module.
tripal_contact_add_cvs in tripal_contact/tripal_contact.install
Adds any cvs needed by this module.
tripal_contact_update_7200 in tripal_contact/tripal_contact.install
This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
tripal_cv_add_cv in tripal_cv/api/tripal_cv.DEPRECATED.inc
tripal_cv_load_obo_v1_2 in tripal_cv/includes/tripal_cv.obo_loader.inc
Imports a given OBO file into Chado. This function is usually called by one of three wrapper functions: tripal_cv_load_obo_v1_2_id, tripal_cv_load_obo_v1_2_file or tirpal_cv_load_obo_v1_2_url. But, it can be called directly if the full path to an…

... See full list

1 string reference to 'tripal_insert_cv'

File

tripal_cv/api/tripal_cv.api.inc, line 344
This module provides a set of functions to simplify working with controlled vocabularies.

Code

function tripal_insert_cv($name, $definition) {

  // insert/update values
  $ins_values = array(
    'name' => $name,
    'definition' => $definition
  );

  // see if the CV (default-namespace) exists already in the database
  $sel_values = array('name' => $name);
  $sel_options = array('statement_name' => 'sel_cv_na');
  $results = chado_select_record('cv', array('*'), $sel_values, $sel_options);

  // if it does not exists then add it
  if (count($results) == 0) {
    $ins_options = array('statement_name' => 'ins_cv_nade');
    $success = chado_insert_record('cv', $ins_values, $ins_options);
    if (!$success) {
      tripal_report_error('tripal_cv', TRIPAL_WARNING, "Failed to create the CV record", NULL);
      return FALSE;
    }
    $results = chado_select_record('cv', array('*'), $sel_values, $sel_options);
  }
  // if it already exists then do an update
  else {
    $upd_options = array('statement_name' => 'upd_cv_nade');
    $success = chado_update_record('cv', $sel_values, $ins_values, $upd_options);
    if (!$success) {
      tripal_report_error('tripal_cv', TRIPAL_WARNING, "Failed to update the CV record", NULL);
      return FALSE;
    }
    $results = chado_select_record('cv', array('*'), $sel_values, $sel_options);
  }

  // return the cv object
  return $results[0];
}