function chado_get_dbxref_url

3.x tripal_chado.db.api.inc chado_get_dbxref_url($dbxref)

Generates a URL for the controlled vocabulary term.

If the URL and URL prefix are provided for the database record of a cvterm then a URL can be created for the term. By default, the db.name and dbxref.accession are concatenated and appended to the end of the db.urlprefix. But Tripal supports the use of {db} and {accession} tokens when if present in the db.urlprefix string will be replaced with the db.name and dbxref.accession respectively.

Parameters

$dbxref: A dbxref object as created by the chado_generate_var() function.

Return value

A string containing the URL.

Related topics

5 calls to chado_get_dbxref_url()
sbo__database_cross_reference::load in tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc
sbo__database_cross_reference_formatter::view in tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc
sio__annotation_formatter::view in tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_formatter.inc
tripal_get_dbxref_url in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
Generates a URL for the controlled vocabulary term.
_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/api/modules/tripal_chado.db.api.inc, line 303
Provides API functions specificially for managing external database reference records in Chado.

Code

function chado_get_dbxref_url($dbxref) {
  $final_url = '';

  // Create the URL for the term.
  if ($dbxref->db_id->urlprefix) {
    $db_count = 0;
    $acc_count = 0;
    $url = $dbxref->db_id->urlprefix;

    // If the URL prefix has replacement tokens then use those.
    $url = preg_replace('/\{db\}/', $dbxref->db_id->name, $url, -1, $db_count);
    $url = preg_replace('/\{accession\}/', $dbxref->accession, $url, -1, $acc_count);
    $final_url = $url;

    // If no replacements were made above then tokens weren't used and we can
    // default to just appending the db name and accession to the end.
    if (!$db_count and !$acc_count) {
      $final_url = $dbxref->db_id->urlprefix . $dbxref->db_id->name . ':' . $dbxref->accession;
    }

    // If the URL prefix is relative then convert it to a full URL.
    if (!preg_match('/^(http|https)/', $final_url)) {
      $final_url = url($final_url, array('absolute' => TRUE));
    }
  }
  return $final_url;
}