function tripal_set_default_cv

2.x tripal_cv.api.inc tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE)
3.x tripal_cv.api.inc tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE)

This function sets the default vocabulary for a given table and field.

Parameters

$table: The name of the table that contains a field with a foreign key relationship to the cvterm table

$field: The table field name that has the foreign key relationship to the cvterm table for which the default vocabulary will be set

$cv_name: The name of the vocabulary

Return value

TRUE if set, FALSE if an error occured

Related topics

11 calls to tripal_set_default_cv()
tripal_analysis_install in legacy/tripal_analysis/tripal_analysis.install
Implementation of hook_install().
tripal_contact_install in legacy/tripal_contact/tripal_contact.install
Implementation of hook_install().
tripal_cv_admin_set_defaults_form_submit in legacy/tripal_cv/includes/tripal_cv.cv_defaults.inc
tripal_featuremap_install in legacy/tripal_featuremap/tripal_featuremap.install
Implementation of hook_install().
tripal_feature_install in legacy/tripal_feature/tripal_feature.install
Implements hook_install().

... See full list

File

legacy/tripal_cv/api/tripal_cv.api.inc, line 159
Provides legacy application programming interface (API) to manage controlled vocabularies in the Chado database.

Code

function tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE) {

  // Get the CV object
  if ($cv_id) {
    $cv = tripal_get_cv(array('cv_id' => $cv_id));
  }
  else {
    $cv = tripal_get_cv(array('name' => $cv_name));
  }

  if ($cv) {
    // first delete any entries for this table and field
    $num_deleted = db_delete('tripal_cv_defaults')
      ->condition('table_name', $table)
      ->condition('field_name', $field)
      ->execute();

    // now add the default value
    $cv_default_id = db_insert('tripal_cv_defaults')
      ->fields(array(
        'table_name' => $table,
        'field_name' => $field,
        'cv_id' => $cv->cv_id,
      ))
      ->execute();

    if (!$cv_default_id) {
      tripal_report_error('tripal_chado', TRIPAL_WARNING, 
      "Cannot set default vocabulary for %table.%field. Check the error logs.", 
      array('%table' => $table, '%field' => $field));
      return FALSE;
    }
  }
  else {
    tripal_report_error('tripal_chado', TRIPAL_WARNING, 
    "Cannot set default vocabulary for %table.%field. The vocabulary name, '%cvname', doesn't exist.", 
    array('%table' => $table, '%field' => $field, '%cvname' => $cv_name));
    return FALSE;
  }
}