Browse Source

Updated tripal_stock to use the new tripal_core_expand_chado_vars()

laceysanderson 14 years ago
parent
commit
7947ef30b2

+ 1 - 4
tripal_stock/tripal_stock-db_references.inc

@@ -229,10 +229,7 @@ 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)
-  );
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_dbxref');
 
   $form['nid'] = array(
     '#type' => 'hidden',

+ 1 - 4
tripal_stock/tripal_stock-properties.inc

@@ -188,10 +188,7 @@ 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)
-  );
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stockprop');
 
   $form['nid'] = array(
     '#type' => 'hidden',

+ 8 - 23
tripal_stock/tripal_stock-relationships.inc

@@ -208,27 +208,14 @@ 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); 
+  // All Stock Relationships
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_relationship');    
+  if (!$node->stock->stock_relationship) { 
+    $node->stock->stock_relationship = array(); 
+  } elseif (!is_array($node->stock->stock_relationship)) { 
+    $node->stock->stock_relationship = array($node->stock->stock_relationship); 
   }  
   
-  // 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',
@@ -241,10 +228,8 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
   );
 
   $i=0;
-  $relationships = array_merge($node->stock->stock_object_relationships, $node->stock->stock_subject_relationships);
-  dpm($relationships, 'relationships');
-  if (sizeof($relationships) != 0) {
-  foreach ($relationships as $r) {
+  if (sizeof($node->stock->stock_relationship) != 0) {
+  foreach ($node->stock->stock_relationship as $r) {
 
     $i++;
     $form["num-$i"] = array(

+ 22 - 16
tripal_stock/tripal_stock.module

@@ -391,6 +391,14 @@ function chado_stock_load($node) {
   
   // Get stock content and add to node
   $stock = tripal_core_generate_chado_var('stock', array('stock_id'=>$map->stock_id));
+  //
+  // move expandable fields downwards
+  $node->expandable_fields = $stock->expandable_fields;
+  unset($stock->expandable_fields);
+  $node->expandable_tables = $stock->expandable_tables;
+  unset($stock->expandable_tables);
+  $node->expandable_nodes = $stock->expandable_nodes;
+  unset($stock->expandable_nodes);
   $node->stock = $stock;
   
   return $node;
@@ -421,6 +429,15 @@ function chado_stock_load($node) {
 function chado_stock_form($node, $form_state) {
   $type = node_get_types('type', $node);
 
+  // Expand all fields needed
+  $fields_needed = array('stock.uniquename', 'stock.name', 'stock.stock_id', 'stock.type_id', 'stock.organism_id', 'stock.description', 'stock.dbxref_id', 'dbxref.accession', 'dbxref.description', 'dbxref.db_id', 'db.db_id');
+  foreach ($fields_needed as $field_name) {
+    // Check to see if it's excluded and expand it if so
+    if (in_array($field_name, $node->expandable_fields)) {
+      $node = tripal_core_expand_chado_vars($node, 'field', $field_name);
+    }    
+  }
+
   // This defines the path for the next step in a simulated multipart form
   // NOTE: The %node gets replaced with the nid in insert
   $form['next_step_path'] = array(
@@ -494,6 +511,7 @@ function chado_stock_form($node, $form_state) {
     '#required'	  => TRUE
   );
 
+
   $form['details']['stock_description'] = array(
     '#type' => 'textarea',
     '#title' => t('Notes'),
@@ -951,10 +969,7 @@ function tripal_stock_preprocess(&$variables){
   // 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)
-    );
+    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stockprop');
 
     // stock synonyms
     $variables['node']->stock->stock_synonyms = tripal_core_generate_chado_var(
@@ -969,10 +984,7 @@ function tripal_stock_preprocess(&$variables){
     );
     
     // Stock database references
-    $variables['node']->stock->stock_dbxref = tripal_core_generate_chado_var(
-      'stock_dbxref', 
-      array('stock_id'=>$variables['node']->stock->stock_id)
-    );
+    $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(
@@ -995,10 +1007,7 @@ function tripal_stock_preprocess(&$variables){
  */
 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)
-    );
+    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stockprop');
 }
 
 /**
@@ -1027,10 +1036,7 @@ function tripal_stock_preprocess_tripal_stock_synonyms(&$variables){
  */
 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)
-    );
+    $variables['node'] = tripal_core_expand_chado_vars($variables['node'], 'table', 'stock_dbxref');
 }
 
 /**