function tripal_feature_match_features_page

2.x tripal_feature.module tripal_feature_match_features_page($id)
3.x tripal_chado.module tripal_feature_match_features_page($id)
1.x tripal_feature.module tripal_feature_match_features_page($id)
1 string reference to 'tripal_feature_match_features_page'
tripal_feature_menu in tripal_feature/tripal_feature.module
Menu items are automatically added for the new node types created by this module to the 'Create Content' Navigation menu item. This function adds more menu items needed for this module.

File

tripal_feature/tripal_feature.module, line 2306
@todo Add file header description

Code

function tripal_feature_match_features_page($id) {

  // if the URL alias configuration is set such that the URL
  // always begins with 'feature' then we want to use the ID as it is and
  // forward it on. Otherwise, try to find the matching feature.
  $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  
  if (preg_match('/^feature\//', $url_alias)) {
    drupal_goto($id);
  }

  $sql = "
    SELECT
      F.name, F.uniquename, F.feature_id,
      O.genus, O.species, O.organism_id,
      CVT.cvterm_id, CVT.name as type_name,
      CF.nid,
      array_agg(S.name) as synonyms
    FROM {feature} F
      INNER JOIN {organism} O on F.organism_id = O.organism_id
      INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
      LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
      LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
      INNER JOIN public.chado_feature CF on CF.feature_id = F.feature_id
    WHERE
      F.uniquename = '%s' or
      F.name = '%s' or
      S.name = '%s'
    GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
      O.organism_id, CVT.cvterm_id, CVT.name, CF.nid
  ";
  $results = chado_query($sql, $id, $id, $id);

  $num_matches = 0;

  // iterate through the matches and build the table for showing matches
  $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
  $rows = array();
  $curr_match;
  while ($match = db_fetch_object($results)) {
    $curr_match = $match;
    $synonyms = $match->synonyms;
    $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
    $rows[] = array(
      $match->uniquename,
      "<a href=\"" . url("node/" . $match->nid) . "\">" . $match->name . "</a>",
      $match->type_name,
      '<i>' . $match->genus . ' ' . $match->species . '</i>',
      $synonyms,
    );
    $num_matches++;
  }

  // if we have more than one match then generate the table, otherwise, redirect
  // to the matched feature
  if ($num_matches == 1) {
    drupal_goto("node/" . $curr_match->nid);
  }
  if ($num_matches == 0) {
    return "<p>No features matched the given name '$id'</p>";
  }

  $table_attrs = array(
    'class' => 'tripal-table tripal-table-horz'
  );
  $output = "<p>The following features match the name '$id'.</p>";
  $output .= theme_table($header, $rows, $table_attrs, $caption);
  return $output;
}