function tripal_chado_vocab_get_vocabulary
3.x tripal_chado.vocab_storage.inc | tripal_chado_vocab_get_vocabulary($vocabulary) |
Implements hook_vocab_get_vocabulary().
This hook is created by the Tripal module and is not a Drupal hook.
1 call to tripal_chado_vocab_get_vocabulary()
- _tripal_chado_format_term_description in tripal_chado/
includes/ tripal_chado.vocab_storage.inc - A helper functions for the hook_vocab_xxx functions.
File
- tripal_chado/
includes/ tripal_chado.vocab_storage.inc, line 78
Code
function tripal_chado_vocab_get_vocabulary($vocabulary) {
// It's possible that Chado is not available (i.e. it gets renamed
// for copying) but Tripal has already been prepared and the
// entities exist. If this is the case we don't want to run the
// commands below.
if (!chado_table_exists('cv')) {
return FALSE;
}
// Make sure the materiailzd view is present.
if (!chado_table_exists('db2cv_mview')) {
drupal_set_message('Please update the database using "drush updatedb" before continuing');
return FALSE;
}
$sql = "
SELECT DB.name as short_name, DB.description, DB.url, DB.urlprefix,
SUM(DBCVM.num_terms) as num_terms,
array_to_string(array_agg(DBCVM.cvname), ', ') as name
FROM {db} DB
INNER JOIN {db2cv_mview} DBCVM ON DBCVM.db_id = DB.db_id
WHERE DB.name = :name
GROUP BY DB.name, DB.description, DB.url, DB.urlprefix
";
$result = chado_query($sql, array(':name' => $vocabulary));
$result = $result->fetchAssoc();
if (!$result) {
return FALSE;
}
if (!$result['name']) {
$result['name'] = $result['short_name'];
}
$sw_url = $result['urlprefix'];
if ($sw_url) {
$sw_url = preg_replace('/\{db\}/', $result['short_name'], $sw_url);
$sw_url = preg_replace('/\{accession\}/', '', $sw_url);
$sw_url = url($sw_url, array('absolute' => TRUE));
}
$result['sw_url'] = $sw_url;
return $result;
}