Quellcode durchsuchen

Project module is converted. Added publication templates to library, stock and feature

Stephen Ficklin vor 11 Jahren
Ursprung
Commit
15cf37dff9

+ 8 - 1
tripal_contact/theme/tripal_contact/tripal_contact_publications.tpl.php

@@ -46,7 +46,14 @@ if (count($pubauthor_contacts) > 0) { ?>
       if ($pub->nid) {
         // replace the title with a link
         $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
-        $citation = preg_replace('/' . $pub->title . '/', $link, $citation);
+        $patterns = array(
+          '/(\()/', '/(\))/', 
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/', 
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
       }
       
       $rows[] = array(

+ 175 - 0
tripal_feature/theme/tripal_feature.theme.inc

@@ -0,0 +1,175 @@
+<?php 
+
+
+/**
+ * @ingroup tripal_feature
+ */
+function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
+  // we want to provide a new variable that contains the matched features.
+  $feature = $variables['node']->feature;
+
+  // get the featureloc src features
+  $options = array(
+    'return_array' => 1,
+    'include_fk' => array(
+      'srcfeature_id' => array(
+        'type_id' => 1
+      ),
+    ),
+  );
+
+  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
+
+  // because there are two foriegn keys in the featureloc table with the feature table
+  // we have to access the records for each by specifying the field name after the table name:
+  $ffeaturelocs = $feature->featureloc->feature_id;
+
+  // now extract the sequences
+  $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
+  $feature->featureloc_sequences = $featureloc_sequences;
+}
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
+  // we want to provide a new variable that contains the matched features.
+  $feature = $variables['node']->feature;
+
+  if (!property_exists($feature, 'all_relationships')) {
+    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
+  }
+}
+
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_preprocess_tripal_feature_proteins(&$variables) {
+  // we want to provide a new variable that contains the matched features.
+  $feature = $variables['node']->feature;
+
+  if (!property_exists($feature, 'all_relationships')) {
+    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
+  }
+}
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
+
+  // we want to provide a new variable that contains the matched features.
+  $feature = $variables['node']->feature;
+  $options = array(
+    'return_array' => 1,
+    'include_fk' => array(
+      'srcfeature_id' => array(
+        'type_id' => 1,
+      ),
+      'feature_id' => array(
+        'type_id' => 1
+      ),
+    )
+  );
+  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
+
+  // get alignments as child
+  $cfeaturelocs = $feature->featureloc->feature_id;
+  if (!$cfeaturelocs) {
+    $cfeaturelocs = array();
+  }
+  // get alignment as parent
+  $pfeaturelocs = $feature->featureloc->srcfeature_id;
+  if (!$pfeaturelocs) {
+    $pfeaturelocs = array();
+  }
+
+  // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
+  $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
+  $feature->matched_featurelocs = $mfeaturelocs;
+
+  // combine all three alignments into a single array for printing together in
+  // a single list
+  $alignments = array();
+  foreach ($pfeaturelocs as $featureloc) {
+    // if type is a 'match' then ignore it. We will handle those below
+    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
+      continue;
+    }
+    $alignment = new stdClass();
+    $alignment->record = $featureloc;
+    $alignment->name = $featureloc->feature_id->name;
+    $alignment->type = $featureloc->feature_id->type_id->name;
+    $alignment->fmin = $featureloc->fmin;
+    $alignment->fmax = $featureloc->fmax;
+    $alignment->phase = $featureloc->phase;
+    $alignment->strand = $featureloc->strand;
+    $alignments[] = $alignment;
+    if (property_exists($featureloc->feature_id, 'nid')) {
+      $alignment->nid = $featureloc->feature_id->nid;
+    }
+  }
+  foreach ($cfeaturelocs as $featureloc) {
+    // if type is a 'match' then ignore it. We will handle those below
+    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
+      continue;
+    }
+    $alignment = new stdClass();
+    $alignment->record = $featureloc;
+    $alignment->name = $featureloc->srcfeature_id->name;
+    $alignment->type = $featureloc->srcfeature_id->type_id->name;
+    $alignment->fmin = $featureloc->fmin;
+    $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
+    $alignment->fmax = $featureloc->fmax;
+    $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
+    $alignment->phase = $featureloc->phase;
+    $alignment->strand = $featureloc->strand;
+    $alignments[] = $alignment;
+    if (property_exists($featureloc->srcfeature_id, 'nid')) {
+      $alignment->nid = $featureloc->srcfeature_id->nid;
+    }
+  }
+  // in matching features, the left feature is always the feature
+  // provided to this function.
+  foreach ($mfeaturelocs as $featureloc) {
+    // get more information about the right feature
+    $select = array('feature_id' => $featureloc->right_srcfeature_id);
+    $rfeature = tripal_core_generate_chado_var('feature', $select);
+    // now add to the list
+    $alignment = new stdClass();
+    $alignment->record = $featureloc;
+    $alignment->right_feature = $rfeature;
+    $alignment->name = $rfeature->name;
+    $alignment->type = $rfeature->type_id->name;
+    $alignment->fmin = $featureloc->left_fmin;
+    $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
+    $alignment->fmax = $featureloc->left_fmax;
+    $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
+    $alignment->phase = $featureloc->left_phase;
+    $alignment->strand = $featureloc->left_strand;
+    $alignment->right_fmin = $featureloc->right_fmin;
+    $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
+    $alignment->right_fmax = $featureloc->right_fmax;
+    $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
+    $alignment->right_phase = $featureloc->right_phase;
+    $alignment->right_strand = $featureloc->right_strand;
+    $alignments[] = $alignment;
+    if (property_exists($rfeature, 'nid')) {
+      $alignment->nid = $rfeature->nid;
+    }
+  }
+  $feature->all_featurelocs = $alignments;
+}
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
+  $organism = $variables['node']->organism;
+  $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
+}

+ 85 - 0
tripal_feature/theme/tripal_feature/tripal_feature_publications.tpl.php

@@ -0,0 +1,85 @@
+<?php
+$feature = $variables['node']->feature;
+
+// expand feature to include pubs 
+$options = array('return_array' => 1);
+$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_pub', $options);
+$feature_pubs = $feature->feature_pub; 
+
+
+if (count($feature_pubs) > 0) { ?>
+  <div id="tripal_feature_pub-pub-box" class="tripal_feature_pub-info-box tripal-info-box">
+    <div class="tripal_feature_pub-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_feature_pub-info-box-desc tripal-info-box-desc"></div> <?php 
+  
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Year', 'Publication');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($feature_pubs as $feature_pub) {
+      $pub = $feature_pub->pub_id;
+      $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+      $citation = $pub->title;  // use the title as the default citation
+      
+      // get the citation for this pub if it exists
+      $values = array(
+        'pub_id' => $pub->pub_id, 
+        'type_id' => array(
+          'name' => 'Citation',
+        ),
+      );
+      $options = array('return_array' => 1);
+      $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+      if (count($citation_prop) == 1) {
+        $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+        $citation = $citation_prop[0]->value;
+      }
+      
+      // if the publication is synced then link to it
+      if ($pub->nid) {
+        // replace the title with a link
+        $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
+        $patterns = array(
+          '/(\()/', '/(\))/',
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/',
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
+      }
+      
+      $rows[] = array(
+        $pub->pyear,
+        $citation,
+      );
+    }
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_feature-table-publications',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php 
+}

+ 9 - 173
tripal_feature/tripal_feature.module

@@ -15,7 +15,7 @@
 
 require_once "api/tripal_feature.api.inc";
 require_once "api/tripal_feature.schema.api.inc";
-
+require_once "theme/tripal_feature.theme.inc";
 require_once "includes/tripal_feature.admin.inc";
 require_once "includes/tripal_feature.sync_features.inc";
 require_once "includes/tripal_feature.fasta_loader.inc";
@@ -330,6 +330,11 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_proteins',
       'path' => "$path/theme/tripal_feature",
     ),
+    'tripal_feature_publications' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature_publications',
+      'path' => "$path/theme/tripal_feature",
+    ),
     'tripal_feature_synonyms' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_feature_synonyms',
@@ -1387,6 +1392,9 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
         $node->content['tripal_feature_properties'] = array(
           '#value' => theme('tripal_feature_properties', array('node' => $node)),
         );
+        $node->content['tripal_feature_publications'] = array(
+          '#value' => theme('tripal_feature_properties', array('node' => $node)),
+        );
         $node->content['tripal_feature_references'] = array(
           '#value' => theme('tripal_feature_references', array('node' => $node)),
         );
@@ -1449,178 +1457,6 @@ function tripal_feature_node_update($node) {
   }
 }
 
-/**
- * @ingroup tripal_feature
- */
-function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
-  // we want to provide a new variable that contains the matched features.
-  $feature = $variables['node']->feature;
-
-  // get the featureloc src features
-  $options = array(
-    'return_array' => 1,
-    'include_fk' => array(
-      'srcfeature_id' => array(
-        'type_id' => 1
-      ),
-    ),
-  );
-
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
-
-  // because there are two foriegn keys in the featureloc table with the feature table
-  // we have to access the records for each by specifying the field name after the table name:
-  $ffeaturelocs = $feature->featureloc->feature_id;
-
-  // now extract the sequences
-  $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
-  $feature->featureloc_sequences = $featureloc_sequences;
-}
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
-  // we want to provide a new variable that contains the matched features.
-  $feature = $variables['node']->feature;
-
-  if (!property_exists($feature, 'all_relationships')) {
-    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
-  }
-}
-
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_preprocess_tripal_feature_proteins(&$variables) {
-  // we want to provide a new variable that contains the matched features.
-  $feature = $variables['node']->feature;
-
-  if (!property_exists($feature, 'all_relationships')) {
-    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
-  }
-}
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
-
-  // we want to provide a new variable that contains the matched features.
-  $feature = $variables['node']->feature;
-  $options = array(
-    'return_array' => 1,
-    'include_fk' => array(
-      'srcfeature_id' => array(
-        'type_id' => 1,
-      ),
-      'feature_id' => array(
-        'type_id' => 1
-      ),
-    )
-  );
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
-
-  // get alignments as child
-  $cfeaturelocs = $feature->featureloc->feature_id;
-  if (!$cfeaturelocs) {
-    $cfeaturelocs = array();
-  }
-  // get alignment as parent
-  $pfeaturelocs = $feature->featureloc->srcfeature_id;
-  if (!$pfeaturelocs) {
-    $pfeaturelocs = array();
-  }
-
-  // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
-  $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
-  $feature->matched_featurelocs = $mfeaturelocs;
-
-  // combine all three alignments into a single array for printing together in
-  // a single list
-  $alignments = array();
-  foreach ($pfeaturelocs as $featureloc) {
-    // if type is a 'match' then ignore it. We will handle those below
-    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
-       continue;
-    }
-    $alignment = new stdClass();
-    $alignment->record = $featureloc;
-    $alignment->name = $featureloc->feature_id->name;
-    $alignment->type = $featureloc->feature_id->type_id->name;
-    $alignment->fmin = $featureloc->fmin;
-    $alignment->fmax = $featureloc->fmax;
-    $alignment->phase = $featureloc->phase;
-    $alignment->strand = $featureloc->strand;
-    $alignments[] = $alignment;
-    if (property_exists($featureloc->feature_id, 'nid')) {
-      $alignment->nid = $featureloc->feature_id->nid;
-    }
-  }
-  foreach ($cfeaturelocs as $featureloc) {
-    // if type is a 'match' then ignore it. We will handle those below
-    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
-      continue;
-    }
-    $alignment = new stdClass();
-    $alignment->record = $featureloc;
-    $alignment->name = $featureloc->srcfeature_id->name;
-    $alignment->type = $featureloc->srcfeature_id->type_id->name;
-    $alignment->fmin = $featureloc->fmin;
-    $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
-    $alignment->fmax = $featureloc->fmax;
-    $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
-    $alignment->phase = $featureloc->phase;
-    $alignment->strand = $featureloc->strand;
-    $alignments[] = $alignment;
-    if (property_exists($featureloc->srcfeature_id, 'nid')) {
-      $alignment->nid = $featureloc->srcfeature_id->nid;
-    }
-  }
-  // in matching features, the left feature is always the feature
-  // provided to this function.
-  foreach ($mfeaturelocs as $featureloc) {
-     // get more information about the right feature
-     $select = array('feature_id' => $featureloc->right_srcfeature_id);
-     $rfeature = tripal_core_generate_chado_var('feature', $select);
-     // now add to the list
-     $alignment = new stdClass();
-     $alignment->record = $featureloc;
-     $alignment->right_feature = $rfeature;
-     $alignment->name = $rfeature->name;
-     $alignment->type = $rfeature->type_id->name;
-     $alignment->fmin = $featureloc->left_fmin;
-     $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
-     $alignment->fmax = $featureloc->left_fmax;
-     $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
-     $alignment->phase = $featureloc->left_phase;
-     $alignment->strand = $featureloc->left_strand;
-     $alignment->right_fmin = $featureloc->right_fmin;
-     $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
-     $alignment->right_fmax = $featureloc->right_fmax;
-     $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
-     $alignment->right_phase = $featureloc->right_phase;
-     $alignment->right_strand = $featureloc->right_strand;
-     $alignments[] = $alignment;
-     if (property_exists($rfeature, 'nid')) {
-       $alignment->nid = $rfeature->nid;
-     }
-  }
-  $feature->all_featurelocs = $alignments;
-}
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
-  $organism = $variables['node']->organism;
-  $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
-}
 
 /**
  *

+ 43 - 22
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.publication.tpl.php

@@ -1,16 +1,16 @@
 <?php
-$featuremap  = $variables['node']->featuremap;
+$featuremap = $variables['node']->featuremap;
 
 // expand featuremap to include pubs 
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_pub');
-$pubs = $featuremap->featuremap_pub;
-$pubs = tripal_core_expand_chado_vars($pubs, 'field', 'pub.title');
+$options = array('return_array' => 1);
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_pub', $options);
+$featuremap_pubs = $featuremap->featuremap_pub; 
 
-if (count($pubs) > 0) { ?>
 
-  <div id="tripal_featuremap-pub-box" class="tripal_featuremap-info-box tripal-info-box">
-    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Publications</div>
-    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc"></div> <?php 
+if (count($featuremap_pubs) > 0) { ?>
+  <div id="tripal_featuremap_pub-pub-box" class="tripal_featuremap_pub-info-box tripal-info-box">
+    <div class="tripal_featuremap_pub-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_featuremap_pub-info-box-desc tripal-info-box-desc"></div> <?php 
   
     // the $headers array is an array of fields to use as the colum headers.
     // additional documentation can be found here
@@ -20,28 +20,48 @@ if (count($pubs) > 0) { ?>
     // the $rows array contains an array of rows where each row is an array
     // of values for each column of the table in that row.  Additional documentation
     // can be found here:
-    // https://api.dr
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
     $rows = array();
     
-    foreach ($pubs AS $pub) {
-      // get the citation
+    foreach ($featuremap_pubs as $featuremap_pub) {
+      $pub = $featuremap_pub->pub_id;
+      $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+      $citation = $pub->title;  // use the title as the default citation
+      
+      // get the citation for this pub if it exists
       $values = array(
-        'pub_id' => $pub->pub_id->pub_id,
+        'pub_id' => $pub->pub_id, 
         'type_id' => array(
           'name' => 'Citation',
         ),
       );
-      $citation = tripal_core_generate_chado_var('pubprop', $values);
-      $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
-      if(property_exists($pub->pub_id, 'nid')) {
-        $citation->value = l($citation->value, 'node/' . $pub->pub_id->nid, array('attributes' => array('target' => '_blank')));
+      $options = array('return_array' => 1);
+      $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+      if (count($citation_prop) == 1) {
+        $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+        $citation = $citation_prop[0]->value;
+      }
+      
+      // if the publication is synced then link to it
+      if (property_exists($pub, 'nid')) {
+        // replace the title with a link
+        $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
+        $patterns = array(
+          '/(\()/', '/(\))/', 
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/', 
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
       }
+      
       $rows[] = array(
-        $pub->pub_id->pyear,
-        $citation->value,
+        $pub->pyear,
+        $citation,
       );
     }
-      
+    
     // the $table array contains the headers and rows array as well as other
     // options for controlling the display of the table.  Additional
     // documentation can be found here:
@@ -50,15 +70,16 @@ if (count($pubs) > 0) { ?>
       'header' => $headers,
       'rows' => $rows,
       'attributes' => array(
-        'id' => 'tripal_pub-table-publications',
+        'id' => 'tripal_featuremap-table-publications',
       ),
       'sticky' => FALSE,
       'caption' => '',
       'colgroups' => array(),
       'empty' => '',
     );
+    
     // once we have our table array structure defined, we call Drupal's theme_table()
     // function to generate the table.
-    print theme_table($table);?>
+    print theme_table($table); ?>
   </div> <?php 
-}?>
+}

+ 25 - 25
tripal_featuremap/tripal_featuremap.module

@@ -132,7 +132,7 @@ function tripal_featuremap_menu() {
     'title' => 'Help',
     'description' => 'Basic Description of Tripal Map Module Functionality',
     'page callback' => 'theme',
-    'page arguments' => array('tripal_featuremap.help'),
+    'page arguments' => array('tripal_featuremap_help'),
     'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 10
@@ -226,37 +226,37 @@ function tripal_featuremap_theme($existing, $type, $theme, $path) {
       'base hook' => 'node',
       'path' => "$core_path/theme",
     ),
-    'tripal_featuremap.base' => array(
+    'tripal_featuremap_base' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_featuremap.base',
       'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap.properties' => array(
+    'tripal_featuremap_properties' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_featuremap.properties',
       'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap.featurepos' => array(
+    'tripal_featuremap_featurepos' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_featuremap.featurepos',
       'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap.publication' => array(
+    'tripal_featuremap_publication' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_featuremap.publication',
       'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap.references' => array(
+    'tripal_featuremap_references' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_featuremap.references',
       'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap.help' => array(
+    'tripal_featuremap_help' => array(
       'template' => 'tripal_featuremap.help',
       'variables' =>  array(NULL),
       'path' => "$path/theme",
     ),
-    'tripal_featuremap.teaser' => array(
+    'tripal_featuremap_teaser' => array(
       'template' => 'tripal_featuremap.teaser',
       'variables' =>  array(NULL),
       'path' => "$path/theme/tripal_featuremap",
@@ -273,25 +273,25 @@ function tripal_featuremap_node_view($node, $view_mode, $langcode) {
     case 'chado_featuremap':
       // Show feature browser and counts
       if ($view_mode == 'full') {
-        $node->content['tripal_featuremap.base'] = array(
-          '#value' => theme('tripal_featuremap.base', array('node' => $node)),
+        $node->content['tripal_featuremap_base'] = array(
+          '#value' => theme('tripal_featuremap_base', array('node' => $node)),
         );
-        $node->content['tripal_featuremap.featurepos'] = array(
-          '#value' => theme('tripal_featuremap.featurepos', array('node' => $node)),
+        $node->content['tripal_featuremap_featurepos'] = array(
+          '#value' => theme('tripal_featuremap_featurepos', array('node' => $node)),
         );
-        $node->content['tripal_featuremap.properties'] = array(
-          '#value' => theme('tripal_featuremap.properties', array('node' => $node)),
+        $node->content['tripal_featuremap_properties'] = array(
+          '#value' => theme('tripal_featuremap_properties', array('node' => $node)),
         );
-        $node->content['tripal_featuremap.publication'] = array(
-          '#value' => theme('tripal_featuremap.publication', array('node' => $node)),
+        $node->content['tripal_featuremap_publication'] = array(
+          '#value' => theme('tripal_featuremap_publication', array('node' => $node)),
         );
-        $node->content['tripal_featuremap.references'] = array(
-          '#value' => theme('tripal_featuremap.references', array('node' => $node)),
+        $node->content['tripal_featuremap_references'] = array(
+          '#value' => theme('tripal_featuremap_references', array('node' => $node)),
         );
       }
       if ($view_mode == 'teaser') {
-        $node->content['tripal_featuremap.teaser'] = array(
-          '#value' => theme('tripal_featuremap.teaser', array('node' => $node)),
+        $node->content['tripal_featuremap_teaser'] = array(
+          '#value' => theme('tripal_featuremap_teaser', array('node' => $node)),
         );
       }
       break;
@@ -332,23 +332,23 @@ function tripal_featuremap_block_view($delta = '') {
     switch ($delta) {
       case 'mapbase':
         $block['subject'] = t('Library Details');
-        $block['content'] = theme('tripal_featuremap.base', $node);
+        $block['content'] = theme('tripal_featuremap_base', $node);
         break;
       case 'mapprops':
         $block['subject'] = t('Properties');
-        $block['content'] = theme('tripal_featuremap.properties', $node);
+        $block['content'] = theme('tripal_featuremap_properties', $node);
         break;
       case 'mappos':
         $block['subject'] = t('Features');
-        $block['content'] = theme('tripal_featuremap.featurepos', $node);
+        $block['content'] = theme('tripal_featuremap_featurepos', $node);
         break;
       case 'mappubs':
         $block['subject'] = t('Publications');
-        $block['content'] = theme('tripal_featuremap.publication', $node);
+        $block['content'] = theme('tripal_featuremap_publication', $node);
         break;
       case 'maprefs':
         $block['subject'] = t('References');
-        $block['content'] = theme('tripal_featuremap.references', $node);
+        $block['content'] = theme('tripal_featuremap_references', $node);
         break;
       default :
     }

+ 85 - 0
tripal_library/theme/tripal_library/tripal_library.publications.tpl.php

@@ -0,0 +1,85 @@
+<?php
+$library = $variables['node']->library;
+
+// expand library to include pubs 
+$options = array('return_array' => 1);
+$library = tripal_core_expand_chado_vars($library, 'table', 'library_pub', $options);
+$library_pubs = $library->library_pub; 
+
+
+if (count($library_pubs) > 0) { ?>
+  <div id="tripal_library_pub-pub-box" class="tripal_library_pub-info-box tripal-info-box">
+    <div class="tripal_library_pub-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_library_pub-info-box-desc tripal-info-box-desc"></div> <?php 
+  
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Year', 'Publication');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($library_pubs as $library_pub) {
+      $pub = $library_pub->pub_id;
+      $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+      $citation = $pub->title;  // use the title as the default citation
+      
+      // get the citation for this pub if it exists
+      $values = array(
+        'pub_id' => $pub->pub_id, 
+        'type_id' => array(
+          'name' => 'Citation',
+        ),
+      );
+      $options = array('return_array' => 1);
+      $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+      if (count($citation_prop) == 1) {
+        $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+        $citation = $citation_prop[0]->value;
+      }
+      
+      // if the publication is synced then link to it
+      if ($pub->nid) {
+        // replace the title with a link
+        $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
+        $patterns = array(
+          '/(\()/', '/(\))/',
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/',
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
+      }
+      
+      $rows[] = array(
+        $pub->pyear,
+        $citation,
+      );
+    }
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_library-table-publications',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php 
+}

+ 37 - 30
tripal_library/tripal_library.module

@@ -100,7 +100,7 @@ function tripal_library_menu() {
     'title' => 'Help',
     'description' => 'Basic Description of Tripal Library Module Functionality',
     'page callback' => 'theme',
-    'page arguments' => array('tripal_library.help'),
+    'page arguments' => array('tripal_library_help'),
     'access arguments' => array('administer tripal libraries'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 10
@@ -167,26 +167,28 @@ function tripal_library_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {
     case 'chado_library':
       if ($view_mode == 'full') {
-        $node->content['tripal_library.base'] = array(
-          '#value' => theme('tripal_library.base', array('node' => $node)),
+        $node->content['tripal_library_base'] = array(
+          '#value' => theme('tripal_library_base', array('node' => $node)),
         );      
-        $node->content['tripal_library.properties'] = array(
-          '#value' => theme('tripal_library.properties', array('node' => $node)),
+        $node->content['tripal_library_properties'] = array(
+          '#value' => theme('tripal_library_properties', array('node' => $node)),
         );
-        
-        $node->content['tripal_library.references'] = array(
-          '#value' => theme('tripal_library.references', array('node' => $node)),
+        $node->content['tripal_library_publications'] = array(
+          '#value' => theme('tripal_library_publications', array('node' => $node)),
+        );
+        $node->content['tripal_library_references'] = array(
+          '#value' => theme('tripal_library_references', array('node' => $node)),
         );      
-        $node->content['tripal_library.synonyms'] = array(
-          '#value' => theme('tripal_library.synonyms', array('node' => $node)),
+        $node->content['tripal_library_synonyms'] = array(
+          '#value' => theme('tripal_library_synonyms', array('node' => $node)),
         );
-        $node->content['tripal_library.terms'] = array(
-          '#value' => theme('tripal_library.terms', array('node' => $node)),
+        $node->content['tripal_library_terms'] = array(
+          '#value' => theme('tripal_library_terms', array('node' => $node)),
         );
       }
       if ($view_mode == 'teaser') {
-        $node->content['tripal_library.teaser'] = array(
-          '#value' => theme('tripal_library.teaser', array('node' => $node)),
+        $node->content['tripal_library_teaser'] = array(
+          '#value' => theme('tripal_library_teaser', array('node' => $node)),
         );
       }
       break;
@@ -225,53 +227,58 @@ function tripal_library_theme($existing, $type, $theme, $path) {
     ),
 
     // tripal_library templates
-    'tripal_library.base' => array(
+    'tripal_library_base' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.base',
       'path' => "$path/theme/tripal_library",
     ),
-    'tripal_library.properties' => array(
+    'tripal_library_properties' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.properties',
       'path' => "$path/theme/tripal_library",
     ),
-    'tripal_library.references' => array(
+    'tripal_library_publications' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_library.publications',
+      'path' => "$path/theme/tripal_library",
+    ),
+    'tripal_library_references' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.references',
       'path' => "$path/theme/tripal_library",
     ),
-    'tripal_library.synonyms' => array(
+    'tripal_library_synonyms' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.synonyms',
       'path' => "$path/theme/tripal_library",
     ),
-    'tripal_library.terms' => array(
+    'tripal_library_terms' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.terms',
       'path' => "$path/theme/tripal_library",
     ),
-    'tripal_library.help' => array(
+    'tripal_library_help' => array(
       'template' => 'tripal_library.help',
       'variables' =>  array(NULL),
       'path' => "$path/theme",
     ),
     
     // teaser
-    'tripal_library.teaser' => array(
+    'tripal_library_teaser' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library.teaser',
       'path' => "$path/theme/tripal_library",
     ),
     
     // tripal_organism templates
-    'tripal_organism.libraries' => array(
+    'tripal_organism_libraries' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_organism.libraries',
       'path' => "$path/theme/tripal_organism",
     ),
     
     // tripal_feature templates
-    'tripal_feature.libraries' => array(
+    'tripal_feature_libraries' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_feature.libraries',
       'path' => "$path/theme/tripal_feature",
@@ -331,31 +338,31 @@ function tripal_library_block_view($delta = '') {
     switch ($delta) {
       case 'libreferences':
         $block['subject'] = t('Cross References');
-        $block['content'] = theme('tripal_library.references', $node);
+        $block['content'] = theme('tripal_library_references', $node);
         break;
       case 'libbase':
         $block['subject'] = t('Library Details');
-        $block['content'] = theme('tripal_library.base', $node);
+        $block['content'] = theme('tripal_library_base', $node);
         break;
       case 'libsynonyms':
         $block['subject'] = t('Synonyms');
-        $block['content'] = theme('tripal_library.synonyms', $node);
+        $block['content'] = theme('tripal_library_synonyms', $node);
         break;
       case 'libproperties':
         $block['subject'] = t('Properties');
-        $block['content'] = theme('tripal_library.properties', $node);
+        $block['content'] = theme('tripal_library_properties', $node);
         break;
       case 'libterms':
         $block['subject'] = t('Library Terms');
-        $block['content'] = theme('tripal_library.terms', $node);
+        $block['content'] = theme('tripal_library_terms', $node);
         break;
       case 'featurelibs':
         $block['subject'] = t('Libraries');
-        $block['content'] = theme('tripal_feature.libraries', $node);
+        $block['content'] = theme('tripal_feature_libraries', $node);
         break;
       case 'orglibs':
         $block['subject'] = t('Libraries');
-        $block['content'] = theme('tripal_organism.libraries', $node);
+        $block['content'] = theme('tripal_organism_libraries', $node);
         break;
       default :
     }

+ 8 - 8
tripal_project/includes/tripal_project.chado_node.inc

@@ -21,7 +21,6 @@
 function chado_project_form(&$node, $form_state) {
   $form = array();
   
-dpm("hi");
   // Default values can come in the following ways:
   //
   // 1) as elements of the $node object.  This occurs when editing an existing project
@@ -48,22 +47,25 @@ dpm("hi");
     // is in the $node->body field. If it is we'll use that.  When the node is
     // edited the text will be moved out of the body and into the projectprop
     // table where it should belong.
-    if ($node->body) {
+    if (property_exists($node, 'body')) {
       $description = $node->body;
     }
     else {
-      $description = $node->description;
+      $description = $project->description;
     }
     if (!$description) {
       $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
       $description = $projectprop->value;
     }
     
+    $title = $project->name;
+    $project_id = $project->project_id;
+    
     // keep track of the project id if we have.  If we do have one then
     // this is an update as opposed to an insert.
     $form['project_id'] = array(
       '#type' => 'value',
-      '#value' => $project->project_id,
+      '#value' => $project_id,
     );
   }
   
@@ -86,7 +88,6 @@ dpm("hi");
     '#description'   => t('Please enter the title for this project. This appears at the top of the project page.'),
     '#required'      => TRUE,
     '#default_value' => $node->title,
-    '#weight'        => 1
   );
 
   $form['description']= array(
@@ -95,7 +96,6 @@ dpm("hi");
     '#description'   => t('A brief description of the project'),
     '#required'      => TRUE,
     '#default_value' => $description,
-    '#weight'        => 5
   );
 
   // get the project properties
@@ -128,7 +128,7 @@ dpm("hi");
   // as a property even though it will be stored as a property. 
   $exclude = array('Project Description');
   $include = array();
-  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the project_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
+  $instructions = t('To add properties to the drop down list, you must ' . l("add terms to the project_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
   tripal_core_properties_form($form, $form_state, 'projectprop', 'project_id', 'project_property',
     $properties, $project_id, $exclude, $include, $instructions, 'Properties');
   
@@ -159,7 +159,7 @@ function chado_project_validate($node, $form, &$form_state) {
   $project = 0;
   // check to make sure the name on the project is unique
   // before we try to insert into chado.
-  if ($node->project_id) {
+  if (property_exists($node, 'project_id')) {
     $sql = "SELECT * FROM {project} WHERE name = :name AND NOT project_id = :project_id";
     $project = chado_query($sql, array(':name' => $node->title, ':project_id' => $node->project_id))->fetchObject();
   }

+ 74 - 0
tripal_project/theme/tripal_project.theme.inc

@@ -1 +1,75 @@
 <?php
+/**
+ *
+ *
+ * @ingroup tripal_project
+ */
+function tripal_project_preprocess_tripal_project_relationships(&$variables) {
+  $project = $variables['node']->project;
+  
+  // expand the project object to include the project relationships.
+  $options = array(
+    'return_array' => 1,
+    // we don't want to fully recurse we only need information about the 
+    // relationship type and the object and subject projects
+    'include_fk' => array(
+      'type_id'    => 1,
+      'object_project_id'  => 1,
+      'subject_project_id' => 1,
+    ),
+  );
+  $project = tripal_core_expand_chado_vars($project, 'table', 'project_relationship', $options);
+  
+  // get the subject relationships
+  $srelationships = $project->project_relationship->subject_project_id;
+  $orelationships = $project->project_relationship->object_project_id;
+  
+  // combine both object and subject relationshisp into a single array
+  $relationships = array();
+  $relationships['object'] = array();
+  $relationships['subject'] = array();
+  
+  // iterate through the object relationships
+  if ($orelationships) {
+    foreach ($orelationships as $relationship) {      
+       $rel = new stdClass(); 
+       $rel->record = $relationship;
+       
+       // get the relationship and child types
+       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+
+       // get the node id of the subject
+       $sql = "SELECT nid FROM {chado_project} WHERE project_id = :project_id";
+       $n = db_query($sql, array(':project_id' => $relationship->subject_project_id->project_id))->fetchObject();
+       if ($n) {
+          $rel->record->nid = $n->nid;
+       }
+  
+       if (!array_key_exists($rel_type, $relationships['object'])) {
+         $relationships['object'][$rel_type][] = $rel;
+       }
+    }
+  }
+  
+  // now add in the subject relationships
+  if ($srelationships) {
+    foreach ($srelationships as $relationship) {
+       $rel = new stdClass(); 
+       $rel->record = $relationship;
+       
+       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+       
+       // get the node id of the subject
+       $sql = "SELECT nid FROM {chado_project} WHERE project_id = :project_id";
+       $n = db_query($sql, array(':project_id' => $relationship->object_project_id->project_id))->fetchObject();
+       if ($n) {
+          $rel->record->nid = $n->nid;
+       }
+       
+       if (!array_key_exists($rel_type, $relationships['subject'])) {
+         $relationships['subject'][$rel_type][] = $rel;
+       }
+    }
+  }
+  $project->all_relationships = $relationships;
+}

+ 2 - 2
tripal_project/theme/tripal_project/tripal_project.base.tpl.php

@@ -11,10 +11,10 @@ $project = $variables['node']->project;
 // if there is data in the projectprop table for a descrtion then that takes 
 // precedence 
 $description = '';
-if ($node->body) {
+if (property_exists($node, 'body')) {
   $description = $node->body;
 }
-if ($node->description) {
+if ($project->description) {
   $description = $project->description;
 }
 else {

+ 7 - 4
tripal_project/theme/tripal_project/tripal_project.contact.tpl.php

@@ -8,20 +8,20 @@ $project_contacts = $project->project_contact;
 
 if (count($project_contacts) > 0) { ?>
   <div id="tripal_project-contacts-box" class="tripal_project-info-box tripal-info-box">
-    <div class="tripal_project-info-box-title tripal-info-box-title">People</div>
-    <div class="tripal_project-info-box-desc tripal-info-box-desc">The following people particpated in development or execution of this project</div><?php     
+    <div class="tripal_project-info-box-title tripal-info-box-title">Participants</div>
+    <div class="tripal_project-info-box-desc tripal-info-box-desc">The following indivuals or groups have particpated in development or execution of this project</div><?php     
     
     // the $headers array is an array of fields to use as the colum headers.
     // additional documentation can be found here
     // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-    $headers = array('Property Name', 'Value');
+    $headers = array('', 'Details');
     
     // the $rows array contains an array of rows where each row is an array
     // of values for each column of the table in that row.  Additional documentation
     // can be found here:
     // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
     $rows = array();
-    
+    $i = 1;
     foreach ($project_contacts as $project_contact) {
       $contact = $project_contact->contact_id;
       $contact_name = $contact->name;
@@ -31,6 +31,7 @@ if (count($project_contacts) > 0) { ?>
       
       // Get some additional details about this contact if they exists.
       $details = '';
+      $options = array('return_array' => 1);
       $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
       $properties = $contact->contactprop;
       $options = array('order_by' => array('rank' => 'ASC'));
@@ -51,8 +52,10 @@ if (count($project_contacts) > 0) { ?>
       }
       
       $rows[] = array(
+        $i,
         $contact_name . $details,
       );
+      $i++;
     } 
         // the $table array contains the headers and rows array as well as other
     // options for controlling the display of the table.  Additional

+ 8 - 1
tripal_project/theme/tripal_project/tripal_project.publications.tpl.php

@@ -46,7 +46,14 @@ if (count($project_pubs) > 0) { ?>
       if ($pub->nid) {
         // replace the title with a link
         $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
-        $citation = preg_replace('/' . $pub->title . '/', $link, $citation);
+        $patterns = array(
+          '/(\()/', '/(\))/',
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/',
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
       }
       
       $rows[] = array(

+ 55 - 96
tripal_project/theme/tripal_project/tripal_project.relationships.tpl.php

@@ -25,105 +25,64 @@ $subject_rels = $all_relationships['subject'];
 if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
   <div id="tripal_project-relationships-box" class="tripal_project-info-box tripal-info-box">
     <div class="tripal_project-info-box-title tripal-info-box-title">Relationships</div>
-    <div class="tripal_project-info-box-desc tripal-info-box-desc"></div> <?php
-    // first add in the subject relationships.  
-    foreach ($subject_rels as $rel_type => $rels){
-      foreach ($rels as $obj_type => $objects){ ?>
-        <p>This <?php print $project->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> project(s): <?php
-         
-        // the $headers array is an array of fields to use as the colum headers.
-        // additional documentation can be found here
-        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-        $headers = array('Name');
-        
-        // the $rows array contains an array of rows where each row is an array
-        // of values for each column of the table in that row.  Additional documentation
-        // can be found here:
-        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-        $rows = array();
-        
-        foreach ($objects as $object){
-          // link the project to it's node
-          $project_name = $object->record->object_id->name;
-          if (property_exists($object->record, 'nid')) {
-            $project_name = "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
-          }
+    <div class="tripal_project-info-box-desc tripal-info-box-desc">This project is related to the following other projects:</div> <?php
 
-          $rows[] = array(
-            $project_name, 
-          ); 
-         } 
-         // the $table array contains the headers and rows array as well as other
-         // options for controlling the display of the table.  Additional
-         // documentation can be found here:
-         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-         $table = array(
-           'header' => $headers,
-           'rows' => $rows,
-           'attributes' => array(
-             'id' => 'tripal_project-table-relationship-object',
-           ),
-           'sticky' => FALSE,
-           'caption' => '',
-           'colgroups' => array(),
-           'empty' => '',
-         );
-         
-         // once we have our table array structure defined, we call Drupal's theme_table()
-         // function to generate the table.
-         print theme_table($table); ?>
-         </p>
-         <br><?php
-       }
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Relationship');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    // first add in the subject relationships.  
+    foreach ($subject_rels as $rel_type => $objects){ 
+      foreach ($objects as $object){
+        // link the project to it's node
+        $object_name = $object->record->object_project_id->name;
+        if (property_exists($object->record, 'nid')) {
+          $object_name = l($object_name, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
+        }
+        $rows[] = array(
+          "$project->name is a \"$rel_type\" of $object_name",
+        ); 
+      }
     }
     
     // second add in the object relationships.  
-    foreach ($object_rels as $rel_type => $rels){
-      foreach ($rels as $subject_type => $subjects){?>
-        <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> project(s) are <?php print $rel_type ?> this <?php print $project->type_id->name;?>: <?php 
-        // the $headers array is an array of fields to use as the colum headers.
-        // additional documentation can be found here
-        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-        $headers = array('Name');
-        
-        // the $rows array contains an array of rows where each row is an array
-        // of values for each column of the table in that row.  Additional documentation
-        // can be found here:
-        // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-        $rows = array();
-        
-        foreach ($subjects as $subject){
-          // link the project to it's node
-          $project_name = $subject->record->subject_id->name;
-          if (property_exists($subject->record, 'nid')) {
-            $project_name = "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
-          }
-          $rows[] = array(
-            $project_name, 
-          ); 
-         } 
-         // the $table array contains the headers and rows array as well as other
-         // options for controlling the display of the table.  Additional
-         // documentation can be found here:
-         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-         $table = array(
-           'header' => $headers,
-           'rows' => $rows,
-           'attributes' => array(
-             'id' => 'tripal_project-table-relationship-subject',
-           ),
-           'sticky' => FALSE,
-           'caption' => '',
-           'colgroups' => array(),
-           'empty' => '',
-         );
-         
-         // once we have our table array structure defined, we call Drupal's theme_table()
-         // function to generate the table.
-         print theme_table($table); ?>
-         </p>
-         <br><?php
-       }
-    }?>
+    foreach ($object_rels as $rel_type => $subjects){
+      foreach ($subjects as $subject){
+        // link the project to it's node
+        $subject_name = $subject->record->subject_project_id->name;
+        if (property_exists($subject->record, 'nid')) {
+          $subject_name = l($subject_name, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
+        }
+        $rows[] = array(
+          "$subject_name is a \"$rel_type\" of $project->name",
+        ); 
+      }
+    }
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_project-table-relationship-subject',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+     
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
   </div> <?php
 }

+ 19 - 1
tripal_project/tripal_project.install

@@ -97,7 +97,7 @@ function tripal_project_add_cvs() {
  */
 function tripal_project_add_cvterms() {
 
-  // Insert cvterm 'project_description' into cvterm table of chado
+  // Insert cvterm 'Project Description' into cvterm table of chado
   // database. This CV term is used to keep track of the project
   // description in the projectprop table.
   tripal_cv_add_cvterm(
@@ -107,6 +107,21 @@ function tripal_project_add_cvterms() {
     ),
     'project_property', 0, 1, 'tripal'
   );
+  
+  tripal_cv_add_cvterm(
+    array(
+      'name' => 'Project Type',
+      'def'  => 'The short few word description of the type of project.'
+    ),
+   'project_property', 0, 1, 'tripal'
+  );
+  tripal_cv_add_cvterm(
+    array(
+      'name' => 'Funding Source',
+      'def'  => 'The funding source for this project.'
+    ),
+    'project_property', 0, 1, 'tripal'
+  );
 }
 
 /**
@@ -131,4 +146,7 @@ function tripal_project_update_7000() {
   if (!$success) {
     throw new DrupalUpdateException('Failed to move project properties to new project_property CV.');
   }
+  
+  // add in new CVterms
+  tripal_project_add_cvterms();
 }

+ 21 - 92
tripal_project/tripal_project.module

@@ -1,7 +1,8 @@
 <?php
-
-require('includes/tripal_project.admin.inc');
 require('api/tripal_project.api.inc');
+require('theme/tripal_project.theme.inc');
+require('includes/tripal_project.admin.inc');
+require('includes/tripal_project.chado_node.inc');
 
 /**
  *  @file
@@ -85,7 +86,7 @@ function tripal_project_menu() {
     'title' => 'Help',
     'description' => ("Basic Description of Tripal Project Module Functionality."),
     'page callback' => 'theme',
-    'page arguments' => array('tripal_project.help'),
+    'page arguments' => array('tripal_project_help'),
     'access arguments' => array('adminster tripal projects'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 6
@@ -184,37 +185,37 @@ function tripal_project_theme($existing, $type, $theme, $path) {
       'base hook' => 'node',
       'path' => "$core_path/theme",
     ),
-    'tripal_project.base' => array(
+    'tripal_project_base' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.base',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.contact' => array(
+    'tripal_project_contact' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.contact',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.properties' => array(
+    'tripal_project_properties' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.properties',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.publications' => array(
+    'tripal_project_publications' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.publications',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.relationships' => array(
+    'tripal_project_relationships' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.relationships',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.teaser' => array(
+    'tripal_project_teaser' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_project.teaser',
       'path' => "$path/theme/tripal_project",
     ),
-    'tripal_project.help' => array(
+    'tripal_project_help' => array(
       'variables' => 'tripal_project.help',
       'variables' =>  array(NULL),
       'path' => "$path/theme",
@@ -232,20 +233,20 @@ function tripal_project_node_view($node, $view_mode, $langcode) {
     case 'chado_project':
       // Show feature browser and counts
       if ($view_mode == 'full') {
-        $node->content['tripal_project.base'] = array(
-          '#value' => theme('tripal_project.base', array('node' => $node)),
+        $node->content['tripal_project_base'] = array(
+          '#value' => theme('tripal_project_base', array('node' => $node)),
         );
-        $node->content['tripal_project.contact'] = array(
-          '#value' => theme('tripal_project.contact', array('node' => $node)),
+        $node->content['tripal_project_contact'] = array(
+          '#value' => theme('tripal_project_contact', array('node' => $node)),
         );
-        $node->content['tripal_project.properties'] = array(
-          '#value' => theme('tripal_project.properties', array('node' => $node)),
+        $node->content['tripal_project_properties'] = array(
+          '#value' => theme('tripal_project_properties', array('node' => $node)),
         );
-        $node->content['tripal_project.publications'] = array(
-          '#value' => theme('tripal_project.publications', array('node' => $node)),
+        $node->content['tripal_project_publications'] = array(
+          '#value' => theme('tripal_project_publications', array('node' => $node)),
         );
-        $node->content['tripal_project.relationships'] = array(
-          '#value' => theme('tripal_project.relationships', array('node' => $node)),
+        $node->content['tripal_project_relationships'] = array(
+          '#value' => theme('tripal_project_relationships', array('node' => $node)),
         );
       }
       if ($view_mode == 'teaser') {
@@ -316,79 +317,7 @@ function tripal_project_block_view($delta = '') {
     return $block;
   }
 }
-/**
- *
- *
- * @ingroup tripal_project
- */
-function tripal_project_preprocess_tripal_project_relationships(&$variables) {
-  // we want to provide a new variable that contains the matched projects.
-  $project = $variables['node']->project;
-
-  // normally we would use tripal_core_expand_chado_vars to expand our
-  // organism object and add in the relationships, however whan a large
-  // number of relationships are present this significantly slows the
-  // query, therefore we will manually perform the query
-  $sql = "
-    SELECT P.name, P.project_id, CP.nid, CVT.name as rel_type
-    FROM project_relationship PR
-      INNER JOIN {project} P            ON PR.object_project_id = P.project_id
-      INNER JOIN {cvterm} CVT           ON PR.type_id           = CVT.cvterm_id
-      LEFT JOIN public.chado_project CP ON P.project_id         = CP.project_id
-    WHERE PR.subject_project_id = :project_id
-  ";
-  $as_subject = chado_query($sql, array(':project_id' => $project->project_id));
-  $sql = "
-    SELECT P.name, P.project_id, CP.nid, CVT.name as rel_type
-    FROM project_relationship PR
-      INNER JOIN {project} P            ON PR.subject_project_id = P.project_id
-      INNER JOIN {cvterm} CVT           ON PR.type_id            = CVT.cvterm_id
-      LEFT JOIN public.chado_project CP ON P.project_id          = CP.project_id
-    WHERE PR.object_project_id = :project_id
-  ";
-  $as_object = chado_query($sql, array(':project_id' => $project->project_id));
-
-  // combine both object and subject relationshisp into a single array
-  $relationships = array();
-  $relationships['object'] = array();
-  $relationships['subject'] = array();
-
-  // iterate through the object relationships
-  while ($relationship = $as_object->fetchObject()) {
 
-     // get the relationship and child types
-     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
-     $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
-
-     if (!array_key_exists($rel_type, $relationships['object'])) {
-       $relationships['object'][$rel_type] = array();
-     }
-     if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
-       $relationships['object'][$rel_type][$sub_type] = array();
-     }
-     $relationships['object'][$rel_type][$sub_type][] = $relationship;
-  }
-
-  // now add in the subject relationships
-  while ($relationship = $as_subject->fetchObject()) {
-
-     // get the relationship and child types
-     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
-     $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
-
-     if (!array_key_exists($rel_type, $relationships['subject'])) {
-       $relationships['subject'][$rel_type] = array();
-     }
-     if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
-       $relationships['subject'][$rel_type][$obj_type] = array();
-     }
-     $relationships['subject'][$rel_type][$obj_type][] = $relationship;
-  }
-
-
-  $project->all_relationships = $relationships;
-
-}
 /**
  * Implementation of hook_form_alter()
  *

+ 4 - 0
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -879,6 +879,10 @@ function tripal_stock_node_view($node, $view_mode, $langcode) {
         $node->content['tripal_stock_properties'] = array(
           '#value' => theme('tripal_stock_properties', array('node' => $node)),
         );
+        // Publications
+        $node->content['tripal_stock_publications'] = array(
+          '#value' => theme('tripal_stock_publications', array('node' => $node)),
+        );
         // Synonyms
         $node->content['tripal_stock_synonyms'] = array(
           '#value' => theme('tripal_stock_synonyms', array('node' => $node)),

+ 85 - 0
tripal_stock/theme/tripal_stock/tripal_stock.publications.tpl.php

@@ -0,0 +1,85 @@
+<?php
+$stock = $variables['node']->stock;
+
+// expand stock to include pubs 
+$options = array('return_array' => 1);
+$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_pub', $options);
+$stock_pubs = $stock->stock_pub; 
+
+
+if (count($stock_pubs) > 0) { ?>
+  <div id="tripal_stock_pub-pub-box" class="tripal_stock_pub-info-box tripal-info-box">
+    <div class="tripal_stock_pub-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_stock_pub-info-box-desc tripal-info-box-desc"></div> <?php 
+  
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Year', 'Publication');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($stock_pubs as $stock_pub) {
+      $pub = $stock_pub->pub_id;
+      $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+      $citation = $pub->title;  // use the title as the default citation
+      
+      // get the citation for this pub if it exists
+      $values = array(
+        'pub_id' => $pub->pub_id, 
+        'type_id' => array(
+          'name' => 'Citation',
+        ),
+      );
+      $options = array('return_array' => 1);
+      $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+      if (count($citation_prop) == 1) {
+        $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+        $citation = $citation_prop[0]->value;
+      }
+      
+      // if the publication is synced then link to it
+      if ($pub->nid) {
+        // replace the title with a link
+        $link = l($pub->title, 'node/' . $pub->nid ,array('attributes' => array('target' => '_blank')));
+        $patterns = array(
+          '/(\()/', '/(\))/',
+          '/(\])/', '/(\[)/',
+          '/(\{)/', '/(\})/',
+          '/(\+)/', '/(\.)/', '/(\?)/',
+        );
+        $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
+        $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
+      }
+      
+      $rows[] = array(
+        $pub->pyear,
+        $citation,
+      );
+    }
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_stock-table-publications',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
+  </div> <?php 
+}

+ 5 - 0
tripal_stock/tripal_stock.module

@@ -321,6 +321,11 @@ function tripal_stock_theme() {
       'template' => 'tripal_stock_properties',
       'path' => "$theme_path/tripal_stock",
     ),
+    'tripal_stock_publications' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_stock.publications',
+      'path' => "$theme_path/tripal_stock",
+    ),
     'tripal_stock_references' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_references',