function tripal_feature_get_feature_url

1.x tripal_feature.sync_features.inc tripal_feature_get_feature_url($node, $url_alias = NULL)

Parameters

$node: A node object containing at least the feature_id and nid

$url_alias: Optional. This should be the URL alias syntax string that contains placeholders such as [id], [genus], [species], [name], [uniquename], and [type]. These placeholders will be substituted for actual values. If this parameter is not provided then the value of the chado_feature_url_string Drupal variable will be used.

2 calls to tripal_feature_get_feature_url()
tripal_feature_nodeapi in tripal_feature/tripal_feature.module
Display feature information for associated organisms. This function also provides contents for indexing
tripal_feature_set_urls in tripal_feature/includes/tripal_feature.sync_features.inc

File

tripal_feature/includes/tripal_feature.sync_features.inc, line 236
@todo Add file header description

Code

function tripal_feature_get_feature_url($node, $url_alias = NULL) {

  // get the starting URL alias
  if (!$url_alias) {
    $url_alias = variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]');
    if (!$url_alias) {
      $url_alias = '/feature/[genus]/[species]/[type]/[uniquename]';
    }
    $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash
  }

  // get the feature 
  $values = array('feature_id' => $node->feature_id);
  $options = array('statement_name' => 'sel_feature_id');
  $feature = tripal_core_chado_select('feature', array('*'), $values, $options);
  if (!$feature) {
    watchdog('trp-seturl', "Cannot find feature when setting URL alias for feature: %id", array('%id' => $node->feature_id), WATCHDOG_ERROR);
    return FALSE;
  }
  $feature = (object) $feature[0];

  // get the organism
  $values = array('organism_id' => $feature->organism_id);
  $options = array('statement_name' => 'sel_organism_id');
  $organism = tripal_core_chado_select('organism', array('*'), $values, $options);
  if (!$organism) {
    watchdog('trp-seturl', "Cannot find organism when setting URL alias for feature: %id", array('%id' => $node->feature_id), WATCHDOG_ERROR);
    return FALSE;
  }
  $genus = preg_replace('/\s/', '_', strtolower($organism[0]->genus));
  $species = preg_replace('/\s/', '_', strtolower($organism[0]->species));

  // get the type
  $values = array('cvterm_id' => $feature->type_id);
  $options = array('statement_name' => 'sel_cvterm_id');
  $cvterm = tripal_core_chado_select('cvterm', array('name'), $values, $options);
  if (!$cvterm) {
    watchdog('trp-seturl', "Cannot find type when setting URL alias for feature: %id", array('%id' => $node->feature_id), WATCHDOG_ERROR);
    return FALSE;
  }
  $type = preg_replace('/\s/', '_', $cvterm[0]->name);

  // now substitute in the values
  $url_alias = preg_replace('/\[id\]/', $feature->feature_id, $url_alias);
  $url_alias = preg_replace('/\[genus\]/', $genus, $url_alias);
  $url_alias = preg_replace('/\[species\]/', $species, $url_alias);
  $url_alias = preg_replace('/\[type\]/', $type, $url_alias);
  $url_alias = preg_replace('/\[name\]/', $feature->name, $url_alias);
  $url_alias = preg_replace('/\[uniquename\]/', $feature->uniquename, $url_alias);

  // the dst field of the url_alias table is only 128 characters long. 
  // if this is the case then simply return the node URL, we can't set this one
  if (strlen($url_alias) > 128) {
    watchdog('trp-seturl', "Cannot set alias longer than 128 characters: %alias.", array('%alias' => $url_alias), WATCHDOG_ERROR);
    return "node/" . $node->nid;
  }

  return $url_alias;
}