Browse Source

updated templates for ND and genetic modules

spficklin 12 years ago
parent
commit
e3b1a0cb49

+ 24 - 13
tripal_core/api/tripal_core.api.inc

@@ -2097,9 +2097,14 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
  *
  * @ingroup tripal_chado_api
  */
-function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_options = array()) {
-  $base_table = $object->tablename;
+function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_options = array()) {  
 
+  // make sure we have a value
+  if (!$object) {
+    watchdog('tripal_core', 'Cannot pass non array as $object.', array(),WATCHDOG_ERROR);
+    return $object;  
+  }
+  
   // check to see if we are expanding an array of objects
   if (is_array($object)) {
     foreach ($object as $index => $o) {
@@ -2107,6 +2112,10 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
     }
     return $object;
   }
+  
+  // get the base table name
+  $base_table = $object->tablename;
+  
   switch ($type) {
     case "field": //--------------------------------------------------------------------------------
       if (preg_match('/(\w+)\.(\w+)/', $to_expand, $matches)) {
@@ -2149,28 +2158,29 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
         return $object;
       }
       $foreign_table_desc = tripal_core_get_chado_table_schema($foreign_table);
-      // If it's connected to the base table
-      if ($foreign_table_desc['foreign keys'][$base_table]) {
+      
+      // If it's connected to the base table via a FK constraint
+      if ($foreign_table_desc['foreign keys'][$base_table]) {       
         foreach ($foreign_table_desc['foreign keys'][$base_table]['columns'] as $left => $right) {
+          // if the FK value in the base table is not there then we can't expand it, so just skip it.
           if (!$object->{$right}) {
             continue;
           }
-          if (is_array($values)) {
-            $values = array_merge($values, array($left => $object->{$right}) );
-          }
-          else {
-            $values = array($left => $object->{$right});
-          }
-          // if a prepared statement is provide then generate a new name
+
+          // generate a new object for this table using the FK values in the base table.
+          // if a prepared statement is provided generate a new statement_name so that
+          // we don't conflict when we recurse.
           $new_options = $table_options;
           if (array_key_exists('statement_name', $table_options)) {
              $new_options['statement_name'] = "exp_" . $foreign_table . "_" . substr($left, 0, 2) . substr($right, 0, 2);
           }
           $foreign_object = tripal_core_generate_chado_var($foreign_table, array($left => $object->{$right}), $new_options);
+          
+          // if the generation of the object was successful, update the base object to include it.
           if ($foreign_object) {
             // in the case where the foreign key relationships exists more
-            // than once with the same table we want to alter the
-            // array structure
+            // than once with the same table we want to alter the array structure. rather than
+            // add the object with a key of the table name, we will add the FK field name in between
             if (count($foreign_table_desc['foreign keys'][$base_table]['columns']) > 1) {
               if (!is_object($object->{$foreign_table})) {
                 $object->{$foreign_table} = new stdClass();
@@ -2194,6 +2204,7 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
           }
         }
       }
+      // if the foreign table is not connected to the base table through a FK constraint
       else {
         // We need to recurse -the table has a relationship to one of the nested objects
         $did_expansion = 0;

+ 0 - 40
tripal_genetic/api/tripal_genetic.api.inc

@@ -3,43 +3,3 @@
  * @file
  * @todo Add file header description
  */
-
-/**
- *
- */
-function tripal_genetic_get_genotypes_by_feature_id($feature_id) {
-
-  /**
-  $sql = 'SELECT nd_experiment_id FROM nd_experiment_genotype WHERE genotype_id IN (SELECT genotype_id FROM feature_genotype WHERE feature_id=%d)';
-  $resource = db_query($sql, $feature_id);
-
-  $values['nd_experiment_id'] = array();
-  while ($r = db_fetch_object($resource)) {
-    $values['nd_experiment_id'][] = $r->nd_experiment_id;
-  }
-
-  $object = tripal_core_generate_chado_var('nd_experiment',$values);
-  $object = tripal_core_expand_chado_vars($object, 'table', 'nd_experiment_genotype');
-  $object = tripal_core_expand_chado_vars($object, 'table', 'feature_genotype');
-  $object = tripal_core_expand_chado_vars($object, 'table', 'nd_experiment_stock');
-  */
-
-  $sql = 'SELECT genotype_id FROM {genotype} WHERE genotype_id IN (SELECT genotype_id FROM {feature_genotype} WHERE feature_id=%d)';
-  $resource = db_query($sql, $feature_id);
-
-  $values['genotype_id'] = array();
-  while ($r = db_fetch_object($resource)) {
-    $values['genotype_id'][] = $r->genotype_id;
-  }
-
-  if (!empty($values['genotype_id'])) {
-    $object = tripal_core_generate_chado_var('genotype', $values);
-  }
-  else {
-    $object = array();
-  }
-  return $object;
-}
-
-
-

+ 6 - 13
tripal_genetic/tripal_genetic.module

@@ -25,6 +25,9 @@ function tripal_genetic_views_api() {
   );
 }
 
+/*
+ * 
+ */
 function tripal_genetic_theme() {
   return array(
     'tripal_feature_genotypes' => array(
@@ -41,19 +44,9 @@ function tripal_genetic_nodeapi(&$node, $op, $teaser, $page) {
   switch ($op) {
     case 'view':
       if ($node->type == 'chado_feature') {
-        if (!isset($node->content['tripal_feature_genotypes'])) {
-          $node->content['tripal_feature_genotypes'] = array(
-             '#value' => theme('tripal_feature_genotypes', $node),
-          );
-        }
+        $node->content['tripal_feature_genotypes'] = array(
+          '#value' => theme('tripal_feature_genotypes', $node),
+        );
       }
   }
 }
-
-/**
- *
- */
-function tripal_genetic_preprocess_tripal_feature_genotypes(&$variables) {
-    $feature = $variables['node']->feature;
-    $variables['tripal_feature']['genotypes'] = tripal_genetic_get_genotypes_by_feature_id($feature->feature_id);
-}

+ 24 - 4
tripal_natural_diversity/tripal_natural_diversity.module

@@ -29,14 +29,22 @@ function tripal_natural_diversity_views_api() {
  */
 function tripal_natural_diversity_theme() {
   return array(
-    'tripal_feature_genotype_experiments' => array(
+    'tripal_feature_nd_genotypes' => array(
       'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature-genotype_experiments',
+      'template' => 'tripal_feature_nd_genotypes',
     ),
     'tripal_stock_nd_genotypes' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_nd_genotypes',
     ),
+    'tripal_stock_nd_phenotypes' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_stock_nd_phenotypes',
+    ),
+    'tripal_stock_nd_locations' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_stock_nd_locations',
+    ),
   );
 }
 
@@ -47,10 +55,22 @@ function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
   switch ($op) {
     case 'view':
       if ($node->type == 'chado_feature') {
-        $node->content['tripal_feature_genotype_experiments'] = array(
-           '#value' => theme('tripal_feature_genotype_experiments', $node),
+        $node->content['tripal_feature_nd_genotypes'] = array(
+           '#value' => theme('tripal_feature_nd_genotypes', $node),
+        );
+      }
+      if ($node->type == 'chado_stock') {
+        $node->content['tripal_stock_nd_genotypes'] = array(
+           '#value' => theme('tripal_stock_nd_genotypes', $node),
+        );
+        $node->content['tripal_stock_nd_phenotypes'] = array(
+           '#value' => theme('tripal_stock_nd_phenotypes', $node),
+        );
+        $node->content['tripal_stock_nd_locations'] = array(
+           '#value' => theme('tripal_stock_nd_locations', $node),
         );
       }
+      break;
   }
 }