Browse Source

fixed merge conflicts

spficklin 11 years ago
parent
commit
455f096346

+ 2 - 2
tripal_analysis/tripal_analysis.module

@@ -592,10 +592,10 @@ function tripal_analysis_theme() {
  */
 function tripal_analysis_block_info() {
   $blocks['base']['info'] = t('Tripal Analysis Details');
-  $blocks['base']['cache'] = BLOCK_NO_CACHE;
+  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
-  $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
+  $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
 
   return $blocks;
 }

+ 1 - 1
tripal_bulk_loader/api/tripal_bulk_loader.api.templates.inc

@@ -29,7 +29,7 @@ function tripal_bulk_loader_is_record_name_unique($new_record_name, $template_id
 
   // get the template array if it's not supplied
   if (empty($template_array)) {
-    $template = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $template_id));
+    $template = db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template", array(':template' => $template_id))->fetchObject();
     $template_array = unserialize($template->template_array);
     if (!is_array($template_array)) {
       watchdog(

+ 12 - 2
tripal_bulk_loader/includes/tripal_bulk_loader.admin.inc

@@ -71,13 +71,23 @@ function tripal_bulk_loader_admin_jobs() {
     array('data' => 'Progress', 'field' => 'progress'),
     '');
   $rows = array();
+  $query = db_select('tripal_bulk_loader', 'n')->extend('TableSort');
+  $query->join('tripal_bulk_loader_template', 't', 'cast(n.template_id as integer) = t.template_id');
+  $query->join('tripal_jobs', 'j', 'n.job_id = j.job_id');
+  $query->fields('n')
+    ->fields('t', array('name'))
+    ->fields('j', array('progress'))
+    ->orderByHeader($header);
+  $result = $query->execute();
+  /**
   $resource = pager_query("SELECT n.*, t.name as template_name, j.progress
     FROM {tripal_bulk_loader} n
     LEFT JOIN {tripal_bulk_loader_template} t ON cast(n.template_id as integer) = t.template_id
     LEFT JOIN {tripal_jobs} j ON n.job_id = j.job_id"
     . tablesort_sql($header),
     $num_jobs_per_page);
-  while ($n = db_fetch_object($resource)) {
+    */
+  foreach ($result as $n) {
     $rows[] = array(
       l($n->job_id, 'admin/tripal/tripal_jobs/view/' . $n->job_id),
       l($n->loader_name, 'node/' . $n->nid),
@@ -87,7 +97,7 @@ function tripal_bulk_loader_admin_jobs() {
       l('View', 'node/' . $n->nid) . ' | ' .  l('Edit', 'node/' . $n->nid . '/edit')
     );
   }
-  $output .= theme_table($header, $rows);
+  $output .= theme_table(array('header' => $header, 'rows' => $rows));
 
   $output .= theme('pager');
 

+ 18 - 18
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -26,8 +26,8 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
       $form_state['storage']['template_id'] = $_GET['template_id'];
     }
 
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
+    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+    $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
     $form_state['storage']['template'] = unserialize($result->template_array);
     $form_state['storage']['template_name'] = $result->name;
 
@@ -65,7 +65,7 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
       $resource = db_query($sql);
       $templates = array();
       $templates[''] = 'Select a Template';
-      while ($r = db_fetch_object($resource)) {
+      while ($r = $resource->fetchObject()) {
         $templates[$r->template_id] = $r->name;
       }
 
@@ -356,8 +356,8 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
 
   $form_state['rebuild'] = TRUE;
   if ($form_state['storage']['template_id']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
+    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+    $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
     $form_state['storage']['template'] = unserialize($result->template_array);
   }
 
@@ -373,8 +373,8 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
     case 'Edit Template':
       $form_state['storage']['template_id'] = $form_state['values']['template_id'];
 
-      $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-      $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
+      $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+      $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
       $form_state['storage']['template'] = unserialize($result->template_array);
       $form_state['storage']['template_name'] = $result->name;
 
@@ -512,7 +512,7 @@ function tripal_bulk_loader_delete_template_base_form() {
   $resource = db_query($sql);
   $templates = array();
   $templates[''] = 'Select a Template';
-  while ($r = db_fetch_object($resource)) {
+  while ($r = $resource->fetchObject()) {
     $templates[$r->template_id] = $r->name;
   }
   $form['template_name'] = array(
@@ -543,8 +543,8 @@ function tripal_bulk_loader_delete_template_base_form() {
  * @ingroup tripal_bulk_loader
  */
 function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state) {
-  $sql = "DELETE FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  db_query($sql, $form_state['values']['template_name']);
+  $sql = "DELETE FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+  db_query($sql, array(':template' => $form_state['values']['template_name']))->execute();
 }
 
 /**
@@ -590,7 +590,7 @@ function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mod
     $resource = db_query($sql);
     $templates = array();
     $templates[''] = 'Select a Template';
-    while ($r = db_fetch_object($resource)) {
+    while ($r = $resource->fetchObject()) {
       $templates[$r->template_id] = $r->name;
     }
 
@@ -637,7 +637,7 @@ function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mod
 function tripal_bulk_loader_import_export_template_form_submit($form, &$form_state) {
   switch ($form_state['values']['mode']) {
     case 'export':
-      $record = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $form_state['values']['template_id']));
+      $record = db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template", array(':template' => $form_state['values']['template_id']))->fetchObject();
       //$form_state['storage']['template_array'] = $record->template_array;
       $t = var_export(unserialize($record->template_array), TRUE);
       $t = preg_replace("/\n\s+array/", "array", $t); // move array( to previous line
@@ -699,8 +699,8 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
 
   // If this is the first load of the form (no form state) we need to initialize some variables
   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
+    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+    $template = db_query($sql, array(':template' => $template_id))->fetchObject();
     $form_state['storage']['template_array'] = unserialize($template->template_array);
     $form_state['storage']['template'] = $template;
 
@@ -1040,8 +1040,8 @@ function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
 
    // If this is the first load of the form (no form state) we need to initialize some variables
   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
+    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+    $template = db_query($sql, array(':template' => $template_id))->fetchObject();
     $form_state['storage']['template_array'] = unserialize($template->template_array);
     $form_state['storage']['template'] = $template;
 
@@ -1780,8 +1780,8 @@ function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
 
   // If this is the first load of the form (no form state) we need to initialize some variables
   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
+    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+    $template = db_query($sql, array(':template' => $template_id))->fetchObject();
     $form_state['storage']['template_array'] = unserialize($template->template_array);
     $form_state['storage']['template'] = $template;
 

+ 10 - 9
tripal_bulk_loader/includes/tripal_bulk_loader.constants.inc

@@ -41,13 +41,14 @@ function tripal_bulk_loader_update_constant($nid, $group_id, $table, $field, $re
   );
 
   // Check to see if already exists
-  $exists = db_fetch_object(db_query(
-    "SELECT constant_id FROM {tripal_bulk_loader_constants} WHERE nid=%d AND record_id=%d AND field_id=%d AND group_id=%d",
-    $record['nid'],
-    $record['record_id'],
-    $record['field_id'],
-    $record['group_id']
-  ));
+  $exists = db_query(
+    "SELECT constant_id FROM {tripal_bulk_loader_constants} WHERE nid=:nid AND record_id=:record AND field_id=:field AND group_id=:group",
+    array(
+      ':nid' => $record['nid'],
+      ':record' => $record['record_id'],
+      ':field' => $record['field_id'],
+      ':group' => $record['group_id']
+  ))->fetchObject();
   if ($exists->constant_id) {
     $record['constant_id'] = $exists->constant_id;
     $status = drupal_write_record('tripal_bulk_loader_constants', $record, 'constant_id');
@@ -327,7 +328,7 @@ function tripal_bulk_loader_set_constants_form_submit($form, $form_state) {
 
   $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
   if (strcmp('Add Constant Set', $op) == 0) {
-      $max_group = db_fetch_object(db_query("SELECT max(group_id) as value FROM {tripal_bulk_loader_constants} WHERE nid=%d", $form_state['values']['nid']));
+      $max_group = db_query("SELECT max(group_id) as value FROM {tripal_bulk_loader_constants} WHERE nid=:nid", array(':nid' => $form_state['values']['nid']))->fetchObject();
       foreach ($indexes as $record_id => $array) {
         foreach ($array as $field_id) {
           tripal_bulk_loader_update_constant(
@@ -592,7 +593,7 @@ function tripal_bulk_loader_delete_constant_set_form_submit($form, $form_state)
   $group_id = $form_state['values']['group_id'];
   $nid = $form_state['values']['nid'];
   if ($nid && $form_state['values']['confirm']) {
-    db_query("DELETE FROM {tripal_bulk_loader_constants} WHERE nid=%d AND group_id=%d", $nid, $group_id);
+    db_query("DELETE FROM {tripal_bulk_loader_constants} WHERE nid=:nid AND group_id=:group", array(':nid' => $nid, ':group' => $group_id))->execute();
     drupal_set_message(t('Constant set successfully deleted.'));
   }
 

+ 23 - 22
tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc

@@ -74,10 +74,10 @@ function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
       $job_id = tripal_add_job("Bulk Loading Job: $fname", 'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
 
       // add job_id to bulk_loader node
-      $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=%d WHERE nid=%d", $job_id, $form_state['values']['nid']);
+      $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=:job WHERE nid=:nid", array(':job' => $job_id, ':nid' => $form_state['values']['nid']))->execute();
 
       // change status
-      db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Submitted to Queue', $form_state['values']['nid']);
+      db_query("UPDATE {tripal_bulk_loader} SET job_status=:status' WHERE nid=:nid", array(':status' => 'Submitted to Queue', ':nid' => $form_state['values']['nid']))->execute();
     }
     else {
       drupal_set_message(t("Can not open %file. Job not scheduled.", array('%file' => $form_state['values']['file'])));
@@ -85,23 +85,23 @@ function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
   }
   elseif (preg_match('/Re-Submit Job/', $form_state['values']['op'])) {
     tripal_jobs_rerun($form_state['values']['job_id']);
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Submitted to Queue', $form_state['values']['nid']);
+    db_query("UPDATE {tripal_bulk_loader} SET job_status=:status WHERE nid=:nid", array(':status' => 'Submitted to Queue', 'nid' => $form_state['values']['nid']))->execute();
   }
   elseif (preg_match('/Cancel Job/', $form_state['values']['op'])) {
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Job Cancelled', $form_state['values']['nid']);
+    db_query("UPDATE {tripal_bulk_loader} SET job_status=:status WHERE nid=:nid", array(':status' => 'Job Cancelled', ':nid' => $form_state['values']['nid']))->execute();
     tripal_jobs_cancel($form_state['values']['job_id']);
   }
   elseif (preg_match('/Revert/', $form_state['values']['op'])) {
 
     // Remove the records from the database that were already inserted
-    $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d ORDER BY tripal_bulk_loader_inserted_id DESC', $form_state['values']['nid']);
-    while ($r = db_fetch_object($resource)) {
+    $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=:nid ORDER BY tripal_bulk_loader_inserted_id DESC', array(':nid' => $form_state['values']['nid']));
+    while ($r = $resource->fetchObject()) {
       $ids = preg_split('/,/', $r->ids_inserted);
-      db_query('DELETE FROM {%s} WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted);
-      $result = db_fetch_object(db_query('SELECT true as present FROM {%s} WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted));
+      db_query('DELETE FROM {'.$r->table_inserted_into.'} WHERE '.$r->table_primary_key.' IN ('.$r->ids_inserted.')')->execute();
+      $result = db_query('SELECT true as present FROM {'.$r->table_inserted_into.'} WHERE '.$r->table_primary_key.' IN ('.$r->ids_inserted.')')->fetchObject();
       if (!$result->present) {
         drupal_set_message(t('Successfully Removed data Inserted into the %tableto table.', array('%tableto' => $r->table_inserted_into)));
-        db_query('DELETE FROM {tripal_bulk_loader_inserted} WHERE tripal_bulk_loader_inserted_id=%d', $r->tripal_bulk_loader_inserted_id);
+        db_query('DELETE FROM {tripal_bulk_loader_inserted} WHERE tripal_bulk_loader_inserted_id=:id', array(':id' => $r->tripal_bulk_loader_inserted_id))->execute();
       }
       else {
         drupal_set_message(t('Unable to remove data Inserted into the %tableto table!', array('%tableto' => $r->table_inserted_into)), 'error');
@@ -109,7 +109,7 @@ function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
     }
 
     // reset status
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Reverted -Data Deleted', $form_state['values']['nid']);
+    db_query("UPDATE {tripal_bulk_loader} SET job_status=:status WHERE nid=:nid", array(':status' => 'Reverted -Data Deleted', ':nid' => $form_state['values']['nid']))->execute();
   }
 
 }
@@ -131,10 +131,10 @@ function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
 function tripal_bulk_loader_load_data($nid, $job_id) {
 
   // ensure no timeout
-  set_time_limit(0);
+  drupal_set_time_limit(0);
 
   // set the status of the job (in the node not the tripal jobs)
-  db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Loading...', $nid);
+  db_query("UPDATE {tripal_bulk_loader} SET job_status=:status WHERE nid=:nid", array(':status' => 'Loading...', ':nid' => $nid))->execute();
 
 
   $node = node_load($nid);
@@ -344,7 +344,7 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
       $lockmode = variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE');
       foreach ($tables as $table) {
         print "\t\t\t$lockmode for $table\n";
-        chado_query("LOCK TABLE %s IN %s MODE", $table, $lockmode);
+        chado_query("LOCK TABLE ".$table." IN ".$lockmode." MODE");
       }
     }
 
@@ -460,7 +460,7 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
   else {
     $status = 'Errors Encountered';
   }
-  db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", $status, $nid);
+  db_query("UPDATE {tripal_bulk_loader} SET job_status=:status WHERE nid=:nid", array(':status' => $status, ':nid' => $nid))->execute();
 
 }
 
@@ -500,10 +500,10 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   // get the table description
   $table_desc = tripal_core_get_chado_table_schema($table);
   if (!$table_desc) {
-    watchdog('T_bulk_loader', "Failure: Tripal does not know about the table named '%table'. If this is a custom table, 
+    watchdog('T_bulk_loader', "Failure: Tripal does not know about the table named '%table'. If this is a custom table,
       please define it first", array('%table' => $table), WATCHDOG_ERROR);
     $data[$priority]['error'] = TRUE;
-    return;  
+    return;
   }
 
   // Check that template required fields are present. if a required field is
@@ -600,7 +600,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   // We check for "insert_unique" for backwards compatibilty but that mode no longer exists
   $data[$priority]['is_duplicate'] = 0;
   if (preg_match('/insert_unique/', $table_data['mode']) or
-     $table_data['select_if_duplicate'] == 1 or 
+     $table_data['select_if_duplicate'] == 1 or
      $table_data['update_if_duplicate'] == 1) {
     $options = array('is_duplicate' => TRUE);
     $duplicate = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, $options);
@@ -735,11 +735,12 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
 
       // add to tripal_bulk_loader_inserted
       if ($addt->node->keep_track_inserted) {
-        $insert_record = db_fetch_object(db_query(
-          "SELECT * FROM {tripal_bulk_loader_inserted} WHERE table_inserted_into='%s' AND nid=%d",
-          $table,
-          $addt->nid
-        ));
+        $insert_record = db_query(
+          "SELECT * FROM {tripal_bulk_loader_inserted} WHERE table_inserted_into=:table AND nid=:nid",
+          array(
+          ':table' => $table,
+          'nid' => $addt->nid
+        ))->fetchObject();
         if ($insert_record) {
           $insert_record->ids_inserted .= ',' . $record[$table_desc['primary key'][0] ];
           drupal_write_record('tripal_bulk_loader_inserted', $insert_record, 'tripal_bulk_loader_inserted_id');

+ 3 - 2
tripal_bulk_loader/tripal_bulk_loader.info

@@ -1,7 +1,8 @@
 name = Tripal Bulk Loader
 description = A module for uploading tab-delimit data into GMOD chado database using templates.
-core = 6.x
+core = 7.x
 project = tripal_bulk_loader
 package = Tripal
-version = 6.x-1.1
+version = 7.x-2.0-beta1
+
 dependencies[] = tripal_core

+ 5 - 25
tripal_bulk_loader/tripal_bulk_loader.install

@@ -4,21 +4,6 @@
  * @todo Add file header description
  */
 
-
-/**
- * Implements hook_install
- */
-function tripal_bulk_loader_install() {
-  drupal_install_schema('tripal_bulk_loader');
-}
-
-/**
- * Implements hook_uninstall
- */
-function tripal_bulk_loader_uninstall() {
-  drupal_uninstall_schema('tripal_bulk_loader');
-}
-
 /**
  * Implements hook_schema
  *
@@ -166,10 +151,9 @@ function tripal_bulk_loader_update_6150() {
 
   // Create tripal_bulk_loader_constants table
   $schema = tripal_bulk_loader_schema();
-  $ret = array();
-  db_create_table($ret, 'tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
+  db_create_table('tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
 
-  return $ret;
+  return 'Added support for loader-specific constants.';
 
 }
 
@@ -179,11 +163,9 @@ function tripal_bulk_loader_update_6150() {
  *   to allow multiple sets of constants per job
  */
 function tripal_bulk_loader_update_6151() {
-  $ret = array();
 
   $schema = tripal_bulk_loader_schema();
   db_add_field(
-    $ret,
     'tripal_bulk_loader_constants',
     'group_id',
     array(
@@ -194,14 +176,12 @@ function tripal_bulk_loader_update_6151() {
       )
     );
 
-  return $ret;
+  return 'Added support for multiple sets of loader-specific constants.';
 }
 
 function tripal_bulk_loader_update_6152() {
-  $ret = array();
 
   db_add_field(
-    $ret,
     'tripal_bulk_loader',
     'keep_track_inserted',
     array(
@@ -212,10 +192,10 @@ function tripal_bulk_loader_update_6152() {
     )
   );
 
-  return $ret;
+  return 'Added ability to rollback loading job based on storing loaded ids.';
 }
 /**
- * Implementation of hook_requirements(). 
+ * Implementation of hook_requirements().
   */
 function tripal_bulk_loader_requirements($phase) {
   $requirements = array();

+ 46 - 27
tripal_bulk_loader/tripal_bulk_loader.module

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @file
  * The functions for the Tripal bulk loader.
@@ -218,11 +219,11 @@ function tripal_bulk_loader_theme() {
  *  @return
  *  If the permission for the specified operation is not set then return FALSE. If the
  *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always 
+ *  access.  The only exception is when the $op == 'create'.  We will always
  *  return TRUE if the permission is set.
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_access($op, $node, $account) {
+function tripal_bulk_loader_node_access($node, $op, $account) {
   if ($op == 'create') {
     if (!user_access('create tripal_bulk_loader', $account)) {
       return FALSE;
@@ -252,7 +253,7 @@ function tripal_bulk_loader_access($op, $node, $account) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_perm() {
+function tripal_bulk_loader_permission() {
   return array(
       'access tripal_bulk_loader',
       'create tripal_bulk_loader',
@@ -275,7 +276,7 @@ function tripal_bulk_loader_node_info() {
   $nodes = array();
   $nodes['tripal_bulk_loader'] = array(
       'name' => t('Bulk Loading Job'),
-      'module' => 'tripal_bulk_loader',
+      'base' => 'tripal_bulk_loader',
       'description' => t('A bulk loader for inserting tab-delimited data into chado database'),
       'has_title' => TRUE,
       'has_body' => FALSE,
@@ -299,9 +300,9 @@ function tripal_bulk_loader_form($node, $form_state) {
   }
 
   $sql = "SELECT * FROM {tripal_bulk_loader_template}";
-  $results = db_query($sql);
+  $results = db_query($sql)->execute();
   $templates = array();
-  while ($template = db_fetch_object ($results)) {
+  foreach ($results as $template) {
     $templates [$template->template_id] = $template->name;
   }
 
@@ -376,27 +377,27 @@ function tripal_bulk_loader_form($node, $form_state) {
  * @ingroup tripal_bulk_loader
  */
 function tripal_bulk_loader_load($node) {
-  $sql = "SELECT * FROM {tripal_bulk_loader} WHERE nid = %d";
-  $node = db_fetch_object(db_query($sql, $node->nid));
+  $sql = "SELECT * FROM {tripal_bulk_loader} WHERE nid = :nid";
+  $node = db_query($sql, array(':nid' => $node->nid))->fetchObject();
 
   $node->title = 'Bulk Loading Job: ' . $node->loader_name;
 
   // Add job details
   $progress = tripal_bulk_loader_progess_file_get_progress($node->job_id);
-  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id=%d";
-  $node->job = db_fetch_object(db_query($sql, $node->job_id));
+  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id=:job_id";
+  $node->job = db_query($sql, array(':job_id' => $node->job_id))->fetchObject();
 
   // Add the loader template
-  $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  $results = db_fetch_object(db_query($sql, $node->template_id));
+  $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
+  $results = db_query($sql, array(':template' => $node->template_id))->fetchObject();
   $template = unserialize($results->template_array);
   $node->template = $results;
   $node->template->template_array = $template;
 
   // Add inserted records
-  $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d';
-  $resource = db_query($sql, $node->nid);
-  while ($r = db_fetch_object($resource)) {
+  $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=:nid';
+  $resource = db_query($sql, array(':nid' => $node->nid))->execute();
+  foreach ($resource as $r) {
     $r->num_inserted = sizeof(preg_split('/,/', $r->ids_inserted));
     $node->inserted_records->{$r->table_inserted_into} = $r;
   }
@@ -423,9 +424,9 @@ function tripal_bulk_loader_load($node) {
 
 
   // Add constants
-  $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY group_id, record_id, field_id';
-  $resource = db_query($sql, $node->nid);
-  while ($r = db_fetch_object($resource)) {
+  $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=:nid ORDER BY group_id, record_id, field_id';
+  $resource = db_query($sql, array(':nid' => $node->nid))->execute();
+  foreach ($resource as $r) {
     $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
       'constant_id' => $r->constant_id,
       'group_id' => $r->group_id,
@@ -452,8 +453,17 @@ function tripal_bulk_loader_load($node) {
 function tripal_bulk_loader_insert($node) {
 
   // Insert into tripal_bulk_loader
-  $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status, keep_track_inserted) VALUES (%d, '%s', %d, '%s', %d, '%s', %d)";
-  db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, 'Initialized', $node->keep_track_inserted);
+  $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status, keep_track_inserted) VALUES (:nid, :loader, :template, :file, :header, :status, :ids)";
+  db_query($sql,
+    array(':nid' => $node->nid,
+      ':loader' => $node->loader_name,
+      ':template' => $node->template_id,
+      ':file' => $node->file,
+      ':header' => $node->has_header,
+      ':status' => 'Initialized',
+      ':ids' => $node->keep_track_inserted
+    )
+  )->execute();
 
   // Update title
   $node->title =$node->loader_name;
@@ -471,8 +481,8 @@ function tripal_bulk_loader_insert($node) {
  * @ingroup tripal_bulk_loader
  */
 function tripal_bulk_loader_delete($node) {
-  $sql = "DELETE FROM {tripal_bulk_loader} WHERE nid = %d";
-  db_query($sql, $node->nid);
+  $sql = "DELETE FROM {tripal_bulk_loader} WHERE nid = :nid";
+  db_query($sql, array(':nid' => $node->nid))->execute();
 }
 
 /**
@@ -484,8 +494,17 @@ function tripal_bulk_loader_delete($node) {
 function tripal_bulk_loader_update($node) {
 
   // Update tripal_bulk_loader
-  $sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s', keep_track_inserted = %d WHERE nid = %d";
-  db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->keep_track_inserted, $node->nid);
+  $sql = "UPDATE {tripal_bulk_loader} SET nid = :nid, loader_name = :loader, template_id = :template, file = :file, file_has_header = :header, keep_track_inserted = :ids WHERE nid = :wherenid";
+  db_query($sql,
+    array(':nid' => $node->nid,
+      ':loader' => $node->loader_name,
+      ':template' => $node->template_id,
+      ':file' => $node->file,
+      ':header' => $node->has_header,
+      ':ids' => $node->keep_track_inserted,
+      ':wherenid' => $node->nid
+    )
+  )->execute();
 
   // Add a job if the user want to load the data
   global $user;
@@ -514,7 +533,7 @@ function tripal_bulk_loader_update($node) {
 function tripal_bulk_loader_preprocess_tripal_bulk_loader_template(&$variables) {
 
   $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  $template = db_fetch_object(db_query($sql, $variables['template_id']));
+  $template = db_query($sql, array(':template' => $variables['template_id']))->fetchObject();
   $template->template_array = unserialize($template->template_array);
   $variables['template'] = $template;
 
@@ -550,7 +569,7 @@ function tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress
   $num_lines = trim(`wc --lines < $filename`);
   $num_records = trim(`grep -o "." $filename | wc --lines`);
 
-  $job = db_fetch_object(db_query("SELECT j.*, b.file, b.file_has_header, c.num as num_constant_sets
+  $job = db_query("SELECT j.*, b.file, b.file_has_header, c.num as num_constant_sets
                               FROM {tripal_jobs} j
                               LEFT JOIN {tripal_bulk_loader} b ON b.job_id=j.job_id
                               LEFT JOIN (
@@ -558,7 +577,7 @@ function tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress
                                   FROM {tripal_bulk_loader_constants}
                                   GROUP BY nid
                                 ) c ON c.nid=b.nid
-                              WHERE j.job_id=%d", $job_id));
+                              WHERE j.job_id=:job", array(':job' =>$job_id))->execute();
   if ($job->num_constant_sets) {
     $num_constant_sets_loaded = round($job->progress / (100 / $job->num_constant_sets), 4);
 

+ 62 - 63
tripal_feature/tripal_feature.module

@@ -47,13 +47,26 @@ function tripal_feature_views_api() {
 }
 
 /**
- * Implements hook_help()
- * Purpose: Adds a help page to the module list
+ * 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_feature
  */
-function tripal_feature_help ($path, $arg) {
-  if ($path == 'admin/help#tripal_feature') {
-    return theme('tripal_feature_help', array());
+function tripal_feature_help($path, $arg) {
+  $output = '';
+  switch ($path) {
+  case "admin/help#tripal_feature":
+    $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
+    break;
   }
+  return $output;
 }
 
 /**
@@ -189,7 +202,7 @@ function tripal_feature_menu() {
     'title' => 'Features',
     'description' => 'Basic Description of Tripal Organism Module Functionality',
     'page callback' => 'theme',
-    'page arguments' => array('tripal_feature_help'),
+    'page arguments' => array('tripal_feature_admin'),
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
@@ -197,7 +210,7 @@ function tripal_feature_menu() {
     'title' => 'Configuration',
     'description' => 'Configure the Tripal Feature module.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_feature_help'),
+    'page arguments' => array('tripal_feature_admin'),
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
@@ -254,98 +267,84 @@ function tripal_feature_menu() {
  * @ingroup tripal_feature
  */
 function tripal_feature_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_feature') . '/theme';
-  $items = array(
-    // themed functions
-    'tripal_feature_seq_extract_form' => array(
-      'arguments' => array('form'),
-    ),
+  return array(
     'tripal_feature_search_index' => array(
       'arguments' => array('node'),
     ),
     'tripal_feature_search_results' => array(
-      'arguments' => array('node'),
+       'arguments' => array('node'),
     ),
-    // tripal_organism templates
     'tripal_organism_feature_browser' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_organism_feature_browser',
-      'path' => "$theme_path/tripal_organism",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_organism_feature_browser',
     ),
     'tripal_organism_feature_counts' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_organism_feature_counts',
-      'path' => "$theme_path/tripal_organism",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_organism_feature_counts',
     ),
-    // tripal_feature templates
     'tripal_feature_base' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_base',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_base',
     ),
     'tripal_feature_sequence' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_sequence',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_sequence',
     ),
     'tripal_feature_proteins' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_proteins',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_proteins',
     ),
     'tripal_feature_synonyms' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_synonyms',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_synonyms',
     ),
     'tripal_feature_phenotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_phenotypes',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_phenotypes',
     ),
     'tripal_feature_featurepos' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_featurepos',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_featurepos',
     ),
     'tripal_feature_featureloc_sequences' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_featureloc_sequences',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_featureloc_sequences',
     ),
     'tripal_feature_references' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_references',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_references',
     ),
     'tripal_feature_properties' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_properties',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_properties',
     ),
     'tripal_feature_terms' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_terms',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_terms',
     ),
     'tripal_feature_alignments' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_alignments',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_alignments',
     ),
     'tripal_feature_relationships' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_relationships',
-      'path' => "$theme_path/tripal_feature",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_feature_relationships',
     ),
-    'tripal_feature_help' => array(
-      'template' => 'tripal_feature_help',
+    'tripal_feature_edit_ALL_properties_form' => array(
+      'arguments' => array('form' => NULL),
+      'function' => 'theme_tripal_feature_edit_ALL_properties_form',
+    ),
+    'tripal_feature_admin' => array(
+      'template' => 'tripal_feature_admin',
       'arguments' =>  array(NULL),
-      'path' => $theme_path
+      'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
     ),
-
+    
+    // themed forms
+    'tripal_feature_seq_extract_form' => array(
+       'arguments' => array('form'),
+    )
   );
-  return $items;
 }
 /**
  *

+ 12 - 29
tripal_featuremap/tripal_featuremap.module

@@ -138,7 +138,7 @@ function tripal_featuremap_menu() {
     'title' => 'Maps',
     'description' => 'Basic Description of Tripal Map Module Functionality',
     'page callback' => 'theme',
-    'page arguments' => array('tripal_featuremap_help'),
+    'page arguments' => array('tripal_featuremap_admin'),
     'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_NORMAL_ITEM,
   );
@@ -147,7 +147,7 @@ function tripal_featuremap_menu() {
     'title' => 'Configuration',
     'description' => 'Manage integration of Chado maps including associated features.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_featuremap_help'),
+    'page arguments' => array('tripal_featuremap_admin'),
     'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_NORMAL_ITEM,
   );
@@ -203,63 +203,46 @@ function tripal_featuremap_views_api() {
  * @ingroup tripal_featuremap
  */
 function tripal_featuremap_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_featuremap') . '/theme';
-  $items = array(
-    // themed functions
+  return array(
     'tripal_featuremap_search_index' => array(
-      'arguments' => array('node'),
+       'arguments' => array('node'),
     ),
     'tripal_featuremap_search_result' => array(
-      'arguments' => array('node'),
+       'arguments' => array('node'),
     ),
-    // tripal_featuremap templates
     'tripal_featuremap_base' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_featuremap_base',
-      'path' => "$theme_path/tripal_featuremap",
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_featuremap_base',
     ),
     'tripal_featuremap_properties' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_featuremap_properties',
-      'path' => "$theme_path/tripal_featuremap",
     ),
     'tripal_featuremap_featurepos' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_featuremap_featurepos',
-      'path' => "$theme_path/tripal_featuremap",
     ),
     'tripal_featuremap_publication' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_featuremap_publication',
-      'path' => "$theme_path/tripal_featuremap",
     ),
     'tripal_featuremap_references' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_featuremap_references',
-      'path' => "$theme_path/tripal_featuremap",
     ),
-    'tripal_featuremap_help' => array(
-      'template' => 'tripal_featuremap_help',
+    'tripal_featuremap_admin' => array(
+      'template' => 'tripal_featuremap_admin',
       'arguments' =>  array(NULL),
-      'path' => $theme_path,
+      'path' => drupal_get_path('module', 'tripal_featuremap') . '/theme'
     ),
     
     // Themed Forms
     'chado_featuremap_node_form' => array(
-      'arguments' => array('form'),
+     'arguments' => array('form'),
     ),      
   );
-  return $items;
-}
-/**
- * Implements hook_help()
- * Purpose: Adds a help page to the module list
- */
-function tripal_featuremap_help ($path, $arg) {
-  if ($path == 'admin/help#tripal_featuremap') {
-    return theme('tripal_featuremap_help', array());
-  }
 }
+
 /**
  * @ingroup tripal_library
  */

+ 22 - 22
tripal_library/tripal_library.module

@@ -87,7 +87,7 @@ function tripal_library_permisssions() {
  * Implement hook_access().
  *
  * This hook allows node modules to limit access to the node types they define.
- * 
+ *
  *  @param $node
  *  The node on which the operation is to be performed, or, if it does not yet exist, the
  *  type of node to be created
@@ -101,7 +101,7 @@ function tripal_library_permisssions() {
  *  @return
  *  If the permission for the specified operation is not set then return FALSE. If the
  *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always 
+ *  access.  The only exception is when the $op == 'create'.  We will always
  *  return TRUE if the permission is set.
  *
  * @ingroup tripal_library
@@ -287,25 +287,25 @@ function tripal_library_help ($path, $arg) {
 function tripal_library_block_info() {
 
   $blocks['libreferences']['info'] = t('Tripal Library Cross References');
-  $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
+  $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['libbase']['info'] = t('Tripal Library Details');
-  $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
+  $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['libterms']['info'] = t('Tripal Library Terms');
-  $blocks['libterms']['cache'] = BLOCK_NO_CACHE;
+  $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
-  $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
+  $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['libproperties']['info'] = t('Tripal Library Properties');
-  $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
+  $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
-  $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
+  $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
-  $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
+  $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
 
   return $blocks;
 }
@@ -371,9 +371,9 @@ function theme_tripal_library_search_index($node) {
     while ($library = $results->fetchObject()) {
       // get the description
       $sql = "
-        SELECT * 
-        FROM {libraryprop} LP 
-          INNER JOIN {cvterm} CVT ON CVT.cvterm_id = LP.type_id 
+        SELECT *
+        FROM {libraryprop} LP
+          INNER JOIN {cvterm} CVT ON CVT.cvterm_id = LP.type_id
         WHERE LP.library_id = :library_id
           AND CVT.name = 'library_description'
       ";
@@ -393,11 +393,11 @@ function theme_tripal_library_search_index($node) {
     $content = "";
     $organism_id = $node->feature->organism_id;
     $sql = "
-      SELECT * 
-      FROM {library} L 
-        INNER JOIN {library_feature} LF ON L.library_id = LF.library_id 
+      SELECT *
+      FROM {library} L
+        INNER JOIN {library_feature} LF ON L.library_id = LF.library_id
       WHERE LF.feature_id = :feature_id
-    "; 
+    ";
     $libraries = array();
     $results = chado_query($sql, array(':feature_id' => $node->feature->feature_id));
     while ($library = $results->fetchObject()) {
@@ -438,9 +438,9 @@ function theme_tripal_library_node_libraries($node) {
   elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
     $organism_id = $node->feature->organism_id;
     $sql = "
-      SELECT * 
-      FROM {library} L 
-        INNER JOIN Library_feature LF ON L.library_id = LF.library_id 
+      SELECT *
+      FROM {library} L
+        INNER JOIN Library_feature LF ON L.library_id = LF.library_id
       WHERE LF.feature_id = :feature_id
     ";
     $libraries = array();
@@ -599,8 +599,8 @@ function chado_library_validate($node) {
   // before we try to insert into chado.
   if ($node->library_id) {
     $sql = "
-      SELECT * 
-      FROM {library} 
+      SELECT *
+      FROM {library}
       WHERE uniquename = :uname AND NOT library_id = :library_id
     ";
     $lib = chado_query($sql, array(':uname' => $node->uniquename, ':library_id' => $node->library_id))->fetchObject();
@@ -646,7 +646,7 @@ function chado_library_insert($node) {
     if (!$library_id) {
        // next add the item to the drupal table
       $sql = "
-        INSERT INTO {chado_library} (nid, vid, library_id) 
+        INSERT INTO {chado_library} (nid, vid, library_id)
         VALUES (:nid, :vid, :library_id)
       ";
       db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':library_id' => $library['library_id']));

+ 3 - 3
tripal_organism/tripal_organism.module

@@ -46,13 +46,13 @@ function tripal_organism_node_info() {
 function tripal_organism_block_info() {
 
   $blocks['base']['info'] = t('Tripal Organism Details');
-  $blocks['base']['cache'] = BLOCK_NO_CACHE;
+  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['description']['info'] = t('Tripal Organism Description');
-  $blocks['description']['cache'] = BLOCK_NO_CACHE;
+  $blocks['description']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['image']['info'] = t('Tripal Organism Image');
-  $blocks['image']['cache'] = BLOCK_NO_CACHE;
+  $blocks['image']['cache'] = DRUPAL_NO_CACHE;
 
   return $blocks;
 

+ 6 - 6
tripal_project/tripal_project.module

@@ -352,7 +352,7 @@ function chado_project_insert($node) {
     if (!$project_id) {
        // next add the item to the drupal table
       $sql = "
-        INSERT INTO {chado_project} (nid, vid, project_id) 
+        INSERT INTO {chado_project} (nid, vid, project_id)
         VALUES (:nid, :vid, :project_id)
       ";
       db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':project_id' => $project['project_id']));
@@ -460,19 +460,19 @@ function chado_project_load($node) {
 function tripal_project_block_info() {
 
   $blocks['projectbase']['info'] = t('Tripal Project Details');
-  $blocks['projectbase']['cache'] = BLOCK_NO_CACHE;
+  $blocks['projectbase']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['projectprops']['info'] = t('Tripal Project Properties');
-  $blocks['projectprops']['cache'] = BLOCK_NO_CACHE;
+  $blocks['projectprops']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['projectpubs']['info'] = t('Tripal Project Publications');
-  $blocks['projectpubs']['cache'] = BLOCK_NO_CACHE;
+  $blocks['projectpubs']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['projectcont']['info'] = t('Tripal Project Contact');
-  $blocks['projectcont']['cache'] = BLOCK_NO_CACHE;
+  $blocks['projectcont']['cache'] = DRUPAL_NO_CACHE;
 
   $blocks['projectrels']['info'] = t('Tripal Project Relationships');
-  $blocks['projectrels']['cache'] = BLOCK_NO_CACHE;
+  $blocks['projectrels']['cache'] = DRUPAL_NO_CACHE;
 
   return $blocks;
 }

+ 1 - 2
tripal_views/api/tripal_views.api.inc

@@ -603,7 +603,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
         'name' => $field_name,
         'title' => ucwords(str_replace('_', ' ', $field_name)),
         'type' => $field_schema['type'],
-        'description' => ($field_schema['description']) ? $field_schema['description'] : ucwords(str_replace('_', ' ', $field_name)),
+        'description' => (isset($field_schema['description'])) ? $field_schema['description'] : ucwords(str_replace('_', ' ', $field_name)),
         'handlers' => array(),
         'joins' => array()
       );
@@ -708,7 +708,6 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
   // Add Joins & Relationships for foreign keys to fields
   if (!isset($schema['foreign keys'])) {
     $schema['foreign keys'] = array();
-    watchdog('tripal_views', 'There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_WARNING);
   }
   foreach ($schema['foreign keys'] as $foreign_key_schema) {
     foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {

+ 204 - 132
tripal_views/includes/tripal_views_integration.inc

@@ -465,6 +465,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
       '#title' => t('Table Fields'),
       '#prefix' => '<div id="fieldset-table-rows-wrapper">',
       '#suffix' => '</div>',
+      '#collapsible' => TRUE
     );
 
     // get the columns in this materialized view.  They are separated by commas
@@ -499,6 +500,40 @@ function tripal_views_integration_form($form, $form_state, $arg) {
     );
     $data['field_types'] = array();
 
+    $form['view_setup_table']['header'] = array(
+      '#type' => 'markup',
+      '#prefix' => '<div class="joins-new-row field-headers">',
+      '#suffix' => '</div>',
+    );
+
+    $form['view_setup_table']['header']['column-1'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"column-one\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Field'
+    );
+
+    $form['view_setup_table']['header']['column-2'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"column-two\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Labels'
+    );
+
+    $form['view_setup_table']['header']['column-3'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"column-three\">",
+         '#suffix' => "</div>",
+         '#markup' => ''
+    );
+
+    $form['view_setup_table']['header']['column-4'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"column-four\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Handlers'
+    );
+
     // get the list of chado tables to join on
     $chado_join_tables = tripal_core_get_chado_tables(TRUE);
     $chado_join_tables = array_merge(array('Select a Join Table'), $chado_join_tables);
@@ -616,77 +651,6 @@ function tripal_views_integration_form($form, $form_state, $arg) {
            '#value' => filter_xss('')
       );
 
-      // set the default values for the join table and columns
-      $default_join_table = 0;
-      $default_join_field = 0;
-      if (isset($setup_id) && !isset($form_state['values']["fields_join_$table_id-$i"]) && isset($default_joins[$column_name])) {
-        $default_join_table = $default_joins[$column_name]['left_table'];
-        $default_join_field = $default_joins[$column_name]['left_field'];
-        $form_state['values']["fields_join_$table_id-$i"] = $default_join_table;
-        $form_state['values']["fields_join_column_$table_id-$i"] = $default_join_field;
-      }
-      else {
-        if (isset($form_state['values']["fields_join_$table_id-$i"])) {
-          $default_join_table = $form_state['values']["fields_join_$table_id-$i"];
-        }
-        if (isset($form_state['values']["fields_join_column_$table_id-$i"])) {
-          $default_join_field = $form_state['values']["fields_join_column_$table_id-$i"];
-        }
-      }
-
-      $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_$table_id-$i"] = array(
-        '#type' => 'select',
-        '#prefix' => "<div class=\"fields-column-join\">",
-        '#suffix' => "</div>",
-        '#options' => $chado_join_tables,
-        '#required' => FALSE,
-        '#default_value' => $default_join_table,
-        '#ajax' => array(
-           'callback' => 'tripal_views_integration_ajax_join_field',
-           'wrapper' => "fields-column-join-column-$table_id-$i",
-           'effect' => 'fade',
-           'event' => 'change',
-           'method' => 'replace',
-        ),
-      );
-
-      $columns = array();
-      if ($default_join_table) {
-        // get the table description
-        $table_desc = tripal_core_get_chado_table_schema($default_join_table);
-        foreach ($table_desc['fields'] as $column => $def) {
-          $columns[$column] = $column;
-        }
-      }
-      else {
-        $columns = array('Select Join Column');
-      }
-      $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_column_$table_id-$i"] = array(
-        '#type' => 'select',
-        '#prefix' => "  <div id=\"fields-column-join-column-$table_id-$i\" class=\"fields-column-join-column\">",
-        '#suffix' => "</div>",
-        '#options' => $columns,
-        '#required' => FALSE,
-        '#default_value' => $default_join_field
-      );
-
-      $default_join_handler = 0;
-      if (isset($setup_id) && !isset($form_state['values']["fields_join_handler_$table_id-$i"]) && isset($default_handlers[$column_name]['join'])) {
-        $default_join_handler = $default_handlers[$column_name]['join']['handler_name'];
-        $form_state['values']["fields_join_handler_$table_id-$i"] = $default_join_handler;
-      }
-      elseif (isset($form_state['values']["fields_join_handler_$table_id-$i"])) {
-        $default_join_handler = $form_state['values']["fields_join_handler_$table_id-$i"];
-      }
-      $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_handler_$table_id-$i"] = array(
-        '#type' => 'select',
-        '#prefix' => "<div class=\"fields-join-handler\">",
-        '#suffix' => "</div>",
-        '#options' => $handlers_join,
-        '#required' => FALSE,
-        '#default_value' => $default_join_handler,
-      );
-
       // COLUMN 4
       $form['view_setup_table']["$table_id-$i"]['column-4'] = array(
         '#type' => 'markup',
@@ -838,54 +802,172 @@ function tripal_views_integration_form($form, $form_state, $arg) {
         '#default_value' => $default_argument_handler,
       );
 
-      $default_relationship_handler = 0;
-      if (isset($setup_id)
-        && !isset($form_state['values']["fields_relationship_handler_$table_id-$i"])
-        && isset($default_handlers[$column_name]['relationship']))
-      {
-        $default_relationship_handler = $default_handlers[$column_name]['relationship']['handler_name'];
-        $form_state['values']["fields_relationship_handler_$table_id-$i"]=$default_relationship_handler;
-      }
-      else {
-        if (isset($form_state['values']["fields_relationship_handler_$table_id-$i"])) {
-          $default_relationship_handler = $form_state['values']["fields_relationship_handler_$table_id-$i"];
-        }
-        if (!$default_relationship_handler) {
-          if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
-            $default_relationship_handler = 'views_handler_relationship';
-          }
-          elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
-            $default_relationship_handler = 'views_handler_relationship';
-          }
-          elseif ($column_type == 'boolean') {
-            $default_relationship_handler = 'views_handler_relationship';
-          }
-          elseif ($column_type == 'float') {
-            $default_relationship_handler = 'views_handler_relationship';
-          }
-          elseif ($column_type == 'datetime') {
-            $default_relationship_handler = 'views_handler_relationship';
-          }
-        }
-      }
-      $form['view_setup_table']["$table_id-$i"]['column-4']["fields_relationship_handler_$table_id-$i"] = array(
+      $i++;
+    }
+
+    $form['view_setup_join'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Joins & Relationships'),
+      '#prefix' => '<div id="fieldset-join-rows-wrapper">',
+      '#suffix' => '</div>',
+      '#description' => t('Below is a list of the joins/relationships between the '
+        . 'current base table and other chado tables.'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE
+    );
+
+    $form['view_setup_join']['header'] = array(
+      '#type' => 'markup',
+      '#prefix' => '<div class="joins-new-row field-headers">',
+      '#suffix' => '</div>',
+    );
+
+    $form['view_setup_join']['header']['column-1'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"join-column-one\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Base'
+    );
+
+    $form['view_setup_join']['header']['column-2'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"join-column-two\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Handlers'
+    );
+
+    $form['view_setup_join']['header']['column-3'] = array(
+         '#type' => 'markup',
+         '#prefix' => "<div class=\"join-column-three\">",
+         '#suffix' => "</div>",
+         '#markup' => 'Joined to'
+    );
+
+    $base_field_options = array('Select the Base Column');
+    $table_desc = tripal_core_get_chado_table_schema($table_name);
+    foreach ($table_desc['fields'] as $column => $def) {
+      $base_field_options[$column] = $column;
+    }
+    $chado_join_tables[0] = 'Select the Left Table';
+    unset($handlers_join[0]);
+
+    $query = db_select('tripal_views_join','tvj');
+    $query->fields('tvj')
+      ->condition('tvj.setup_id',$setup_id,'=')
+      ->orderBy('tvj.relationship_only','ASC')
+      ->orderBy('tvj.base_field', 'ASC')
+      ->orderBy('tvj.left_table', 'ASC');
+    foreach ($query->execute() as $i => $result) {
+      $form['view_setup_join']["$table_id-$i"] = array(
+           '#type' => 'markup',
+           '#prefix' => "<div class=\"joins-new-row\">",
+           '#suffix' => "</div>",
+           '#value' => filter_xss('')
+      );
+
+      // COLUMN I
+      $form['view_setup_join']["$table_id-$i"]['column-1'] = array(
+           '#type' => 'markup',
+           '#prefix' => "<div class=\"join-column-one\">",
+           '#suffix' => "</div>",
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-1']['join_base_table'] = array(
+        '#type' => 'item',
+        '#markup' => '<span class="column-name">' . filter_xss($result->base_table) . '</span>'
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-1']["join_base_table-$i"] = array(
+        '#type' => 'hidden',
+        '#value' => $result->base_table
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-1']["join_base_field-$i"] = array(
+        '#type' => 'select',
+        '#options' => $base_field_options,
+        '#required' => FALSE,
+        '#default_value' => $result->base_field
+      );
+
+      // COLUMN II
+      $form['view_setup_join']["$table_id-$i"]['column-2'] = array(
+           '#type' => 'markup',
+           '#prefix' => "<div class=\"join-column-two\">",
+           '#suffix' => "</div>",
+           '#value' => filter_xss('')
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-2']["join_join_handler-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-join-handler\">",
+        '#suffix' => "</div>",
+        '#options' => $handlers_join,
+        '#required' => FALSE,
+        '#default_value' => $result->handler,
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-2']["join_relationship_handler-$i"] = array(
         '#type' => 'select',
         '#prefix' => "<div class=\"fields-relationship-handler\">",
         '#suffix' => "</div>",
         '#options' => $handlers_rel,
         '#required' => FALSE,
-        '#default_value' => $default_relationship_handler,
+        '#default_value' => $result->relationship_handler,
       );
 
-      $i++;
+      $form['view_setup_join']["$table_id-$i"]['column-2']["join_relationship_only-$i"] = array(
+        '#type' => 'checkbox',
+        '#title' => 'Relationship Only?',
+        '#default_value' => $result->relationship_only
+      );
+
+      // COLUMN III
+      $form['view_setup_join']["$table_id-$i"]['column-3'] = array(
+           '#type' => 'markup',
+           '#prefix' => "<div class=\"join-column-three\">",
+           '#suffix' => "</div>",
+           '#value' => filter_xss('')
+      );
+
+      $form['view_setup_join']["$table_id-$i"]['column-3']["join_left_table-$i"] = array(
+        '#type' => 'select',
+        '#options' => $chado_join_tables,
+        '#default_value' => $result->left_table,
+      );
+
+      $columns = array();
+      if ($result->left_table) {
+        // get the table description
+        $table_desc = tripal_core_get_chado_table_schema($result->left_table);
+        foreach ($table_desc['fields'] as $column => $def) {
+          $columns[$column] = $column;
+        }
+      }
+      else {
+        $columns = array('Select Left Column');
+      }
+      $form['view_setup_join']["$table_id-$i"]['column-3']["join_left_field-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "  <div id=\"fields-column-join-column-$table_id-$i\" class=\"fields-column-join-column\">",
+        '#suffix' => "</div>",
+        '#options' => $columns,
+        '#required' => FALSE,
+        '#default_value' => $result->left_field
+      );
     }
-    $form['view_setup_table']['save'] = array(
+
+    $form['num_joins'] = array(
+      '#type' => 'hidden',
+      '#value' => $i
+    );
+
+    $form['save'] = array(
       '#type'  => 'submit',
       '#value' => t('Save'),
     );
 
     $data['row_count'] = $i - 1;
-  }
+  } //end of if table/mview
 
   //use this to put values into $form_state['values']
   $form['data'] = array();
@@ -945,7 +1027,6 @@ function tripal_views_integration_form_validate($form, &$form_state) {
       .'views integrations created by core modules. Please set the priority between '
       .'0 and -10 to ensure your changes are used rather over the defaults.');
   }
-  // TODO: do we need to require that a handler be set for each field and each type of handler?
 }
 
 /**
@@ -1061,32 +1142,8 @@ function tripal_views_integration_form_submit($form, &$form_state) {
     );
     drupal_write_record('tripal_views_field', $view_field_record);
 
-    // first add the join if it exists
-    $left_table = $form_state['values']["fields_join_$table_id-$i"];
-    $left_column = $form_state['values']["fields_join_column_$table_id-$i"];
-
-    if ($left_column) {
-      if ($mview_id) {
-        $base_table = $mview->mv_table;
-      }
-      else {
-        $base_table = $table_name;
-      }
-      $view_join_record = array(
-        'setup_id' => $tripal_views_record['setup_id'],
-        'base_table' => $base_table,
-        'base_field' => $key,
-        'left_table' => $left_table,
-        'left_field' => $left_column,
-        'handler' => $form_state['values']["fields_join_handler_$table_id-$i"],
-      );
-
-      // write the new joins to the database
-      drupal_write_record('tripal_views_join', $view_join_record);
-    }
-
     // add the hanlders
-    $handlers = array('filter', 'field', 'sort', 'argument', 'join', 'relationship');
+    $handlers = array('filter', 'field', 'sort', 'argument');
 
     foreach ($handlers as $handler) {
       $handler_name = $form_state['values']["fields_" . $handler . "_handler_$table_id-$i"];
@@ -1103,6 +1160,21 @@ function tripal_views_integration_form_submit($form, &$form_state) {
     $i++;
   }
 
+  // Now add all the joins
+  for($i = 0; $i <= $form_state['values']['num_joins']; $i++) {
+    $join_record = array(
+      'setup_id' => $tripal_views_record['setup_id'],
+      'base_table' => $form_state['values']["join_base_table-$i"],
+      'base_field' => $form_state['values']["join_base_field-$i"],
+      'left_table' => $form_state['values']["join_left_table-$i"],
+      'left_field' => $form_state['values']["join_left_field-$i"],
+      'handler' => $form_state['values']["join_join_handler-$i"],
+      'relationship_handler' => $form_state['values']["join_relationship_handler-$i"],
+      'relationship_only' => $form_state['values']["join_relationship_only-$i"]
+    );
+    drupal_write_record('tripal_views_join', $join_record);
+  }
+
   if ($setup_id) {
     drupal_set_message(t('Record Updated'));
   }

+ 25 - 3
tripal_views/tripal_views_integration_fields_form.tpl.php

@@ -28,12 +28,14 @@
 
 #tripal-views-integration-form  .field-headers {
    font-weight: bold;
+   height: 15px;
 }
 
 #tripal-views-integration-form  .field-headers div {
    display: inline-block;
    margin: 0px;
    vertical-align: top;
+   padding-left: 15px;
 }
 
 #tripal-views-integration-form .column-name {
@@ -45,12 +47,16 @@
 }
 
 #tripal-views-integration-form .column-one {
-   width: 10%;
+   width: 30%;
    height: 50px;
 }
 
-#tripal-views-integration-form .column-two, .column-three, .column-four {
-   width: 25%;
+#tripal-views-integration-form .column-two, .column-four {
+   width: 30%;
+}
+
+#tripal-views-integration-form .column-three {
+   width: 0%;
 }
 
 #tripal-views-integration-form  .fields-new-row {
@@ -59,6 +65,22 @@
    padding-top: 10px;
 }
 
+#tripal-views-integration-form  .joins-new-row {
+   padding-bottom: 10px;
+   margin-bottom: 5px;
+   padding-top: 10px;
+   border-bottom-style: solid;
+   border-bottom-width: 1px;
+}
+
+#tripal-views-integration-form .join-column-one, .join-column-two, .join-column-three {
+   display: inline-block;
+   margin: 0px;
+   vertical-align: top;
+   margin-left: 15px;
+   width: 30%;
+}
+
 </style>
 
 <?php print drupal_render_children($form); ?>