function tripal_cv_cvterm_form_submit

1.x tripal_cv_admin.inc tripal_cv_cvterm_form_submit($form, &$form_state)

Purpose: Adds terms to an existing controlled vocabulary

Related topics

File

tripal_cv/includes/tripal_cv_admin.inc, line 449

Code

function tripal_cv_cvterm_form_submit($form, &$form_state) {

  // Ensure the AHAH in the form was called
  if (!empty($form_state['ahah_submission'])) {
    return;
  }

  // get the database
  $values = array('db_id' => $form_state['values']['db_id']);
  $results = tripal_core_chado_select('db', array('name'), $values);
  if (!$results or count($results) == 0) {
    drupal_set_message(t('Unable to add term.  Cannot find the database.'), 'error');
    return;
  }
  $db = $results[0];

  // get the cv
  $values = array('cv_id' => $form_state['values']['cv_id']);
  $results = tripal_core_chado_select('cv', array('name'), $values);
  if (!$results or count($results) == 0) {
    drupal_set_message(t('Unable to add term.  Cannot find the vocabulary.'), 'error');
    return;
  }
  $cv = $results[0];

  // get the accession for this term
  $accession = $form_state['values']['accession'];
  if (!$accession) {
    $accession = $form_state['values']['name'];
  }
  if (is_numeric($accession)) {
    $accession = $db->name . ":" . $accession;
  }


  $update = 0;
  if ($form_state['values']['form_action'] == 'edit') {
    $update = 1;
  }

  // now add the term
  $term = array(
    'name' => $form_state['values']['name'],
    'namespace' => $cv->name,
    'id' => $accession,
    'def' => $form_state['values']['definition'],
    'is_obsolete' => $form_state['values']['is_obsolete'],
  );

  $is_relationship = $form_state['values']['is_relationshiptype'];
  $cvterm = tripal_cv_add_cvterm($term, $cv->name, $is_relationship, $update, $db->name);
  if ($cvterm) {
    if (!$update) {
      drupal_set_message('Term added successfully.');
    }
    else {
      drupal_set_message('Term updated successfully.');
    }
  }
  else {
    drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
  }

}