Переглянути джерело

Tripal: Moved chado_expand_vars out of template_preprocessor hooks and into .tpl file for easy manipulation (Stock Templates)

laceysanderson 13 роки тому
батько
коміт
b0f4ed46b4

+ 2 - 4
theme_tripal/node-chado_stock.tpl.php

@@ -145,11 +145,9 @@ drupal_add_css('./tripal-node-templates.css');
   <!-- Synonyms -->
   <?php include('tripal_stock/tripal_stock_synonyms.tpl.php'); ?>
 
-  <!-- Object Relationships -->
-  <?php include('tripal_stock/tripal_stock_relationships_as_object.tpl.php'); ?>
+  <!-- Relationships -->
+  <?php include('tripal_stock/tripal_stock_relationships.tpl.php'); ?>
 
-  <!-- Subject Relationships -->
-  <?php include('tripal_stock/tripal_stock_relationships_as_subject.tpl.php'); ?>
 </div>
 
 <!-- Table of contents -->

+ 6 - 5
theme_tripal/tripal_stock/tripal_stock_properties.tpl.php

@@ -24,11 +24,7 @@
 ?>
 
 <?php
- //uncomment this line to see a full listing of the fields avail. to $node
- //print '<pre>'.print_r($node,TRUE).'</pre>';
-?>
-
-<?php
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stockprop');
   $properties = $node->stock->stockprop;
   if (!$properties) {
     $properties = array();
@@ -37,6 +33,11 @@
   }
 ?>
 
+<?php
+ //uncomment this line to see a full listing of the fields avail. to $node
+ //print '<pre>'.print_r($node,TRUE).'</pre>';
+?>
+
 <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>

+ 6 - 5
theme_tripal/tripal_stock/tripal_stock_references.tpl.php

@@ -26,11 +26,7 @@
 ?>
 
 <?php
- //uncomment this line to see a full listing of the fields avail. to $node
- //print '<pre>'.print_r($node,TRUE).'</pre>';
-?>
-
-<?php
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_dbxref');
   $db_references = $node->stock->stock_dbxref;
   if (!$db_references) {
     $db_references = array();
@@ -39,6 +35,11 @@
   }
 ?>
 
+<?php
+ //uncomment this line to see a full listing of the fields avail. to $node
+ //print '<pre>'.print_r($node,TRUE).'</pre>';
+?>
+
 <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">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>

+ 66 - 5
theme_tripal/tripal_stock/tripal_stock_relationships_as_object.tpl.php → theme_tripal/tripal_stock/tripal_stock_relationships.tpl.php

@@ -27,12 +27,28 @@
 ?>
 
 <?php
+
+
+// expand the stock object to include the stock relationships.
+// since there two foreign keys (object_id and subject_id) in the 
+// stock_relationship table, we will access each one separately 
+$node = tripal_core_expand_chado_vars($node,
+   'table','stock_relationship', array('order_by'=>array('rank' => 'ASC')));
+
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($node,TRUE).'</pre>';
+ 
 ?>
 
+<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> 
+
 <?php
-  $relationships = $node->stock->stock_object_relationships;
+  /////////////////////////////////////////////////
+  // Subject Relationships
+  /////////////////////////////////////////////////
+  
+  $relationships = $node->stock->stock_relationship->subject_id;
   if (!$relationships) {
     $relationships = array();
   } elseif (!is_array($relationships)) { 
@@ -40,9 +56,8 @@
   }
 ?>
 
-<div id="tripal_stock-object_relationships-box" class="tripal_stock-info-box tripal-info-box">
-  <div class="tripal_stock-info-box-title tripal-info-box-title">Object Relationships</div>
-  <div class="tripal_stock-info-box-desc tripal-info-box-desc">The stock '<?php print $node->stock->name ?>' is the subject in the following relationships:</div>
+  <div class="tripal_stock-info-box-desc tripal-info-box-desc">Subject relationships</div> 
+  
   <?php if(count($relationships) > 0){ ?>
   <table class="tripal_stock-table tripal-table tripal-table-horz">
     <tr>
@@ -70,6 +85,52 @@
     <?php } //end of foreach?>
   </table>
   <?php } else {
-    print '<b>There are no relationships where the current stock is the subject</b>';
+    print '<div class="tripal-no-results">There are no relationships where the current stock is the subject</div>';
   } //end of if there are object relationships ?>
+
+
+<?php
+  /////////////////////////////////////////////////
+  // Object Relationships
+  /////////////////////////////////////////////////
+  
+  $relationships = $node->stock->stock_relationship->object_id;
+  if (!$relationships) {
+    $relationships = array();
+  } elseif (!is_array($relationships)) { 
+    $relationships = array($relationships); 
+  }
+?>
+
+  <br><br><div class="tripal_stock-info-box-desc tripal-info-box-desc">Object relationships</div>
+  
+  <?php if(count($relationships) > 0){ ?>
+  <table class="tripal_stock-table tripal-table tripal-table-horz">
+    <tr>
+      <th>Subject</th>
+      <th>Type</th>
+      <th>Current Stock (Object)</th>
+    </tr>
+    <?php
+    $i = 0; 
+    foreach ($relationships as $result){   
+      $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 ?>">
+				<?php $subject = $result->subject_id;
+					if ($subject->nid) {?>
+					<td><?php print l($subject->name.' ('.$subject->uniquename.')', 'node/'.$subject->nid); ?></td>
+				<?php } else { ?>
+					<td><?php print $subject->name.' ('.$subject->uniquename.')'; ?></td>
+				<?php } ?>
+				<td><?php print $result->type_id->name; ?></td>
+				<td><?php print $node->stock->name; ?></td>
+      </tr>
+    <?php } //end of foreach?>
+  </table>
+  <?php } else {
+    print '<div class="tripal-no-results">There are no relationships where the current stock is the object.</div>';
+  } //end of if there are subject relationships ?>
 </div>

+ 0 - 75
theme_tripal/tripal_stock/tripal_stock_relationships_as_subject.tpl.php

@@ -1,75 +0,0 @@
-<?php
-// Copyright 2010 University of Saskatchewan (Lacey-Anne Sanderson)
-//
-// Purpose: Provides layout and content for Stock Relationships where
-//   the current stock is the Object of the relationships. This includes all 
-//   fields in the stock_relationship table.
-//
-// Note: This template controls the layout/content for the default stock node
-//   template (node-chado_stock.tpl.php) and the Stock Subject Relationships 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.
-//   - $node->subject_relationships: an array of stock relaionship objects 
-//       where each object has the following fields: stock_relationship_id,
-//       subject, type_id, type, value, rank, object_id (current stock_id)
-//   - $node->subject_relationships->subject: a stock object describing the
-//       subject stock with the fields: stock_id, stock_name, uniquename, 
-//       description, stock_type_id, organism(object), man_db_reference(object),
-//       nid (if sync'd with Drupal)
-//   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
-?>
-
-<?php
- //uncomment this line to see a full listing of the fields avail. to $node
- //print '<pre>'.print_r($node,TRUE).'</pre>';
-?>
-
-<?php
-  $relationships = $node->stock->stock_subject_relationships;
-  if (!$relationships) {
-    $relationships = array();
-  } elseif (!is_array($relationships)) { 
-    $relationships = array($relationships); 
-  }
-?>
-
-<div id="tripal_stock-subject_relationships-box" class="tripal_stock-info-box tripal-info-box">
-  <div class="tripal_stock-info-box-title tripal-info-box-title">Subject Relationships</div>
-  <div class="tripal_stock-info-box-desc tripal-info-box-desc">The stock '<?php print $node->stock->name ?>' is the object in the following relationships:</div>
-  <?php if(count($relationships) > 0){ ?>
-  <table class="tripal_stock-table tripal-table tripal-table-horz">
-    <tr>
-      <th>Subject</th>
-      <th>Type</th>
-      <th>Current Stock (Object)</th>
-    </tr>
-    <?php
-    $i = 0; 
-    foreach ($relationships as $result){   
-      $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 ?>">
-				<?php $subject = $result->subject_id;
-					if ($subject->nid) {?>
-					<td><?php print l($subject->name.' ('.$subject->uniquename.')', 'node/'.$subject->nid); ?></td>
-				<?php } else { ?>
-					<td><?php print $subject->name.' ('.$subject->uniquename.')'; ?></td>
-				<?php } ?>
-				<td><?php print $result->type_id->name; ?></td>
-				<td><?php print $node->stock->name; ?></td>
-      </tr>
-    <?php } //end of foreach?>
-  </table>
-  <?php } else {
-    print '<b>There are no relationships where the current stock is the object.</b>';
-  } //end of if there are subject relationships ?>
-</div>

+ 15 - 5
theme_tripal/tripal_stock/tripal_stock_synonyms.tpl.php

@@ -23,11 +23,16 @@
 ?>
 
 <?php
- //uncomment this line to see a full listing of the fields avail. to $node
- //print '<pre>'.print_r($node,TRUE).'</pre>';
-?>
-
-<?php
+  $node->stock->stock_synonyms = tripal_core_generate_chado_var(
+    'stockprop', 
+    array(
+      'stock_id'=>$node->stock->stock_id,
+      'type_id' => array(
+        'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
+        'name' => 'synonym'
+      ),
+    )
+  );
   $synonyms = $node->stock->stock_synonyms;
   if (!$synonyms) {
     $synonyms = array();
@@ -36,6 +41,11 @@
   }
 ?>
 
+<?php
+ //uncomment this line to see a full listing of the fields avail. to $node
+ //print '<pre>'.print_r($node,TRUE).'</pre>';
+?>
+
 <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">Synonyms for the stock '<?php print $node->stock->name ?>' include:</div>

+ 0 - 107
tripal_stock/tripal_stock.module

@@ -957,111 +957,4 @@ function tripal_stock_block ($op = 'list', $delta = 0, $edit=array()) {
 				return $block;
 			}
 	}
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess(&$variables){
-
-  // if the template file is the default node template file then we want
-  // to add all of our variables.
-  if($variables['template_files'][0] == 'node-chado_stock'){
-    // stock properties
-    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stockprop');
-
-    // stock synonyms
-    $variables['node']->stock->stock_synonyms = tripal_core_generate_chado_var(
-      'stockprop', 
-      array(
-        'stock_id'=>$variables['node']->stock->stock_id,
-        'type_id' => array(
-          'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
-          'name' => 'synonym'
-        ),
-      )
-    );
-    
-    // Stock database references
-    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stock_dbxref');
-
-    // Stock Object Relationships
-    $variables['node']->stock->stock_object_relationships = tripal_core_generate_chado_var(
-      'stock_relationship', 
-      array('subject_id'=>$variables['node']->stock->stock_id)
-    );    
-
-    // Stock Subject Relationships
-    $variables['node']->stock->stock_subject_relationships = tripal_core_generate_chado_var(
-      'stock_relationship', 
-      array('object_id'=>$variables['node']->stock->stock_id)
-    );  
-  }
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_properties(&$variables){
-    // stock properties
-    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stockprop');
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_synonyms(&$variables){
-    // stock synonyms
-    $variables['node']->stock->stock_synonyms = tripal_core_generate_chado_var(
-      'stockprop', 
-      array(
-        'stock_id'=>$variables['node']->stock->stock_id,
-        'type_id' => array(
-          'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
-          'name' => 'synonym'
-        ),
-      )
-    );
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_references(&$variables){
-    // Stock database references
-    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stock_dbxref');
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_relationships_as_object(&$variables){
-    // Stock Object Relationships
-    $variables['node']->stock->stock_object_relationships = tripal_core_generate_chado_var(
-      'stock_relationship', 
-      array('subject_id'=>$variables['node']->stock->stock_id)
-    ); 
-}
-
-/**
- *  
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_relationships_as_subject(&$variables){
-    // Stock Subject Relationships
-    $variables['node']->stock->stock_subject_relationships = tripal_core_generate_chado_var(
-      'stock_relationship', 
-      array('object_id'=>$variables['node']->stock->stock_id)
-    ); 
 }