Browse Source

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson 11 years ago
parent
commit
3362a01ab7

+ 0 - 137
tripal_analysis/theme/node--chado-analysis.tpl.php

@@ -1,137 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the organism node (page)
-//   using the same templates used for the various feature content blocks.
-//
-// To Customize the Featture Node Page:
-//   - This Template: customize basic layout and which elements are included
-//   - Using Panels: Override the node page using Panels3 and place the blocks
-//       of content as you please. This method requires no programming. See
-//       the Tripal User Guide for more details
-//   - Block Templates: customize the content/layout of each block of stock 
-//       content. These templates are found in the tripal_stock subdirectory
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-$analysis  = $variables['node']->organism;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and 
-   $template_settings['tripal_no_sidebar']['analysis']) {
-  $no_sidebar = 1;
-}
- 
-if ($teaser) { 
-  print theme('tripal_analysis_teaser', $variables); 
-} 
-else { ?>
-
-<script type="text/javascript">
-(function ($) {
-  Drupal.behaviors.analysisBehavior = {
-    attach: function (context, settings){<?php 
-      if ($no_sidebar) { ?>    
-        // hide the resource side bar and strech the details section    
-        $(".tripal_toc").hide();
-        $(".tripal_details").addClass("tripal_details_full");
-        $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
-      } ?>
-	    
-      // hide all tripal info boxes at the start
-      $(".tripal-info-box").hide();
- 
-      // iterate through all of the info boxes and add their titles
-      // to the table of contents
-      $(".tripal-info-box-title").each(function(){
-        var parent = $(this).parent();
-        var id = $(parent).attr('id');
-        var title = $(this).text();
-        $('#tripal_analysis_toc_list').append('<li><a href="#'+id+'" class="tripal_analysis_toc_item">'+title+'</a></li>');
-      });
-
-      // when a title in the table of contents is clicked, then
-      // show the corresponding item in the details box
-      $(".tripal_analysis_toc_item").click(function(){
-         $(".tripal-info-box").hide();
-         href = $(this).attr('href');
-         $(href).fadeIn('slow');
-         // we want to make sure our table of contents and the details
-         // box stay the same height
-         $("#tripal_analysis_toc").height($(href).parent().height());
-         return false;
-      }); 
-
-      // we want the base details to show up when the page is first shown 
-      // unless the user specified a specific block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
-      if(block == null){
-         block = window.location.href.match(/[\?|\&]block=(.+)/)
-      }
-      if(block != null){
-         $("#tripal_analysis-"+block[1]+"-box").show();
-      } else {
-         $("#tripal_analysis-base-box").show();
-      }
-      
-      // make the height of the table of contents match the height of the details box
-      $("#tripal_analysis_toc").height($("#tripal_analysis-base-box").parent().height());
-      
-    }     
-  };
-})(jQuery);
-</script>
-
-<div id="tripal_analysis_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_analysis_base',$node); ?>
-   
-   <!-- Resource Blocks CCK elements --><?php
-   for($i = 0; $i < count($node->field_resource_titles); $i++){
-     if($node->field_resource_titles[$i]['value']){ ?>
-       <div id="tripal_analysis-resource_<?php print $i?>-box" class="tripal_analysis-info-box tripal-info-box">
-         <div class="tripal_analysis-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-         <?php print $node->field_resource_blocks[$i]['value']; ?>
-       </div><?php
-     }
-   }?>
-   
-   <!-- Properties Theme -->
-   <?php print theme('tripal_analysis_properties',$node); ?>
-   
-   <!-- Let modules add more content -->
-   <?php print $content ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_analysis_toc" class="tripal_toc">
-   <div id="tripal_analysis_toc_title" class="tripal_toc_title">Resources</i></div>
-   <span id="tripal_analysis_toc_desc" class="tripal_toc_desc"></span>
-   <ul id="tripal_analysis_toc_list"  class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }?>
-     
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-
-<?php } ?>

+ 18 - 11
tripal_analysis/tripal_analysis.module

@@ -554,31 +554,38 @@ function tripal_analysis_permission() {
  *
  * @ingroup tripal_analysis
  */
-function tripal_analysis_theme() {
+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(
-       'arguments' => array('node' => NULL),
-       'template' => 'tripal_analysis_base',
-       'path' => "$theme_path/tripal_analysis",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_analysis_base',
+      'path' => "$path/theme/tripal_analysis",
     ),
     'tripal_feature_analyses' => array(
       'template' => 'tripal_feature_analyses',
-      'arguments' =>  array('node' => NULL),
-      'path' => "$theme_path/tripal_analysis",
+      'variables' =>  array('node' => NULL),
+      'path' => "$path/theme/tripal_analysis",
     ),
    'tripal_analysis_properties' => array(
-     'arguments' => array('node' => NULL),
-     'path' => "$theme_path/tripal_analysis",
+     'variables' => array('node' => NULL),
+     'path' => "$path/theme/tripal_analysis",
     ),
     'tripal_analysis_help' => array(
       'template' => 'tripal_analysis_help',
-      'arguments' =>  array(NULL),
-      'path' => $theme_path,
+      'variables' =>  array(NULL),
+      'path' => "$path/theme",
     ),
     'chado_analysis_node_form' => array(
-      'arguments' => array('form'),
+      'variables' => array('form'),
       'path' => $theme_path,
     ),
   );

+ 3 - 6
tripal_core/api/tripal_core_chado.api.inc

@@ -391,7 +391,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
       foreach ($table_desc['primary key'] as $field) {
         $sql = "SELECT CURRVAL('{" . $table . "_" . $field . "_seq}')";
         $results = chado_query($sql);
-        $value = $results->fetchObject();
+        $value = $results->fetchField();
         if (!$value) {
           tripal_core_report_error(
             'tripal_core',
@@ -2185,9 +2185,7 @@ function chado_query($sql, $args = array()) {
  */
 function chado_get_id_for_node($table, $nid) {
   $sql = "SELECT " . $table . "_id as id FROM {chado_$table} WHERE nid = :nid";
-  $result = db_query($sql, array(':nid' => $nid))->fetchObject();
-
-  return $result->id;
+  return db_query($sql, array(':nid' => $nid))->fetchField();
 }
 
 /**
@@ -2202,8 +2200,7 @@ function chado_get_id_for_node($table, $nid) {
  */
 function chado_get_node_id($table, $id) {
   $sql = "SELECT nid FROM {chado_$table} WHERE " . $table . "_id = :" . $table . "_id";
-  $result = db_query($sql, array(":" . $table . "_id" => $id))->fetchObject();
-  return $results->nid;
+  return db_query($sql, array(":" . $table . "_id" => $id))->fetchField();
 }
 
 /**

+ 4 - 3
tripal_core/includes/jobs.inc

@@ -173,9 +173,10 @@ function tripal_jobs_report() {
     
   // create the report page
   $output = "Waiting jobs are executed first by priority level (the lower the " .
-             "number the higher the priority) and second by the order they " .
-             "were entered";  
-  $output .= drupal_render(drupal_get_form('tripal_jobs_report_form'));   
+            "number the higher the priority) and second by the order they " .
+            "were entered";
+  $report_form = drupal_get_form('tripal_jobs_report_form');
+  $output .= drupal_render($report_form);   
   $output .= theme_table($table);
   $output .= theme('pager');
   return $output;

+ 19 - 10
tripal_core/theme/css/tripal.css

@@ -117,10 +117,19 @@ table.tripal-table-horz .tripal-table-odd-row {
    padding: 10px;
    background-color: #FFEEEE;
 }
+/**
+ * Tripal Contents container: contains both the details 
+ * section and the resources sidebar
+ */
+.tripal_contents {
+  width: 100%;
+}
 
+/**
+ * Resources Sidebar
+ */
 .tripal_toc {
-  float: left;
-  width: 20%;
+  float: right;  
   background-color: #EEEEEE;
 
   -moz-border-radius: 15px;
@@ -138,9 +147,8 @@ table.tripal-table-horz .tripal-table-odd-row {
   border-width:1px;
 }
 .tripal_toc ul {
- margin-left: 0px;
- margin-top: 5px;
- padding-left: 15px;
+  margin: 0 !important;
+  padding: 0 0 0.25em 1em !important;
 }
 .tripal_toc_title {
   font-size: 1.5em;
@@ -148,13 +156,13 @@ table.tripal-table-horz .tripal-table-odd-row {
   padding-bottom: 10px;
 }
 .tripal_toc_desc {
- /*font-style: italic; */
 }
+/**
+ * Details Section
+ */
 .tripal_details {
   float: left;
-  width: 69%;
   background-color: #FFFFFF;
-
   -moz-border-radius: 15px;
   -webkit-border-radius: 15px;
   -khtml-border-radius: 15px;
@@ -175,7 +183,6 @@ table.tripal-table-horz .tripal-table-odd-row {
 
 .tripal_details_full {
   float: left;
-  width: 95%;
   background-color: #FFFFFF;
 
   -moz-border-radius: 15px;
@@ -195,7 +202,9 @@ table.tripal-table-horz .tripal-table-odd-row {
   
   overflow:auto;
 }
-
+/**
+ * Tables
+ */
 .tripal-subtable {
   border-collapse:collapse;
   border: 0px solid black;

+ 154 - 0
tripal_core/theme/node--chado-generic.tpl.php

@@ -0,0 +1,154 @@
+<?php
+// Purpose: This template provides a generic layout for all Tripal nodes (page)
+
+// get the template type of node (e.g. if type == chado_organism then template type == organism)
+$ttype = $variables['type'];
+$ttype = preg_replace('/chado_/','', $ttype);
+
+// get the template settings
+$template_settings = theme_get_setting('tripal');
+
+// toggle the sidebar if desired
+$no_sidebar = 0;
+if (is_array($template_settings['tripal_no_sidebar']) and 
+   $template_settings['tripal_no_sidebar'][$ttype]) {
+  $no_sidebar = 1;
+}
+
+if ($teaser) { 
+  print theme('tripal_' . $ttype . '_teaser', $variables); 
+} 
+else { ?>
+
+<script type="text/javascript">
+(function ($) {
+  Drupal.behaviors.<?php print $ttype?>Behavior = {
+    attach: function (context, settings){ <?php
+      // hide the resource sidbar if requested and strech the details section
+      if ($no_sidebar) { ?>    
+        $(".tripal_toc").hide();
+        $(".tripal_details").addClass("tripal_details_full");
+        $(".tripal_details_full").removeClass("tripal_details"); <?php
+      } 
+      // use default resource sidebar
+      else { ?>        
+        $(".tripal-info-box").hide();
+
+        // set the widths of the details and sidebar sections so they can work 
+        // seemlessly with any theme.
+        total_width = $(".tripal_contents").width();
+        details_width = (total_width * 0.70) - 52; // 52 == 20  x 2 left/right padding + 10 right margin + 2pt border
+        toc_width = (total_width * 0.30) - 42;  // 42 == 20 x 2 left/right padding + 2pt border
+        // don't let sidebar get wider than 200px
+        if (toc_width > 200) {
+          details_width += toc_width - 200;
+          toc_width = 200;
+        }
+        $('#tripal_<?php print $ttype?>_toc').width(toc_width);
+        $('#tripal_<?php print $ttype?>_details').width(details_width);
+        <?php
+      } ?>
+ 
+      // iterate through all of the info boxes and add their titles
+      // to the table of contents
+      $(".tripal-info-box-title").each(function(){
+        var parent = $(this).parent();
+        var id = $(parent).attr('id');
+        var title = $(this).text();
+        $('#tripal_<?php print $ttype?>_toc_list').append('<li><a href="#'+id+'" class="tripal_<?php print $ttype?>_toc_item">'+title+'</a></li>');
+      });
+
+      // when a title in the table of contents is clicked, then
+      // show the corresponding item in the details box
+      $(".tripal_<?php print $ttype?>_toc_item").click(function(){
+        $(".tripal-info-box").hide();
+        href = $(this).attr('href');
+        if(href.match(/^#/)){
+           //alert("correct: " + href);
+        }
+        else{
+          tmp = href.replace(/^.*?#/, "#");
+          href = tmp;
+          //alert("fixed: " + href);
+        }
+        $(href).fadeIn('slow');
+        // we want to make sure our table of contents and the details
+        // box stay the same height
+        $("#tripal_<?php print $ttype?>_toc").height($(href).parent().height());
+        return false;
+      }); 
+
+      // we want the base details to show up when the page is first shown 
+      // unless we're using the feature browser then we want that page to show
+      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
+      if(block == null){
+        block = window.location.href.match(/[\?|\&]block=(.+)/)
+      }
+      if(block != null){
+        $("#tripal_<?php print $ttype?>-"+block[1]+"-box").show();
+      }
+      else {
+        $("#tripal_<?php print $ttype?>-base-box").show();
+      }
+
+      // make sure the sidebar and details sections are the same hieght
+      base_height = $("#tripal_<?php print $ttype?>_details").height();
+      toc_height = $("#tripal_<?php print $ttype?>_toc").height();
+      if (toc_height > base_height) {
+        $("#tripal_<?php print $ttype?>_details").height(toc_height);
+      }
+      else {
+        $("#tripal_<?php print $ttype?>_toc").height(base_height);
+      }
+    }
+  };
+})(jQuery);
+</script>
+
+<div id="tripal_<?php print $ttype?>_content" class="tripal_contents">
+  <div id="tripal_<?php print $ttype?>_details" class="tripal_details">
+  
+     <!-- Resource Blocks CCK elements --> <?php
+     if (property_exists($node, 'field_resource_titles')) {
+       for ($i = 0; $i < count($node->field_resource_titles); $i++){
+         if ($node->field_resource_titles[$i]['value']){ ?>
+           <div id="tripal_<?php print $ttype?>-resource_<?php print $i?>-box" class="tripal_<?php print $ttype?>-info-box tripal-info-box">
+             <div class="tripal_<?php print $ttype?>-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
+             <?php print $node->field_resource_blocks[$i]['value']; ?>
+           </div> <?php
+         }
+       } 
+     }?>
+     <!-- Let modules add more content -->
+     <?php
+       foreach ($content as $key => $values) {
+         if (array_key_exists('#value', $values)) {
+           print $content[$key]['#value'];
+         }
+       }
+     ?>
+     
+  </div>
+  
+  <!-- Table of contents -->
+  <div id="tripal_<?php print $ttype?>_toc" class="tripal_toc">
+     <div id="tripal_<?php print $ttype?>_toc_title" class="tripal_toc_title">Resources</i></div>
+     <span id="tripal_<?php print $ttype?>_toc_desc" class="tripal_toc_desc"></span>
+     <ul id="tripal_<?php print $ttype?>_toc_list" class="tripal_toc_list">
+     
+       <!-- Resource Links CCK elements --><?php
+       if(property_exists($node, 'field_resource_links')) {
+         for($i = 0; $i < count($node->field_resource_links); $i++){
+           if($node->field_resource_links[$i]['value']){
+             $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
+             <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
+           }
+         }
+       }
+       ?> 
+     </ul>
+  </div>
+</div> 
+<?php 
+} ?>
+

+ 2 - 2
tripal_core/tripal_core.module

@@ -61,8 +61,8 @@ function tripal_core_init() {
   global $base_url;
 
   // add javascript files
-  drupal_add_js(drupal_get_path('module', 'tripal_core') . '/theme/js/tripal_core.js');
-  drupal_add_css(drupal_get_path('module', 'tripal_core') . '/theme/css/tripal_core.css');
+  drupal_add_js(drupal_get_path('module', 'tripal_core') . '/theme/js/tripal.js');
+  drupal_add_css(drupal_get_path('module', 'tripal_core') . '/theme/css/tripal.css');
   
 
   // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and

+ 0 - 173
tripal_feature/theme/node--chado-feature.tpl.php

@@ -1,173 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the feature node (page)
-//   using the same templates used for the various feature content blocks.
-//
-// To Customize the Featture Node Page:
-//   - This Template: customize basic layout and which elements are included
-//   - Using Panels: Override the node page using Panels3 and place the blocks
-//       of content as you please. This method requires no programming. See
-//       the Tripal User Guide for more details
-//   - Block Templates: customize the content/layout of each block of stock 
-//       content. These templates are found in the tripal_stock subdirectory
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-
-$feature  = $variables['node']->feature;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and 
-   $template_settings['tripal_no_sidebar']['feature']) {
-  $no_sidebar = 1;
-}
-$feature_no_sidebar = preg_split('/\n/', $template_settings['tripal_feature_no_sidebar']);
-
-if ($teaser) { 
-  print theme('tripal_feature_teaser', $variables); 
-} 
-else { ?>
-
-<script type="text/javascript">
-(function ($) {
-  Drupal.behaviors.featureBehavior = {
-    attach: function (context, settings){ <?php 
-      if ($no_sidebar or in_array($feature->type_id->name, $feature_no_sidebar)) { ?>    
-        // hide the resource side bar and strech the details section    
-        $(".tripal_toc").hide();
-        $(".tripal_details").addClass("tripal_details_full");
-        $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
-      } ?>
- 
-      // iterate through all of the info boxes and add their titles
-      // to the table of contents
-      $(".tripal-info-box-title").each(function(){
-        var parent = $(this).parent();
-        var id = $(parent).attr('id');
-        var title = $(this).text();
-        $('#tripal_feature_toc_list').append('<li><a href="#'+id+'" class="tripal_feature_toc_item">'+title+'</a></li>');
-      });
-
-      // when a title in the table of contents is clicked, then
-      // show the corresponding item in the details box
-      $(".tripal_feature_toc_item").click(function(){
-         $(".tripal-info-box").hide();
-         href = $(this).attr('href');
-         $(href).fadeIn('slow');
-         // we want to make sure our table of contents and the details
-         // box stay the same height
-         $("#tripal_feature_toc").height($(href).parent().height());
-         return false;
-      }); 
-
-      // we want the base details to show up when the page is first shown 
-      // unless the user specified a specific block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
-      if(block == null){
-         block = window.location.href.match(/[\?|\&]block=(.+)/)
-      }
-      if(block != null){
-         $("#tripal_feature-"+block[1]+"-box").show();
-      } else {
-         $("#tripal_feature-base-box").show();
-      }
-
-      $("#tripal_organism_toc").height($("#tripal_feature-base-box").parent().height());
-    }     
-  };
-})(jQuery);
-</script>
-
-<div id="tripal_feature_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_feature_base',$node); ?>
-
-   <!-- Database References -->
-   <?php print theme('tripal_feature_references', $node); ?>
-
-   <!-- Properties -->
-   <?php print theme('tripal_feature_properties', $node); ?>
-
-   <!-- Annotated Terms -->
-   <?php print theme('tripal_feature_terms', $node); ?>
-
-   <!-- Synonyms -->
-   <?php print theme('tripal_feature_synonyms', $node); ?>
-   
-   <!-- Phenotypes -->
-   <?php print theme('tripal_feature_phenotypes', $node); ?>
-   
-   <!-- Maps -->   
-   <?php print theme('tripal_feature_featurepos', $node); ?>
-
-   <!-- Sequence --> <?php 
-   if(strcmp($feature->type_id->name,'scaffold')!=0 and 
-      strcmp($feature->type_id->name,'chromosome')!=0 and
-      strcmp($feature->type_id->name,'supercontig')!=0 and
-      strcmp($feature->type_id->name,'pseudomolecule')!=0)
-   {
-      print theme('tripal_feature_sequence', $node); 
-   } ?>
-
-   <!-- Formatted Sequences -->
-   <?php print theme('tripal_feature_featureloc_sequences', $node); ?>
-
-   <!-- Relationships -->
-   <?php print theme('tripal_feature_relationships', $node); ?>
-   
-   <!-- Feature locations --> <?php 
-   if(strcmp($feature->type_id->name,'scaffold')!=0 and 
-      strcmp($feature->type_id->name,'chromosome')!=0 and
-      strcmp($feature->type_id->name,'supercontig')!=0 and
-      strcmp($feature->type_id->name,'pseudomolecule')!=0)
-   {
-      print theme('tripal_feature_alignments', $node); 
-   } ?>
-     
-  
-   <!-- Resource Blocks CCK elements --><?php
-   for($i = 0; $i < count($node->field_resource_titles); $i++){
-     if($node->field_resource_titles[$i]['value']){ ?>
-       <div id="tripal_feature-resource_<?php print $i?>-box" class="tripal_feature-info-box tripal-info-box">
-         <div class="tripal_feature-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-         <?php print $node->field_resource_blocks[$i]['value']; ?>
-       </div><?php
-     }
-   }?>
-   
-   <!-- Let modules add more content -->
-   <?php print $content ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_feature_toc" class="tripal_toc">
-   <div id="tripal_feature_toc_title" class="tripal_toc_title">Resources</div>
-   <ul id="tripal_feature_toc_list" class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }?>
-     
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-
-<?php } ?>

+ 8 - 3
tripal_feature/theme/tripal_organism/tripal_organism_feature_browser.tpl.php

@@ -1,9 +1,14 @@
 <?php
 
 $organism = $variables['node']->organism;
-$features = $organism->feature_browser['features'];
-$pager    = $organism->feature_browser['pager'];
-$enabled  = $organism->feature_browser['enabled'];
+$enabled = 1;
+$features = array();
+
+if(property_exists($organism, 'feature_browser')) {
+  $features = $organism->feature_browser['features'];
+  $pager    = $organism->feature_browser['pager'];
+  $enabled  = $organism->feature_browser['enabled'];
+}
 
 // only show this block if it is enabled
 if ($enabled) { 

+ 8 - 3
tripal_feature/theme/tripal_organism/tripal_organism_feature_counts.tpl.php

@@ -1,9 +1,14 @@
 <?php
 
 $organism = $variables['node']->organism;
-$types    = $organism->feature_counts['types'];
-$names    = $organism->feature_counts['names'];
-$enabled  = $organism->feature_counts['enabled'];
+$enabled = 1;
+$types = array();
+
+if(property_exists($organism, 'feature_counts')) {
+  $types    = $organism->feature_counts['types'];
+  $names    = $organism->feature_counts['names'];
+  $enabled  = $organism->feature_counts['enabled'];
+}
 
 // only show this block if it is enabled
 if ($enabled) { 

+ 37 - 35
tripal_feature/tripal_feature.module

@@ -198,7 +198,7 @@ function tripal_feature_menu() {
   );
   
   // the administative settings menu
-  $items['admin/tripal/tripal_feature'] = array(
+  $items['admin/tripal/chado/tripal_feature'] = array(
     'title' => 'Features',
     'description' => 'Basic Description of Tripal Organism Module Functionality',
     'page callback' => 'theme',
@@ -206,7 +206,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/configuration'] = array(
+  $items['admin/tripal/chado/tripal_feature/configuration'] = array(
     'title' => 'Configuration',
     'description' => 'Configure the Tripal Feature module.',
     'page callback' => 'drupal_get_form',
@@ -214,7 +214,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/fasta_loader'] = array(
+  $items['admin/tripal/chado/tripal_feature/fasta_loader'] = array(
     'title' => 'Import a multi-FASTA file',
     'description' => 'Load sequences from a multi-FASTA file into Chado',
     'page callback' => 'drupal_get_form',
@@ -222,7 +222,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/gff3_load'] = array(
+  $items['admin/tripal/chado/tripal_feature/gff3_load'] = array(
     'title' => 'Import a GFF3 file',
     'description' => 'Import a GFF3 file into Chado',
     'page callback' => 'drupal_get_form',
@@ -231,7 +231,7 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/tripal_feature/delete'] = array(
+  $items['admin/tripal/chado/tripal_feature/delete'] = array(
     'title' => ' Delete Features',
     'description' => 'Delete multiple features from Chado',
     'page callback' => 'drupal_get_form',
@@ -240,7 +240,7 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/tripal_feature/sync'] = array(
+  $items['admin/tripal/chado/tripal_feature/sync'] = array(
     'title' => ' Sync Features',
     'description' => 'Sync features from Chado with Drupal',
     'page callback' => 'drupal_get_form',
@@ -266,40 +266,42 @@ function tripal_feature_menu() {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_theme() {
+function tripal_feature_theme($existing, $type, $theme, $path) {
   return array(
     'tripal_feature_search_index' => array(
-      'arguments' => array('node'),
+      'variables' => array('node'),
     ),
     'tripal_feature_search_results' => array(
-       'arguments' => array('node'),
+       'variables' => array('node'),
     ),
     'tripal_organism_feature_browser' => array(
-       'arguments' => array('node' => NULL),
-       'template' => 'tripal_organism_feature_browser',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_organism_feature_browser',
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_organism_feature_counts' => array(
-       'arguments' => array('node' => NULL),
-       'template' => 'tripal_organism_feature_counts',
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_organism_feature_counts',
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_feature_base' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_base',
     ),
     'tripal_feature_sequence' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_sequence',
     ),
     'tripal_feature_proteins' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_proteins',
     ),
     'tripal_feature_synonyms' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_synonyms',
     ),
     'tripal_feature_phenotypes' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_phenotypes',
     ),
     'tripal_feature_featurepos' => array(
@@ -307,27 +309,27 @@ function tripal_feature_theme() {
        'template' => 'tripal_feature_featurepos',
     ),
     'tripal_feature_featureloc_sequences' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_featureloc_sequences',
     ),
     'tripal_feature_references' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_references',
     ),
     'tripal_feature_properties' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_properties',
     ),
     'tripal_feature_terms' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_terms',
     ),
     'tripal_feature_alignments' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_alignments',
     ),
     'tripal_feature_relationships' => array(
-       'arguments' => array('node' => NULL),
+       'variables' => array('node' => NULL),
        'template' => 'tripal_feature_relationships',
     ),
     'tripal_feature_edit_ALL_properties_form' => array(
@@ -336,7 +338,7 @@ function tripal_feature_theme() {
     ),
     'tripal_feature_admin' => array(
       'template' => 'tripal_feature_admin',
-      'arguments' =>  array(NULL),
+      'variables' =>  array(NULL),
       'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
     ),
     
@@ -439,11 +441,11 @@ function tripal_feature_block_view($delta = '') {
         break;
       case 'org_feature_counts':
         $block['subject'] = t('Feature Type Summary');
-        $block['content'] = theme('tripal_organism_feature_counts', $node);
+        $block['content'] = theme('tripal_organism_feature_counts', array('node' => $node));
         break;
       case 'org_feature_browser':
         $block['subject'] = t('Feature Browser');
-        $block['content'] = theme('tripal_organism_feature_browser', $node);
+        $block['content'] = theme('tripal_organism_feature_browser', array('node' => $node));
         break;
       case 'library_feature_browser':
         $block['subject'] = t('Library Feature Browser');
@@ -1890,10 +1892,10 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
       // Show feature browser and counts
       if ($view_mode == 'full') {
         $node->content['tripal_organism_feature_counts'] = array(
-          '#value' => theme('tripal_organism_feature_counts', $node),
+          '#value' => theme('tripal_organism_feature_counts', array('node' => $node)),
         );
         $node->content['tripal_organism_feature_browser'] = array(
-          '#value' => theme('tripal_organism_feature_browser', $node),
+          '#value' => theme('tripal_organism_feature_browser', array('node' => $node)),
         );
       }
       break;
@@ -2056,9 +2058,9 @@ function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables) {
-  $organism = $variables['node']->organism;
-  $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
+function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
+ // $organism = $variables['node']->organism;
+  //$organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
 }
 
 /**
@@ -2066,9 +2068,9 @@ function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables) {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables) {
-  $organism = $variables['node']->organism;
-  $organism->feature_browser = tripal_feature_load_organism_feature_browser($organism);
+function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables, $hook) {
+  //$organism = $variables['node']->organism;
+  //$organism->feature_browser = tripal_feature_load_organism_feature_browser($organism);
 }
 
 /**

+ 212 - 0
tripal_organism/includes/organism_sync.inc

@@ -0,0 +1,212 @@
+<?php 
+
+/**
+ * 
+ */
+function tripal_organism_sync () {
+  $form = array();
+  
+  get_tripal_organism_admin_form_sync_set($form);
+  get_tripal_organism_admin_form_cleanup_set($form);
+  
+  return $form;
+}
+
+/**
+ *
+ *
+ * @ingroup tripal_organism
+ */
+function get_tripal_organism_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up'),
+    '#description' => t("With Drupal and chado residing in different databases or database schemas " .
+        "it is possible that nodes in Drupal and organisms in Chado become " .
+        "\"orphaned\".  This can occur if an organism node in Drupal is " .
+        "deleted but the corresponding chado organism is not and/or vice " .
+        "versa. Click the button below to resolve these discrepancies."),
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned organisms'),
+  );
+}
+/**
+ *
+ * @ingroup tripal_organism
+ */
+function get_tripal_organism_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync Organisms')
+  );
+
+  // get the list of organisms
+  $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
+  $org_rset = chado_query($sql);
+
+  // if we've added any organisms 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 organisms are currently synced.
+  $org_boxes = array();
+  $added = 0;
+  foreach ($org_rset as $organism) {
+    // check to see if the organism is already present as a node in drupal.
+    // if so, then skip it.
+    $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
+    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
+      $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
+      $added++;
+    }
+  }
+
+  // if we have organisms we need to add to the checkbox then
+  // build that form element
+  if ($added > 0) {
+    $org_boxes['all'] = "All Organisms";
+
+    $form['sync']['organisms'] = array(
+      '#title'       => t('Available Organisms'),
+      '#type'        => t('checkboxes'),
+      '#description' => t("Check the organisms you want to sync.  Drupal content will be created for each of the organisms listed above.  Select 'All Organisms' to sync all of them."),
+      '#required'    => FALSE,
+      '#prefix'      => '<div id="org_boxes">',
+      '#suffix'      => '</div>',
+      '#options'     => $org_boxes,
+    );
+    $form['sync']['button'] = array(
+      '#type' => 'submit',
+      '#value' => t('Submit Sync Job')
+    );
+  }
+  // we don't have any organisms to select from
+  else {
+    $form['sync']['value'] = array(
+      '#markup' => t('All organisms in Chado are currently synced with Drupal.')
+    );
+  }
+}
+
+/**
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_sync_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
+    $organisms = $form_state['values']['organisms'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($organisms as $organism_id) {
+      if (preg_match("/^all$/i" , $organism_id)) {
+        $do_all = TRUE;
+      }
+      if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
+        // get the list of organisms
+        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
+        $to_sync[$organism_id] = "$organism->genus $organism->species";
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all organisms' , 'tripal_organism',
+      'tripal_organism_sync_organisms' , $job_args , $user->uid);
+    }
+    else{
+      foreach ($to_sync as $organism_id => $name) {
+        $job_args[0] = $organism_id;
+        tripal_add_job("Sync organism: $name" , 'tripal_organism',
+        'tripal_organism_sync_organisms' , $job_args , $user->uid);
+      }
+    }
+  }
+
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
+    tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
+    'tripal_organism_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * Synchronize organisms from chado to drupal
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$organism_id) {
+    $sql = "SELECT * FROM {Organism} O";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+    $results = chado_query($sql, array(':organism_id' => $organism_id));
+  }
+
+  // We'll use the following SQL statement for checking if the organism
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_organism} " .
+      "WHERE organism_id = :organism_id";
+
+  foreach ($results as $organism) {
+
+    // check if this organism already exists in the drupal database. if it
+    // does then skip this organism and go to the next one.
+    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_organism';
+      $new_node->uid = $user->uid;
+      $new_node->title = "$organism->genus $organism->species";
+      $new_node->organism_id = $organism->organism_id;
+      $new_node->genus = $organism->genus;
+      $new_node->species = $organism->species;
+      $new_node->description = '';
+      $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 $organism->common_name\n";
+        }
+      }
+      else {
+        print "Failed to insert organism $organism->common_name\n";
+      }
+    }
+    else {
+      print "Skipped $organism->common_name\n";
+    }
+  }
+  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_organism
+ */
+function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('organism', $job_id);
+}

+ 3 - 233
tripal_organism/includes/tripal_organism.admin.inc

@@ -9,58 +9,12 @@ function tripal_organism_admin() {
 
   $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) {
-    get_tripal_organism_admin_form_sync_set($form);
-    get_tripal_organism_admin_form_reindex_set($form);
-    get_tripal_organism_admin_form_taxonomy_set($form);
-    get_tripal_organism_admin_form_cleanup_set($form);
-  }
-  else {
-    $form['notice'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Organism Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-      '#value' => t('Currently, organism 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.'),
-    );
-  }
+  get_tripal_organism_admin_form_reindex_set($form);
+  get_tripal_organism_admin_form_taxonomy_set($form);  
 
   return system_settings_form($form);
 }
-/**
- *
- *
- * @ingroup tripal_organism
- */
-function get_tripal_organism_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 organisms in Chado become " .
-    "\"orphaned\".  This can occur if an organism node in Drupal is " .
-    "deleted but the corresponding chado organism 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 organisms'),
-    '#weight' => 2,
-  );
-}
+
 /**
  *
  *
@@ -150,80 +104,7 @@ function get_tripal_organism_admin_form_reindex_set(&$form) {
     '#weight' => 3,
   );
 }
-/**
- *
- * @ingroup tripal_organism
- */
-function get_tripal_organism_admin_form_sync_set(&$form) {
-  // define the fieldsets
-  $form['sync'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sync Organisms')
-  );
-
-  // 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;
-  }
-
-  if (!$active_jobs) {
-
-    // get the list of organisms
-    $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-    $org_rset = chado_query($sql);
 
-    // if we've added any organisms 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 organisms are currently synced.
-    $org_boxes = array();
-    $added = 0;
-    foreach ($org_rset as $organism) {
-      // check to see if the organism is already present as a node in drupal.
-      // if so, then skip it.
-      $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
-      if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
-        $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-        $added++;
-      }
-    }
-
-    // if we have organisms we need to add to the checkbox then
-    // build that form element
-    if ($added > 0) {
-      $org_boxes['all'] = "All Organisms";
-
-      $form['sync']['organisms'] = array(
-        '#title'       => t('Available Organisms'),
-        '#type'        => t('checkboxes'),
-        '#description' => t("Check the organisms you want to sync.  Drupal content will be created for each of the organisms listed above.  Select 'All Organisms' to sync all of them."),
-        '#required'    => FALSE,
-        '#prefix'      => '<div id="org_boxes">',
-        '#suffix'      => '</div>',
-        '#options'     => $org_boxes,
-      );
-      $form['sync']['button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Submit Sync Job')
-      );
-    }
-    // we don't have any organisms to select from
-    else {
-    $form['sync']['value'] = array(
-        '#value' => t('All organisms 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 organisms. Please check back later for organisms that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
-    );
-  }
-}
 /**
  *
  * @ingroup tripal_organism
@@ -232,40 +113,6 @@ function tripal_organism_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
-    $organisms = $form_state['values']['organisms'];
-    $do_all = FALSE;
-    $to_sync = array();
-
-    foreach ($organisms as $organism_id) {
-      if (preg_match("/^all$/i" , $organism_id)) {
-        $do_all = TRUE;
-      }
-      if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
-        // get the list of organisms
-        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
-        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
-        $to_sync[$organism_id] = "$organism->genus $organism->species";
-      }
-    }
-
-    // submit the job the tripal job manager
-    if ($do_all) {
-      tripal_add_job('Sync all organisms' , 'tripal_organism',
-      'tripal_organism_sync_organisms' , $job_args , $user->uid);
-    }
-    else{
-      foreach ($to_sync as $organism_id => $name) {
-        $job_args[0] = $organism_id;
-        tripal_add_job("Sync organism: $name" , 'tripal_organism',
-          'tripal_organism_sync_organisms' , $job_args , $user->uid);
-      }
-    }
-  }
-
   // -------------------------------------
   // Submit the Reindex Job if selected
   if ($form_state['values']['op'] == t('Reindex Features')) {
@@ -299,72 +146,9 @@ function tripal_organism_admin_validate($form, &$form_state) {
       }
     }
   }
-
-  // -------------------------------------
-  // Submit the Cleanup Job if selected
-  if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
-    tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
-      'tripal_organism_cleanup', $job_args, $user->uid);
-  }
 }
 
-/**
- * Synchronize organisms from chado to drupal
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
-  global $user;
-  $page_content = '';
-
-  if (!$organism_id) {
-    $sql = "SELECT * FROM {Organism} O";
-    $results = chado_query($sql);
-  }
-  else {
-    $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
-    $results = chado_query($sql, array(':organism_id' => $organism_id));
-  }
 
-  // We'll use the following SQL statement for checking if the organism
-  // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_organism} " .
-         "WHERE organism_id = :organism_id";
-
-  foreach ($results as $organism) {
-
-    // check if this organism already exists in the drupal database. if it
-    // does then skip this organism and go to the next one.
-    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
-
-      $new_node = new stdClass();
-      $new_node->type = 'chado_organism';
-      $new_node->uid = $user->uid;
-      $new_node->title = "$organism->genus $organism->species";
-      $new_node->organism_id = $organism->organism_id;
-      $new_node->genus = $organism->genus;
-      $new_node->species = $organism->species;
-      $new_node->description = '';
-      $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 $organism->common_name\n";
-        }
-      }
-      else {
-        print "Failed to insert organism $organism->common_name\n";
-      }
-    }
-    else {
-      print "Skipped $organism->common_name\n";
-    }
-  }
-  return $page_content;
-}
 /**
  *
  * @ingroup tripal_organism
@@ -447,17 +231,3 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
     $i++;
   }
 }
-/**
- * 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_organism
- */
-function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
-
-  return tripal_core_clean_orphaned_nodes('organism', $job_id);
-}

+ 0 - 8
tripal_organism/theme/css/tripal_organism.css

@@ -25,11 +25,3 @@
  margin-top: 5px;
 
 }
-#tripal_organism-table-base {
- width: auto;
- margin-bottom: 10px;
- min-width: 300px;
- margin-top: 0px;
-
-}
-

+ 64 - 45
tripal_organism/theme/node--chado-organism.tpl.php

@@ -19,6 +19,7 @@
 //   NOTE: For a full listing of fields available in the node object the
 //       print_r $node line below or install the Drupal Devel module which 
 //       provides an extra tab at the top of the node page labelled Devel
+dpm($variables);
 
 $organism  = $variables['node']->organism;
 
@@ -40,15 +41,29 @@ else { ?>
 <script type="text/javascript">
 (function ($) {
   Drupal.behaviors.organismBehavior = {
-    attach: function (context, settings){<?php 
+    attach: function (context, settings){<?php
+      // hide the resource sidbar if requested and strech the details section
       if ($no_sidebar) { ?>    
-        // hide the resource side bar and strech the details section    
         $(".tripal_toc").hide();
         $(".tripal_details").addClass("tripal_details_full");
         $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
+      } 
+      // use default resource sidebar
+      else { ?>        
+        $(".tripal-info-box").hide();
+
+        // set the widths of the details and sidebar sections so they can work 
+        // seemlessly with any theme.
+        total_width = $(".tripal_contents").width();
+        details_width = (total_width * 0.70) - 52; // 52 == 20  x 2 left/right padding + 10 right margin + 2pt border
+        toc_width = (total_width * 0.30) - 42;  // 42 == 20 x 2 left/right padding + 2pt border
+        // don't let sidebar get wider than 200px
+        if (toc_width > 200) {
+          details_width += toc_width - 200;
+          toc_width = 200;
+        }
+        $('#tripal_organism_toc').width(toc_width);
+        $('#tripal_organism_details').width(details_width); <?php
       } ?>
  
       // iterate through all of the info boxes and add their titles
@@ -102,46 +117,50 @@ else { ?>
 })(jQuery);
 </script>
 
-<div id="tripal_organism_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_organism_base', $variables); ?>
-   
-   <!-- Resource Blocks CCK elements --> <?php
-   if(property_exists($node, 'field_resource_titles')) {
-	   for($i = 0; $i < count($node->field_resource_titles); $i++){
-	     if($node->field_resource_titles[$i]['value']){ ?>
-	       <div id="tripal_organism-resource_<?php print $i?>-box" class="tripal_organism-info-box tripal-info-box">
-	         <div class="tripal_organism-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-	         <?php print $node->field_resource_blocks[$i]['value']; ?>
-	       </div> <?php
-	     }
-	   } 
-	 }?>
-   <!-- Let modules add more content -->
-   <?php print $content ?>
-   
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_organism_toc" class="tripal_toc">
-   <div id="tripal_organism_toc_title" class="tripal_toc_title">Resources</i></div>
-   <span id="tripal_organism_toc_desc" class="tripal_toc_desc"></span>
-   <ul id="tripal_organism_toc_list" class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     if(property_exists($node, 'field_resource_links')) {
-	     for($i = 0; $i < count($node->field_resource_links); $i++){
-	       if($node->field_resource_links[$i]['value']){
-	         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-	         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-	       }
-	     }
-     }
+<div id="tripal_organism_content" class="tripal_contents">
+  <div id="tripal_organism_details" class="tripal_details">
+  
+     <!-- Resource Blocks CCK elements --> <?php
+     if (property_exists($node, 'field_resource_titles')) {
+       for ($i = 0; $i < count($node->field_resource_titles); $i++){
+         if ($node->field_resource_titles[$i]['value']){ ?>
+           <div id="tripal_organism-resource_<?php print $i?>-box" class="tripal_organism-info-box tripal-info-box">
+             <div class="tripal_organism-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
+             <?php print $node->field_resource_blocks[$i]['value']; ?>
+           </div> <?php
+         }
+       } 
+     }?>
+     <!-- Let modules add more content -->
+     <?php
+       foreach ($content as $key => $values) {
+         if (array_key_exists('#value', $values)) {
+           print $content[$key]['#value'];
+         }
+       }
+     ?>
      
-     // ADD CUSTOMIZED <li> LINKS HERE 
-     ?> 
-   </ul>
-</div> <?php 
+  </div>
+  
+  <!-- Table of contents -->
+  <div id="tripal_organism_toc" class="tripal_toc">
+     <div id="tripal_organism_toc_title" class="tripal_toc_title">Resources</i></div>
+     <span id="tripal_organism_toc_desc" class="tripal_toc_desc"></span>
+     <ul id="tripal_organism_toc_list" class="tripal_toc_list">
+     
+       <!-- Resource Links CCK elements --><?php
+       if(property_exists($node, 'field_resource_links')) {
+         for($i = 0; $i < count($node->field_resource_links); $i++){
+           if($node->field_resource_links[$i]['value']){
+             $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
+             <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
+           }
+         }
+       }
+       ?> 
+     </ul>
+  </div>
+</div> 
+<?php 
 } ?>
 

+ 12 - 11
tripal_organism/theme/tripal_organism/tripal_organism_base.tpl.php

@@ -1,6 +1,7 @@
 <?php
 // the comment field is a database text field so we have to expand it so that
 // it is included in the organism object
+$organism  = $variables['node']->organism;
 $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
  
 ?>
@@ -28,15 +29,6 @@ $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
   // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
   $rows = array();
   
-  // common name row
-  $rows[] = array(
-    array(
-      'data' => 'Common Name', 
-      'header' => TRUE
-    ), 
-    $organism->common_name,
-  );
-  
   // genus row
   $rows[] = array(
     array(
@@ -55,6 +47,15 @@ $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
     '<i>' . $organism->species . '</i>'
   );
   
+  // common name row
+  $rows[] = array(
+    array(
+      'data' => 'Common Name',
+      'header' => TRUE
+    ),
+    $organism->common_name,
+  );
+  
   // abbreviation row
   $rows[] = array(
     array(
@@ -68,7 +69,8 @@ $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
   $rows[] = array(
     array(
       'data' => $image . $organism->comment, 
-      'colspan' => 2
+      'colspan' => 2,
+      'style' => 'text-align: justify;',
     ),
   );
   
@@ -81,7 +83,6 @@ $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
     'rows' => $rows, 
     'attributes' => array(
       'id' => 'tripal_organism-table-base',
-      'class' => 'tripal-table',
     ), 
     'sticky' => FALSE,
     'caption' => '',

+ 0 - 0
tripal_organism/theme/tripal_organism_admin.tpl.php → tripal_organism/theme/tripal_organism_help.tpl.php


+ 108 - 41
tripal_organism/tripal_organism.module

@@ -2,6 +2,7 @@
 
 require_once "api/tripal_organism.api.inc";
 require_once "includes/tripal_organism.admin.inc";
+require_once "includes/organism_sync.inc";
 
 /**
  * @file
@@ -117,11 +118,19 @@ function tripal_organism_menu() {
    'title' => 'Configuration',
    'description' => 'Manage integration of Chado organisms including associated features',
    'page callback' => 'drupal_get_form',
-   'page arguments' => array('tripal_organism_help'),
+   'page arguments' => array('tripal_organism_admin'),
    'access arguments' => array('adminster tripal organism'),
    'type' => MENU_NORMAL_ITEM,
   );
 
+  $items['admin/tripal/chado/tripal_organism/sync'] = array(
+    'title' => 'Sync Organisms',
+    'description' => 'Sync Chado organisms with Drupal',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_organism_sync'),
+    'access arguments' => array('adminster tripal organism'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
   return $items;
 }
@@ -143,33 +152,40 @@ function tripal_organism_help ($path, $arg) {
  *
  * @ingroup tripal_organism
  */
-function tripal_organism_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_organism') . '/theme';
+function tripal_organism_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   $items = array(
+    'node__chado_organism' => array(
+      'template' => 'node--chado-generic',
+      'render element' => 'node',
+      'base hook' => 'node',
+      'path' => "$core_path/theme",
+    ),
     'tripal_organism_base' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_organism_base',
-      'path' => "$theme_path/tripal_organism",
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_organism_description' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_organism_description',
-      'path' => "$theme_path/tripal_organism",
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_organism_image' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_organism_image',
-      'path' => "$theme_path/tripal_organism",
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_organism_teaser' => array(
-      'arguments' => array('node' => NULL),
+      'variables' => array('node' => NULL),
       'template' => 'tripal_organism_teaser',
-      'path' => "$theme_path/tripal_organism",
+      'path' => "$path/theme/tripal_organism",
     ),
     'tripal_organism_help' => array(
       'template' => 'tripal_organism_help',
       'arguments' =>  array(NULL),
-      'path' => $theme_path,
+      'path' => $path,
     ),
   );
   return $items;
@@ -265,9 +281,16 @@ function tripal_organism_permission() {
  *  @ingroup tripal_organism
  */
 function chado_organism_validate($node, $form, &$form_state) {
+  // remove any white space around values
+  $node->genus        = trim($node->genus);
+  $node->species      = trim($node->species);
+  $node->abbreviation = trim($node->abbreviation);
+  $node->common_name  = trim($node->common_name);
+  $node->description  = trim($node->description);
+  
   // if this is an update, we want to make sure that a different organism doesn't
   // already have this genus and speces
-  if ($node->organism_id) {
+  if (property_exists($node, 'organism_id')) {
     $sql = "
       SELECT *
       FROM {organism} O
@@ -312,6 +335,12 @@ function chado_organism_validate($node, $form, &$form_state) {
  * @ingroup tripal_organism
  */
 function chado_organism_insert($node) {
+  // remove any white space around values
+  $node->genus        = trim($node->genus);
+  $node->species      = trim($node->species);
+  $node->abbreviation = trim($node->abbreviation);
+  $node->common_name  = trim($node->common_name);
+  $node->description  = trim($node->description);
 
   $values = array(
     'genus'        => $node->genus,
@@ -320,10 +349,11 @@ function chado_organism_insert($node) {
     '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 (!$node->organism_id) {
+  if (!property_exists($node,'organism_id')) {
     $organism = tripal_core_chado_insert('organism', $values);
     if (!$organism) {
       drupal_set_message(t('Unable to add organism.', 'warning'));
@@ -339,13 +369,13 @@ function chado_organism_insert($node) {
 
   // Make sure the entry for this organism doesn't already exist in the
   // chado_organism table if it doesn't exist then we want to add it.
-
-  if (!chado_get_id_for_node('organism', $node->nid) ) {
-    // next add the item to the drupal table
-    $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) " .
-           "VALUES (:nid, :vid, :organism_id)";
-    $args = array(':nid' => $node->nid, ':vid' => $node->vid, ':organism_id' => $organism_id);
-    db_query($sql, $args);
+  $check_org_id = chado_get_id_for_node('organism', $node->nid);  
+  if (!$check_org_id) {
+    $record = new stdClass();
+    $record->nid = $node->nid;
+    $record->vid = $node->vid;
+    $record->organism_id = $organism_id;
+    drupal_write_record('chado_organism', $record);
   }
 
   // set the title for the node
@@ -364,6 +394,13 @@ function chado_organism_insert($node) {
  * @ingroup tripal_organism
  */
 function chado_organism_update($node) {
+  // remove any white space around values
+  $node->genus        = trim($node->genus);
+  $node->species      = trim($node->species);
+  $node->abbreviation = trim($node->abbreviation);
+  $node->common_name  = trim($node->common_name);
+  $node->description  = trim($node->description);
+  
   if ($node->revision) {
     // there is no way to handle revisions in Chado but leave
     // this here just to make not we've addressed it.
@@ -429,6 +466,22 @@ 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;
+  }
+}
 /**
  *
  *
@@ -465,29 +518,42 @@ function chado_organism_add_image($node) {
  *
  * @ingroup tripal_organism
  */
-function chado_organism_form($node, $param) {
-  $organism = $node->organism;
-
-  // add in the comment since it is a text field and may not be included if too big
-  $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
-
-  // get form defaults
-  $abbreviation   = property_exists($node, 'abbreviation')   ? property_exists($node, 'abbreviation')   : $organism->abbreviation;
-  $genus          = property_exists($node, 'genus')          ? property_exists($node, 'genus')          : $organism->genus;
-  $species        = property_exists($node, 'species')        ? property_exists($node, 'species')        : $organism->species;
-  $common_name    = property_exists($node, 'common_name')    ? property_exists($node, 'common_name')    : $organism->common_name;
-  $description    = property_exists($node, 'description')    ? property_exists($node, 'description')    : $organism->comment;
-  $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
-
+function chado_organism_form($node, $form_state) {
   $form = array();
+  
+  // we have a file upload element on the form soe we need the multipart encoding type
   $form['#attributes']['enctype'] = 'multipart/form-data';
+  
+  // if the organism is part of the node object then we are editing. If not we are inserting
+  if (property_exists($node, 'organism')) {
+    $organism = $node->organism;
 
-  // keep track of the organism id if we have one.  If we do have one then
-  // this would indicate an update as opposed to an insert.
-  $form['organism_id'] = array(
-    '#type' => 'value',
-    '#value' => $organism->organism_id,
-  );
+    // add in the comment since it is a text field and may not be included if too big
+    $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
+    
+    // get form defaults
+    $abbreviation   = property_exists($node, 'abbreviation')   ? property_exists($node, 'abbreviation')   : $organism->abbreviation;
+    $genus          = property_exists($node, 'genus')          ? property_exists($node, 'genus')          : $organism->genus;
+    $species        = property_exists($node, 'species')        ? property_exists($node, 'species')        : $organism->species;
+    $common_name    = property_exists($node, 'common_name')    ? property_exists($node, 'common_name')    : $organism->common_name;
+    $description    = property_exists($node, 'description')    ? property_exists($node, 'description')    : $organism->comment;
+    $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
+    
+    // set the organism_id in the form
+    $form['organism_id'] = array(
+      '#type' => 'value',
+      '#value' => $organism->organism_id,
+    );
+  }
+  else {
+    // get form defaults
+    $abbreviation   = property_exists($node, 'abbreviation')   ? property_exists($node, 'abbreviation')   : '';
+    $genus          = property_exists($node, 'genus')          ? property_exists($node, 'genus')          : '';
+    $species        = property_exists($node, 'species')        ? property_exists($node, 'species')        : '';
+    $common_name    = property_exists($node, 'common_name')    ? property_exists($node, 'common_name')    : '';
+    $description    = property_exists($node, 'description')    ? property_exists($node, 'description')    : '';
+    $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
+  }
 
   $form['abbreviation']= array(
     '#type' => 'textfield',
@@ -544,6 +610,7 @@ function chado_organism_load($nodes) {
     // build the organism variable
     $values = array('organism_id' => $organism_id);
     $organism = tripal_core_generate_chado_var('organism', $values);
+    
 
     // add in the description field
     $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');

+ 1 - 1
tripal_pub/api/tripal_pub.api.inc

@@ -694,7 +694,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
   $values = array(
     'title'       => $pub_details['Title'],
     'volume'      => $pub_details['Volume'],
-    'series_name' => $pub_details['Journal Name'],
+    'series_name' => substr($pub_details['Journal Name'], 0, 255),
     'issue'       => $pub_details['Issue'],
     'pyear'       => $pub_details['Year'],
     'pages'       => $pub_details['Pages'],

+ 4 - 4
tripal_pub/tripal_pub.module

@@ -488,7 +488,7 @@ function chado_pub_insert($node) {
     // insert the pub record
     $values = array(
       'title'       => trim($node->pubtitle),
-      'series_name' => trim($node->series_name),
+      'series_name' => substr(trim($node->series_name), 0, 255),
       'type_id'     => trim($node->type_id),
       'pyear'       => trim($node->pyear),
       'is_obsolete' => $node->is_obsolete ? 'true' : 'false', 
@@ -497,9 +497,9 @@ function chado_pub_insert($node) {
       'volume'      => $volume,    
       'issue'       => $issue,    
       'pages'       => $pages,
-      'miniref'     => $miniref,        
-      'publisher'   => $publisher,
-      'pubplace'    => $pubplace,
+      'miniref'     => substr($miniref, 0, 255),        
+      'publisher'   => substr($publisher, 0, 255),
+      'pubplace'    => substr($pubplace, 0, 255),
     );
     $pub = tripal_core_chado_insert('pub', $values);
     if (!$pub) {