ソースを参照

Changed chado_get_id_for_node API call to accept nid as second parameter and fixed all calls in all modules. Organism module can now sync, edit, upload image for an organism

spficklin 11 年 前
コミット
9d7bf94295

+ 2 - 2
tripal_analysis/tripal_analysis.module

@@ -248,7 +248,7 @@ function chado_analysis_insert($node) {
  * @ingroup tripal_analysis
  */
 function chado_analysis_delete($node) {
-  $analysis_id = chado_get_id_for_node('analysis', $node);
+  $analysis_id = chado_get_id_for_node('analysis', $node->nid);
   
   // if we don't have an organism id for this node then this isn't a node of
   // type chado_organism or the entry in the chado_organism table was lost.
@@ -401,7 +401,7 @@ function chado_analysis_update($node) {
 function chado_analysis_load($node) {
 
    // get the feature details from chado
-  $analysis_id = chado_get_id_for_node('analysis', $node);
+  $analysis_id = chado_get_id_for_node('analysis', $node->nid);
 
   $values = array('analysis_id' => $analysis_id);
   $analysis = tripal_core_generate_chado_var('analysis', $values);

+ 4 - 4
tripal_contact/tripal_contact.module

@@ -325,7 +325,7 @@ function chado_contact_insert($node) {
     
     // make sure the entry for this contact doesn't already exist in the chado_contact table
     // if it doesn't exist then we want to add it.
-    $contact_id = chado_get_id_for_node('contact', $node) ;
+    $contact_id = chado_get_id_for_node('contact', $node->nid) ;
     if (!$contact_id) {
        // next add the item to the drupal table
       $sql = "INSERT INTO {chado_contact} (nid, vid, contact_id) ".
@@ -360,7 +360,7 @@ function chado_contact_update($node) {
     // this here just to make not we've addressed it.
   }
   
-  $contact_id = chado_get_id_for_node('contact', $node) ;
+  $contact_id = chado_get_id_for_node('contact', $node->nid) ;
   
   // check to see if this contact name doens't already exists.    
   $sql = "SELECT contact_id FROM {contact} WHERE NOT contact_id = %d AND name = '%s'";
@@ -464,7 +464,7 @@ function chado_contact_update($node) {
  */
 function chado_contact_load($node) {
   // get the feature details from chado
-  $contact_id = chado_get_id_for_node('contact', $node);
+  $contact_id = chado_get_id_for_node('contact', $node->nid);
 
   $values = array('contact_id' => $contact_id);
   $contact = tripal_core_generate_chado_var('contact', $values);
@@ -506,7 +506,7 @@ function chado_contact_load($node) {
  */
 function chado_contact_delete(&$node) {
 
-  $contact_id = chado_get_id_for_node('contact', $node);
+  $contact_id = chado_get_id_for_node('contact', $node->nid);
 
   // if we don't have a contact id for this node then this isn't a node of
   // type chado_contact or the entry in the chado_contact table was lost.

+ 32 - 69
tripal_core/api/tripal_core_chado.api.inc

@@ -779,22 +779,12 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   if (!array_key_exists('order_by', $options)) {
     $options['order_by'] = array();
   }
-/*  
-  if (!array_key_exists('is_prepared', $options)) {
-    $options['is_prepared'] = FALSE;
-  }
-*/  
   if (!array_key_exists('return_sql', $options)) {
     $options['return_sql'] = FALSE;
   }
   if (!array_key_exists('has_record', $options)) {
     $options['has_record'] = FALSE;
   }
-/*  
-  if (!array_key_exists('statement_name', $options)) {
-    $options['statement_name'] = FALSE;
-  }
-*/  
   if (!array_key_exists('is_duplicate', $options)) {
     $options['is_duplicate'] = FALSE;
   }
@@ -802,27 +792,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   if (array_key_exists('pager', $options)) {
     $pager = $options['pager'];
   }
-/*
-  // if this is a prepared statement check to see if it has already been prepared
-  $prepared = FALSE;
-  if ($options['statement_name']) {
-    $prepared = TRUE;
-    // we need to get a persistent connection.  If one exists this function
-    // will not recreate it, but if not it will create one and store it in
-    // a Drupal variable for reuse later.
-    $connection = tripal_db_persistent_chado();
 
-    // if we cannot get a connection the abandon the prepared statement
-    if (!$connection) {
-      $prepared = FALSE;
-      unset($options['statement_name']);
-    }
-  }
-  else {
-    //print "NO STATEMENT (select): $table\n";
-    //debug_print_backtrace();
-  }
-*/
   // check that our columns and values arguments are proper arrays
   if (!is_array($columns)) {
     watchdog('tripal_core', 'the $columns argument for tripal_core_chado_select must be an array.');
@@ -837,7 +807,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   $table_desc = tripal_core_get_chado_table_schema($table);
   $select = '';
   $from = '';
-  $where = '';
+  $where = array();
   $args = array();
 
   // if the 'use_unique' option is turned on then we want
@@ -947,20 +917,8 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
         // select the value from the foreign key relationship for this value
         $foreign_options = array(
           'regex_columns' => $options['regex_columns'],
-//          'case_insensitive_columns' => $options['case_insensitive_columns']
         );
-/*        
-        if (array_key_exists('statement_name', $options) and $options['statement_name']) {
-          // add the fk relationship info to the prepared statement name so that
-          // we can prepare the selects run by the recrusive tripal_core_chado_get_foreign_key
-          // function. we need the statement name to be unique so take the first two characters of each column
-          $fk_sname = "fk_" . $table . "_" . $field;
-          foreach ($value as $k => $v) {
-            $fk_sname .= substr($k, 0, 2);
-          }
-          $foreign_options['statement_name'] = $fk_sname;
-        }
-*/
+
         $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value, $foreign_options);
         if (!$results or count($results)==0) {
           return array();
@@ -985,6 +943,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     }
   }
 
+  
   // now build the SQL and prepared SQL statements. We may not use
   // the prepared statement if it wasn't requested in the options or if the
   // argument in a where statement has multiple values.
@@ -1003,8 +962,6 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     if (!empty($values)) {
       $sql .= "WHERE ";
     }
-    $i = 1;
-    $itypes = array();
     foreach ($where as $field => $value) {
 
       // if we have multiple values returned then we need an 'IN' statement
@@ -1024,7 +981,6 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
       elseif ($value === NULL) {
         $sql .= "$field IS NULL AND ";
         // Need to remove one from the argument count b/c nulls don't add an argument
-        $i--;
       }
       // if we have a single value then we need an = in our where statement
       else {
@@ -1041,7 +997,6 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
 	        $args[":$field"] = $value[0];        	
         }
       }
-      $i++;
     } // end foreach item in where clause
     $sql = drupal_substr($sql, 0, -4);  // get rid of the trailing 'AND '
   } // end if (empty($where)){ } else {
@@ -1060,7 +1015,6 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   if ($options['return_sql'] == TRUE) {
     return array('sql' => $sql, 'args' => $args);
   }
- 
   if (array_key_exists('limit', $pager)) {
     $resource = chado_pager_query($sql, $pager['limit'], $pager['element'], NULL, $args);
   }
@@ -1384,6 +1338,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
 */
   // get the values for the record in the current table---------------------------------------------
   $results = tripal_core_chado_select($table, $table_columns, $values, $base_options);
+  
   if ($results) {
     foreach ($results as $key => $object) {
       // Add empty expandable_x arrays
@@ -1402,8 +1357,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
           SELECT $table_primary_key, nid 
           FROM {chado_$table} 
           WHERE $table_primary_key = :$table_primary_key";
-        $results = db_query($sql, array(":$table_primary_key" . $object->{$table_primary_key}));
-        $mapping = $results->fetchObject();
+        $mapping = db_query($sql, array(":$table_primary_key" => $object->{$table_primary_key}))->fetchObject();
         if ($mapping->{$table_primary_key}) {
           $object->nid = $mapping->nid;
           $object->expandable_nodes[] = $table;
@@ -1483,15 +1437,20 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
       }
     }
   }
-
+  
+  // convert the results into an array
+  $results_arr = array(); 
+  foreach ($results as $record) {
+  	$results_arr[] = $record;
+  }
   // check only one result returned
   if (!$return_array) {
-    if (sizeof($results) == 1) {
+    if (sizeof($results_arr) == 1) {
       // add results to object
-      return $results[0];
+      return $results_arr[0];
     }
-    elseif (!empty($results)) {
-      return $results;
+    elseif (!empty($results_arr)) {
+      return $results_arr;
     }
     else {
       // no results returned
@@ -1500,11 +1459,11 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
   // the caller has requested results are always returned as
   // an array
   else {
-    if (!$results) {
+    if (!$results_arr) {
       return array();
     }
     else {
-      return $results;
+      return $results_arr;
     }
   }
 }
@@ -1964,18 +1923,22 @@ function chado_query($sql, $args = array()) {
 
 /**
  * Get chado id for a node. E.g, if you want to get 'analysis_id' from the
- * 'analysis' table for a synced 'chado_analysis' node, use:
- * $analysis_id = chado_get_id_for_node ('analysis', $node)
- * Likewise,
- * $organism_id = chado_get_id_for_node ('organism', $node)
- * $feature_id = chado_get_id_for_node ('feature', $node)
+ * 'analysis' table for a synced 'chado_analysis' node, (the same for
+ * organisms and features):
+ * $analysis_id = chado_get_id_for_node ('analysis', $node->nid)
+ * $organism_id = chado_get_id_for_node ('organism', $node->nid)
+ * $feature_id  = chado_get_id_for_node ('feature', $node->nid)
  *
+ * @param $table
+ * @param $nid
+ * 
  * @ingroup tripal_chado_api
  */
-function chado_get_id_for_node($table, $node) {
-	$sql = "SELECT " . $table . "_id FROM {chado_$table} WHERE nid = :nid";
-	$results = db_query($sql, array(':nid' => $node->nid));
-	return $results->fetchObject();
+function chado_get_id_for_node($table, $nid) {
+	$sql = "SELECT " . $table . "_id as id FROM {chado_$table} WHERE nid = :nid";
+	$result = db_query($sql, array(':nid' => $nid))->fetchObject();
+	
+	return $result->id;
 }
 
 /**
@@ -1990,8 +1953,8 @@ function chado_get_id_for_node($table, $node) {
  */
 function chado_get_node_id($table, $id) {
 	$sql = "SELECT nid FROM {chado_$table} WHERE " . $table . "_id = :" . $table . "_id";
-  $results = db_query($sql, array(":" . $table . "_id" => $id));
-  return $results->fetchObject();
+  $result = db_query($sql, array(":" . $table . "_id" => $id))->fetchObject();
+  return $results->nid;
 }
 
 /**

+ 23 - 2
tripal_core/api/tripal_core_files.api.inc

@@ -46,7 +46,7 @@ function tripal_file_directory_path() {
 function tripal_create_moddir($module_name) {
 
   // make the data directory for this module
-  $data_dir = tripal_file_directory_path() . "$module_name";
+  $data_dir = tripal_file_directory_path() . "/$module_name";
   if (!file_prepare_directory($data_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
     $message = "Cannot create directory $data_dir. This module may not " .
                "behave correctly without this directory.  Please  create " .
@@ -56,6 +56,27 @@ function tripal_create_moddir($module_name) {
   }
 }
 
+/**
+ * This function creates directories inside of the module's
+ * Data directory.
+ * 
+ * @param $module_name
+ * @param $path
+ */
+function tripal_create_mod_subdir($module_name, $path) {
+
+  // make sure the module data directory exists
+	tripal_create_moddir($module_name);
+  
+  // now make sure the sub dir exists
+  $sub_dir = tripal_file_directory_path() . $module_name . $path;
+  if (!file_prepare_directory($sub_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
+    $message = "Cannot create directory $sub_dir. ";
+    drupal_set_message(check_plain(t($message)), 'error');
+    watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
+  }
+}
+
 /**
  * Each Tripal module has a unique data directory which was creatd using the
  * tripal_create_moddir function during installation.  This function
@@ -70,6 +91,6 @@ function tripal_create_moddir($module_name) {
  * @ingroup tripal_files_api
  */
 function tripal_get_moddir($module_name) {
-  $data_dir = tripal_file_directory_path() . "$module_name";
+  $data_dir = tripal_file_directory_path() . "/$module_name";
   return $data_dir;
 }

+ 1 - 1
tripal_core/tripal_core.install

@@ -14,7 +14,7 @@ function tripal_core_install() {
 
   // make the data directory for this module
   $data_dir = tripal_file_directory_path();
-  if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY)) {
+  if (!file_prepare_directory($data_dir, FILE_CREATE_DIRECTORY)) {
     $message = "Cannot create directory $data_dir. This module may not " .
                "behave correctly without this directory.  Please  create " .
                "the directory manually or fix the problem and reinstall.";

+ 3 - 3
tripal_feature/tripal_feature.module

@@ -603,7 +603,7 @@ function chado_feature_update($node) {
   );
   $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
 
-  $feature_id = chado_get_id_for_node('feature', $node) ;
+  $feature_id = chado_get_id_for_node('feature', $node->nid) ;
 
   if (sizeof($type) > 0) {
     $match = array(
@@ -641,7 +641,7 @@ function chado_feature_update($node) {
  */
 function chado_feature_delete($node) {
 
-  $feature_id  = chado_get_id_for_node('feature', $node);
+  $feature_id  = chado_get_id_for_node('feature', $node->nid);
 
   // if we don't have a library id for this node then this isn't a node of
   // type chado_library or the entry in the chado_library table was lost.
@@ -1019,7 +1019,7 @@ function chado_feature_validate($node) {
 function chado_feature_load($node) {
 
   // get the feature details from chado
-  $feature_id = chado_get_id_for_node('feature', $node);
+  $feature_id = chado_get_id_for_node('feature', $node->nid);
 
   $values = array('feature_id' => $feature_id);
   $feature = tripal_core_generate_chado_var('feature', $values);

+ 4 - 4
tripal_featuremap/tripal_featuremap.module

@@ -420,7 +420,7 @@ function chado_featuremap_insert($node) {
   if ($featuremap) {
     // make sure the entry for this feature doesn't already exist in the chado_featuremap table
     // if it doesn't exist then we want to add it.
-    $featuremap_id = chado_get_id_for_node('featuremap', $node) ;
+    $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
     if (!$featuremap_id) {
        // next add the item to the drupal table
       $sql = "INSERT INTO {chado_featuremap} (nid, vid, featuremap_id) VALUES (%d, %d, %d)";
@@ -442,7 +442,7 @@ function chado_featuremap_update($node) {
     // there is no way to handle revisions in Chado but leave
     // this here just to make not we've addressed it.
   }
-  $featuremap_id = chado_get_id_for_node('featuremap', $node) ;
+  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
 
   // update the map record
   $match = array(
@@ -551,7 +551,7 @@ function chado_featuremap_update($node) {
  */
 function chado_featuremap_load($node) {
   // get the feature details from chado
-  $featuremap_id = chado_get_id_for_node('featuremap', $node);
+  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
 
   $values = array('featuremap_id' => $featuremap_id);
   $featuremap = tripal_core_generate_chado_var('featuremap', $values);
@@ -585,7 +585,7 @@ function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
  */
 function chado_featuremap_delete(&$node) {
 
-  $featuremap_id = chado_get_id_for_node('featuremap', $node);
+  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
 
   // if we don't have a map id for this node then this isn't a node of
   // type chado_featuremap or the entry in the chado_featuremap table was lost.

+ 4 - 4
tripal_library/tripal_library.module

@@ -566,7 +566,7 @@ function chado_library_insert($node) {
 
     // make sure the entry for this feature doesn't already exist in the chado_library table
     // if it doesn't exist then we want to add it.
-    $library_id = chado_get_id_for_node('library', $node) ;
+    $library_id = chado_get_id_for_node('library', $node->nid) ;
     if (!$library_id) {
        // next add the item to the drupal table
       $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
@@ -594,7 +594,7 @@ function chado_library_update($node) {
     // this here just to make not we've addressed it.
   }
 
-  $library_id = chado_get_id_for_node('library', $node) ;
+  $library_id = chado_get_id_for_node('library', $node->nid ;
   // update the library record
   $match = array(
      'library_id' => $library_id,
@@ -618,7 +618,7 @@ function chado_library_update($node) {
  */
 function chado_library_load($node) {
   // get the feature details from chado
-  $library_id = chado_get_id_for_node('library', $node);
+  $library_id = chado_get_id_for_node('library', $node->nid);
 
   $values = array('library_id' => $library_id);
   $library = tripal_core_generate_chado_var('library', $values);
@@ -660,7 +660,7 @@ function chado_library_view($node, $teaser = FALSE, $page = FALSE) {
  */
 function chado_library_delete(&$node) {
 
-  $library_id = chado_get_id_for_node('library', $node);
+  $library_id = chado_get_id_for_node('library', $node->nid);
 
   // if we don't have a library id for this node then this isn't a node of
   // type chado_library or the entry in the chado_library table was lost.

+ 35 - 6
tripal_organism/api/tripal_organism.api.inc

@@ -30,8 +30,8 @@ function tripal_organism_get_organism_by_nid($nid) {
  */
 function tripal_organism_get_organism_by_organism_id($organism_id) {
 
-  $sql = "SELECT nid FROM {chado_organism} WHERE organism_id=%d";
-  $r = db_fetch_object(db_query($sql, $organism_id));
+  $sql = "SELECT nid FROM {chado_organism} WHERE organism_id = :organism_id";
+  $r = db_query($sql, array(':organism_id' => $organism_id))->fetchObject();
   if (!empty($r->nid)) {
     return node_load($r->nid);
   }
@@ -55,14 +55,43 @@ function tripal_organism_get_synced() {
 
   // use this SQL statement for getting the organisms
   $csql =  "SELECT * FROM {Organism} ".
-          "WHERE organism_id = %d";
+           "WHERE organism_id = :organism_id";
 
   $org_list = array();
 
   // iterate through the organisms and build an array of those that are synced
-  while ($org = db_fetch_object($orgs)) {
-    $info = db_fetch_object(chado_query($csql, $org->organism_id));
-    $org_list[] = $info;
+  foreach ($orgs as $org) {
+  	$args = array(':organism_id' => $org->organism_id);
+    $org = chado_query($csql, $args)->fetchObject();
+    $org_list[] = $org;
   }
   return $org_list;
 }
+
+/**
+ * 
+ * @param $organism
+ * @param $nid
+ */
+function tripal_organism_get_image_url($organism, $nid = NULL) {
+	$url = '';
+	
+	// first look for an image with the genus/species name.  This is old-style tripal
+  // and we keep it for backwards compatibility.  If we don't find that file
+  // then look for the image with the node ID in the name. If we don't find that then
+  // no image tag is generated  
+  $base_path = realpath('.');
+  $image_dir = tripal_get_moddir('tripal_organism') . "/images";
+  $image_name =  $organism->genus . "_" . $organism->species . ".jpg";
+
+  if (file_exists("$base_path/$image_dir/$image_name")) { 
+    $url = file_create_url("$image_dir/$image_name"); 
+  } 
+  else {
+     $image_name = $nid . ".jpg";
+     if (file_exists("$base_path/$image_dir/$image_name")) { 
+       $url = file_create_url("$image_dir/$image_name"); 
+     }  
+  } 
+  return $url;
+}

+ 36 - 31
tripal_organism/includes/tripal_organism.admin.inc

@@ -78,7 +78,7 @@ function get_tripal_organism_admin_form_taxonomy_set(&$form) {
 
   // iterate through all of the libraries
   $org_boxes = array();
-  while ($organism = db_fetch_object($org_rset)) {
+  foreach ($org_rset as $organism) {
     $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
   }
 
@@ -123,7 +123,7 @@ function get_tripal_organism_admin_form_reindex_set(&$form) {
 
   // iterate through all of the libraries
   $org_boxes = array();
-  while ($organism = db_fetch_object($org_rset)) {
+  foreach ($org_rset as $organism) {
     $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
   }
   $form['reindex']['description'] = array(
@@ -179,11 +179,11 @@ function get_tripal_organism_admin_form_sync_set(&$form) {
     // a message stating that all organisms are currently synced.
     $org_boxes = array();
     $added = 0;
-    while ($organism = db_fetch_object($org_rset)) {
+    foreach ($org_rset as $organism) {
       // check to see if the organism is already present as a node in drupal.
       // if so, then skip it.
-      $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d";
-      if (!db_fetch_object(db_query($sql, $organism->organism_id))) {
+      $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
+      if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
         $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
         $added++;
       }
@@ -244,8 +244,8 @@ function tripal_organism_admin_validate($form, &$form_state) {
       }
       if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
         // get the list of organisms
-        $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
-        $organism = db_fetch_object(chado_query($sql, $organism_id));
+        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
         $to_sync[$organism_id] = "$organism->genus $organism->species";
       }
     }
@@ -271,8 +271,8 @@ function tripal_organism_admin_validate($form, &$form_state) {
     foreach ($organisms as $organism_id) {
       if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
         // get the organism info
-        $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-        $organism = db_fetch_object(chado_query($sql , $organism_id));
+        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
         $job_args[0] = $organism_id;
         tripal_add_job("Reindex features for organism: $organism->genus ".
          "$organism->species", 'tripal_organism' ,
@@ -288,8 +288,8 @@ function tripal_organism_admin_validate($form, &$form_state) {
     foreach ($organisms as $organism_id) {
       if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
         // get the organism info
-        $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-        $organism = db_fetch_object(chado_query($sql , $organism_id));
+        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
         $job_args[0] = $organism_id;
         tripal_add_job("Set taxonomy for features in organism: ".
           "$organism->genus $organism->species" , 'tripal_organism',
@@ -320,20 +320,20 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
     $results = chado_query($sql);
   }
   else {
-    $sql = "SELECT * FROM {organism} L WHERE organism_id = %d";
-    $results = chado_query($sql, $organism_id);
+    $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+    $results = chado_query($sql, array(':organism_id' => $organism_id));
   }
 
   // We'll use the following SQL statement for checking if the organism
   // already exists as a drupal node.
   $sql = "SELECT * FROM {chado_organism} ".
-         "WHERE organism_id = %d";
+         "WHERE organism_id = :organism_id";
 
-  while ($organism = db_fetch_object($results)) {
+  foreach ($results as $organism) {
 
     // check if this organism already exists in the drupal database. if it
     // does then skip this organism and go to the next one.
-    if (!db_fetch_object(db_query($sql, $organism->organism_id))) {
+    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
 
       $new_node = new stdClass();
       $new_node->type = 'chado_organism';
@@ -343,7 +343,9 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
       $new_node->genus = $organism->genus;
       $new_node->species = $organism->species;
       $new_node->description = '';
-      node_validate($new_node);
+      $form = array(); // dummy variable
+      $form_state = array(); // dummy variable
+      node_validate($new_node, $form, $form_state);
       if (!form_get_errors()) {
         $node = node_submit($new_node);
         node_save($node);
@@ -372,16 +374,17 @@ function tripal_organism_reindex_features($organism_id = NULL, $job_id = NULL) {
     return;
   }
 
-  $sql = "SELECT * ".
-        "FROM {feature} ".
-        "WHERE organism_id = $organism_id ".
-        "ORDER BY feature_id";
-  $results = chado_query($sql);
+  $sql = "
+    SELECT * 
+    FROM {feature} 
+    WHERE organism_id = :organism_id 
+    ORDER BY feature_id";
+  $results = chado_query($sql, array(':organism_id' => $organism_id));
 
   // load into ids array
   $count = 0;
   $ids = array();
-  while ($id = db_fetch_object($results)) {
+  foreach ($results as $id) {
     $ids[$count] = $id->feature_id;
     $count++;
   }
@@ -407,16 +410,18 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
     return;
   }
 
-  $sql = "SELECT * ".
-        "FROM {feature} ".
-        "WHERE organism_id = $organism_id ".
-        "ORDER BY feature_id";
-  $results = chado_query($sql);
+  $sql = "
+    SELECT * 
+    FROM {feature} 
+    WHERE organism_id = :organism_id 
+    ORDER BY feature_id
+  ";
+  $results = chado_query($sql, array(':organism_id' => $organism_id));
 
   // load into ids array
   $count = 0;
   $ids = array();
-  while ($id = db_fetch_object($results)) {
+  foreach ($results as $id) {
     $ids[$count] = $id->feature_id;
     $count++;
   }
@@ -427,7 +432,7 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
   // use this SQL for getting the nodes
   $nsql =  "SELECT * FROM {chado_feature} CF ".
           "  INNER JOIN {node} N ON N.nid = CF.nid ".
-          "WHERE feature_id = %d";
+          "WHERE feature_id = :feature_id";
 
   // iterate through the features and set the taxonomy
   $interval = intval($count * 0.01);
@@ -436,7 +441,7 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
     if ($job_id and $i % $interval == 0) {
       tripal_job_set_progress($job_id, intval(($i/$count)*100));
     }
-    $node = db_fetch_object(db_query($nsql, $feature_id));
+    $node = db_query($nsql, array(':feature_id' => $feature_id))->fetchObject();
     tripal_feature_set_taxonomy($node, $feature_id);
     $i++;
   }

+ 2 - 2
tripal_organism/tripal_organism.info

@@ -1,9 +1,9 @@
 name = Tripal Organism
 description = A module for interfacing the GMOD chado database with Drupal, providing viewing, inserting and editing of organisms.
-core = 6.x
+core = 7.x
 project = tripal_organism
 package = Tripal
-version = 6.x-1.1
+version = 7.x-2.0
 dependencies[] = tripal_core
 dependencies[] = search
 dependencies[] = path

+ 22 - 54
tripal_organism/tripal_organism.install

@@ -16,17 +16,7 @@ function tripal_organism_install() {
   tripal_create_moddir('tripal_organism');
 
   // create the directory where image files will be stored.  We create this
-  // here otherwise it will get created when the first organism is synced.
-  // The user that performs the syncing will receive ownership of the
-  // images directory which may not allow for write access by the web server
-  // user.  So, we create it here
-  $dest = tripal_file_directory_path() . "/tripal_organism/images";
-  file_check_directory($dest, FILE_CREATE_DIRECTORY);
-
-  // create the tables that correlate drupal nodes with chado
-  // features, organisms, etc....
-  drupal_install_schema('tripal_organism');
-
+  tripal_create_mod_subdir('tripal_organism', '/images');
 }
 
 /**
@@ -35,48 +25,7 @@ function tripal_organism_install() {
  * @ingroup tripal_organism
  */
 function tripal_organism_schema() {
-  $schema = tripal_organism_get_schemas();
-  return $schema;
-}
-
-/**
- * Implementation of hook_uninstall().
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_uninstall() {
-  drupal_uninstall_schema('tripal_organism');
-
-  // Get the list of nodes to remove
-  $sql_lib_id = "SELECT nid, vid ".
-               "FROM {node} ".
-               "WHERE type='chado_organism'";
-  $result = db_query($sql_lib_id);
-  while ($node = db_fetch_object($result)) {
-    node_delete($node->nid);
-  }
-
-  // remove the materialized views
-
-  // Remove the custom view if exists
-  if (db_table_exists('tripal_organism_views_common_name')) {
-    $sql = "DROP TABLE {tripal_organism_views_common_name}";
-    db_query($sql);
-  }
-}
-
-/**
- * This function simply defines all tables needed for the module to work
- * correctly.  By putting the table definitions in a separate function we
- * can easily provide the entire list for hook_install or individual
- * tables for an update.
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_get_schemas() {
-  $schema = array();
-
-  $schema['chado_organism'] = array(
+ $schema['chado_organism'] = array(
       'fields' => array(
          'vid' => array(
             'type' => 'int',
@@ -105,7 +54,26 @@ function tripal_organism_get_schemas() {
       ),
       'primary key' => array('nid'),
   );
-  return $schema;
+  return $schema;  
+}
+
+/**
+ * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_uninstall() {
+
+  // Get the list of nodes to remove
+  $sql_lib_id = "
+    SELECT nid, vid 
+    FROM {node} 
+    WHERE type='chado_organism'
+  ";
+  $result = db_query($sql_lib_id);
+  foreach ($result as $node) {
+    node_delete($node->nid);
+  }
 }
 
 /**

+ 105 - 191
tripal_organism/tripal_organism.module

@@ -29,12 +29,10 @@ function tripal_organism_node_info() {
   $nodes = array();
   $nodes['chado_organism'] = array(
     'name' => t('Organism'),
-    'module' => 'chado_organism',
-    'description' => t('An organism from the chado database'),
+    'base' => 'chado_organism',
+    'description' => t('An organism'),
     'has_title' => FALSE,
     'title_label' => t('Organism'),
-    'has_body' => FALSE,
-    'body_label' => t('Organism Description'),
     'locked' => TRUE
   );
   return $nodes;
@@ -188,53 +186,54 @@ function chado_organism_access($op, $node, $account) {
   *
   @ingroup tripal_organism
   */
-function tripal_organism_perm() {
+function tripal_organism_permission() {
   return array(
-    'access chado_organism content',
-    'create chado_organism content',
-    'delete chado_organism content',
-    'edit chado_organism content',
-    'adminster tripal organism',
+    'access chado_organism content' => array(
+      'title' => t('View Organisms'),
+      'description' => t('Allow users to view organism pages.'),
+    ),
+    'create chado_organism content'=> array(
+      'title' => t('Create Organisms'),
+      'description' => t('Allow users to create new organism pages.'),
+    ),
+    'delete chado_organism content'=> array(
+      'title' => t('Delete Organisms'),
+      'description' => t('Allow users to delete organism pages.'),
+    ),
+    'edit chado_organism content'=> array(
+      'title' => t('Edit Organisms'),
+      'description' => t('Allow users to edit organism pages.'),
+    ),
+    'adminster tripal organism'=> array(
+      'title' => t('Administer Organisms'),
+      'description' => t('Allow users to administer all organisms.'),
+    ),
   );
 }
 
-
-/**
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_nodeapi(&$node, $op, $teaser, $page) {
-
-  switch ($op) {
-    case 'view':
-      switch ($node->type) {
-
-      }
-  }
-}
-/**
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_cron() {
-   // we want to make sure that any new organisms or features that were
-   // added to the database external to drupal automatically get new
-   // nodes created for themselves in drupal.
-//   tripal_organism_sync_organisms();
-}
-
 /**
- *
- * @ingroup tripal_organism
+ * Implementation of hook_validate 
+ * 
+ * @param $node
+ * @param $form
+ * @param $form_state
+ * 
+ *  @ingroup tripal_organism
  */
-function chado_organism_validate($node, &$form) {
+function chado_organism_validate($node, $form, &$form_state) {
   // if this is an update, we want to make sure that a different organism doesn't
   // already have this genus and speces
   if ($node->organism_id) {
-    $sql = "SELECT *
-          FROM {organism} O
-          WHERE genus = '%s' and species = '%s' AND NOT organism_id = %d";
-    $result = db_fetch_object(chado_query($sql, $node->genus, $node->species, $node->organism_id));
+    $sql = "
+      SELECT *
+      FROM {organism} O
+      WHERE 
+        genus = :genus AND 
+        species = :species AND NOT 
+        organism_id = :organism_id
+    ";
+    $args = array(':genus' => $node->genus, ':species' => $node->species, ':organism_id' => $node->organism_id);
+    $result = chado_query($sql, $args)->fetchObject();
     if ($result) {
       form_set_error('genus', t("Update cannot proceed. The organism genus
         '$node->genus' and species '$node->species' is already present in the database."));
@@ -271,11 +270,11 @@ function chado_organism_validate($node, &$form) {
 function chado_organism_insert($node) {
 
   $values = array(
-    'genus' => $node->genus,
-    'species' => $node->species,
+    'genus'        => $node->genus,
+    'species'      => $node->species,
     'abbreviation' => $node->abbreviation,
-    'common_name' => $node->common_name,
-    'comment' => $node->description
+    'common_name'  => $node->common_name,
+    'comment'      => $node->description
   );
   // if there is an organism_id in the $node object then this must be a sync so
   // we can skip adding the organism as it is already there, although
@@ -297,11 +296,12 @@ function chado_organism_insert($node) {
   // Make sure the entry for this organism doesn't already exist in the
   // chado_organism table if it doesn't exist then we want to add it.
 
-  if (!chado_get_id_for_node('organism', $node) ) {
+  if (!chado_get_id_for_node('organism', $node->nid) ) {
     // next add the item to the drupal table
     $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ".
-           "VALUES (%d, %d, %d)";
-    db_query($sql, $node->nid, $node->vid, $organism_id);
+           "VALUES (:nid, :vid, :organism_id)";
+    $args = array(':nid' => $node->nid, ':vid' => $node->vid, ':organism_id' => $organism_id);
+    db_query($sql, $args);
   }
 
   // set the title for the node
@@ -325,7 +325,7 @@ function chado_organism_update($node) {
     // this here just to make not we've addressed it.
   }
   $match = array(
-    'organism_id' => chado_get_id_for_node('organism', $node),
+    'organism_id' => chado_get_id_for_node('organism', $node->nid),
   );
   $values = array(
     'genus' => $node->genus,
@@ -353,7 +353,7 @@ function chado_organism_update($node) {
  * @ingroup tripal_organism
  */
 function chado_organism_delete($node) {
-  $organism_id = chado_get_id_for_node('organism', $node);
+  $organism_id = chado_get_id_for_node('organism', $node->nid);
 
   // if we don't have an organism id for this node then this isn't a node of
   // type chado_organism or the entry in the chado_organism table was lost.
@@ -363,27 +363,27 @@ function chado_organism_delete($node) {
 
   // Remove data from the {chado_organism}, {node}, and {node_revisions} tables
   $sql_del = "DELETE FROM {chado_organism} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
+             "WHERE nid = :nid ".
+             "AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
   $sql_del = "DELETE FROM {node} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
+             "WHERE nid = :nid ".
+             "AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
   $sql_del = "DELETE FROM {node_revisions} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
+             "WHERE nid = ':nid' ".
+             "AND vid = ':vid'";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 
   // Test dependency before deleting from chado database. If a library or
   // feature depends on this organism, don't delete it
 
-  $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d";
-  $check_feature = db_result(chado_query($sql, $organism_id));
-  $sql = "SELECT library_id FROM {library} WHERE organism_id = %d";
-  $check_lib = db_result(chado_query($sql, $organism_id));
+  $sql = "SELECT feature_id FROM {feature} WHERE organism_id = :organism_id";
+  $check_feature = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
+  $sql = "SELECT library_id FROM {library} WHERE organism_id = :organism_id";
+  $check_lib = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
 
-  if ($check_lib == 0 && $check_feature == 0) {
+  if (!$check_lib && !$check_feature) {
     tripal_core_chado_delete('organism', array('organism_id' => $organism_id));
   }
   else {
@@ -400,18 +400,24 @@ function chado_organism_delete($node) {
 function chado_organism_add_image($node) {
   // check to see if a file was uploaded. If so then copy it to the images
   // directory for display with the organism
-  if (isset($_FILES['files']) && $_FILES['files']['name']['organism_image'] &&
-    is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
-      $dest = tripal_file_directory_path() . "/tripal_organism/images";
-      $validators = array(
-        'file_validate_is_image' => array(),
-      );
-      file_check_directory($dest, FILE_CREATE_DIRECTORY, 'organism_image');
-      if (!$file = file_save_upload('organism_image', $validators, $dest)) {
-        drupal_set_message(t("Organism image was not uploaded."));
-      }
-      // move this image into the images directory
-      file_move($file->filepath, $dest . "/" . $node->nid . ".jpg", FILE_EXISTS_REPLACE);
+  if (isset($_FILES['files']) && 
+      $_FILES['files']['name']['organism_image'] &&
+      is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
+      	
+    // make sure the destination directory exists
+    $dest = tripal_file_directory_path() . "/tripal_organism/images";    
+    file_prepare_directory($dest, FILE_CREATE_DIRECTORY);
+        
+    // now move the file
+    $validators = array('file_validate_is_image' => array()); 
+    $destination = "public://tripal/tripal_organism/images/";
+    $file = file_save_upload('organism_image', $validators, $destination);
+    if (!$file) {
+      drupal_set_message(t("Organism image was not uploaded."));
+    }
+    else {
+    	file_move($file, $destination . "/" . $node->nid . ".jpg", FILE_EXISTS_REPLACE);
+    }
   }
 }
 
@@ -429,28 +435,12 @@ function chado_organism_form($node, $param) {
   $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
 
   // get form defaults
-  $abbreviation = $node->abbreviation;
-  if (!$abbreviation) {
-    $abbreviation = $organism->abbreviation;
-  }
-  $genus = $node->genus;
-  if (!$genus) {
-    $genus = $organism->genus;
-  }
-  $species = $node->species;
-  if (!$species) {
-    $species = $organism->species;
-  }
-  $common_name = $node->common_name;
-  if (!$common_name) {
-    $common_name = $organism->common_name;
-  }
-  $description = $node->description;
-  if (!$description) {
-    $description = $organism->comment;
-  }
-  $organism_image = $node->organism_image;
-
+  $abbreviation   = property_exists($node, 'abbreviation')   ? property_exists($node, 'abbreviation')   : $organism->abbreviation;
+  $genus          = property_exists($node, 'genus')          ? property_exists($node, 'genus')          : $organism->genus;
+  $species        = property_exists($node, 'species')        ? property_exists($node, 'species')        : $organism->species;
+  $common_name    = property_exists($node, 'common_name')    ? property_exists($node, 'common_name')    : $organism->common_name;
+  $description    = property_exists($node, 'description')    ? property_exists($node, 'description')    : $organism->comment;
+  $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';   
 
   $form = array();
   $form['#attributes']['enctype'] = 'multipart/form-data';
@@ -466,43 +456,38 @@ function chado_organism_form($node, $param) {
     '#type' => 'textfield',
     '#title' => t('Abbreviation'),
     '#required' => TRUE,
-    '#default_value' => $organism->abbreviation,
-    '#weight' => 3
+    '#default_value' => $abbreviation,
   );
   $form['genus']= array(
     '#type' => 'textfield',
     '#title' => t('Genus'),
     '#required' => TRUE,
-    '#default_value' => $organism->genus,
-    '#weight' => 1
+    '#default_value' => $genus,
   );
   $form['species']= array(
     '#type' => 'textfield',
     '#title' => t('Species'),
     '#required' => TRUE,
-    '#default_value' => $organism->species,
-    '#weight' => 2
+    '#default_value' => $species,
   );
   $form['common_name']= array(
     '#type' => 'textfield',
     '#title' => t('Common Name'),
     '#required' => TRUE,
-    '#default_value' => $organism->common_name,
-    '#weight' => 4
+    '#default_value' => $common_name,
   );
   $form['description']= array(
     '#type' => 'textarea',
     '#rows' => 15,
     '#title' => t('Description'),
     '#required' => TRUE,
-    '#default_value' => $organism->comment,
-    '#weight' => 5
+    '#default_value' => $description,
   );
   $form['organism_image']= array(
     '#type' => 'file',
     '#title' => t('Organism Image'),
     '#description' => 'Add an image for this organism',
-    '#weight' => 6
+    '#progress_indicator' => 'bar',
   );
   return $form;
 }
@@ -513,93 +498,22 @@ function chado_organism_form($node, $param) {
  *
  * @ingroup tripal_organism
  */
-function chado_organism_load($node) {
-  // find the organism and add in the details
-  $organism_id = chado_get_id_for_node('organism', $node);
-  $values = array('organism_id' => $organism_id);
-
-  $organism = tripal_core_generate_chado_var('organism', $values);
-
-  // add in the description field
-  $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
-
-  $additions = new stdClass();
-  $additions->organism = $organism;
-  return $additions;
-}
+function chado_organism_load($nodes) {
 
-/**
- *  This function customizes the view of the chado_organism node.  It allows
- *  us to generate the markup.
- *
- * @ingroup tripal_organism
- */
-function chado_organism_view($node, $teaser = FALSE, $page = FALSE) {
-  // use drupal's default node view:
-  $node = node_prepare($node, $teaser);
-  return $node;
-}
+  foreach ($nodes as $nid => $node) {
+  	// find the organism and add in the details
+    $organism_id = chado_get_id_for_node('organism', $nid);
 
+    // build the organism variable
+    $values = array('organism_id' => $organism_id);
+    $organism = tripal_core_generate_chado_var('organism', $values);
 
-/**
- * Display help and module information
- * @param path which path of the site we're displaying help
- * @param arg array that holds the current path as would be returned from arg()
- * function
- * @return help text for the path
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_help($path, $arg) {
-  $output = '';
-  switch ($path) {
-    case "admin/help#tripal_organism":
-      $output = '<p>'.
-                  t("Displays links to nodes created on this date") .
-                '</p>';
-      break;
+    // add in the description field
+    $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');    
+    $nodes[$nid]->organism = $organism;
   }
-  return $output;
 }
 
-
-/**
- * This function uses organism_id's of all drupal organism nodes as input and
- * pull the organism information (genus, species, common_name, comment) from
- * chado database. The return type is an object array that stores $organism
- * objects sorted by common_name
- *
- * @ingroup tripal_organism
- */
-function get_chado_organisms() {
-  $sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}";
-  $no_orgs = db_result(db_query($sql_drupal));
-  if ($no_orgs != 0) {
-    $sql = "SELECT organism_id, nid FROM {chado_organism}";
-    $result = chado_query($sql);
-    $sql = "SELECT genus, species, common_name, comment ".
-           "FROM {Organism} ".
-           "WHERE organism_id=%d";
-    $organisms = array();
-    $count = 0;
-    while ($data = db_fetch_object($result)) {
-      $organism = db_fetch_object(chado_query($sql, $data->organism_id));
-      $organism->node_id = $data->nid;
-      // Use common_name plus $count as the key so we can sort by common
-      // name later. Since common_name is not unique, we need to add $count
-      // to the key
-      $key = drupal_strtolower($organism->common_name) . $count;
-      $organisms [$key] = $organism;
-      $count ++;
-    }
-
-    //Sort organisms by common name
-    ksort($organisms, SORT_STRING);
-    return $organisms;
-  }
-}
-
-
 /**
  * Implements hook_views_api()
  * Purpose: Essentially this hook tells drupal that there is views support for

+ 4 - 4
tripal_project/tripal_project.module

@@ -302,7 +302,7 @@ function chado_project_insert($node) {
 
     // make sure the entry for this feature doesn't already exist in the chado_project table
     // if it doesn't exist then we want to add it.
-    $project_id = chado_get_id_for_node('project', $node) ;
+    $project_id = chado_get_id_for_node('project', $node->nid) ;
     if (!$project_id) {
        // next add the item to the drupal table
       $sql = "INSERT INTO {chado_project} (nid, vid, project_id) ".
@@ -330,7 +330,7 @@ function chado_project_insert($node) {
  */
 function chado_project_delete($node) {
 
-  $project_id = chado_get_id_for_node('project', $node);
+  $project_id = chado_get_id_for_node('project', $node->nid);
 
   // if we don't have a project id for this node then this isn't a node of
   // type chado_project or the entry in the chado_project table was lost.
@@ -376,7 +376,7 @@ function chado_project_update($node) {
   }
 
   // update the project and the description
-  $project_id = chado_get_id_for_node('project', $node) ;
+  $project_id = chado_get_id_for_node('project', $node->nid) ;
   $match = array(
      'project_id' => $project_id,
   );
@@ -405,7 +405,7 @@ function chado_project_update($node) {
 function chado_project_load($node) {
 
   // get the feature details from chado
-  $project_id = chado_get_id_for_node('project', $node);
+  $project_id = chado_get_id_for_node('project', $node->nid);
 
   $values = array('project_id' => $project_id);
   $project = tripal_core_generate_chado_var('project', $values);

+ 7 - 7
tripal_pub/tripal_pub.module

@@ -460,7 +460,7 @@ function chado_pub_insert($node) {
   if ($pub) {
     // make sure the entry for this feature doesn't already exist in the chado_pub table
     // if it doesn't exist then we want to add it.
-    $pub_id = chado_get_id_for_node('pub', $node) ;
+    $pub_id = chado_get_id_for_node('pub', $node->nid) ;
     if (!$pub_id) {
       // next add the item to the drupal table
       $sql = "INSERT INTO {chado_pub} (nid, vid, pub_id) ".
@@ -495,7 +495,7 @@ function chado_pub_update($node) {
   }
 
   // get the publication ID for this publication
-  $pub_id = chado_get_id_for_node('pub', $node) ;
+  $pub_id = chado_get_id_for_node('pub', $node->nid) ;
 
   $properties = array(); // stores all of the properties we need to add
   $cross_refs = array(); // stores any cross references for this publication
@@ -656,7 +656,7 @@ function chado_pub_update($node) {
  */
 function chado_pub_load($node) {
   // get the feature details from chado
-  $pub_id = chado_get_id_for_node('pub', $node);
+  $pub_id = chado_get_id_for_node('pub', $node->nid);
 
   $values = array('pub_id' => $pub_id);
   $pub = tripal_core_generate_chado_var('pub', $values);
@@ -691,7 +691,7 @@ function chado_pub_load($node) {
  */
 function chado_pub_delete(&$node) {
 
-  $pub_id = chado_get_id_for_node('pub', $node);
+  $pub_id = chado_get_id_for_node('pub', $node->nid);
 
   // if we don't have a pub id for this node then this isn't a node of
   // type chado_pub or the entry in the chado_pub table was lost.
@@ -868,17 +868,17 @@ function tripal_pub_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
       case 'presave':
         break;
       case 'insert':
-        $pub_id = chado_get_id_for_node('pub', $node);
+        $pub_id = chado_get_id_for_node('pub', $node->nid);
         tripal_pub_set_pub_url($node, $pub_id);
         break;
       case 'load':
         if (!$node->path) {
-          $pub_id = chado_get_id_for_node('pub', $node);
+          $pub_id = chado_get_id_for_node('pub', $node->nid);
           $path = tripal_pub_set_pub_url($node, $pub_id);
         }
         break;
       case 'update':
-        $pub_id = chado_get_id_for_node('pub', $node);
+        $pub_id = chado_get_id_for_node('pub', $node->nid);
         tripal_pub_set_pub_url($node, $pub_id);
         break;
       case 'view':

+ 1 - 1
tripal_stock/tripal_stock.module

@@ -330,7 +330,7 @@ function tripal_stock_node_info() {
 function chado_stock_load($node) {
 
   // get the stock details from chado
-  $stock_id = chado_get_id_for_node('stock', $node);
+  $stock_id = chado_get_id_for_node('stock', $node->nid);
   
   // build the variable with all the stock details
   $values = array('stock_id' => $stock_id);