123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- function tripal_get_default_cv($table, $field) {
- $sql = "
- SELECT cv_id
- FROM {tripal_cv_defaults}
- WHERE table_name = :table and field_name = :field
- ";
- $cv_id = db_query($sql, array(':table' => $table, ':field' => $field))->fetchField();
- return tripal_get_cv(array('cv_id' => $cv_id));
- }
- function tripal_get_default_cv_table($cv_id) {
- $default = db_select('tripal_cv_defaults', 't')
- ->fields('t', array('table_name', 'field_name'))
- ->condition('cv_id', $cv_id)
- ->execute()
- ->fetchObject();
- return $default;
- }
- function tripal_get_cvterm_default_select_options($table, $field, $field_desc) {
- $default_cv = tripal_get_default_cv($table, $field);
- $options = array();
- if ($default_cv) {
- $options = tripal_get_cvterm_select_options($default_cv->cv_id);
- if (count($options) == 0) {
- tripal_set_message('There are no ' . $field_desc . '. Please ' .
- l('add terms',
- 'admin/tripal/loaders/chado_vocabs/chado_cv/' .$default_cv->cv_id. '/cvterm/add',
- array('attributes' => array('target' => '_blank'))) . ' to the ' .
- $default_cv->name .' vocabulary.',
- TRIPAL_WARNING);
- }
- }
- else {
- tripal_set_message('There is not a default vocabulary set for ' . $field_desc . '. '.
- 'Please set one using the ' .
- l('vocabulary defaults configuration page',
- 'admin/tripal/vocab/defaults',
- array('attributes' => array('target' => '_blank'))) . '.',
- TRIPAL_WARNING);
- }
- return $options;
- }
- function tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE) {
-
- if ($cv_id) {
- $cv = tripal_get_cv(array('cv_id' => $cv_id));
- }
- else {
- $cv = tripal_get_cv(array('name' => $cv_name));
- }
- if ($cv) {
-
- $num_deleted = db_delete('tripal_cv_defaults')
- ->condition('table_name', $table)
- ->condition('field_name', $field)
- ->execute();
-
- $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;
- }
- }
|