Selaa lähdekoodia

Updated tripal_stock to use new tripal_core_generate_chado_var()

laceysanderson 14 vuotta sitten
vanhempi
commit
18b66ae346

+ 17 - 13
theme_tripal/tripal_stock/tripal_stock_base.tpl.php

@@ -24,37 +24,41 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
-<?php $organism = $node->organism->organism; ?>
+<?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">Stock Details</div>
   <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div>
 
-   <?php if($node->is_obsolete == 't'){ ?>
+   <?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 $node->stock_name; ?></td>
+        <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 $node->uniquename; ?></td>
+        <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($node->main_db_reference->dbxref_id)) { ?>
+        <?php if (!empty($main_db_reference->dbxref_id)) { ?>
         	<?php 
-        		if ($node->main_db_reference->db_urlprefix) {
-        			$accession = l($node->main_db_reference->accession, $node->main_db_reference->db_urlprefix.$node->main_db_reference->accession);
+        		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 = $node->main_db_reference->accession;
+        			$accession = $main_db_reference->accession;
         		}
-        		if ($node->main_db_reference->db_url) {
-        			$accession .= ' ('.l($node->main_db_reference->db_name, $node->main_db_reference->db_url).')';
+        		if ($main_db_reference->db_id->url) {
+        			$accession .= ' ('.l($main_db_reference->db_id->name, $main_db_reference->db_id->url).')';
         		} else {
-        			$accession .= ' ('.$node->main_db_reference->db_name.')';
+        			$accession .= ' ('.$main_db_reference->db_id->name.')';
         		}
         	?>
         	<td><?php print $accession; ?></td>
@@ -64,12 +68,12 @@
       </tr>
       <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
         <th>Type</th>
-        <td><?php print $node->stock_type; ?></td>
+        <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 ($node->organism->nid) { ?>
+          <?php if ($organism->nid) { ?>
       	   <a href="<?php print url("node/$organism->nid") ?>"><?php print $organism->genus ." " . $organism->species ." (" .$organism->common_name ." )"?></a>
       	 <?php 
           } else { 

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

@@ -28,22 +28,33 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
+<?php
+  $properties = $node->stock->stockprop;
+  if (!$properties) {
+    $properties = array();
+  } elseif (!is_array($properties)) { 
+    $properties = array($properties); 
+  }
+?>
+
 <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>
-	<?php if(count($node->properties) > 0){ ?>
+  <div class="tripal_stock-info-box-desc tripal-info-box-desc">Properties for the stock '<?php print $node->stock->name ?>' include:</div>
+	<?php if(count($properties) > 0){ ?>
   <table class="tripal_stock-table tripal-table tripal-table-horz">
   <tr><th>Type</th><th>Value</th></tr>
 	<?php	// iterate through each property
 		$i = 0;
-		foreach ($node->properties as $result){
+		foreach ($properties 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';
       }
-			print '<tr class="'.$class.'"><td>'.$result->type.'</td><td>'.$result->value.'</td></tr>';
+			print '<tr class="'.$class.'"><td>'.$result->type_id->name.'</td><td>'.$result->value.'</td></tr>';
 			$i++;
 		} ?>
 		</table>
-	<?php } ?>
+	<?php } else {
+	  print '<b>There are no properties for the current stock.</b>';
+	} ?>
 </div>

+ 20 - 8
theme_tripal/tripal_stock/tripal_stock_references.tpl.php

@@ -30,10 +30,19 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
+<?php
+  $db_references = $node->stock->stock_dbxref;
+  if (!$db_references) {
+    $db_references = array();
+  } elseif (!is_array($db_references)) {
+    $db_references = array($db_references);
+  }
+?>
+
 <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>
-  <?php if(count($node->db_references) > 0){ ?>
+  <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>
+  <?php if(count($db_references) > 0){ ?>
   <table class="tripal_stock-table tripal-table tripal-table-horz">
     <tr>
       <th>Dababase</th>
@@ -41,19 +50,20 @@
     </tr>
     <?php
     $i = 0; 
-    foreach ($node->db_references as $result){ 
+    foreach ($db_references as $result){ 
+      $dbxref = $result->dbxref_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 print $result->db_name?></td>
+        <td><?php print $dbxref->db_id->name?></td>
         <td><?php 
-           if($result->db_urlprefix){ 
-           	 print l($result->accession, $result->db_urlprefix.$result->accession);
+           if($dbxref->db_id->urlprefix){ 
+           	 print l($dbxref->accession, $dbxref->db_id->urlprefix.$dbxref->accession);
            } else { 
-             print $result->accession; 
+             print $dbxref->accession; 
            } 
            ?>
         </td>
@@ -62,5 +72,7 @@
       $i++;  
     } ?>
   </table>
-  <?php } ?>
+  <?php } else {
+    print '<b>There are no external database references for the current stock.</b>';
+  }?>
 </div>

+ 20 - 9
theme_tripal/tripal_stock/tripal_stock_relationships_as_object.tpl.php

@@ -31,10 +31,19 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
+<?php
+  $relationships = $node->stock->stock_object_relationships;
+  if (!$relationships) {
+    $relationships = array();
+  } elseif (!is_array($relationships)) { 
+    $relationships = array($relationships); 
+  }
+?>
+
 <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>
-  <?php if(count($node->object_relationships) > 0){ ?>
+  <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>
+  <?php if(count($relationships) > 0){ ?>
   <table class="tripal_stock-table tripal-table tripal-table-horz">
     <tr>
       <th>Current Stock (Subject)</th>
@@ -43,22 +52,24 @@
     </tr>
     <?php
     $i = 0; 
-    foreach ($node->object_relationships as $result){   
+    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 ?>">
-				<td><?php print $node->stock_name; ?></td>
-				<td><?php print $result->type; ?></td>
-				<?php $object = $result->object;
+				<td><?php print $node->stock->name; ?></td>
+				<td><?php print $result->type_id->name; ?></td>
+				<?php $object = $result->object_id;
 					if ($object->nid) {?>
-					<td><?php print l($object->stock_name.' ('.$object->uniquename.')', 'node/'.$object->nid); ?></td>
+					<td><?php print l($object->name.' ('.$object->uniquename.')', 'node/'.$object->nid); ?></td>
 				<?php } else { ?>
-					<td><?php print $object->stock_name.' ('.$object->uniquename.')'; ?></td>
+					<td><?php print $object->name.' ('.$object->uniquename.')'; ?></td>
 				<?php } ?>
       </tr>
     <?php } //end of foreach?>
   </table>
-  <?php } //end of if there are object relationships ?>
+  <?php } else {
+    print '<b>There are no relationships where the current stock is the subject</b>';
+  } //end of if there are object relationships ?>
 </div>

+ 20 - 9
theme_tripal/tripal_stock/tripal_stock_relationships_as_subject.tpl.php

@@ -31,10 +31,19 @@
  //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($node->subject_relationships) > 0){ ?>
+  <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>
@@ -43,22 +52,24 @@
     </tr>
     <?php
     $i = 0; 
-    foreach ($node->subject_relationships as $result){   
+    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;
+				<?php $subject = $result->subject_id;
 					if ($subject->nid) {?>
-					<td><?php print l($subject->stock_name.' ('.$subject->uniquename.')', 'node/'.$subject->nid); ?></td>
+					<td><?php print l($subject->name.' ('.$subject->uniquename.')', 'node/'.$subject->nid); ?></td>
 				<?php } else { ?>
-					<td><?php print $subject->stock_name.' ('.$subject->uniquename.')'; ?></td>
+					<td><?php print $subject->name.' ('.$subject->uniquename.')'; ?></td>
 				<?php } ?>
-				<td><?php print $result->type; ?></td>
-				<td><?php print $node->stock_name; ?></td>
+				<td><?php print $result->type_id->name; ?></td>
+				<td><?php print $node->stock->name; ?></td>
       </tr>
     <?php } //end of foreach?>
   </table>
-  <?php } //end of if there are subject relationships ?>
+  <?php } else {
+    print '<b>There are no relationships where the current stock is the object.</b>';
+  } //end of if there are subject relationships ?>
 </div>

+ 14 - 3
theme_tripal/tripal_stock/tripal_stock_synonyms.tpl.php

@@ -27,15 +27,26 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
+<?php
+  $synonyms = $node->stock->stock_synonyms;
+  if (!$synonyms) {
+    $synonyms = array();
+  } elseif (!is_array($synonyms)) { 
+    $synonyms = array($synonyms); 
+  }
+?>
+
 <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>
-	<?php if(count($node->synonyms) > 0){
+  <div class="tripal_stock-info-box-desc tripal-info-box-desc">Synonyms for the stock '<?php print $node->stock->name ?>' include:</div>
+	<?php if(count($synonyms) > 0){
 		print '<ul>';
 			// iterate through each synonym
-			foreach ($node->synonyms as $result){
+			foreach ($synonyms as $result){
 				print '<li>'.$result->value.'</li>';
 			}
 		print '</ul>';
+	} else {
+	  print '<b>There are no synonyms for the current stock.</b>';
 	} ?>
 </div>

+ 18 - 14
theme_tripal/tripal_stock/tripal_stock_teaser.tpl.php

@@ -24,39 +24,43 @@
  //print '<pre>'.print_r($node,TRUE).'</pre>';
 ?>
 
-<?php $organism = $node->organism->organism; ?>
+<?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); ?>
+    <?php print l($node->stock->name, 'node/'.$node->nid); ?>
   </div>
   <div class="tripal_stock-info-box-desc tripal-info-box-desc"></div>
   
-   <?php if($node->is_obsolete == 't'){ ?>
+   <?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 $node->stock_name; ?></td>
+        <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 $node->uniquename; ?></td>
+        <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($node->main_db_reference->dbxref_id)) { ?>
+        <?php if (!empty($main_db_reference->dbxref_id)) { ?>
         	<?php 
-        		if ($node->main_db_reference->db_urlprefix) {
-        			$accession = l($node->main_db_reference->accession, $node->main_db_reference->db_urlprefix.$node->main_db_reference->accession);
+        		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 = $node->main_db_reference->accession;
+        			$accession = $main_db_reference->accession;
         		}
-        		if ($node->main_db_reference->db_url) {
-        			$accession .= ' ('.l($node->main_db_reference->db_name, $node->main_db_reference->db_url).')';
+        		if ($main_db_reference->db_id->url) {
+        			$accession .= ' ('.l($main_db_reference->db_id->name, $main_db_reference->db_id->url).')';
         		} else {
-        			$accession .= ' ('.$node->main_db_reference->db_name.')';
+        			$accession .= ' ('.$main_db_reference->db_id->name.')';
         		}
         	?>
         	<td><?php print $accession; ?></td>
@@ -66,12 +70,12 @@
       </tr>
       <tr class="tripal_stock-table-odd-row tripal-table-odd-row">
         <th>Type</th>
-        <td><?php print $node->stock_type; ?></td>
+        <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 ($node->organism->nid) { ?>
+          <?php if ($organism->nid) { ?>
       	   <a href="<?php print url("node/$organism->nid") ?>"><?php print $organism->genus ." " . $organism->species ." (" .$organism->common_name ." )"?></a>
       	 <?php 
           } else { 

+ 5 - 1
tripal_core/tripal_core.api.inc

@@ -633,7 +633,11 @@ function tripal_core_generate_chado_var($table, $values) {
 
   // Expandable fields without value needed for criteria--------------------------------------------
   $all->expandable_fields = array();
-  $all->expandable_tables = $table_desc['referring_tables'];
+  if ($table_desc['referring_tables']) {
+    $all->expandable_tables = $table_desc['referring_tables'];
+  } else {
+    $all->expandable_tables = array();
+  }
   $all->expandable_nodes = array();
     
   // Get fields to be removed by name.................................

+ 20 - 9
tripal_stock/tripal_stock-db_references.inc

@@ -19,8 +19,8 @@ function tripal_stock_add_ALL_dbreferences_page($node) {
 
   $output .= tripal_stock_add_chado_properties_progress('db_references').'<br>';
   $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br>';
-  $output .= '<br><b>Current Database References</b><br>';
-  $output .= tripal_stock_list_dbreferences_for_node($node->db_references);
+  $output .= '<br>';
+  $output .= theme('tripal_stock_references', $node);
   $output .= '<br><br>';
   $output .= drupal_get_form('tripal_stock_add_ONE_dbreference_form', $node);
   $output .= '<br>';
@@ -44,7 +44,7 @@ function tripal_stock_add_ALL_dbreferences_page($node) {
  */
 function tripal_stock_add_ONE_dbreference_form($form_state, $node) {
 
-  $stock_id = $node->stock_id;
+  $stock_id = $node->stock->stock_id;
 
   $form['db_nid'] = array(
     '#type' => 'hidden',
@@ -225,17 +225,28 @@ function tripal_stock_edit_ALL_dbreferences_page($node) {
  *
  * @ingroup tripal_stock
  */                                        
-function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
+function tripal_stock_edit_ALL_db_references_form($form_state, &$node) {
   $form = array();
 
+  // Add database references to the node
+  $node->stock->stock_dbxref = tripal_core_generate_chado_var(
+    'stock_dbxref', 
+    array('stock_id'=>$node->stock->stock_id)
+  );
+
   $form['nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
 
   $i=0;
-  if (sizeof($node->db_references) != 0) {
-  foreach ($node->db_references as $ref) {
+  if (!$node->stock->stock_dbxref) { 
+    $node->stock->stock_dbxref = array(); 
+  } elseif (!is_array($node->stock->stock_dbxref)) { 
+    $node->stock->stock_dbxref = array($node->stock->stock_dbxref); 
+  }  
+  if (sizeof($node->stock->stock_dbxref) != 0) {
+  foreach ($node->stock->stock_dbxref as $ref) {
     $i++;
     $form["num-$i"] = array(
       '#type' => 'item',
@@ -247,7 +258,7 @@ function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
       //'#title' => t('Accession'),
       '#size' => 30,
       '#required' => TRUE,
-      '#default_value' => $ref->accession
+      '#default_value' => $ref->dbxref_id->accession
     );
 
     $db_options = tripal_db_get_db_options();
@@ -257,13 +268,13 @@ function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
       '#type' => 'select', 
       //'#title' => t('Database'),
       '#options' => $db_options, 
-      '#default_value' => $ref->db_id
+      '#default_value' => $ref->dbxref_id->db_id->db_id
     );
 
 
     $form["id-$i"] = array(
       '#type' => 'hidden',
-      '#value' => $ref->dbxref_id
+      '#value' => $ref->dbxref_id->dbxref_id
     );
 
     $form["submit-$i"] = array(

+ 18 - 25
tripal_stock/tripal_stock-properties.inc

@@ -10,8 +10,8 @@ function tripal_stock_add_ALL_property_page($node) {
 
   $output .= tripal_stock_add_chado_properties_progress('properties').'<br>';
   $output .= '<b>All Properties should strictly pertain to THE CURRENT Individual</b><br>';
-  $output .= '<br><b>Current Properties</b><br>';
-  $output .= tripal_stock_list_properties_for_node($node->properties, $node->synonyms);
+  $output .= '<br>';
+  $output .= theme('tripal_stock_properties', $node);
   $output .= '<br><br>';
   $output .= drupal_get_form('tripal_stock_add_ONE_property_form', $node);
   $output .= '<br>';
@@ -26,7 +26,7 @@ function tripal_stock_add_ALL_property_page($node) {
  */
 function tripal_stock_add_ONE_property_form($form_state, $node) {
   $form = array();
-  $stock_id = $node->stock_id;
+  $stock_id = $node->stock->stock_id;
 
   $form['add_properties'] = array(
     '#type' => 'fieldset',
@@ -184,25 +184,28 @@ function tripal_stock_edit_ALL_properties_page($node) {
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_edit_ALL_properties_form($form_state, $node) {
+function tripal_stock_edit_ALL_properties_form($form_state, &$node) {
   $form = array();
 
+  // Add properties and synonyms
+  $node->stock->stockprop = tripal_core_generate_chado_var(
+    'stockprop', 
+    array('stock_id'=>$node->stock->stock_id)
+  );
+
   $form['nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
 
   $i=0;
-  if (is_array($node->properties) && is_array($node->synonyms)) { 
-  	$all_properties = array_merge($node->properties, $node->synonyms);
-  } elseif (is_array($node->properties)) { 
-  	$all_properties = $node->properties; 
-  } elseif (is_array($node->synonyms)) { 
-  	$all_properties = $node->synonyms;
-  } else { $all_properties = array(); }
-
-  if (sizeof($all_properties) != 0) {
-  foreach ($all_properties as $property) {
+  if (!$node->stock->stockprop) { 
+    $node->stock->stockprop = array(); 
+  } elseif (!is_array($node->stock->stockprop)) { 
+    $node->stock->stockprop = array($node->stock->stockprop); 
+  }
+  if (sizeof($node->stock->stockprop) != 0) {
+  foreach ($node->stock->stockprop as $property) {
     $i++;
     $form["num-$i"] = array(
       '#type' => 'item',
@@ -216,14 +219,11 @@ function tripal_stock_edit_ALL_properties_form($form_state, $node) {
 
     $prop_type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
     ksort($prop_type_options);
- 
-    $default = array_search($property->type, $prop_type_options);
-
     $form["type-$i"] = array(
       '#type' => 'select',
       //'#title' => t('Type of Property'),
       '#options' => $prop_type_options,
-      '#default_value' => $default 
+      '#default_value' => $property->type_id->cvterm_id
     );
 
     $form["value-$i"] = array(
@@ -232,13 +232,6 @@ function tripal_stock_edit_ALL_properties_form($form_state, $node) {
       '#default_value' => $property->value
     );
 
-    if ($property->type == 'synonym') {
-      $form["preferred-$i"] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Preferred Synonym'),
-      );
-    }
-
     $form["submit-$i"] = array(
       '#type' => 'submit',
       '#value' => t("Delete #$i")

+ 47 - 22
tripal_stock/tripal_stock-relationships.inc

@@ -9,9 +9,11 @@ function tripal_stock_add_ALL_relationships_page($node) {
   $output = '';
 
   $output .= tripal_stock_add_chado_properties_progress('relationships').'<br>';
-  $output .= '<b>All Relationships should include the CURRENT Individual ('.$node->uniquename.')</b><br>';
-  $output .= '<br><b>Current Relationships</b><br>';
-  $output .= tripal_stock_list_relationships_for_node($node->uniquename, $node->subject_relationships, $node->object_relationships);
+  $output .= '<b>All Relationships should include the CURRENT Individual ('.$node->stock->uniquename.')</b><br>';
+  $output .= '<br>';
+  $output .= theme('tripal_stock_relationships_as_object', $node);
+  $output .= '<br>';
+  $output .= theme('tripal_stock_relationships_as_subject', $node);
   $output .= '<br><br>';
   $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
   $output .= '<br>';
@@ -26,8 +28,8 @@ function tripal_stock_add_ALL_relationships_page($node) {
  */
 function tripal_stock_add_ONE_relationship_form($form_state, $node) {
 
-  $stock_id = $node->stock_id;
-  $organism_id = $node->organism->organism_id;
+  $stock_id = $node->stock->stock_id;
+  $organism_id = $node->stock->organism_id->organism_id;
   $_SESSION['organism'] = $organism_id; //needed for autocomplete enter stock to work
 
   $form['rel_nid'] = array(
@@ -87,7 +89,7 @@ function tripal_stock_add_ONE_relationship_form($form_state, $node) {
 
   $form['add_relationships']['r_stock_uniquename'] = array( 
     '#type' => 'value',
-    '#value' => $node->uniquename,
+    '#value' => $node->stock->uniquename,
     '#required' => TRUE
   );
 
@@ -117,7 +119,7 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
     } elseif (sizeof($subject_results) < 1) {
       form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
     } elseif (sizeof($subject_results) == 1) {
-      $form_state['values']['subject_id'] = $subject_results[0]->stock_id;
+      $form_state['values']['subject_id'] = $subject_results[0]->stock->stock_id;
     }
 
     // check valid stock selected for object
@@ -133,7 +135,7 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
     } elseif (sizeof($object_results) < 1) {
       form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));                                                                         
     } elseif (sizeof($object_results) == 1) {
-      $form_state['values']['object_id'] = $object_results[0]->stock_id;
+      $form_state['values']['object_id'] = $object_results[0]->stock->stock_id;
     }
 
     // check valid type selected
@@ -164,7 +166,7 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
  * @ingroup tripal_stock
  */
 function tripal_stock_add_ONE_relationship_form_submit($form, &$form_state) {
-
+  
   if ($form_state['values']['subject_id'] > 0) {
     $previous_db = tripal_db_set_active('chado');
     db_query(
@@ -206,6 +208,28 @@ function tripal_stock_edit_ALL_relationships_page($node) {
 function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
   $form = array();
 
+  // Stock Object Relationships
+  $node->stock->stock_object_relationships = tripal_core_generate_chado_var(
+    'stock_relationship', 
+    array('subject_id'=>$node->stock->stock_id)
+  );    
+  if (!$node->stock->stock_object_relationships) { 
+    $node->stock->stock_object_relationships = array(); 
+  } elseif (!is_array($node->stock->stock_object_relationships)) { 
+    $node->stock->stock_object_relationships = array($node->stock->stock_object_relationships); 
+  }  
+  
+  // Stock Subject Relationships
+  $node->stock->stock_subject_relationships = tripal_core_generate_chado_var(
+    'stock_relationship', 
+    array('object_id'=>$node->stock->stock_id)
+  ); 
+  if (!$node->stock->stock_subject_relationships) { 
+    $node->stock->stock_subject_relationships = array(); 
+  } elseif (!is_array($node->stock->stock_subject_relationships)) { 
+    $node->stock->stock_subject_relationships = array($node->stock->stock_subject_relationships); 
+  }  
+    
   $form['nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
@@ -213,11 +237,12 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
   
   $form['r_stock_uniquename'] = array(
     '#type' => 'hidden',
-    '#value' => $node->uniquename
+    '#value' => $node->stock->uniquename
   );
 
   $i=0;
-  $relationships = array_merge($node->object_relationships, $node->subject_relationships);
+  $relationships = array_merge($node->stock->stock_object_relationships, $node->stock->stock_subject_relationships);
+  dpm($relationships, 'relationships');
   if (sizeof($relationships) != 0) {
   foreach ($relationships as $r) {
 
@@ -233,10 +258,10 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
     );
 
     //Enter relationship specific fields
-    if ( !empty($r->subject_id) ) { 
-      $default = $r->subject_uniquename;
-      $description = l($r->subject_name, 'node/'.$r->subject_nid); 
-    } else { $default = $node->uniquename; $description = 'Current Stock'; }
+    if ( $node->stock->stock_id != $r->subject_id->stock_id ) { 
+      $default = $r->subject_id->uniquename;
+      $description = l($r->subject_id->name, 'node/'.$r->subject_id->nid); 
+    } else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
     $form["subject_id-$i"] = array(
       '#type' => 'textfield',      
       //'#title' => t('Subject'), 
@@ -253,13 +278,13 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
       //'#title' => t('Type of Relationship'), 
       '#options' => $type_options,
       '#required' => TRUE,
-      '#default_value' => $r->relationship_type_id
+      '#default_value' => $r->type_id->cvterm_id
     );
 
-    if ( !empty($r->object_id) ) { 
-      $default = $r->object_uniquename;
-      $description = l($r->object_name, 'node/'.$r->object_nid);
-    } else { $default = $node->uniquename; $description = 'Current Stock'; }
+    if ( $node->stock->stock_id != $r->object_id->stock_id ) { 
+      $default = $r->object_id->uniquename;
+      $description = l($r->object_id->name, 'node/'.$r->object_id->nid);
+    } else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
     $form["object_id-$i"] = array(
       '#type' => 'textfield',          
       //'#title' => t('Object'),      
@@ -314,7 +339,7 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
       } elseif (sizeof($subject_results) < 1) { 
         form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
       } elseif (sizeof($subject_results) == 1) {
-        $form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
+        $form_state['values']["subject_id-$i"] = $subject_results[0]->stock->stock_id;
       } 
 
       // check valid stock selected for object
@@ -330,7 +355,7 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
       } elseif (sizeof($object_results) < 1) {
         form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
       } elseif (sizeof($object_results) == 1) {
-        $form_state['values']["object_id-$i"] = $object_results[0]->stock_id;
+        $form_state['values']["object_id-$i"] = $object_results[0]->stock->stock_id;
       } 
 
       // check valid type selected

+ 0 - 1
tripal_stock/tripal_stock.api.inc

@@ -79,7 +79,6 @@ function tripal_stock_load_properties($stock_id) {
     array('stock_id' => $stock_id)
   );
   
-  dpm($properties);
   return $properties;  
 }
 

+ 134 - 199
tripal_stock/tripal_stock.module

@@ -383,192 +383,17 @@ function tripal_stock_node_info() {
  */
 function chado_stock_load($node) {
 
-  // Gets the stock_id from the drupal chado_stock table---------------------------------------
+  // Get stock_id from chado_stock linking table
   $map = db_fetch_object(db_query(
     "SELECT stock_id as stock_id FROM {chado_stock} WHERE vid=%d",
     $node->vid
   ));
-  $node->stock_id = $map->stock_id;  
   
-  //Get the main stock information from the chado stock table-----------------------------------
-  $columns = array('name', 'uniquename', 'description', 'type_id', 'is_obsolete', 'organism_id', 'dbxref_id');
-  $values = array('stock_id' => $node->stock_id);
-  $results = tripal_core_chado_select('stock', $columns, $values);
+  // Get stock content and add to node
+  $stock = tripal_core_generate_chado_var('stock', array('stock_id'=>$map->stock_id));
+  $node->stock = $stock;
   
-  $node->stock_name = $results[0]->name;
-  $node->uniquename = $results[0]->uniquename;
-  $node->description = $results[0]->description;
-  $node->stock_type_id = $results[0]->type_id;
-  $node->organism->organism_id = $results[0]->organism_id;
-  $node->main_db_reference->dbxref_id = $results[0]->dbxref_id;
-  
-  if (preg_match('/t/', $results[0]->is_obsolete)) {
-    $node->is_obsolete = TRUE;
-  } else {
-    $node->is_obsolete = FALSE;
-  }
-
-  // Get type for current stock------------------------------------------------------------------
-  $columns = array('name');
-  $values = array('cvterm_id' => $node->stock_type_id);
-  $results = tripal_core_chado_select('cvterm', $columns, $values);
-  
-  $node->stock_type = $results[0]->name;
-  
-  // Get organism details from chado & add to node-----------------------------------------------
-  // get organism if for current stock
-  // pull all data from chado for the organism and assign it to the current node
-  $node->organism = tripal_organism_get_organism_by_organism_id($node->organism->organism_id);
-
-  // Add Synonyms for stock----------------------------------------------------------------------
-  // These are a special case of property (stockprop table) where cvterm='synonym'
-  $columns = array('stockprop_id', 'type_id', 'value', 'rank');
-  $values = array(
-    'stock_id' => $node->stock_id, 
-    'type_id' => array(
-      'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'), 
-      'name' => 'synonym'
-    ) 
-  );
-  $results = tripal_core_chado_select('stockprop', $columns, $values);
-  if (!empty($results)) {
-  	foreach ($results as $r) {
-    	$r->type = 'synonym';
-    	$node->synonyms[] = $r;
-  	}
-	}
-	
-  // Add properties for stock (not including synonyms)-------------------------------------------
-  // $node->properties is an array of objects where each object describes a single property and has a type and value
-  $columns = array('stockprop_id', 'type_id', 'value', 'rank');
-  $values = array(
-    'stock_id' => $node->stock_id, 
-  );
-  $results = tripal_core_chado_select('stockprop', $columns, $values);
-  foreach ($results as $r) {
-    $columns = array('name');
-    $values = array('cvterm_id' => $r->type_id);
-    $type_results = tripal_core_chado_select('cvterm', $columns, $values);
-    $r->type = $type_results[0]->name;
-    
-    $node->properties[] = $r;
-  }
-  
-  // Add in main db reference-----------------------------------------------------------------------
-  // this is the dbxref_id in the stock table
-  if (!empty($node->main_db_reference->dbxref_id)) {
-    $columns = array('dbxref_id', 'accession', 'version', 'description', 'db_id');
-    $values = array('dbxref_id' => $node->main_db_reference->dbxref_id);
-    $results = tripal_core_chado_select('dbxref', $columns, $values);
-    $node->main_db_reference = $results[0];
-    
-    //get db info
-    $columns = array('name', 'description', 'url', 'urlprefix');
-    $values = array('db_id' => $node->main_db_reference->db_id);
-    $results = tripal_core_chado_select('db', $columns, $values);
-    $node->main_db_reference->db_name = $results[0]->name;
-    $node->main_db_reference->db_description = $results[0]->description;
-    $node->main_db_reference->db_url = $results[0]->url;
-    $node->main_db_reference->db_urlprefix = $results[0]->urlprefix;
-  }
-
-  // Add in extra references to external databases--------------------------------------------------
-  // this includes all the dbxref entries in stock_dbxref
-  $columns = array('dbxref_id');
-  $values = array('stock_id' => $node->stock_id);
-  $results = tripal_core_chado_select('stock_dbxref',$columns,$values);
-  $node->db_references = array();
-  foreach ($results as $r) {
-    $columns = array('dbxref_id', 'accession', 'version', 'description', 'db_id');
-    $values = array('dbxref_id' => $r->dbxref_id);
-    $sub_results = tripal_core_chado_select('dbxref', $columns, $values);   
-    $dbxref = $sub_results[0];
-    
-    //get db info
-    $columns = array('name', 'description', 'url', 'urlprefix');
-    $values = array('db_id' => $dbxref->db_id);
-    $results = tripal_core_chado_select('db', $columns, $values);
-    $dbxref->db_name = $results[0]->name;
-    $dbxref->db_description = $results[0]->description;
-    $dbxref->db_url = $results[0]->url;
-    $dbxref->db_urlprefix = $results[0]->urlprefix;    
-    
-    $node->db_references[] = $dbxref;
-  }
-  
-  // Add relationships for stock--------------------------------------------------------------------
-  // Relationships are broken down into those where the current stock is the subject (other details stored in $node->object_relationships)
-  // and those where the current stock is the object (other details stored in $node->subject_relationships)
-  // fields available to each include object/subject_name, object/subject_id (stock_id in chado) and object/subject_nid (node id in drupal)
-  
-     // where current is subject.............................
-    $columns = array('stock_relationship_id', 'subject_id', 'type_id', 'object_id', 'value', 'rank');
-    $values = array('subject_id' => $node->stock_id);
-    $results = tripal_core_chado_select('stock_relationship', $columns, $values);
-    
-    $node->object_relationships = array();
-    foreach ($results as $r) {
-      $columns = array('name', 'uniquename', 'description', 'type_id', 'is_obsolete', 'organism_id', 'dbxref_id');
-
-      $values = array('stock_id' => $r->object_id);
-      $results = tripal_core_chado_select('stock', $columns, $values);
-
-			// Type
-			$type_results = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id' => $r->type_id));
-			$r->type = $type_results[0]->name;
-			
-			// Object
-      $r->object->stock_id = $r->object_id;
-      unset($r->object_id);
-      
-      $r->object->stock_name = $results[0]->name;
-      $r->object->uniquename = $results[0]->uniquename;
-      $r->object->description = $results[0]->description;
-      $r->object->stock_type_id = $results[0]->type_id;
-      $r->object->organism->organism_id = $results[0]->organism_id;
-      $r->object->main_db_reference->dbxref_id = $results[0]->dbxref_id;        
-
-      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id=%d";
-      $object_node = db_fetch_object(db_query($sql, $r->object->stock_id));
-      $r->object->nid = $object_node->nid;
-      
-      $node->object_relationships[] = $r;
-    }
-
-     // where current is object.............................
-    $columns = array('stock_relationship_id', 'subject_id', 'type_id', 'object_id', 'value', 'rank');
-    $values = array('object_id' => $node->stock_id);
-    $results = tripal_core_chado_select('stock_relationship', $columns, $values);
-
-    $node->subject_relationships = array();    
-    foreach ($results as $r) {
-      $columns = array('name', 'uniquename', 'description', 'type_id', 'is_obsolete', 'organism_id', 'dbxref_id');
-      $values = array('stock_id' => $r->subject_id);
-      $results = tripal_core_chado_select('stock', $columns, $values);
-
-			// Type
-			$type_results = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id' => $r->type_id));
-			$r->type = $type_results[0]->name;
-			
-			// Subject
-      $r->subject->stock_id = $r->subject_id;
-      unset($r->subject_id);  
-      
-      $r->subject->stock_name = $results[0]->name;
-      $r->subject->uniquename = $results[0]->uniquename;
-      $r->subject->description = $results[0]->description;
-      $r->subject->stock_type_id = $results[0]->type_id;
-      $r->subject->organism->organism_id = $results[0]->organism_id;        
-      $r->subject->main_db_reference->dbxref_id = $results[0]->dbxref_id;        
-
-      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id=%d";
-      $subject_node = db_fetch_object(db_query($sql, $r->subject->stock_id));
-      $r->subject->nid = $subject_node->nid;
-      
-      $node->subject_relationships[] = $r;
-    }
-
-     return $node;
+  return $node;
 }
 
 
@@ -611,7 +436,7 @@ function chado_stock_form($node, $form_state) {
     '#default_value' => TRUE
   );
 
-  if (!isset($node->uniquename)) {
+  if (!isset($node->stock->uniquename)) {
     $form['progress'] = array( 
       '#type' => 'item', 
       '#value' => tripal_stock_add_chado_properties_progress('main')
@@ -626,20 +451,20 @@ function chado_stock_form($node, $form_state) {
   $form['names']['title'] = array(
     '#type' => 'textfield',
     '#title' => t('Name'),
-    '#default_value' => $node->title,
+    '#default_value' => $node->stock->name,
     '#required'	     => TRUE
   );
 
   $form['names']['uniquename'] = array(
     '#type' => 'textfield',
     '#title' => t('Unique Name'),
-    '#default_value' => $node->uniquename,
+    '#default_value' => $node->stock->uniquename,
     '#required'	     => TRUE
   );
 
   $form['names']['stock_id'] = array(
     '#type' => 'hidden',
-    '#value' => $node->stock_id
+    '#value' => $node->stock->stock_id
   );
 
   $form['details'] = array(
@@ -649,7 +474,7 @@ function chado_stock_form($node, $form_state) {
 
   $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'null') );
   $type_options[0] = 'Select a Type';
-  if ($node->nid == '') { $type_default = 0; } else { $type_default = $node->stock_type_id; }
+  if ($node->nid == '') { $type_default = 0; } else { $type_default = $node->stock->type_id->cvterm_id; }
   $form['details']['type_id'] = array(
     '#type' => 'select',
     '#title' => t('Type of Stock'),
@@ -660,7 +485,7 @@ function chado_stock_form($node, $form_state) {
 
   $stock_oganism_options = tripal_organism_get_organism_options();
   $stock_oganism_options[0] = 'Select An Organism';
-  if ($node->nid == '') { $organism_default = 0; } else {  $organism_default = $node->organism->organism_id; }
+  if ($node->nid == '') { $organism_default = 0; } else {  $organism_default = $node->stock->organism_id->organism_id; }
   $form['details']['organism_id'] = array(
     '#type' => 'select',
     '#title' => t('Source Organism for stock'),
@@ -672,7 +497,7 @@ function chado_stock_form($node, $form_state) {
   $form['details']['stock_description'] = array(
     '#type' => 'textarea',
     '#title' => t('Notes'),
-    '#default_value' => $node->description,
+    '#default_value' => $node->stock->description,
     '#description' => t('Briefly enter any notes on the above stock. This should not include phenotypes or genotypes.'),
   );
 
@@ -684,19 +509,19 @@ function chado_stock_form($node, $form_state) {
   $form['database_reference']['accession'] = array(
     '#type' => 'textfield',
     '#title' => t('Accession'),
-    '#default_value' => $node->main_db_reference->accession
+    '#default_value' => $node->stock->dbxref_id->accession
   );
 
   $form['database_reference']['db_description'] = array(
     '#type' => 'textarea',
     '#title' => t('Description of Database Reference'),
-    '#default_value' => $node->main_db_reference->db_description,
+    '#default_value' => $node->stock->dbxref_id->description,
     '#description' => t('Optionally enter a description about the database accession.')
   );
 
   $db_options = tripal_db_get_db_options();
   $db_options[0] = 'Select a Database';
-  if ($node->nid == '') { $db_default = 0; } else { $db_default = $node->main_db_reference->db_id; }
+  if ($node->nid == '') { $db_default = 0; } else { $db_default = $node->stock->dbxref_id->db_id->db_id; }
   $form['database_reference']['database'] = array(
     '#type' => 'select',
     '#title' => t('Database'),
@@ -783,15 +608,6 @@ function chado_stock_validate($node, &$form) {
       form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
   }
 
-  // Check Accession is unique for database ( $form['values']['database_reference']['accession'] )
-  if ( $node->accession != '') {
-  	$previous_db = tripal_db_set_active('chado');
-    $num_rows = db_fetch_object(db_query($string_in_chado_sql, 'dbxref', 'accession', $node->accession));
-    tripal_db_set_active($previous_db);
-    if ($num_rows->count > 0) {
-      form_set_error('accession', 'This accession ('.$node->accession.') has already been assigned to another stock.'); }
-  }
-
 }
 
 /**
@@ -1122,4 +938,123 @@ 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']->stock->stockprop = tripal_core_generate_chado_var(
+      'stockprop', 
+      array('stock_id'=>$variables['node']->stock->stock_id)
+    );
+
+    // 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']->stock->stock_dbxref = tripal_core_generate_chado_var(
+      'stock_dbxref', 
+      array('stock_id'=>$variables['node']->stock->stock_id)
+    );
+
+    // 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']->stock->stockprop = tripal_core_generate_chado_var(
+      'stockprop', 
+      array('stock_id'=>$variables['node']->stock->stock_id)
+    );
+}
+
+/**
+ *  
+ *
+ * @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']->stock->stock_dbxref = tripal_core_generate_chado_var(
+      'stock_dbxref', 
+      array('stock_id'=>$variables['node']->stock->stock_id)
+    );
+}
+
+/**
+ *  
+ *
+ * @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)
+    ); 
 }