function tripal_stock_match_stocks_page

2.x tripal_stock.module tripal_stock_match_stocks_page($id)
3.x tripal_stock.module tripal_stock_match_stocks_page($id)
1.x tripal_stock.module tripal_stock_match_stocks_page($id)
1 string reference to 'tripal_stock_match_stocks_page'
tripal_stock_menu in tripal_stock/tripal_stock.module
Implements hook_menu(): Adds menu items for the tripal_stock

File

tripal_stock/tripal_stock.module, line 1189
Implements Tripal Stock Module hooks

Code

function tripal_stock_match_stocks_page($id) {

  // if the URL alias configuration is set such that the URL
  // always begins with 'stock' then we want to use the ID as it is and
  // forward it on. Otherwise, try to find the matching stock.
  $url_alias = variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]');
  if (!$url_alias) {
    $url_alias = '/stock/[genus]/[species]/[type]/[uniquename]';
  }
  $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash  
  if (preg_match('/^stock\//', $url_alias)) {
    drupal_goto($id);
  }


  $sql = "
    SELECT
      S.name, S.uniquename, S.stock_id,
      O.genus, O.species, O.organism_id,
      CVT.cvterm_id, CVT.name as type_name,
      CS.nid
    FROM {stock} S
      INNER JOIN {organism} O on S.organism_id = O.organism_id
      INNER JOIN {cvterm} CVT on CVT.cvterm_id = S.type_id
      INNER JOIN public.chado_stock CS on CS.stock_id = S.stock_id
    WHERE
      S.uniquename = '%s' or S.name = '%s'
  ";
  $results = chado_query($sql, $id, $id);

  $num_matches = 0;

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

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

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