Ver Fonte

Stock templates converted. Fixed some other templates

Stephen Ficklin há 11 anos atrás
pai
commit
df26ed8bea

+ 1 - 1
tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php

@@ -72,7 +72,7 @@ $analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.descriptio
     preg_replace("/^(\d+-\d+-\d+) .*/","$1", $analysis->timeexecuted),
   ); 
   
-  // allow site admins to see the feature ID
+  // allow site admins to see the analysis ID
   if (user_access('access administration pages')) {
     // Analysis ID
     $rows[] = array(

+ 1 - 153
tripal_feature/api/tripal_feature.api.inc

@@ -831,159 +831,7 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
   return $residues;
 }
 
-/**
- * Using the tripal_core_expand_chado_vars function to retrieve a set
- * of relationships can be very slow, especialy if there are many relationships
- * This function is intended to help speed up the retrieval of relationships
- * by only retrieving the base information for the relationship and returning
- * an array with  
- *
- * @param $feature
- *   The feature object 
- 
- * @return
- *   An array with two objects
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_get_feature_relationships($feature) {
-  // expand the feature object to include the feature relationships.
-  $options = array(
-    'return_array' => 1,
-    'order_by' => array('rank' => 'ASC'),
-    // we don't want to fully recurse we only need information about the 
-    // relationship type and the object and subject features (including feature type
-    // and organism)
-    'include_fk' => array(
-      'type_id' => 1,
-      'object_id' => array(
-        'type_id' => 1,
-        'organism_id' => 1
-      ),
-      'subject_id'  => array(
-        'type_id' => 1,
-        'organism_id' => 1
-      ),
-    ),
-  );
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_relationship', $options);
-  
-  // get the subject relationships
-  $srelationships = $feature->feature_relationship->subject_id;
-  $orelationships = $feature->feature_relationship->object_id;
-  
-  
-  // get alignment as child. The $feature->featureloc element
-  // is already populated from the alignment preprocess function
-  $options = array(
-    'include_fk' => array(
-      'srcfeature_id' => 1,
-      'feature_id' => 1,
-    ),
-  );
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
-  $cfeaturelocs = $feature->featureloc->feature_id;
-  if (!$cfeaturelocs) {
-     $cfeaturelocs = array();
-  } 
-  elseif (!is_array($cfeaturelocs)) { 
-     $cfeaturelocs = array($cfeaturelocs); 
-  }
-  
-  // prepare the SQL statement to get the featureloc for the 
-  // feature in the relationships. 
-  $flrels_sql = "  
-    SELECT 
-      FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
-      FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
-    FROM {featureloc} FL 
-      INNER JOIN {feature} F ON F.feature_id = FL.srcfeature_id
-    WHERE FL.feature_id = :feature_id and FL.srcfeature_id = :srcfeature_id
-  ";
-  
-  // combine both object and subject relationshisp into a single array
-  $relationships = array();
-  $relationships['object'] = array();
-  $relationships['subject'] = array();
-  
-  // iterate through the object relationships
-  if ($orelationships) {
-    foreach ($orelationships as $relationship) {
-       $rel = new stdClass(); 
-       // get locations where the child feature and this feature overlap with the
-       // same landmark feature.
-       $rel->child_featurelocs = array();     
-       foreach ($cfeaturelocs as $featureloc) {
-          $res = chado_query($flrels_sql, array(':feature_id' => $relationship->subject_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));        
-          while ($loc = $res->fetchObject()) {
-             // add in the node id of the src feature if it exists and save this location
-             if (property_exists($featureloc->srcfeature_id, 'nid')) {
-               $loc->nid = $featureloc->srcfeature_id->nid;
-             }
-             $rel->child_featurelocs[] = $loc;
-          }
-       }
-       $rel->record = $relationship;    
-       
-       // get the relationship and child types
-       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-       $child_type = $relationship->subject_id->type_id->name;
-       
-       // get the node id of the subject
-       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
-       $n = db_query($sql, array(':feature_id' => $relationship->subject_id->feature_id))->fetchObject();
-       if ($n) {
-          $rel->record->nid = $n->nid;
-       }
-  
-       if (!array_key_exists($rel_type, $relationships['object'])) {
-         $relationships['object'][$rel_type] = array();   
-       }
-       if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
-         $relationships['object'][$rel_type][$child_type] = array();   
-       }
-       $relationships['object'][$rel_type][$child_type][] = $rel;     
-    }
-  }
-  
-  // now add in the subject relationships
-  if ($srelationships) {
-    foreach ($srelationships as $relationship) {
-       $rel = new stdClass(); 
-       // get locations where this feature overlaps with the parent
-       $rel->parent_featurelocs = array();     
-       foreach ($cfeaturelocs as $featureloc) {
-          $res = chado_query($flrels_sql, array(':feature_id' => $relationship->object_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
-          while ($loc = $res->fetchObject()) {
-            // add in the node id of the src feature if it exists and save this location
-            if (property_exists($featureloc->srcfeature_id, 'nid')) {
-              $loc->nid = $featureloc->srcfeature_id->nid;
-            }
-            $rel->parent_featurelocs[] = $loc;
-          }
-       }
-       $rel->record = $relationship;
-       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-       $parent_type = $relationship->object_id->type_id->name;
-       
-       // get the node id of the subject
-       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
-       $n = db_query($sql, array(':feature_id' => $relationship->object_id->feature_id))->fetchObject();
-       if ($n) {
-          $rel->record->nid = $n->nid;
-       }
-       
-       if (!array_key_exists($rel_type, $relationships['subject'])) {
-         $relationships['subject'][$rel_type] = array();   
-       }
-       if (!array_key_exists($child_type, $relationships['subject'][$rel_type])) {
-         $relationships['subject'][$rel_type][$parent_type] = array();   
-       }
-       $relationships['subject'][$rel_type][$parent_type][] = $rel;
-    }
-  }
-  return $relationships;
-} 
+
 
 /*
  * This function adds an entry to the feature_dbxref table.

+ 154 - 0
tripal_feature/theme/tripal_feature.theme.inc

@@ -172,4 +172,158 @@ function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
 function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
   $organism = $variables['node']->organism;
   $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
+}
+
+/**
+ * Using the tripal_core_expand_chado_vars function to retrieve a set
+ * of relationships can be very slow, especialy if there are many relationships
+ * This function is intended to help speed up the retrieval of relationships
+ * by only retrieving the base information for the relationship and returning
+ * an array with
+ *
+ * @param $feature
+ *   The feature object
+
+ * @return
+ *   An array with two objects
+ *
+ * @ingroup tripal_feature_api
+ */
+function tripal_feature_get_feature_relationships($feature) {
+  // expand the feature object to include the feature relationships.
+  $options = array(
+    'return_array' => 1,
+    'order_by' => array('rank' => 'ASC'),
+    // we don't want to fully recurse we only need information about the
+    // relationship type and the object and subject features (including feature type
+    // and organism)
+    'include_fk' => array(
+      'type_id' => 1,
+      'object_id' => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+      'subject_id'  => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+    ),
+  );
+  $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_relationship', $options);
+
+  // get the subject relationships
+  $srelationships = $feature->feature_relationship->subject_id;
+  $orelationships = $feature->feature_relationship->object_id;
+
+
+  // get alignment as child. The $feature->featureloc element
+  // is already populated from the alignment preprocess function
+  $options = array(
+    'include_fk' => array(
+      'srcfeature_id' => 1,
+      'feature_id' => 1,
+    ),
+  );
+  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
+  $cfeaturelocs = $feature->featureloc->feature_id;
+  if (!$cfeaturelocs) {
+    $cfeaturelocs = array();
+  }
+  elseif (!is_array($cfeaturelocs)) {
+    $cfeaturelocs = array($cfeaturelocs);
+  }
+
+  // prepare the SQL statement to get the featureloc for the
+  // feature in the relationships.
+  $flrels_sql = "
+    SELECT
+      FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
+      FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
+    FROM {featureloc} FL
+      INNER JOIN {feature} F ON F.feature_id = FL.srcfeature_id
+    WHERE FL.feature_id = :feature_id and FL.srcfeature_id = :srcfeature_id
+  ";
+
+  // combine both object and subject relationshisp into a single array
+  $relationships = array();
+  $relationships['object'] = array();
+  $relationships['subject'] = array();
+
+  // iterate through the object relationships
+  if ($orelationships) {
+    foreach ($orelationships as $relationship) {
+      $rel = new stdClass();
+      // get locations where the child feature and this feature overlap with the
+      // same landmark feature.
+      $rel->child_featurelocs = array();
+      foreach ($cfeaturelocs as $featureloc) {
+        $res = chado_query($flrels_sql, array(':feature_id' => $relationship->subject_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
+        while ($loc = $res->fetchObject()) {
+          // add in the node id of the src feature if it exists and save this location
+          if (property_exists($featureloc->srcfeature_id, 'nid')) {
+            $loc->nid = $featureloc->srcfeature_id->nid;
+          }
+          $rel->child_featurelocs[] = $loc;
+        }
+      }
+      $rel->record = $relationship;
+       
+      // get the relationship and child types
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $child_type = $relationship->subject_id->type_id->name;
+       
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
+      $n = db_query($sql, array(':feature_id' => $relationship->subject_id->feature_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+
+      if (!array_key_exists($rel_type, $relationships['object'])) {
+        $relationships['object'][$rel_type] = array();
+      }
+      if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
+        $relationships['object'][$rel_type][$child_type] = array();
+      }
+      $relationships['object'][$rel_type][$child_type][] = $rel;
+    }
+  }
+
+  // now add in the subject relationships
+  if ($srelationships) {
+    foreach ($srelationships as $relationship) {
+      $rel = new stdClass();
+      // get locations where this feature overlaps with the parent
+      $rel->parent_featurelocs = array();
+      foreach ($cfeaturelocs as $featureloc) {
+        $res = chado_query($flrels_sql, array(':feature_id' => $relationship->object_id->feature_id, ':srcfeature_id' => $featureloc->srcfeature_id->feature_id));
+        while ($loc = $res->fetchObject()) {
+          // add in the node id of the src feature if it exists and save this location
+          if (property_exists($featureloc->srcfeature_id, 'nid')) {
+            $loc->nid = $featureloc->srcfeature_id->nid;
+          }
+          $rel->parent_featurelocs[] = $loc;
+        }
+      }
+      $rel->record = $relationship;
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $parent_type = $relationship->object_id->type_id->name;
+       
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
+      $n = db_query($sql, array(':feature_id' => $relationship->object_id->feature_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+       
+      if (!array_key_exists($rel_type, $relationships['subject'])) {
+        $relationships['subject'][$rel_type] = array();
+      }
+      if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
+        $relationships['subject'][$rel_type][$parent_type] = array();
+      }
+      $relationships['subject'][$rel_type][$parent_type][] = $rel;
+    }
+  }
+  return $relationships;
 }

+ 4 - 4
tripal_feature/theme/tripal_feature/tripal_feature_base.tpl.php

@@ -44,13 +44,13 @@ $feature  = $variables['node']->feature;  ?>
   );
   // Organism row
   $organism = $feature->organism_id->genus ." " . $feature->organism_id->species ." (" . $feature->organism_id->common_name .")";
-  if ($feature->organism_id->nid) {
+  if (property_exists($feature->organism_id, 'nid')) {
     $organism = l("<i>" . $feature->organism_id->genus . " " . $feature->organism_id->species . "</i> (" . $feature->organism_id->common_name .")", "node/".$feature->organism_id->nid, array('html' => TRUE));
   } 
   $rows[] = array(
     array(
       'data' => 'Organism',
-      'header' => TRUE
+      'header' => TRUE,
     ),
     $organism
   );
@@ -59,7 +59,7 @@ $feature  = $variables['node']->feature;  ?>
     $rows[] = array(
       array(
         'data' => 'Sequence length',
-        'header' => TRUE
+        'header' => TRUE,
       ),
       $feature->seqlen
     );
@@ -70,7 +70,7 @@ $feature  = $variables['node']->feature;  ?>
     $rows[] = array(
       array(
         'data' => 'Feature ID',
-        'header' => TRUE
+        'header' => TRUE,
       ),
       $feature->feature_id
     );

+ 2 - 2
tripal_project/theme/tripal_project/tripal_project.teaser.tpl.php

@@ -12,10 +12,10 @@ $project = $variables['node']->project;
 // if there is data in the projectprop table for a descrtion then that takes 
 // precedence 
 $description = '';
-if ($node->body) {
+if (property_exists($node, 'body')) {
   $description = $node->body;
 }
-if ($node->description) {
+if (property_exists($node, 'description')) {
   $description = $project->description;
 }
 else {

+ 7 - 15
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -848,40 +848,26 @@ function tripal_stock_node_update($node) {
 function tripal_stock_node_view($node, $view_mode, $langcode) {
 
   switch ($node->type) {
-    case 'chado_organism':
-      if ($view_mode == 'full') {
-        // Show stock if the organism/feature is not at teaser view
-        $node->content['tripal_organism_stocks'] = array(
-          '#value' => theme('tripal_organism_stocks', $node),
-        );
-      }
-      break;
     case 'chado_stock':
       if ($view_mode == 'full') {
         $node->content['tripal_stock_base'] = array(
           '#value' => theme('tripal_stock_base', array('node' => $node)),
         );
-        // Stock Collections
         $node->content['tripal_stock_collections'] = array(
           '#value' => theme('tripal_stock_collections', array('node' => $node)),
         );
-        // Properties
         $node->content['tripal_stock_properties'] = array(
           '#value' => theme('tripal_stock_properties', array('node' => $node)),
         );
-        // Cross References
         $node->content['tripal_stock_references'] = array(
           '#value' => theme('tripal_stock_references', array('node' => $node)),
         );
-        // Relationships
         $node->content['tripal_stock_relationships'] = array(
           '#value' => theme('tripal_stock_relationships', array('node' => $node)),
         );
-        // Synonyms
         $node->content['tripal_stock_synonyms'] = array(
           '#value' => theme('tripal_stock_synonyms', array('node' => $node)),
         );
-        // Publications
         $node->content['tripal_stock_publications'] = array(
           '#value' => theme('tripal_stock_publications', array('node' => $node)),
         );
@@ -892,6 +878,12 @@ function tripal_stock_node_view($node, $view_mode, $langcode) {
         );
       }
       break;
+    case 'chado_organism':
+      if ($view_mode == 'full') {
+        $node->content['tripal_organism_stocks'] = array(
+          '#value' => theme('tripal_organism_stocks', $node),
+        );
+      }
+      break;
   }
-
 }

+ 0 - 96
tripal_stock/theme/node--chado-stock.tpl.php

@@ -1,96 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the stock node (page)
-//   using the same templates used for the various stock content blocks.
-//
-// To Customize the Stock Node Page:
-//   - This Template: customize basic layout and which elements are included
-//   - Using Panels: Override the node page using Panels3 and place the blocks
-//       of content as you please. This method requires no programming. See
-//       the Tripal User Guide for more details
-//   - Block Templates: customize the content/layout of each block of stock
-//       content. These templates are found in the tripal_stock subdirectory
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which
-//       provides an extra tab at the top of the node page labelled Devel
-
-$stock = $variables['node']->stock;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and
-   $template_settings['tripal_no_sidebar']['stock']) {
-  $no_sidebar = 1;
-}
-
-if ($teaser) {
-  //print theme('tripal_stock_teaser',$node);
-}
-else { ?>
-
-<div id="tripal_stock_details" class="tripal_details">
-
-  <!-- Base Theme -->
-  <?php //print theme('tripal_stock_base',$node); ?>
-
-  <!-- Cross References -->
-  <?php //print theme('tripal_stock_references',$node); ?>
-
-  <!-- Properties -->
-  <?php //print theme('tripal_stock_properties',$node); ?>
-
-  <!-- Synonyms -->
-  <?php //print theme('tripal_stock_synonyms',$node); ?>
-
-  <!-- Relationships -->
-  <?php //print theme('tripal_stock_relationships',$node); ?>
-
-  <!-- Stock Collections -->
-  <?php //print theme('tripal_stock_collections',$node); ?>
-
-  <!-- Stock Genotypes -->
-  <?php //print theme('tripal_stock_genotypes',$node); ?>
-
-  <!-- Resource Blocks CCK elements --><?php
-  /**
-  for($i = 0; $i < count($node->field_resource_titles); $i++){
-    if($node->field_resource_titles[$i]['value']){ ?>
-      <div id="tripal_stock-resource_<?php print $i?>-box" class="tripal_stock-info-box tripal-info-box">
-        <div class="tripal_stock-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-        <?php print $node->field_resource_blocks[$i]['value']; ?>
-      </div><?php
-    }
-  }*/?>
-
-  <!-- Let modules add more content -->
-	<?php print $content; ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_stock_toc" class="tripal_toc">
-   <div id="tripal_stock_toc_title" class="tripal_toc_title">Resources</div>
-   <span id="tripal_stock_toc_desc" class="tripal_toc_desc"></span>
-   <ul id="tripal_stock_toc_list" class="tripal_toc_list">
-
-     <!-- Resource Links CCK elements --><?php
-     /**
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }*/?>
-
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-<?php } ?>

+ 95 - 38
tripal_stock/theme/tripal_stock/tripal_stock_base.tpl.php

@@ -9,43 +9,100 @@ $stock = tripal_core_expand_chado_vars($stock, 'field', 'stock.uniquename');
 ?>
 <div id="tripal_stock-base-box" class="tripal_stock-info-box tripal-info-box">
   <div class="tripal_stock-info-box-title tripal-info-box-title">Details</div>
-  <!-- <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div> -->
+  <!-- <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div> --><?php 
+  
+  // the $headers array is an array of fields to use as the colum headers. 
+  // additional documentation can be found here 
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  // This table for the stock has a vertical header (down the first column)
+  // so we do not provide headers here, but specify them in the $rows array below.
+  $headers = array();
+  
+  // the $rows array contains an array of rows where each row is an array
+  // of values for each column of the table in that row.  Additional documentation
+  // can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+  $rows = array();
+  
+  // Stock Name
+  $rows[] = array(
+    array(
+      'data' => 'Name',
+      'header' => TRUE,
+    ),
+    $stock->name
+  );
+  // Stock Unique Name
+  $rows[] = array(
+    array(
+      'data' => 'Stock Name',
+      'header' => TRUE,
+    ),
+    $stock->uniquename
+  );
+  // Stock Type
+  $rows[] = array(
+    array(
+      'data' => 'Type',
+      'header' => TRUE,
+    ),
+    ucwords(preg_replace('/_/', ' ', $stock->type_id->name))
+  );
 
-   <?php if($stock->is_obsolete == 't'){ ?>
-      <div class="tripal_stock-obsolete">This stock is obsolete and no longer used in analysis, but is here for reference</div>
-   <?php }?>
-   <table class="tripal_stock-table tripal-table tripal-table-vert">
-      <tr class="tripal_stock-table-even-row tripal-table-even-row">
-        <th>Name</th>
-        <td><?php print $stock->name; ?></td>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
-        <th nowrap>Unique Name</th>
-        <td><?php print $stock->uniquename ?></td>
-      </tr>
-      <tr class="tripal_stock-table-even-row tripal-table-even-row">
-        <th>Type</th>
-        <td><?php print ucwords(preg_replace('/_/', ' ', $stock->type_id->name)) ?></td>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
-        <th>Organism</th>
-        <td><?php
-          if ($organism->nid) { ?>
-      	   <a href="<?php print url("node/$organism->nid") ?>"><?php print "<i>" . $organism->genus .
-            " " . $organism->species . "</i> (" . $organism->common_name . " )"?></a><?php
-          } else {
-            print "<i>" . $organism->genus . " " . $organism->species . "</i> (" . $organism->common_name . ")";
-          } ?>
-        </td>
-     	</tr>
-      <tr class="tripal_stock-table-even-row tripal-table-even-row">
-        <th>Description</th>
-        <td><?php print $stock->description ?></td>
-      </tr>
-      <!--
-      <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
-        <th>Internal ID</th>
-        <td><?php print $stock->stock_id ?></td>
-      </tr>     -->
-   </table>
+  // Organism
+  $organism = $stock->organism_id->genus ." " . $stock->organism_id->species ." (" . $stock->organism_id->common_name .")";
+  if (property_exists($stock->organism_id, 'nid')) {
+    $organism = l("<i>" . $stock->organism_id->genus . " " . $stock->organism_id->species . "</i> (" . $stock->organism_id->common_name .")", "node/".$stock->organism_id->nid, array('html' => TRUE));
+  }
+  $rows[] = array(
+    array(
+      'data' => 'Organism',
+      'header' => TRUE
+    ),
+    $organism
+  );
+  // allow site admins to see the stock ID
+  if (user_access('access administration pages')) {
+    // stock ID
+    $rows[] = array(
+      array(
+        'data' => 'Stock ID',
+        'header' => TRUE
+      ),
+      $stock->stock_id
+    );
+  }
+  // Is Obsolete Row
+  if($stock->is_obsolete == TRUE){
+    $rows[] = array(
+      array(
+        'data' => '<div class="tripal_stock-obsolete">This stock is obsolete</div>',
+        'colspan' => 2
+      ),
+    );
+  }
+  // the $table array contains the headers and rows array as well as other
+  // options for controlling the display of the table.  Additional
+  // documentation can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_stock-table-base',
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  
+  // once we have our table array structure defined, we call Drupal's theme_table()
+  // function to generate the table.
+  print theme_table($table);
+  
+  // add in the description if there is one
+  if (property_exists($stock, 'description')) { ?>
+    <div style="text-align: justify"><?php print $stock->description; ?></div> <?php  
+  } ?>
 </div>

+ 51 - 34
tripal_stock/theme/tripal_stock/tripal_stock_collections.tpl.php

@@ -9,39 +9,56 @@ $collections = $stock->stockcollection_stock;
 if (count($collections) > 0) {?>
   <div id="tripal_stock-collections-box" class="tripal_stock-info-box tripal-info-box">
     <div class="tripal_stock-info-box-title tripal-info-box-title">Stock Collections</div>
-    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This stock is found in the following collections.</div>
-    <table id="tripal_stock-table-collection" class="tripal_stock-table tripal-table tripal-table-horz">     
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Collection Name</th>
-        <th>Type</th>
-        <th>Contact</th>
-      </tr> <?php
-      foreach ($collections as $collection_stock){ 
-        // get the stock collection details
-        $collection = $collection_stock->stockcollection_id;
-        
-        $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-          $class = 'tripal_stock-table-odd-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td><?php 
-            if($collection->nid){    
-              $link =  url("node/$collection->nid");        
-              print "<a href=\"$link\">$collection->name</a>";
-            } 
-            else {
-              print $collection->name;
-            } ?>
-          </td>
-          <td><?php print ucwords(preg_replace('/_/', ' ', $collection->type_id->name)) ?> </td>
-          <td><?php 
-            $contact = $collection->contact_id; 
-            print $contact->name . "<br>" .  $contact->description ?>              
-          </td>
-        </tr> <?php
-        $i++; 
-      }?>  
-    </table> 
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This stock is found in the following collections.</div> <?php 
+    
+    // the $headers array is an array of fields to use as the colum headers. 
+    // additional documentation can be found here 
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    // This table for the analysis has a vertical header (down the first column)
+    // so we do not provide headers here, but specify them in the $rows array below.
+    $headers = array('Collection Name', 'Type', 'Contact');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+    $rows = array();
+
+    foreach ($collections as $collection_stock){ 
+      // get the stock collection details
+      $collection = $collection_stock->stockcollection_id; 
+      $contact    = $collection->contact_id;
+      
+      $cname = $collection->name;
+      if (property_exists($collection, 'nid')) {
+        $cname = l($collection->name, "node/" . $collection->nid, array('attributes' => array('target' => '_blank')));
+      }
+      
+      $rows[] = array(
+        $cname,
+        ucwords(preg_replace('/_/', ' ', $collection->type_id->name)),
+        $contact->name,
+      );
+    }
+     
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_stock-table-synonyms',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>  
   </div><?php
 }

+ 54 - 34
tripal_stock/theme/tripal_stock/tripal_stock_properties.tpl.php

@@ -1,47 +1,67 @@
 <?php
 
-$stock = $node->stock;
-$properties = array();
-
-// expand the stock object to include the stockprop records
+$stock = $variables['node']->stock;
 $options = array('return_array' => 1);
 $stock = tripal_core_expand_chado_vars($stock, 'table', 'stockprop', $options);
 $stockprops = $stock->stockprop;
 
-// iterate through all of the properties and pull out only the synonyms
+// the stock synonyms are stored in the stockprop table because we do not have
+// a stock_synonym table. Therefore, we don't want to synonyms in the properties
+// list as those get shown by the tripal_stock_synonyms.tpl.inc template.
+$properties = array();
 if ($stockprops) {
-  foreach ($stockprops as $stockprop){    
-    if($stockprop->type_id->name == 'synonym' or $stockprop->type_id->name == 'alias'){
-      // there is no stock_synonym table, analogous to the feature_synonym table.
-      // Therefore, synonyms have been stored in the stockprop table with a type 
-      // of 'synonym' or 'alias'. Synonyms are shown in the tripal_stock_synonyms.tpl.php
-      // template, so we exclude those types of properties for this template    
-    } 
-    else {
-      $properties[] = $stockprop;  
+  foreach ($stockprops as $property) {
+    // we want to keep all properties but the stock_description as that
+    // property is shown on the base template page.
+    if($property->type_id->name != 'synonym' and  $property->type_id->name != 'alias') {
+      $property = tripal_core_expand_chado_vars($property,'field','stockprop.value');
+      $properties[] = $property;
     }
   }
 }
 
 if(count($properties) > 0){ ?>
-	<div id="tripal_stock-properties-box" class="tripal_stock-info-box tripal-info-box">
-	  <div class="tripal_stock-info-box-title tripal-info-box-title">Properties</div>
-	  <div class="tripal_stock-info-box-desc tripal-info-box-desc">Properties for the stock '<?php print $node->stock->name ?>' include:</div>
-	  <table class="tripal_stock-table tripal-table tripal-table-horz">
-	    <tr><th>Type</th><th>Value</th></tr> <?php	
-			$i = 0;
-			// iterate through each property
-			foreach ($properties as $property){
-			  $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
-	      if($i % 2 == 0 ){
-	         $class = 'tripal_stock-table-even-row tripal-table-even-row';
-	      }?>   
-        <tr class="<?php print $class ?>">
-          <td><?php print ucwords(preg_replace('/_/', ' ', $property->type_id->name)) ?></td>
-          <td><?php print $property->value?></td>
-        </tr> <?php	      
-				$i++;
-			} ?>
-	  </table>
-	</div><?php  
+
+  <div id="tripal_stock-properties-box" class="tripal_stock-info-box tripal-info-box">
+    <div class="tripal_stock-info-box-title tripal-info-box-title">Properties</div> <?php
+
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Property Name', 'Value');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($properties as $property){
+      $property = tripal_core_expand_chado_vars($property,'field','stockprop.value');
+      $rows[] = array(
+        ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
+        urldecode($property->value)
+      );
+    }
+     
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_stock-table-properties',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php
 }

+ 72 - 44
tripal_stock/theme/tripal_stock/tripal_stock_references.tpl.php

@@ -2,9 +2,9 @@
 $stock = $variables['node']->stock;
 $references = array();
 
-// First, get the dbxref record from stock recrod itself if one exists
+// First, get the dbxref record from stock record itself if one exists
 if ($stock->dbxref_id) {
-  $stock->dbxref_id->is_primary = TRUE;  // add this new property so we know it's the primary reference
+  $stock->dbxref_id->is_primary = 1;  // add this new property so we know it's the primary reference
   $references[] = $stock->dbxref_id;
 }
 
@@ -13,49 +13,77 @@ $options = array('return_array' => 1);
 $stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_dbxref', $options);
 $stock_dbxrefs = $stock->stock_dbxref;
 if (count($stock_dbxrefs) > 0 ) {
-  foreach ($stock_dbxrefs as $stock_dbxref) {
-    $references[] = $stock_dbxref->dbxref_id;
+  foreach ($stock_dbxrefs as $stock_dbxref) {    
+    if($stock_dbxref->dbxref_id->db_id->name == 'GFF_source'){
+      // check to see if the reference 'GFF_source' is there.  This reference is
+      // used to if the Chado Perl GFF loader was used to load the stocks   
+    }
+    else {
+      $references[] = $stock_dbxref->dbxref_id;
+    }
   }
 }
 
+
 if(count($references) > 0){ ?>
-	<div id="tripal_stock-references-box" class="tripal_stock-info-box tripal-info-box">
-	  <div class="tripal_stock-info-box-title tripal-info-box-title">Cross References</div>
-	  <div class="tripal_stock-info-box-desc tripal-info-box-desc">The stock '<?php print $node->stock->name ?>' is also available at these locations</div>
-	  <table class="tripal_stock-table tripal-table tripal-table-horz">
-	    <tr>
-	      <th>Dababase</th>
-	      <th>Accession</th>
-	    </tr> <?php
-	    $i = 0;
-	    foreach ($references as $dbxref){
-	      $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
-	      if($i % 2 == 0 ){
-	         $class = 'tripal_stock-table-odd-row tripal-table-even-row';
-	      } ?>
-	      <tr class="<?php print $class ?>">
-	        <td> <?php
-	          if ($dbxref->db_id->url) {
-              print l($dbxref->db_id->name, $dbxref->db_id->url);
-            }
-            else {
-              print $dbxref->db_id->name;
-            } ?>
-	        </td>
-	        <td> <?php
-	          if ($dbxref->db_id->urlprefix) {
-	           	print l($dbxref->accession, $dbxref->db_id->urlprefix.$dbxref->accession);
-	          }
-	          else {
-	            print $dbxref->accession;
-	          }
-	          if (property_exists($dbxref,'is_primary')) {
-	            print " <i>(primary cross-reference)</i>";
-	          } ?>
-	        </td>
-	      </tr> <?php
-	      $i++;
-	    } ?>
-	  </table>
-	</div><?php
-}
+  <div id="tripal_stock-references-box" class="tripal_stock-info-box tripal-info-box">
+    <div class="tripal_stock-info-box-title tripal-info-box-title">Cross References</div>
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc">External references for this <?php print $stock->type_id->name ?></div><?php
+     
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Dababase', 'Accession');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+ 
+    foreach ($references as $dbxref){
+    
+      // skip the GFF_source entry as this is just needed for the GBrowse chado adapter 
+      if ($dbxref->db_id->name == 'GFF_source'){
+         continue;  
+      } 
+      $dbname = $dbxref->db_id->name; 
+      if ($dbxref->db_id->url) { 
+        $dbname = l($dbname, $dbxref->db_id->url, array('attributes' => array('target' => '_blank')));
+      } 
+      
+      $accession = $dbxref->accession; 
+      if ($dbxref->db_id->urlprefix) { 
+        $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+      } 
+      if (property_exists($dbxref, 'is_primary')) {
+        $accession .= " <i>(primary cross-reference)</i>";
+      }
+      $rows[] = array(
+        $dbname,
+        $accession
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_stock-table-references',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div><?php 
+}?>
+

+ 117 - 72
tripal_stock/theme/tripal_stock/tripal_stock_relationships.tpl.php

@@ -16,86 +16,131 @@
  * key 'object' contains relationships where the stock is the object, and the array with
  * the key 'subject' contains relationships where the stock is the subject
  */
-
 $stock = $variables['node']->stock;
 
 $all_relationships = $stock->all_relationships;
 $object_rels = $all_relationships['object'];
 $subject_rels = $all_relationships['subject'];
 
-// make the stock type a bit more human readable
-$stock_type =  preg_replace("/_/", ' ', $stock->type_id->name);
-
-if (count($object_rels) > 0 or count($subject_rels) > 0) {
-?>
+if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
   <div id="tripal_stock-relationships-box" class="tripal_stock-info-box tripal-info-box">
     <div class="tripal_stock-info-box-title tripal-info-box-title">Relationships</div>
-    <!--  <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div> --><?php
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div> <?php
+    // first add in the subject relationships.  
+    foreach ($subject_rels as $rel_type => $rels){
+      foreach ($rels as $obj_type => $objects){ ?>
+        <p>This <?php print $stock->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> stock(s): <?php
+         
+        // the $headers array is an array of fields to use as the colum headers.
+        // additional documentation can be found here
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $headers = array('Stock Name' ,'Unique Name', 'Species', 'Type');
+        
+        // the $rows array contains an array of rows where each row is an array
+        // of values for each column of the table in that row.  Additional documentation
+        // can be found here:
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $rows = array();
+        
+        foreach ($objects as $object){
+          // link the stock to it's node
+          $stock_name = $object->record->object_id->name;
+          if (property_exists($object->record, 'nid')) {
+            $stock_name = l($stock_name, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
+          }
+          // link the organism to it's node
+          $organism = $object->record->object_id->organism_id;
+          $organism_name = $organism->genus ." " . $organism->species;
+          if (property_exists($organism, 'nid')) {
+            $organism_name = l("<i>" . $organism->genus . " " . $organism->species . "</i>", "node/" . $organism->nid, array('html' => TRUE));
+          }
+          $rows[] = array(
+            $stock_name, 
+            $object->record->object_id->uniquename,
+            $organism_name,
+            $object->record->object_id->type_id->name,
+          ); 
+         } 
+         // the $table array contains the headers and rows array as well as other
+         // options for controlling the display of the table.  Additional
+         // documentation can be found here:
+         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+         $table = array(
+           'header' => $headers,
+           'rows' => $rows,
+           'attributes' => array(
+             'id' => 'tripal_stock-table-relationship-object',
+           ),
+           'sticky' => FALSE,
+           'caption' => '',
+           'colgroups' => array(),
+           'empty' => '',
+         );
+         
+         // once we have our table array structure defined, we call Drupal's theme_table()
+         // function to generate the table.
+         print theme_table($table); ?>
+         </p>
+         <br><?php
+       }
+    }
     
-      // first add in the subject relationships.  
-      foreach ($subject_rels as $rel_type => $rels){
-         // make the type a bit more human readable
-         $rel_type = preg_replace("/_/", ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through each parent   
-         foreach ($rels as $obj_type => $objects){?>
-           <p>This stock is a <b><?php print $rel_type ?></b> of the following <?php print $obj_type ?> stock(s):
-           <table id="tripal_stock-relationships_as_object-table" class="tripal_stock-table tripal-table tripal-table-horz">
-             <tr>
-               <th>Stock Name</th>
-               <th>Type</th>
-               <th>Description</th>
-             </tr> <?php
-             foreach ($objects as $object){ ?>
-               <tr>
-                 <td><?php 
-                    if ($object->nid) {
-                      print "<a href=\"" . url("node/" . $object->nid) . "\" target=\"_blank\">" . $object->name . "</a>";
-                    }
-                    else {
-                      print $object->name;
-                    } ?>
-                 </td>
-                 <td><?php print ucwords(preg_replace('/_/', ' ', $object->obj_type)) ?></td> 
-                 <td><?php print $object->value ?></td>                
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      }
-      
-      // second add in the object relationships.  
-      foreach ($object_rels as $rel_type => $rels){
-         // make the type more human readable
-         $rel_type = preg_replace('/_/', ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through the children         
-         foreach ($rels as $subject_type => $subjects){?>
-           <p>The following <?php print $subject_type ?> stocks are a <b><?php print $rel_type ?></b> of this stock:
-           <table id="tripal_stock-relationships_as_object-table" class="tripal_stock-table tripal-table tripal-table-horz">
-             <tr>
-               <th>Stock Name</th>
-               <th>Type</th>
-               <th>Description</th>
-             </tr> <?php
-             foreach ($subjects as $subject){ ?>
-               <tr>
-                 <td><?php 
-                    if ($subject->nid) {
-                      print "<a href=\"" . url("node/" . $subject->nid) . "\" target=\"_blank\">" . $subject->name . "</a>";
-                    }
-                    else {
-                      print $subject->name;
-                    } ?>
-                 </td>
-                 <td><?php print ucwords(preg_replace('/_/', ' ', $subject->sub_type)) ?></td>   
-                 <td><?php print $subject->value ?></td>              
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      } ?>
+    // second add in the object relationships.  
+    foreach ($object_rels as $rel_type => $rels){
+      foreach ($rels as $subject_type => $subjects){?>
+        <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> stock(s) are <?php print $rel_type ?> this <?php print $stock->type_id->name;?>: <?php 
+        // the $headers array is an array of fields to use as the colum headers.
+        // additional documentation can be found here
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $headers = array('Stock Name' ,'Unique Name', 'Species', 'Type');
+        
+        // the $rows array contains an array of rows where each row is an array
+        // of values for each column of the table in that row.  Additional documentation
+        // can be found here:
+        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+        $rows = array();
+        
+        foreach ($subjects as $subject){
+          // link the stock to it's node
+          $stock_name = $subject->record->subject_id->name;
+          if (property_exists($subject->record, 'nid')) {
+            $stock_name = l($stock_name, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
+          }
+          // link the organism to it's node
+          $organism = $subject->record->subject_id->organism_id;
+          $organism_name = $organism->genus ." " . $organism->species;
+          if (property_exists($organism, 'nid')) {
+            $organism_name = l("<i>" . $organism->genus . " " . $organism->species . "</i>", "node/" . $organism->nid, array('html' => TRUE));
+          }
+          $rows[] = array(
+            $stock_name, 
+            $subject->record->subject_id->uniquename,
+            $organism_name,
+            $subject->record->subject_id->type_id->name,
+          ); 
+         } 
+         // the $table array contains the headers and rows array as well as other
+         // options for controlling the display of the table.  Additional
+         // documentation can be found here:
+         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+         $table = array(
+           'header' => $headers,
+           'rows' => $rows,
+           'attributes' => array(
+             'id' => 'tripal_stock-table-relationship-subject',
+           ),
+           'sticky' => FALSE,
+           'caption' => '',
+           'colgroups' => array(),
+           'empty' => '',
+         );
+         
+         // once we have our table array structure defined, we call Drupal's theme_table()
+         // function to generate the table.
+         print theme_table($table); ?>
+         </p>
+         <br><?php
+       }
+    }?>
   </div> <?php
 }

+ 43 - 22
tripal_stock/theme/tripal_stock/tripal_stock_synonyms.tpl.php

@@ -1,5 +1,5 @@
 <?php
-// there is no stock_synonym table, analogous to the feature_synonym table.
+// there is no stock_synonym table, analogous to the stock_synonym table.
 // Therefore, synonyms have been stored in the stockprop table with a type 
 // of 'synonym' or 'alias'.
 $stock = $node->stock;
@@ -20,25 +20,46 @@ if ($stockprops) {
 }
 
 if(count($synonyms) > 0){ ?>
-	<div id="tripal_stock-synonyms-box" class="tripal_stock-info-box tripal-info-box">
-	  <div class="tripal_stock-info-box-title tripal-info-box-title">Synonyms</div>
-	  <div class="tripal_stock-info-box-desc tripal-info-box-desc">The feature '<?php print $stock->name ?>' has the following synonyms</div> 
-	  		
-	  <table id="tripal_stock-synonyms-table" class="tripal_stock-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Name</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($synonyms as $synonym){
-        $class = 'tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td><?php print $synonym->value?></td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table>
-	</div><?php
+  <div id="tripal_stock-synonyms-box" class="tripal_stock-info-box tripal-info-box">
+    <div class="tripal_stock-info-box-title tripal-info-box-title">Synonyms</div>
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc">The stock '<?php print $stock->name ?>' has the following synonyms</div> <?php
+    
+    // the $headers array is an array of fields to use as the colum headers. 
+    // additional documentation can be found here 
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    // This table for the analysis has a vertical header (down the first column)
+    // so we do not provide headers here, but specify them in the $rows array below.
+    $headers = array('Synonym');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+    $rows = array();
+    foreach ($synonyms as $property){
+      $rows[] = array(
+        $property->value,
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_stock-table-synonyms',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+      print theme_table($table); ?>
+  </div><?php
 }

+ 12 - 81
tripal_stock/theme/tripal_stock/tripal_stock_teaser.tpl.php

@@ -1,85 +1,16 @@
 <?php
-// Purpose: Provide layout and content for the basic stock details. This
-//   includes all fields in the chado stock table supplemented with extra
-//   details for each foreign key to provide human-readable output
-//
-// Note: This template controls the layout/content for the default stock node
-//   template (node-chado_stock.tpl.php) and the Stock Details Block
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-?>
+$node  = $variables['node'];
+$stock = $variables['node']->stock;
+$stock = tripal_core_expand_chado_vars($stock,'field','stock.description'); ?>
 
-<?php
- //uncomment this line to see a full listing of the fields avail. to $node
- //print '<pre>'.print_r($node,TRUE).'</pre>';
-?>
-
-<?php 
-  $stock = $node->stock;
-  $organism = $node->stock->organism_id; 
-  $main_db_reference = $stock->dbxref_id;
-?>
-
-<div id="tripal_stock-base-box" class="tripal_stock-info-box tripal-info-box">
-  <div class="tripal_stock-info-box-title tripal-info-box-title">
-    <?php print l($node->stock->name, 'node/'.$node->nid); ?>
+<div class="tripal_stock-teaser tripal-teaser"> 
+  <div class="tripal-stock-teaser-title tripal-teaser-title"><?php 
+    print l($node->title, "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-stock-teaser-text tripal-teaser-text"><?php 
+    print substr($stock->description, 0, 650);
+    if (strlen($stock->description) > 650) {
+      print "... " . l("[more]", "node/$node->nid");
+    } ?>
   </div>
-  <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div>
-  
-   <?php if($stock->is_obsolete == 't'){ ?>
-      <div class="tripal_stock-obsolete">This stock is obsolete and no longer used in analysis, but is here for reference</div>
-   <?php }?>
-   <table class="tripal_stock-table tripal-table tripal-table-vert">
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Name</th>
-        <td><?php print $stock->name; ?></td>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
-        <th nowrap>Unique Name</th>
-        <td><?php print $stock->uniquename; ?></td>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Internal ID</th>
-        <?php if (!empty($main_db_reference->dbxref_id)) { ?>
-        	<?php 
-        		if ($main_db_reference->db_id->urlprefix) {
-        			$accession = l($main_db_reference->accession, $main_db_reference->db_id->urlprefix.$main_db_reference->accession);
-        		} else {
-        			$accession = $main_db_reference->accession;
-        		}
-        		if ($main_db_reference->db_id->url) {
-        			$accession .= ' ('.l($main_db_reference->db_id->name, $main_db_reference->db_id->url).')';
-        		} else {
-        			$accession .= ' ('.$main_db_reference->db_id->name.')';
-        		}
-        	?>
-        	<td><?php print $accession; ?></td>
-        <?php } else { ?>
-        	<td></td>
-        <?php } ?>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
-        <th>Type</th>
-        <td><?php print $stock->type_id->name; ?></td>
-      </tr>
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Organism</th>
-        <td>
-          <?php if ($organism->nid) { ?>
-      	   <a href="<?php print url("node/$organism->nid") ?>"><?php print $organism->genus ." " . $organism->species ." (" .$organism->common_name ." )"?></a>
-      	 <?php 
-          } else { 
-            print $organism->genus ." " . $organism->species ." (" .$organism->common_name ." )";
-          } ?>
-        </td>
-     	</tr>           	                                
-   </table>
 </div>

+ 101 - 87
tripal_stock/tripal_stock.module

@@ -225,91 +225,93 @@ function tripal_stock_views_api() {
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_stock') . '/theme';
+function tripal_stock_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   $items = array(
 
     // property edit forms function templates
     'tripal_stock_edit_ALL_properties_form' => array(
-      'arguments' => array('form'),
+      'variables' => array('form'),
       'function' => 'theme_tripal_stock_edit_ALL_properties_form',
     ),
     'tripal_stock_edit_ALL_db_references_form' => array(
-      'arguments' => array('form'),
+      'variables' => array('form'),
       'function' => 'theme_tripal_stock_edit_ALL_db_references_form',
     ),
     'tripal_stock_edit_ALL_relationships_form' => array(
-      'arguments' => array('form'),
+      'variables' => array('form'),
       'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
     ),
+    
     // tripal_stock templates
     'node__chado_stock' => array(
       'template' => 'node--chado-generic',
-      'path' => drupal_get_path('module', 'tripal_core') . '/theme',
       'render element' => 'node',
       'base hook' => 'node',
+      'path' => "$core_path/theme",
     ),
     'tripal_stock_base' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_base',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_properties' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_properties',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_publications' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock.publications',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_references' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_references',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_relationships' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_relationships',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_synonyms' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_synonyms',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_collections' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_collections',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_collections' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_collections',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_phenotypes' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_phenotypes',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_locations' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_stock_locations',
-      'path' => "$theme_path/tripal_stock",
+      'path' => "$path/theme/tripal_stock",
     ),
     // tripal_organism templates
     'tripal_organism_stocks' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_organism_stocks',
-      'path' => "$theme_path/tripal_organism",
+      'path' => "$path/theme/tripal_organism",
     ),
     // help template
     'tripal_stock_help' => array(
       'template' => 'tripal_stock_help',
-      'arguments' =>  array(NULL),
-      'path' => $theme_path,
+      'variables' =>  array(NULL),
+      'path' => "$path/theme/",
     ),
   );
   return $items;
@@ -436,36 +438,30 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
   // we want to provide a new variable that contains the matched stocks.
   $stock = $variables['node']->stock;
 
-  // normally we would use tripal_core_expand_chado_vars to expand our
-  // organism object and add in the relationships, however whan a large
-  // number of relationships are present this significantly slows the
-  // query, therefore we will manually perform the query
-  $sql = "
-    SELECT
-      S.name, S.uniquename, S.stock_id, CS.nid,
-      CVT.name as rel_type, CVTs.name as obj_type,
-      SR.value
-    FROM {stock_relationship} SR
-      INNER JOIN {stock} S on SR.object_id = S.stock_id
-      INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
-      INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
-      LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
-    WHERE SR.subject_id = :stock_id
-  ";
-  $as_subject = chado_query($sql, array(':stock_id' => $stock->stock_id));
-  $sql = "
-    SELECT
-      S.name, S.uniquename,  S.stock_id, CS.nid,
-      CVT.name as rel_type, CVTs.name as sub_type,
-      SR.value
-    FROM {stock_relationship} SR
-      INNER JOIN {stock} S on SR.subject_id = S.stock_id
-      INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
-      INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
-      LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
-    WHERE SR.object_id = :stock_id
-  ";
-  $as_object = chado_query($sql, array(':stock_id' => $stock->stock_id));
+  // expand the stock object to include the stock relationships.
+  $options = array(
+    'return_array' => 1,
+    'order_by' => array('rank' => 'ASC'),
+    // we don't want to fully recurse we only need information about the
+    // relationship type and the object and subject stocks (including stock type
+    // and organism)
+    'include_fk' => array(
+      'type_id' => 1,
+      'object_id' => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+      'subject_id'  => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+    ),
+  );
+  $stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_relationship', $options);
+
+  // get the subject relationships
+  $srelationships = $stock->stock_relationship->subject_id;
+  $orelationships = $stock->stock_relationship->object_id;
 
   // combine both object and subject relationshisp into a single array
   $relationships = array();
@@ -473,38 +469,56 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
   $relationships['subject'] = array();
 
   // iterate through the object relationships
-  while ($relationship = $as_object->fetchObject()) {
-
-     // get the relationship and child types
-     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
-     $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
-
-     if (!array_key_exists($rel_type, $relationships['object'])) {
-       $relationships['object'][$rel_type] = array();
-     }
-     if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
-       $relationships['object'][$rel_type][$sub_type] = array();
-     }
-     $relationships['object'][$rel_type][$sub_type][] = $relationship;
+  if ($orelationships) {
+    foreach ($orelationships as $relationship) {
+      $rel = new stdClass();
+      $rel->record = $relationship;
+       
+      // get the relationship and child types
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $child_type = $relationship->subject_id->type_id->name;
+       
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
+      $n = db_query($sql, array(':stock_id' => $relationship->subject_id->stock_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+
+      if (!array_key_exists($rel_type, $relationships['object'])) {
+        $relationships['object'][$rel_type] = array();
+      }
+      if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
+        $relationships['object'][$rel_type][$child_type] = array();
+      }
+      $relationships['object'][$rel_type][$child_type][] = $rel;
+    }
   }
 
   // now add in the subject relationships
-  while ($relationship = $as_subject->fetchObject()) {
-
-     // get the relationship and child types
-     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
-     $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
-
-     if (!array_key_exists($rel_type, $relationships['subject'])) {
-       $relationships['subject'][$rel_type] = array();
-     }
-     if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
-       $relationships['subject'][$rel_type][$obj_type] = array();
-     }
-     $relationships['subject'][$rel_type][$obj_type][] = $relationship;
+  if ($srelationships) {
+    foreach ($srelationships as $relationship) {
+      $rel = new stdClass();
+      $rel->record = $relationship;
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $parent_type = $relationship->object_id->type_id->name;
+       
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
+      $n = db_query($sql, array(':stock_id' => $relationship->object_id->stock_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+       
+      if (!array_key_exists($rel_type, $relationships['subject'])) {
+        $relationships['subject'][$rel_type] = array();
+      }
+      if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
+        $relationships['subject'][$rel_type][$parent_type] = array();
+      }
+      $relationships['subject'][$rel_type][$parent_type][] = $rel;
+    }
   }
-
-
   $stock->all_relationships = $relationships;
 
 }