function tripal_cv_cvterm_add_form_submit

2.x tripal_cv.cvterm_form.inc tripal_cv_cvterm_add_form_submit($form, &$form_state)
3.x tripal_chado.cv.inc tripal_cv_cvterm_add_form_submit($form, &$form_state)

Adds new terms to an existing cv

Related topics

File

tripal_cv/includes/tripal_cv.cvterm_form.inc, line 411
Provides a form for creating & editing chado controlled vocabularies

Code

function tripal_cv_cvterm_add_form_submit($form, &$form_state) {
  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
  $definition = array_key_exists('definition', $form_state['values']) ? $form_state['values']['definition'] : '';
  $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? $form_state['values']['is_relationship'] : '';
  $is_obsolete = array_key_exists('is_obsolete', $form_state['values']) ? $form_state['values']['is_obsolete'] : '';

  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';

  // get the database
  $values = array('db_id' => $db_id);
  $results = chado_select_record('db', array('name'), $values);
  $db = $results[0];

  // get the cv
  $values = array('cv_id' => $cv_id);
  $results = chado_select_record('cv', array('name'), $values);
  $cv = $results[0];

  // now add the term
  $term = array(
    'name' => $name,
    'namespace' => $cv->name,
    'id' => $accession,
    'definition' => $definition,
    'is_obsolete' => $is_obsolete,
    'cv_name' => $cv->name,
    'is_relationship' => $is_relationship,
    'db_name' => $db->name
  );

  $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
  if ($cvterm) {
    drupal_set_message('Term added successfully.');
  }
  else {
    drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
  }
}