Browse Source

Fixed to analys, organism and pub modules

Stephen Ficklin 11 years ago
parent
commit
ffedce1c5b

+ 10 - 327
tripal_analysis/includes/tripal_analysis.admin.inc

@@ -24,32 +24,6 @@ function tripal_analysis_admin() {
   // has a setting will be added.
   $form = array();
 
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync libraries
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_organism')) {
-    $active_jobs = TRUE;
-  }
-
-  // add the field set for syncing libraries
-  if (!$active_jobs) {
-    // add the field set for syncing analyses
-    get_tripal_analysis_admin_form_sync_set($form);
-//    get_tripal_analysis_admin_form_reindex_set($form);
-//    get_tripal_analysis_admin_form_taxonomy_set($form);
-    get_tripal_analysis_admin_form_cleanup_set($form);
-  }
-  else {
-    $form['notice'] = array(
-       '#type' => 'fieldset',
-       '#title' => t('Analysis Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-          '#value' => t('Currently, analysis management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
-    );
-  }
-
   // Add sub-module settings. Pull all sub-module information from
   // {tripal_analysis} table
   $sql = "SELECT modulename FROM {tripal_analysis}";
@@ -71,13 +45,19 @@ function tripal_analysis_admin() {
     if ($settings) {
       // Define a fieldset for the sub-module
       $form["field$counter"] = array(
-            '#type' => 'fieldset',
-            '#title' => "$settings->title",
-            '#collapsible' => TRUE
+        '#type' => 'fieldset',
+        '#title' => "$settings->title",
+        '#collapsible' => TRUE
       );
       $form["field$counter"]["$settings->title"] = $settings->form;
     }
-    $counter ++;
+    $counter++;
+  }
+  
+  if($counter == 0) {
+    $form['nothing'] = array(
+      '#markup' => t('There are currently no settings to configure. However, analysis extension modules may add items here when they are installed.')
+    );
   }
   return system_settings_form($form);
 }
@@ -184,121 +164,7 @@ function get_tripal_analysis_admin_form_reindex_set(&$form) {
   );
 }
 
-/**
- * The "Clean-up orphaned analysis & nodes" Form
- *
- * @param $form
- *  The administrative form as it is currently
- *
- * @return
- *  A form API array describing an administrative form
- *
- * @ingroup tripal_analysis
- */
-function get_tripal_analysis_admin_form_cleanup_set(&$form) {
-  $form['cleanup'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Clean Up')
-  );
-  $form['cleanup']['description'] = array(
-       '#type' => 'item',
-       '#value' => t("With Drupal and chado residing in different databases " .
-          "it is possible that nodes in Drupal and analyses in Chado become " .
-          "\"orphaned\".  This can occur if an analysis node in Drupal is " .
-          "deleted but the corresponding chado analysis is not and/or vice " .
-          "versa. Click the button below to resolve these discrepancies."),
-       '#weight' => 1,
-  );
-  $form['cleanup']['button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Clean up orphaned analyses'),
-      '#weight' => 2,
-  );
-}
-
-/**
- * The "sync Analysis in chado with drupal" form
- *
- * @param $form
- *  The administrative form as it is currently
- *
- * @return
- *  A form API array describing an administrative form
- *
- * @ingroup tripal_analysis
- */
-function get_tripal_analysis_admin_form_sync_set(&$form) {
-  // define the fieldsets
-  $form['sync'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Sync Analyses')
-  );
-
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync analyses
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_analysis')) {
-    $active_jobs = TRUE;
-  }
-
-  if (!$active_jobs) {
 
-    // get the list of analyses
-    $sql = "SELECT * FROM {analysis} ORDER BY name";
-    $ana_rset = chado_query($sql);
-
-    // if we've added any analyses to the list that can be synced
-    // then we want to build the form components to allow the user
-    // to select one or all of them.  Otherwise, just present
-    // a message stating that all analyses are currently synced.
-    $ana_boxes = array();
-    $added = 0;
-    while ($analysis = $ana_rset->fetchObject()) {
-      // check to see if the analysis is already present as a node in drupal.
-      // if so, then skip it.
-      $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
-      if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
-        $ana_boxes[$analysis->analysis_id] = "$analysis->name";
-        $added++;
-      }
-    }
-
-    // if we have analyses we need to add to the checkbox then
-    // build that form element
-    if ($added > 0) {
-      $ana_boxes['all'] = "All analyses";
-
-      $form['sync']['analyses'] = array(
-           '#title'       => t('Available analyses'),
-           '#type'        => t('checkboxes'),
-           '#description' => t("Check the analyses you want to sync.  Drupal " .
-              "content will be created for each of the analyses listed above. " .
-              "Select 'All analyses' to sync all of them."),
-           '#required'    => FALSE,
-           '#prefix'      => '<div id="ana_boxes">',
-           '#suffix'      => '</div>',
-           '#options'     => $ana_boxes,
-      );
-      $form['sync']['button'] = array(
-            '#type' => 'submit',
-            '#value' => t('Submit Sync Job')
-      );
-    }
-    // we don't have any analyses to select from
-    else {
-      $form['sync']['value'] = array(
-            '#value' => t('All analyses in Chado are currently synced with Drupal.')
-      );
-    }
-  }
-  // we don't want to present a form since we have an active job running
-  else {
-    $form['sync']['value'] = array(
-          '#value' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
-    );
-  }
-}
 
 /**
  * Validate the administrative form
@@ -315,37 +181,6 @@ function tripal_analysis_admin_validate($form, &$form_state) {
   global $user;  // we need access to the user info
   $job_args = array();
 
-  if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-    // check to see if the user wants to sync chado and drupal.  If
-    // so then we need to register a job to do so with tripal
-    $analyses = $form_state['values']['analyses'];
-    $do_all = FALSE;
-    $to_sync = array();
-
-    foreach ($analyses as $analysis_id) {
-      if (preg_match("/^all$/i", $analysis_id)) {
-        $do_all = TRUE;
-      }
-      if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
-        // get the list of analyses
-        $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
-        $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
-        $to_sync[$analysis_id] = $analysis->name;
-      }
-    }
-
-    // submit the job the tripal job manager
-    if ($do_all) {
-      tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
-    }
-    else{
-      foreach ($to_sync as $analysis_id => $name) {
-        $job_args[0] = $analysis_id;
-        tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
-      }
-    }
-  }
   // -------------------------------------
   // Submit the Reindex Job if selected
   if ($form_state['values']['op'] == t('Reindex Features')) {
@@ -381,156 +216,4 @@ function tripal_analysis_admin_validate($form, &$form_state) {
       }
     }
   }
-
-  // -------------------------------------
-  // Submit the Cleanup Job if selected
-  if ($form_state['values']['op'] == t('Clean up orphaned analyses')) {
-    tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis',
-         'tripal_analyses_cleanup', $job_args, $user->uid);
-  }
-}
-
-/**
- * Synchronize analyses from chado to drupal
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
-  global $user;
-  $page_content = '';
-
-  if (!$analysis_id) {
-    $sql = "SELECT Analysis_id, name, description, program, " .
-        "  programversion, algorithm, sourcename, sourceversion, sourceuri, " .
-          "  timeexecuted " .
-          "FROM {analysis} ";
-    $results = chado_query($sql);
-  }
-  else {
-    $sql = "SELECT Analysis_id, name, description, program, " .
-         "  programversion, algorithm, sourcename, sourceversion, sourceuri, " .
-          "  timeexecuted " .
-          "FROM {analysis} " .
-          "WHERE analysis_id = :analysis_id";
-    $results = chado_query($sql, array(':analysis_id' => $analysis_id));
-  }
-
-
-  // We'll use the following SQL statement for checking if the analysis
-  // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_analysis} " .
-          "WHERE analysis_id = :analysis_id";
-
-  while ($analysis = $results->fetchObject()) {
-        print "syncing analysis ";
-        print $analysis->name;
-        print ", ";
-        print $analysis->analysis_id;
-        print "\n";
-
-    // check if this analysis already exists in the drupal database. if it
-    // does then skip this analysis and go to the next one.
-    if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
-
-      $new_node = new stdClass();
-
-      // try to access analysis type for this analysis
-      $sql = "SELECT * FROM {analysisprop}
-                    WHERE analysis_id = :analysis_id
-                    AND type_id =
-                        (SELECT cvterm_id from {cvterm} where name = :name)
-            ";
-      $analysis_type = chado_query($sql, array(':analysis_id' => $analysis->analysis_id, ':name' => "analysis_type"))->fetchObject();
-
-      // Get the type of analysis using cvterm_id
-            // Current possibilities: kegg, unigene, interpro, blast
-      if ($analysis_type) {
-
-        // This is a unigene analysis
-        if ($analysis_type->value == 'tripal_analysis_unigene') {
-          $new_node->type = 'chado_analysis_unigene';
-        // This is a blast analysis
-        }
-        elseif ($analysis_type->value == 'tripal_analysis_blast') {
-          $new_node->type = 'chado_analysis_blast';
-         // This is a interpro analysis
-        }
-        elseif ($analysis_type->value == 'tripal_analysis_interpro') {
-          $new_node->type = 'chado_analysis_interpro';
-         // This is a kegg analysis
-        }
-        elseif ($analysis_type->value == 'tripal_analysis_kegg' ) {
-          $new_node->type = 'chado_analysis_kegg';
-        }
-        else {
-          $new_node->type = 'chado_analysis';
-        }
-      // If it doesn't exist, this analysis is generic
-      }
-      else {
-        $new_node->type = 'chado_analysis';
-      }
-
-      print "analysis type is $new_node->type\n";
-
-      $new_node->uid = $user->uid;
-      $new_node->analysis_id = $analysis->analysis_id;
-      $new_node->analysisname = $analysis->name;
-      $new_node->description = $analysis->description;
-      $new_node->program = $analysis->program;
-      $new_node->programversion = $analysis->programversion;
-      $new_node->algorithm = $analysis->algorithm;
-      $new_node->sourcename = $analysis->sourcename;
-      $new_node->sourceversion = $analysis->sourceversion;
-      $new_node->sourceuri = $analysis->sourceuri;
-      $new_node->timeexecuted = $analysis->timeexecuted;
-
-      // If the analysis has a name, use it as the node title. If not,
-      // construct the title using program, programversion, and sourcename
-      if ($new_node->analysisname) {
-        $new_node->title = $new_node->analysisname;
-      }
-      else {
-        //Construct node title as "program (version)"
-        $new_node->title = "$analysis->program ($analysis->programversion)";
-      }
-
-      node_validate($new_node);
-
-            $errors = form_get_errors();
-
-            if ($errors) {
-                print_r($errors);
-            }
-            else{
-      // if(!form_get_errors()){
-        $node = node_submit($new_node);
-        node_save($node);
-
-        if ($node->nid) {
-          $page_content .= "Added $new_node->title<br />";
-        }
-      }
-    }
-    else {
-      $page_content .= "Skipped $new_node->title<br />";
-    }
-  }
-  return $page_content;
 }
-
-/**
- * Remove orphaned drupal nodes
- *
- * @param $dummy
- *   Not Used -kept for backwards compatibility
- * @param $job_id
- *   The id of the tripal job executing this function
- *
- * @ingroup tripal_analysis
- */
-function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
-
-  return tripal_core_clean_orphaned_nodes('analysis', $job_id);
-  
-}

+ 8 - 1
tripal_analysis/includes/tripal_analysis.form.inc

@@ -231,7 +231,14 @@ function chado_analysis_validate($node, &$form) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_validate($node, &$form) {
-  
+  $node->analysisname = trim($node->analysisname);
+  $node->description = trim($node->description);
+  $node->program = trim($node->program);
+  $node->programversion = trim($node->programversion);
+  $node->algorithm = trim($node->algorithm);
+  $node->sourcename = trim($node->sourcename);
+  $node->sourceversion = trim($node->sourceversion);
+  $node->sourceuri = trim($node->sourceuri);
  
   // Only nodes being updated will have an nid already
   if (!is_null($node->nid)) {    

+ 270 - 0
tripal_analysis/includes/tripal_analysis.sync.inc

@@ -0,0 +1,270 @@
+<?php 
+
+/**
+ * 
+ */
+function tripal_analysis_sync_form () {
+  $form = array();
+  
+  get_tripal_analysis_admin_form_sync_set($form);
+  get_tripal_analysis_admin_form_cleanup_set($form);
+  
+  return $form;
+}
+
+/**
+ * Validate the administrative form
+ * @todo Stephen: Why is validate used rather then submit?
+ *
+ * @param $form
+ *   The form API array of the form to be validated
+ * @form_state
+ *   The user submitted values
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_sync_form_submit($form, &$form_state) {
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  if ($form_state['values']['op'] == t('Submit Sync Job')) {
+
+    // check to see if the user wants to sync chado and drupal.  If
+    // so then we need to register a job to do so with tripal
+    $analyses = $form_state['values']['analyses'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($analyses as $analysis_id) {
+      if (preg_match("/^all$/i", $analysis_id)) {
+        $do_all = TRUE;
+      }
+      if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
+        // get the list of analyses
+        $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
+        $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
+        $to_sync[$analysis_id] = $analysis->name;
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
+    }
+    else{
+      foreach ($to_sync as $analysis_id => $name) {
+        $job_args[0] = $analysis_id;
+        tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
+      }
+    }
+  }  
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned analyses')) {
+    tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis',
+    'tripal_analyses_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * The "Clean-up orphaned analysis & nodes" Form
+ *
+ * @param $form
+ *  The administrative form as it is currently
+ *
+ * @return
+ *  A form API array describing an administrative form
+ *
+ * @ingroup tripal_analysis
+ */
+function get_tripal_analysis_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#markup' => t("With Drupal and chado residing in different databases " .
+        "it is possible that nodes in Drupal and analyses in Chado become " .
+        "\"orphaned\".  This can occur if an analysis node in Drupal is " .
+        "deleted but the corresponding chado analysis is not and/or vice " .
+        "versa. Click the button below to resolve these discrepancies."),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned analyses'),
+    '#weight' => 2,
+  );
+}
+
+/**
+ * The "sync Analysis in chado with drupal" form
+ *
+ * @param $form
+ *  The administrative form as it is currently
+ *
+ * @return
+ *  A form API array describing an administrative form
+ *
+ * @ingroup tripal_analysis
+ */
+function get_tripal_analysis_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync Analyses')
+  );
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync analyses
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_analysis')) {
+    $active_jobs = TRUE;
+  }
+
+  if (!$active_jobs) {
+
+    // get the list of analyses
+    $sql = "SELECT * FROM {analysis} ORDER BY name";
+    $ana_rset = chado_query($sql);
+
+    // if we've added any analyses to the list that can be synced
+    // then we want to build the form components to allow the user
+    // to select one or all of them.  Otherwise, just present
+    // a message stating that all analyses are currently synced.
+    $ana_boxes = array();
+    $added = 0;
+    while ($analysis = $ana_rset->fetchObject()) {
+      // check to see if the analysis is already present as a node in drupal.
+      // if so, then skip it.
+      $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
+      if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
+        $ana_boxes[$analysis->analysis_id] = "$analysis->name";
+        $added++;
+      }
+    }
+
+    // if we have analyses we need to add to the checkbox then
+    // build that form element
+    if ($added > 0) {
+      $ana_boxes['all'] = "All analyses";
+
+      $form['sync']['analyses'] = array(
+        '#title'       => t('Available analyses'),
+        '#type'        => t('checkboxes'),
+        '#description' => t("Check the analyses you want to sync.  Drupal " .
+            "content will be created for each of the analyses listed above. " .
+            "Select 'All analyses' to sync all of them."),
+        '#required'    => FALSE,
+        '#prefix'      => '<div id="ana_boxes">',
+        '#suffix'      => '</div>',
+        '#options'     => $ana_boxes,
+      );
+      $form['sync']['button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Submit Sync Job')
+      );
+    }
+    // we don't have any analyses to select from
+    else {
+      $form['sync']['value'] = array(
+        '#markup' => t('All analyses in Chado are currently synced with Drupal.')
+      );
+    }
+  }
+  // we don't want to present a form since we have an active job running
+  else {
+    $form['sync']['value'] = array(
+      '#markup' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
+    );
+  }
+}
+
+/**
+ * Synchronize analyses from chado to drupal
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$analysis_id) {
+    $sql = "SELECT * FROM {analysis}";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
+    $results = chado_query($sql, array(':analysis_id' => $analysis_id));
+  }
+
+  // We'll use the following SQL statement for checking if the analysis
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
+
+  foreach ($results as $analysis) {
+
+    // check if this analysis already exists in the drupal database. if it
+    // does then skip this analysis and go to the next one.
+    if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_analysis';
+      $new_node->uid = $user->uid;
+      $new_node->analysis_id    = $analysis->analysis_id;
+      $new_node->analysisname   = $analysis->name;
+      $new_node->description    = $analysis->description;
+      $new_node->program        = $analysis->program;
+      $new_node->programversion = $analysis->programversion;
+      $new_node->algorithm      = $analysis->algorithm;
+      $new_node->sourcename     = $analysis->sourcename;
+      $new_node->sourceversion  = $analysis->sourceversion;
+      $new_node->sourceuri      = $analysis->sourceuri;
+      $new_node->timeexecuted   = $analysis->timeexecuted;
+
+      // If the analysis has a name, use it as the node title. If not,
+      // construct the title using program, programversion, and sourcename
+      if ($new_node->analysisname) {
+        $new_node->title = $new_node->analysisname;
+      }
+      else {
+        // Construct node title as "program (version)"
+        $new_node->title = "$analysis->program ($analysis->programversion)";
+      }
+      
+      $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);
+        if ($node->nid) {
+          print "Added $new_node->title\n";
+        }
+      }
+      else {
+        print "Failed to insert organism $organism->common_name\n";
+      }
+    }
+    else {
+      $page_content .= "Skipped $new_node->title<br />";
+    }
+  }
+  return $page_content;
+}
+
+/**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('analysis', $job_id);
+
+}

+ 0 - 0
tripal_analysis/theme/tripal_analysis_admin.tpl.php → tripal_analysis/theme/tripal_analysis_help.tpl.php


+ 2 - 15
tripal_analysis/tripal_analysis.install

@@ -83,17 +83,7 @@ function tripal_analysis_create_analysisfeatureprop() {
 function tripal_analysis_add_cvterms() {
   
   tripal_cv_add_cv('tripal_analysis', 'Terms used for managing analyses in Tripal');
-  
-  // add analysis_type. This goes in the 'tripal_analysis' CV so that site admins
-  // change change this property
-  $term = array(
-    'name' => 'analysis_type', 
-    'def' => 'The type of analysis was performed. This value is automatically set by ' .
-             'each Tripal Analysis module and should be equal to the module name ' .
-             '(e.g. tripal_analysis_blast, tripal_analysis_go).'
-  );
-  tripal_cv_add_cvterm($term, 'tripal_analysis', 0, 1, 'tripal');
-  
+
   // add analysis_date.  This is no longer used (as far as we can tell) but we don't
   // get rid of it in case it is used, so just keep it in the Tripal CV
   $term = array(
@@ -111,10 +101,7 @@ function tripal_analysis_add_cvterms() {
   tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal');     
   
   
-  // the 'analysis_property' vocabulary is for user definable properties.  Even though we already have
-  // an analysis_type term in the 'tripal_analysis' vocabular we duplicate it here because the 
-  // tripal_analysis vocabulary is intended for use by the extension modules.  user's should not be able
-  // to directly modify properties set by extension modules for an analysis.
+  // the 'analysis_property' vocabulary is for user definable properties.
   tripal_cv_add_cvterm(array('name' => 'Analysis Type', 'def' => 'The type of analysis was performed.'), 
      'analysis_property', 0, 1, 'tripal');
 }

+ 253 - 248
tripal_analysis/tripal_analysis.module

@@ -18,6 +18,7 @@ require('api/tripal_analysis.api.inc');
 require('includes/tripal_analysis_privacy.inc');
 require('includes/tripal_analysis.admin.inc');
 require('includes/tripal_analysis.form.inc');
+require('includes/tripal_analysis.sync.inc');
 
 
 /**
@@ -57,40 +58,45 @@ function tripal_analysis_node_info() {
 function tripal_analysis_menu() {
   //Sync analysis
   $items['chado_sync_analyses'] = array(
-     'title' => 'Sync Data',
-     'page callback' => 'tripal_analysis_sync_analyses',
-     'access arguments' => array('administer tripal analyses'),
-     'type' => MENU_CALLBACK
+    'title' => 'Sync Data',
+    'page callback' => 'tripal_analysis_sync_analyses',
+    'access arguments' => array('administer tripal analyses'),
+    'type' => MENU_CALLBACK
   );
   // Tripal Analysis administrative settings
   $items['admin/tripal/chado/tripal_analysis'] = array(
-      'title' => 'Analyses',
-      'description' => 'A bioinformatics analysis producing features.',
-      'access arguments' => array('administer tripal analyses'),
-      'type' => MENU_NORMAL_ITEM,
+    'title' => 'Analyses',
+    'description' => 'A bioinformatics analysis producing features.',
+    'access arguments' => array('administer tripal analyses'),
+    'type' => MENU_NORMAL_ITEM,
   );
 
   $items['admin/tripal/chado/tripal_analysis/help'] = array(
-      'title' => 'Help',
-      'description' => "A description of the Tripal Analysis module including a short description of it's usage.",
-      'page callback' => 'theme',
-      'page arguments' => array('tripal_analysis_help'),
-      'access arguments' => array('administer tripal analyses'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'includes/tripal_analysis.admin.inc',
-      'weight' => 10
+    'title' => 'Help',
+    'description' => "A description of the Tripal Analysis module including a short description of it's usage.",
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_analysis_help'),
+    'access arguments' => array('administer tripal analyses'),
+    'type' => MENU_NORMAL_ITEM,
   );
 
   $items['admin/tripal/chado/tripal_analysis/configuration'] = array(
-      'title' => 'Configuration',
-      'description' => 'Settings for the displays of analysis results.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_analysis_help'),
-      'access arguments' => array('administer tripal analyses'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'includes/tripal_analysis.admin.inc',
+    'title' => 'Configuration',
+    'description' => 'Settings for the displays of analysis results.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_analysis_admin'),
+    'access arguments' => array('administer tripal analyses'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  
+  $items['admin/tripal/chado/tripal_analysis/sync'] = array(
+    'title' => 'Sync Analyses',
+    'description' => 'Sync Chado analyses with Drupal.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_analysis_sync_form'),
+    'access arguments' => array('administer tripal analyses'),
+    'type' => MENU_NORMAL_ITEM,
   );
-
 
   $items['tripal_analysis/properties/minus/%/%'] = array(
     'page callback' => 'tripal_analysis_property_delete',
@@ -114,34 +120,197 @@ function tripal_analysis_help ($path, $arg) {
 }
 
 /**
- *  When a new chado_analysis node is created we also need to add information
- *  to our chado_analysis table.  This function is called on insert of a new
- *  node of type 'chado_analysis' and inserts the necessary information.
+ *  Set the permission types that the chado module uses.  Essentially we
+ *  want permissionis that protect creation, editing and deleting of chado
+ *  data objects
  *
  * @ingroup tripal_analysis
  */
-function chado_analysis_insert($node) {
-  global $user;
+function tripal_analysis_permission() {
+  return array(
+    'access chado_analysis content' => array(
+      'title' => t('View Analyses'),
+      'description' => t('Allow users to view analysis pages.'),
+    ),
+    'create chado_analysis content' => array(
+      'title' => t('Create Analyses'),
+      'description' => t('Allow users to create new analysis pages.'),
+    ),
+    'delete chado_analysis content' => array(
+      'title' => t('Delete Analyses'),
+      'description' => t('Allow users to delete analysis pages.'),
+    ),
+    'edit chado_analysis content' => array(
+      'title' => t('Edit Analyses'),
+      'description' => t('Allow users to edit analysis pages.'),
+    ),
+    'adminster tripal analysis' => array(
+      'title' => t('Administer Analyses'),
+      'description' => t('Allow users to administer all analyses.'),
+    ),
+  );
+}
 
-  // Create a timestamp so we can insert it into the chado database
-  $time  = $node->timeexecuted;
-  $month = $time['month'];
-  $day   = $time['day'];
-  $year  = $time['year'];
-  $timestamp = $month . '/' . $day . '/' . $year;
+/**
+ *  We need to let drupal know about our theme functions and their arguments.
+ *  We create theme functions to allow users of the module to customize the
+ *  look and feel of the output generated in this module
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+
+  $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
+  $items = array(
+    'node__chado_analysis' => array(
+      'template' => 'node--chado-generic',
+      'render element' => 'node',
+      'base hook' => 'node',
+      'path' => "$core_path/theme",
+    ),
+    'tripal_analysis_base' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_analysis_base',
+      'path' => "$path/theme/tripal_analysis",
+    ),
+    'tripal_feature_analyses' => array(
+      'template' => 'tripal_feature_analyses',
+      'variables' =>  array('node' => NULL),
+      'path' => "$path/theme/tripal_analysis",
+    ),
+    'tripal_analysis_properties' => array(
+      'variables' => array('node' => NULL),
+      'path' => "$path/theme/tripal_analysis",
+    ),
+    'tripal_analysis_help' => array(
+      'template' => 'tripal_analysis_help',
+      'variables' =>  array(NULL),
+      'path' => "$path/theme",
+    ),
+    'chado_analysis_node_form' => array(
+      'variables' => array('form'),
+      'path' => $theme_path,
+    ),
+  );
+
+  return $items;
+}
+/**
+ *
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_block_info() {
+  $blocks['base']['info'] = t('Tripal Analysis Details');
+  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
+
+  $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
+  $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
+
+  return $blocks;
+}
+
+/**
+ *
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_block_view($delta = '') {
+
+  if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
+    $nid = arg(1);
+    $node = node_load($nid);
 
-  // If this analysis already exists then don't recreate it in chado
-  $analysis_id = $node->analysis_id;
-  if ($analysis_id) {
-    $values = array('analysis_id' => $node->analysis_id);
-    $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
-    if ($result and count($result) > 0) {
-      $analysis = $result[0];
+    $block = array();
+    switch ($delta) {
+      case 'base':
+        $block['subject'] = t('Analysis Details');
+        $block['content'] = theme('tripal_analysis_base', $node);
+        break;
+      case 'tripal_feature_analyses':
+        $block['subject'] = t('Feature Analyses');
+        $block['content'] = theme('tripal_feature_analyses', $node);
+        break;
+      default :
     }
+    return $block;
   }
+}
+
+/**
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_analysis_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'chado_analysis':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_analysis_base'] = array(
+          '#value' => theme('tripal_analysis_base', array('node' => $node)),
+        );
+        $node->content['tripal_analysis_properties'] = array(
+          '#value' => theme('tripal_analysis_properties', array('node' => $node)),
+        );
+      }
+      break;
+  }
+}
+/**
+ * Implements hook_views_api()
+ * Purpose: Essentially this hook tells drupal that there is views support for
+ *  for this module which then includes tripal_analysis.views.inc where all the
+ *  views integration code is
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_views_api() {
+  return array(
+    'api' => 2.0,
+  );
+}
+
+
+
+
+/*
+ *
+*/
+function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == "chado_analysis_node_form") {
+  }
+}
+/**
+ *  When a new chado_analysis node is created we also need to add information
+ *  to our chado_analysis table.  This function is called on insert of a new
+ *  node of type 'chado_analysis' and inserts the necessary information.
+ *
+ * @ingroup tripal_analysis
+ */
+function chado_analysis_insert($node) {
 
-  // If the analysis doesn't exist then let's create it in chado.
-  if (!$analysis) {
+  $node->analysisname = trim($node->analysisname);
+  $node->description = trim($node->description);
+  $node->program = trim($node->program);
+  $node->programversion = trim($node->programversion);
+  $node->algorithm = trim($node->algorithm);
+  $node->sourcename = trim($node->sourcename);
+  $node->sourceversion = trim($node->sourceversion);
+  $node->sourceuri = trim($node->sourceuri);
+  
+  // if there is an analysis_id in the $node object then this must be a sync so
+  // we can skip adding the analysis as it is already there, although
+  // we do need to proceed with the rest of the insert
+  if (!property_exists($node,'analysis_id')) {
+    
+    // Create a timestamp so we can insert it into the chado database
+    $time  = $node->timeexecuted;
+    $month = $time['month'];
+    $day   = $time['day'];
+    $year  = $time['year'];
+    $timestamp = $month . '/' . $day . '/' . $year;
+    
     // insert and then get the newly inserted analysis record
     $values = array(
       'name'           => $node->analysisname,
@@ -154,37 +323,28 @@ function chado_analysis_insert($node) {
       'sourceuri'      => $node->sourceuri,
       'timeexecuted'   => $timestamp
     );
-    if (tripal_core_chado_insert('analysis', $values)) {
-      $analysis = tripal_core_chado_select('analysis', array('*'), $values);
-      $analysis_id = $analysis[0]->analysis_id;
+    $analysis = tripal_core_chado_insert('analysis', $values);
+    if (!$analysis) {
+      drupal_set_message(t('Unable to add analysis.', 'warning'));
+      watchdog('tripal_analysis', 'Insert analysis: Unable to create analysis where values:%values',
+      array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
+      return;
     }
+    $analysis_id = $analysis['analysis_id'];
   }
-
+  else {
+    $analysis_id = $node->analysis_id;
+  }
+  
   // Make sure the entry for this analysis doesn't already exist in the
   // chado_analysis table if it doesn't exist then we want to add it.
-  $node_check_sql = "SELECT * FROM {chado_analysis} " .
-                    "WHERE analysis_id = :analysis_id";
-  $node_check = db_query($node_check_sql, array(':analysis_id' => $analysis_id))->fetchObject();
-  if (!$node_check) {
-    // next add the item to the drupal table
-    $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) " .
-           "VALUES (:nid, :vid, :analysis_id)";
-    db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':analysis_id' => $analysis_id));
-    // Create a title for the analysis node using the unique keys so when the
-    // node is saved, it will have a title
+  $check_org_id = chado_get_id_for_node('analysis', $node->nid);  
+  if (!$check_org_id) {
     $record = new stdClass();
-    // If the analysis has a name, use it as the node title. If not, construct
-    // the title using program, programversion, and sourcename
-    if ($node->analysisname) {
-      $record->title = $node->analysisname;
-    }
-    else {
-      //Construct node title as "program (version)
-      $record->title = "$node->program ($node->programversion)";
-    }
     $record->nid = $node->nid;
-    drupal_write_record('node', $record, 'nid');
-    drupal_write_record('node_revisions', $record, 'nid');
+    $record->vid = $node->vid;
+    $record->analysis_id = $analysis_id;
+    drupal_write_record('chado_analysis', $record);
   }
 
   // add the analysis to the node object for
@@ -261,17 +421,11 @@ function chado_analysis_delete($node) {
   }
 
   // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
-  $sql_del = "DELETE FROM {chado_analysis} " .
-              "WHERE nid = :nid " .
-              "AND vid = :vid";
+  $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
   db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node} " .
-              "WHERE nid = :nid " .
-              "AND vid = :vid";
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
   db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node_revision} " .
-              "WHERE nid = :nid " .
-              "AND vid = :vid";
+  $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
   db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 
   //Remove from analysis and analysisprop tables of chado database as well
@@ -287,7 +441,15 @@ function chado_analysis_delete($node) {
  * @ingroup tripal_analysis
  */
 function chado_analysis_update($node) {
-  global $user;
+  $node->analysisname = trim($node->analysisname);
+  $node->description = trim($node->description);
+  $node->program = trim($node->program);
+  $node->programversion = trim($node->programversion);
+  $node->algorithm = trim($node->algorithm);
+  $node->sourcename = trim($node->sourcename);
+  $node->sourceversion = trim($node->sourceversion);
+  $node->sourceuri = trim($node->sourceuri);
+    
   if ($node->revision) {
     // TODO -- decide what to do about revisions
   }
@@ -429,17 +591,21 @@ function chado_analysis_update($node) {
   *
   * @ingroup tripal_analysis
   */
-function chado_analysis_load($node) {
+function chado_analysis_load($nodes) {
 
-   // get the feature details from chado
-  $analysis_id = chado_get_id_for_node('analysis', $node->nid);
+  foreach ($nodes as $nid => $node) {
+    // find the analysis and add in the details
+    $analysis_id = chado_get_id_for_node('analysis', $nid);
 
-  $values = array('analysis_id' => $analysis_id);
-  $analysis = tripal_core_generate_chado_var('analysis', $values);
+    // build the analysis variable
+    $values = array('analysis_id' => $analysis_id);
+    $analysis = tripal_core_generate_chado_var('analysis', $values);
+    
 
-  $additions = new stdClass();
-  $additions->analysis = $analysis;
-  return $additions;
+    // add in the description field
+    $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
+    $nodes[$nid]->analysis = $analysis;
+  }
 }
 
 /**
@@ -515,164 +681,3 @@ function chado_analysis_node_access($node, $op, $account) {
   return NULL;
 }
 
-/**
- *  Set the permission types that the chado module uses.  Essentially we
- *  want permissionis that protect creation, editing and deleting of chado
- *  data objects
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_permission() {
-  return array(
-    'access chado_analysis content' => array(
-      'title' => t('View Analyses'),
-      'description' => t('Allow users to view analysis pages.'),
-    ),
-    'create chado_analysis content' => array(
-      'title' => t('Create Analyses'),
-      'description' => t('Allow users to create new analysis pages.'),
-    ),
-    'delete chado_analysis content' => array(
-      'title' => t('Delete Analyses'),
-      'description' => t('Allow users to delete analysis pages.'),
-    ),
-    'edit chado_analysis content' => array(
-      'title' => t('Edit Analyses'),
-      'description' => t('Allow users to edit analysis pages.'),
-    ),
-    'adminster tripal analysis' => array(
-      'title' => t('Administer Analyses'),
-      'description' => t('Allow users to administer all analyses.'),
-    ),
-  );
-}
-
-/**
- *  We need to let drupal know about our theme functions and their arguments.
- *  We create theme functions to allow users of the module to customize the
- *  look and feel of the output generated in this module
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_theme($existing, $type, $theme, $path) {
-  $core_path = drupal_get_path('module', 'tripal_core');
-  
-  $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
-  $items = array(
-    'node__chado_analysis' => array(
-      'template' => 'node--chado-generic',
-      'render element' => 'node',
-      'base hook' => 'node',
-      'path' => "$core_path/theme",
-    ),
-    'tripal_analysis_base' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_analysis_base',
-      'path' => "$path/theme/tripal_analysis",
-    ),
-    'tripal_feature_analyses' => array(
-      'template' => 'tripal_feature_analyses',
-      'variables' =>  array('node' => NULL),
-      'path' => "$path/theme/tripal_analysis",
-    ),
-   'tripal_analysis_properties' => array(
-     'variables' => array('node' => NULL),
-     'path' => "$path/theme/tripal_analysis",
-    ),
-    'tripal_analysis_help' => array(
-      'template' => 'tripal_analysis_help',
-      'variables' =>  array(NULL),
-      'path' => "$path/theme",
-    ),
-    'chado_analysis_node_form' => array(
-      'variables' => array('form'),
-      'path' => $theme_path,
-    ),
-  );
-
-  return $items;
-}
-/**
- *
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_block_info() {
-  $blocks['base']['info'] = t('Tripal Analysis Details');
-  $blocks['base']['cache'] = DRUPAL_NO_CACHE;
-
-  $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
-  $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
-
-  return $blocks;
-}
-
-/**
- *
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_block_view($delta = '') {
-
-  if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
-    $nid = arg(1);
-    $node = node_load($nid);
-
-    $block = array();
-    switch ($delta) {
-      case 'base':
-        $block['subject'] = t('Analysis Details');
-        $block['content'] = theme('tripal_analysis_base', $node);
-        break;
-      case 'tripal_feature_analyses':
-        $block['subject'] = t('Feature Analyses');
-        $block['content'] = theme('tripal_feature_analyses', $node);
-        break;
-      default :
-    }
-    return $block;
-  }
-}
-
-/**
- *
- * Implements hook_node_view()
- */
-function tripal_analysis_node_view($node, $view_mode, $langcode) {
-  if ($node->type == 'chado_feature') {
-    if ($view_mode == 'search_index') {
-       // return results for searching
-    }
-    if ($view_mode == 'full') {
-       // return normal results
-       $node->content['tripal_feature_analyses'] = array(
-         '#markup' => theme('tripal_feature_analyses',  $node),
-       );
-    }
-  }
-}
-
-/**
- * Implements hook_views_api()
- * Purpose: Essentially this hook tells drupal that there is views support for
- *  for this module which then includes tripal_analysis.views.inc where all the
- *  views integration code is
- *
- * @ingroup tripal_analysis
- */
-function tripal_analysis_views_api() {
-    return array(
-    'api' => 2.0,
-  );
-}
-
-
-
-
-/*
- *
- */
-function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == "chado_analysis_node_form") {
-  }
-}

+ 1 - 2
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -17,8 +17,7 @@
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_modify_template_base_form($form, $form_state = NULL, $mode) {
-
+function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL, $mode) {
   // set the breadcrumb
   $breadcrumb = array();
   $breadcrumb[] = l('Home', '<front>');

+ 2 - 3
tripal_organism/includes/organism_sync.inc

@@ -149,7 +149,7 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
   $page_content = '';
 
   if (!$organism_id) {
-    $sql = "SELECT * FROM {Organism} O";
+    $sql = "SELECT * FROM {organism} O";
     $results = chado_query($sql);
   }
   else {
@@ -159,8 +159,7 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
 
   // 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 = :organism_id";
+  $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
 
   foreach ($results as $organism) {
 

+ 1 - 1
tripal_organism/includes/tripal_organism.admin.inc

@@ -91,7 +91,7 @@ function get_tripal_organism_admin_form_reindex_set(&$form) {
   $form['reindex']['re-organisms'] = array(
     '#title'       => t('Organisms'),
     '#type'        => t('checkboxes'),
-    '#description' => t("Check the organisms whoee features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
+    '#description' => t("Check the organisms whose features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
     '#required'    => FALSE,
     '#prefix'      => '<div id="lib_boxes">',
     '#suffix'      => '</div>',

+ 85 - 88
tripal_organism/tripal_organism.module

@@ -185,11 +185,86 @@ function tripal_organism_theme($existing, $type, $theme, $path) {
     'tripal_organism_help' => array(
       'template' => 'tripal_organism_help',
       'arguments' =>  array(NULL),
-      'path' => $path,
+      'path' => "$path/theme",
     ),
   );
   return $items;
 }
+/**
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_organism_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+  	case 'chado_organism':
+  	  // Show feature browser and counts
+  	  if ($view_mode == 'full') {
+  	    $node->content['tripal_organism_base'] = array(
+  	      '#value' => theme('tripal_organism_base', array('node' => $node)),
+  	    );
+  	  }
+  	  break;
+  }
+}
+/**
+  *  Set the permission types that the chado module uses.  Essentially we
+  *  want permissionis that protect creation, editing and deleting of chado
+  *  data objects
+  *
+  *
+  @ingroup tripal_organism
+  */
+function tripal_organism_permission() {
+  return array(
+    '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.'),
+    ),
+  );
+}
+/**
+ * Implements hook_views_api()
+ * Purpose: Essentially this hook tells drupal that there is views support for
+ *  for this module which then includes tripal_db.views.inc where all the
+ *  views integration code is
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_views_api() {
+  return array(
+    'api' => 2.0,
+  );
+}
+/**
+ *
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_job_describe_args($callback, $args) {
+
+  $new_args = array();
+  if ($callback == 'tripal_organism_sync_organisms') {
+    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
+    $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
+  }
+  return $new_args;
+}
 /**
  * Implement hook_access().
  *
@@ -234,43 +309,10 @@ function chado_organism_node_access($node, $op, $account) {
   if ($op == 'view') {
     if (!user_access('access chado_organism content', $account)) {
       return FALSE;
-      }
+    }
   }
   return NULL;
 }
-/**
-  *  Set the permission types that the chado module uses.  Essentially we
-  *  want permissionis that protect creation, editing and deleting of chado
-  *  data objects
-  *
-  *
-  @ingroup tripal_organism
-  */
-function tripal_organism_permission() {
-  return array(
-    '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.'),
-    ),
-  );
-}
-
 /**
  * Implementation of hook_validate
  *
@@ -341,19 +383,18 @@ function chado_organism_insert($node) {
   $node->abbreviation = trim($node->abbreviation);
   $node->common_name  = trim($node->common_name);
   $node->description  = trim($node->description);
-
-  $values = array(
-    'genus'        => $node->genus,
-    'species'      => $node->species,
-    'abbreviation' => $node->abbreviation,
-    '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
   // we do need to proceed with the rest of the insert
   if (!property_exists($node,'organism_id')) {
+    $values = array(
+      'genus'        => $node->genus,
+      'species'      => $node->species,
+      'abbreviation' => $node->abbreviation,
+      'common_name'  => $node->common_name,
+      'comment'      => $node->description
+    );
     $organism = tripal_core_chado_insert('organism', $values);
     if (!$organism) {
       drupal_set_message(t('Unable to add organism.', 'warning'));
@@ -466,22 +507,7 @@ function chado_organism_delete($node) {
       "library or feature depends on this organism. It was not removed from chado."));
   }
 }
-/**
- *
- * @ingroup tripal_feature
- */
-function tripal_organism_node_view($node, $view_mode, $langcode) {
-  switch ($node->type) {
-    case 'chado_organism':
-      // Show feature browser and counts
-      if ($view_mode == 'full') {
-        $node->content['tripal_organism_base'] = array(
-          '#value' => theme('tripal_organism_base', array('node' => $node)),
-        );
-      }
-      break;
-  }
-}
+
 /**
  *
  *
@@ -583,7 +609,6 @@ function chado_organism_form($node, $form_state) {
     '#type' => 'textarea',
     '#rows' => 15,
     '#title' => t('Description'),
-    '#required' => TRUE,
     '#default_value' => $description,
   );
   $form['organism_image']= array(
@@ -617,31 +642,3 @@ function chado_organism_load($nodes) {
     $nodes[$nid]->organism = $organism;
   }
 }
-
-/**
- * Implements hook_views_api()
- * Purpose: Essentially this hook tells drupal that there is views support for
- *  for this module which then includes tripal_db.views.inc where all the
- *  views integration code is
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_views_api() {
-  return array(
-    'api' => 2.0,
-  );
-}
-/**
- *
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_job_describe_args($callback, $args) {
-
-  $new_args = array();
-  if ($callback == 'tripal_organism_sync_organisms') {
-    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
-    $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
-  }
-  return $new_args;
-}

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

@@ -638,6 +638,12 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $results = tripal_pub_get_pubs_by_dbxref($pub_details['Publication Dbxref']);
     if(count($results) == 1) {
       $pub_id = $results[0];
+      if ($pub_id and !$update_if_exists) {
+        watchdog('tripal_pub', "A publication with this Dbxref already exists... Skipping: %dbxref",
+        array('%dbxref' => $pub_details['Publication Dbxref']), WATCHDOG_WARNING);
+        $action = 'skipped';
+        return $pub_id;
+      }
     }
     elseif (count($results) > 1) {
       watchdog('tripal_pub', "There are two publications with this accession: %db:%accession. Cannot determine which to update.",
@@ -655,6 +661,13 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $results = tripal_pub_get_pubs_by_title_type_pyear_series($pub_details['Title'], NULL, $pub_details['Year']);
     if (count($results) == 1) {
       $pub_id = $results[0];
+      if ($pub_id and !$update_if_exists) {
+        watchdog('tripal_pub', "The publication with the same title, type and year already exists. Skipping. ".
+            " Title: '%title'. Type: '%type'. Year: '%year'",
+            array('%title' => $pub_details['Title'], '%type' => $pub_details['Publication Type'], '%year' => $pub_details['Year']), WATCHDOG_WARNING);
+        $action = 'skipped';
+        return $pub_id;
+      }
     }
     elseif (count($results) > 1) {
       watchdog('tripal_pub', "The publication with the same title, type and year is present multiple times. Cannot ".
@@ -664,12 +677,6 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
       return FALSE;
     }
   }
-  //print "PUB ID: $pub_id\n";
-  // if there is a pub id and we've been told not to update then return
-  if ($pub_id and !$update_if_exists) {
-    $action = 'skipped';
-    return $pub_id;
-  }
 
   // get the publication type (use the first publication type, any others will get stored as properties)
   if (is_array($pub_details['Publication Type'])) {
@@ -1200,6 +1207,11 @@ function tripal_pub_create_citation($pub) {
         $pub_type = $ptype;
         break;
       }
+      else if ($ptype == "Research Support, Non-U.S. Gov't") {
+        $pub_type = $ptype;
+        // we don't break because if the article is also a Journal Article
+        // we prefer that type 
+      }
     }
     if (!$pub_type) {
       watchdog('tripal_pub', "Cannot generate citation for publication type: %types", 
@@ -1252,6 +1264,23 @@ function tripal_pub_create_citation($pub) {
     $citation .= '.';
   }
   //----------------------
+  // Research Support, Non-U.S. Gov't
+  //----------------------
+  elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
+    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+  
+    if ($pub['Journal Name']) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    if ($pub['Publication Date']) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif ($pub['Year']) {
+      $citation .= $pub['Year'];
+    }
+    $citation .= '.';
+  }
+  //----------------------
   // Letter
   //----------------------
   elseif ($pub_type == 'Letter') {

+ 1 - 1
tripal_pub/theme/tripal_pub/tripal_pub_base.tpl.php

@@ -62,7 +62,7 @@ $url = $urls[0]->value;
 
 ?>
 <div id="tripal_pub-base-box" class="tripal_pub-info-box tripal-info-box">
-  <div class="tripal_pub-info-box-title tripal-info-box-title"><?php print $pub->type_id->name ?> Details</div>
+  <div class="tripal_pub-info-box-title tripal-info-box-title">Publication Details</div>
   <!-- <div class="tripal_pub-info-box-desc tripal-info-box-desc"></div> -->
   <?php 
   if ($pub->is_obsolete == 't') { ?>

+ 1 - 1
tripal_pub/tripal_pub.drush.inc

@@ -68,7 +68,7 @@ function drush_tripal_pub_tripal_pubs_import() {
   $create_contacts = drush_get_option('create_contacts');
   $dbxref = drush_get_option('dbxref');
   $do_report = drush_get_option('report');
-  $update = drush_get_option('$update');
+  $update = drush_get_option('update');
 
   if($update == 'Y') {
     $update = TRUE;