Browse Source

All pub templates converted (but some need testing), made all sync functions for all modules consistent and added a session variable for getting pager counts

Stephen Ficklin 11 years ago
parent
commit
3433d53fd8
26 changed files with 1054 additions and 826 deletions
  1. 74 123
      tripal_analysis/includes/tripal_analysis.sync.inc
  2. 34 23
      tripal_contact/includes/contact_sync.inc
  3. 1 1
      tripal_contact/includes/tripal_contact.admin.inc
  4. 11 0
      tripal_contact/theme/tripal_contact/tripal_contact_base.tpl.php
  5. 0 6
      tripal_contact/theme/tripal_contact_help.tpl.php
  6. 11 8
      tripal_core/api/tripal_core_chado.api.inc
  7. 4 5
      tripal_feature/includes/tripal_feature.sync_features.inc
  8. 2 2
      tripal_feature/theme/tripal_feature/tripal_feature_relationships.tpl.php
  9. 0 10
      tripal_feature/theme/tripal_feature_help.tpl.php
  10. 1 1
      tripal_feature/theme/tripal_organism/tripal_organism_feature_browser.tpl.php
  11. 4 4
      tripal_organism/includes/organism_sync.inc
  12. 5 2
      tripal_organism/includes/tripal_organism.admin.inc
  13. 9 10
      tripal_organism/tripal_organism.module
  14. 89 59
      tripal_pub/includes/pub_sync.inc
  15. 62 141
      tripal_pub/includes/tripal_pub.admin.inc
  16. 76 58
      tripal_pub/theme/tripal_pub/tripal_pub_authors.tpl.php
  17. 72 36
      tripal_pub/theme/tripal_pub/tripal_pub_featuremaps.tpl.php
  18. 74 38
      tripal_pub/theme/tripal_pub/tripal_pub_features.tpl.php
  19. 77 40
      tripal_pub/theme/tripal_pub/tripal_pub_libraries.tpl.php
  20. 76 36
      tripal_pub/theme/tripal_pub/tripal_pub_projects.tpl.php
  21. 59 49
      tripal_pub/theme/tripal_pub/tripal_pub_properties.tpl.php
  22. 54 38
      tripal_pub/theme/tripal_pub/tripal_pub_references.tpl.php
  23. 138 69
      tripal_pub/theme/tripal_pub/tripal_pub_relationships.tpl.php
  24. 74 38
      tripal_pub/theme/tripal_pub/tripal_pub_stocks.tpl.php
  25. 0 9
      tripal_pub/theme/tripal_pub_help.tpl.php
  26. 47 20
      tripal_pub/tripal_pub.module

+ 74 - 123
tripal_analysis/includes/tripal_analysis.sync.inc

@@ -6,15 +6,83 @@
 function tripal_analysis_sync_form () {
   $form = array();
   
-  get_tripal_analysis_admin_form_sync_set($form);
-  get_tripal_analysis_admin_form_cleanup_set($form);
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync Analyses')
+  );
+
+  // get the list of analyses
+  $sql = "SELECT * FROM {analysis} ORDER BY name";
+  $ana_rset = chado_query($sql);
+
+  // if we've added any analyses to the list that can be synced
+  // then we want to build the form components to allow the user
+  // to select one or all of them.  Otherwise, just present
+  // a message stating that all analyses are currently synced.
+  $ana_boxes = array();
+  $added = 0;
+  while ($analysis = $ana_rset->fetchObject()) {
+    // check to see if the analysis is already present as a node in drupal.
+    // if so, then skip it.
+    $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
+    if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
+      $ana_boxes[$analysis->analysis_id] = "$analysis->name";
+      $added++;
+    }
+  }
+
+  // if we have analyses we need to add to the checkbox then
+  // build that form element
+  if ($added > 0) {
+    $ana_boxes['all'] = "All analyses";
+
+    $form['sync']['analyses'] = array(
+      '#title'       => t('Available analyses'),
+      '#type'        => t('checkboxes'),
+      '#description' => t("Check the analyses you want to sync.  Drupal " .
+          "content will be created for each of the analyses listed above. " .
+          "Select 'All analyses' to sync all of them."),
+      '#required'    => FALSE,
+      '#prefix'      => '<div id="ana_boxes">',
+      '#suffix'      => '</div>',
+      '#options'     => $ana_boxes,
+    );
+    $form['sync']['button'] = array(
+      '#type' => 'submit',
+      '#value' => t('Submit Sync Job')
+    );
+  }
+  // we don't have any analyses to select from
+  else {
+    $form['sync']['value'] = array(
+      '#markup' => t('All analyses in Chado are currently synced with Drupal.')
+    );
+  }
+  
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#markup' => t("With Drupal and chado residing in different databases " .
+        "it is possible that nodes in Drupal and analyses in Chado become " .
+        "\"orphaned\".  This can occur if an analysis node in Drupal is " .
+        "deleted but the corresponding chado analysis is not and/or vice " .
+        "versa. Click the button below to resolve these discrepancies."),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned analyses'),
+    '#weight' => 2,
+  );
   
   return $form;
 }
 
 /**
  * Validate the administrative form
- * @todo Stephen: Why is validate used rather then submit?
  *
  * @param $form
  *   The form API array of the form to be validated
@@ -65,121 +133,6 @@ function tripal_analysis_sync_form_submit($form, &$form_state) {
     'tripal_analyses_cleanup', $job_args, $user->uid);
   }
 }
-/**
- * The "Clean-up orphaned analysis & nodes" Form
- *
- * @param $form
- *  The administrative form as it is currently
- *
- * @return
- *  A form API array describing an administrative form
- *
- * @ingroup tripal_analysis
- */
-function get_tripal_analysis_admin_form_cleanup_set(&$form) {
-  $form['cleanup'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Clean Up')
-  );
-  $form['cleanup']['description'] = array(
-    '#markup' => t("With Drupal and chado residing in different databases " .
-        "it is possible that nodes in Drupal and analyses in Chado become " .
-        "\"orphaned\".  This can occur if an analysis node in Drupal is " .
-        "deleted but the corresponding chado analysis is not and/or vice " .
-        "versa. Click the button below to resolve these discrepancies."),
-    '#weight' => 1,
-  );
-  $form['cleanup']['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Clean up orphaned analyses'),
-    '#weight' => 2,
-  );
-}
-
-/**
- * The "sync Analysis in chado with drupal" form
- *
- * @param $form
- *  The administrative form as it is currently
- *
- * @return
- *  A form API array describing an administrative form
- *
- * @ingroup tripal_analysis
- */
-function get_tripal_analysis_admin_form_sync_set(&$form) {
-  // define the fieldsets
-  $form['sync'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sync Analyses')
-  );
-
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync analyses
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_analysis')) {
-    $active_jobs = TRUE;
-  }
-
-  if (!$active_jobs) {
-
-    // get the list of analyses
-    $sql = "SELECT * FROM {analysis} ORDER BY name";
-    $ana_rset = chado_query($sql);
-
-    // if we've added any analyses to the list that can be synced
-    // then we want to build the form components to allow the user
-    // to select one or all of them.  Otherwise, just present
-    // a message stating that all analyses are currently synced.
-    $ana_boxes = array();
-    $added = 0;
-    while ($analysis = $ana_rset->fetchObject()) {
-      // check to see if the analysis is already present as a node in drupal.
-      // if so, then skip it.
-      $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id";
-      if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) {
-        $ana_boxes[$analysis->analysis_id] = "$analysis->name";
-        $added++;
-      }
-    }
-
-    // if we have analyses we need to add to the checkbox then
-    // build that form element
-    if ($added > 0) {
-      $ana_boxes['all'] = "All analyses";
-
-      $form['sync']['analyses'] = array(
-        '#title'       => t('Available analyses'),
-        '#type'        => t('checkboxes'),
-        '#description' => t("Check the analyses you want to sync.  Drupal " .
-            "content will be created for each of the analyses listed above. " .
-            "Select 'All analyses' to sync all of them."),
-        '#required'    => FALSE,
-        '#prefix'      => '<div id="ana_boxes">',
-        '#suffix'      => '</div>',
-        '#options'     => $ana_boxes,
-      );
-      $form['sync']['button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Submit Sync Job')
-      );
-    }
-    // we don't have any analyses to select from
-    else {
-      $form['sync']['value'] = array(
-        '#markup' => t('All analyses in Chado are currently synced with Drupal.')
-      );
-    }
-  }
-  // we don't want to present a form since we have an active job running
-  else {
-    $form['sync']['value'] = array(
-      '#markup' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
-    );
-  }
-}
-
 /**
  * Synchronize analyses from chado to drupal
  *
@@ -244,13 +197,11 @@ function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
       }
       else {
         print "Failed to insert analysis $analysis->name\n";
+        watchdog('tanalysis_sync', "Unable to create analysis node. ID: %analysis_id, Name: %name.",
+         array('%analysis_id' => $analysis->analysis_id, '%name' => $analysis->name), WATCHDOG_WARNING);
       }
     }
-    else {
-      $page_content .= "Skipped $new_node->title<br />";
-    }
   }
-  return $page_content;
 }
 
 /**
@@ -267,4 +218,4 @@ function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
 
   return tripal_core_clean_orphaned_nodes('analysis', $job_id);
 
-}
+}

+ 34 - 23
tripal_contact/includes/contact_sync.inc

@@ -73,34 +73,45 @@ function tripal_contact_sync_contacts($job_id = NULL) {
     SELECT C.*
     FROM chado.contact C
       LEFT JOIN {chado_contact} CP ON CP.contact_id = C.contact_id
-    WHERE CP.contact_id IS NULL
+    WHERE CP.contact_id IS NULL and NOT C.name = 'null'
   ";
   $results = db_query($sql);
+  
+  // We'll use the following SQL statement for checking if the contact
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_contact} WHERE contact_id = :contact_id";
 
   while ($contact = $results->fetchObject()) {
-    $new_node = new stdClass();
-    $new_node->uid = $user->uid;
-    $new_node->contact_id = $contact->contact_id;
-    $new_node->type = 'chado_contact';
-    $new_node->title = $contact->name;
-    $new_node->description = $contact->description;
-    $new_node->type_id = $contact->type_id;
-  
-    $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 contact: $new_node->title\n";
+    
+    // check if this contact already exists in the drupal database. if it
+    // does then skip this contact and go to the next one.
+    if (!db_query($sql, array(':contact_id' => $contact->contact_id))->fetchObject()) {
+    
+      $new_node = new stdClass();
+      $new_node->uid = $user->uid;
+      $new_node->contact_id = $contact->contact_id;
+      $new_node->type = 'chado_contact';
+      $new_node->title = $contact->name;
+      $new_node->description = $contact->description;
+      $new_node->type_id = $contact->type_id;
+    
+      $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 contact: $new_node->title\n";
+        }
       }
-    }
-    else {
-      print "ERROR: Unable to create " . $contact->name . "\n" . print_r($errors, TRUE) . "\n";
-      return FALSE;
-    }
-  } 
+      else {
+        watchdog('tcontact_sync', "Unable to create contact node. ID: %contact_id, Name: %name.",
+          array('%contact_id' => $contact->contact_id, '%name' => $contact->name), WATCHDOG_WARNING);      
+        
+      }
+    } 
+  }
 }
 
 /**

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

@@ -43,7 +43,7 @@ function tripal_contact_admin() {
   $form = array();
 
   $form['nothing'] = array(
-    '#markup' => t('There are currently no settings to configure. .')
+    '#markup' => t('There are currently no settings to configure.')
   );
 
   return system_settings_form($form);

+ 11 - 0
tripal_contact/theme/tripal_contact/tripal_contact_base.tpl.php

@@ -34,6 +34,17 @@ $contact = $variables['node']->contact; ?>
     ),
     $contact->type_id->name,
   );
+  // allow site admins to see the contact ID
+  if (user_access('access administration pages')) {
+    // Pub ID
+    $rows[] = array(
+      array(
+        'data' => 'Contact ID',
+        'header' => TRUE
+      ),
+      $contact->contact_id
+    );
+  }
   
   // the $table array contains the headers and rows array as well as other
   // options for controlling the display of the table.  Additional

+ 0 - 6
tripal_contact/theme/tripal_contact_help.tpl.php

@@ -1,9 +1,3 @@
-<h3>Tripal Contact Quick Links:</h3>
-<ul>
-  <li><a href="<?php print url('admin/tripal/tripal_contact/configuration') ?>">Contact Configuration</a></li>
-  <li><a href="<?php print url('admin/tripal/tripal_contact/sync') ?>">Sync Contacts</a></li>
-</ul>
-
 <h3>Module Description:</h3>
 <p>The Tripal Contact module is an interface for the Chado Contact module which provides information about
    people or organizations.  This module provides support for visualization of "contact" pages, editing and updating.

+ 11 - 8
tripal_core/api/tripal_core_chado.api.inc

@@ -892,7 +892,7 @@ function tripal_core_chado_delete($table, $match, $options = NULL) {
  *     should specify the number of records to return and 'element' is a
  *     unique integer to differentiate between pagers when more than one
  *     appear on a page.  The 'element' should start with zero and increment by
- *     one for each pager.  
+ *     one for each pager.    
  *
  * @return
  *  An array of results, FALSE if the query was not executed
@@ -1223,7 +1223,8 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     return array('sql' => $sql, 'args' => $args);
   }
   if (array_key_exists('limit', $pager)) {
-    $resource = chado_pager_query($sql, $args, $pager['limit'], $pager['element']);
+    $total_records = 0;
+    $resource = chado_pager_query($sql, $args, $pager['limit'], $pager['element'], NULL, $total_records);
   }
   else {
     $resource = chado_query($sql, $args);
@@ -1941,7 +1942,7 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
   //try again becasue now we might have moved it down
   if (property_exists($object, 'expanded')) {
     $expandable_name = 'expandable_' . $type . 's';
-    if ($object->{$expandable_name}) {
+    if (property_exists($object, $expandable_name) and $object->{$expandable_name}) {
       $key_to_remove = array_search($object->expanded, $object->{$expandable_name});
       unset($object->{$expandable_name}[$key_to_remove]);
       unset($object->expanded);
@@ -2034,7 +2035,7 @@ function tripal_core_exclude_field_from_feature_by_default() {
  *   An optional integer to distinguish between multiple pagers on one page.
  * @param $count_query
  *   An SQL query used to count matching records.
- *   
+ *
  * @returns
  *   A database query result resource or FALSE if the query was not
  *   executed correctly
@@ -2042,8 +2043,9 @@ function tripal_core_exclude_field_from_feature_by_default() {
  * @ingroup tripal_chado_api
  */
 function chado_pager_query($query, $args, $limit, $element, $count_query = NULL) {
-
-  $page = pager_find_page();
+  
+  // get the page and offset for the pager
+  $page = pager_find_page($element);
   $offset = $limit * $page;
 
   // Construct a count query if none was given.
@@ -2053,9 +2055,10 @@ function chado_pager_query($query, $args, $limit, $element, $count_query = NULL)
   }
 
   // We calculate the total of pages as ceil(items / limit).
-  $pager_total_items = chado_query($count_query, $args)->fetchField();
+  $total_records = chado_query($count_query, $args)->fetchField();
+  $_SESSION['chado_pager'][$element]['total_records'] = $total_records;
   
-  pager_default_initialize($pager_total_items, $limit, $element);
+  pager_default_initialize($total_records, $limit, $element);
   
   $query .= ' LIMIT ' . (int) $limit . ' OFFSET ' . (int) $offset;
   $results = chado_query($query, $args);

+ 4 - 5
tripal_feature/includes/tripal_feature.sync_features.inc

@@ -407,18 +407,17 @@ function tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
       $new_node->uniquename = $feature->uniquename;
       $new_node->feature_type = $feature->cvtname;
       
+      $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);
       }
       else {
-        watchdog('trp-fsync', "Failed to insert feature: %title", array('%title' => $new_node->title), WATCHDOG_ERROR);
+        watchdog('tfeature_sync', "Unable to create feature node. ID: %feature_id, Name: %name.",
+          array('%feature_id' => $feature->feature_id, '%name' => $feature->uniquename), WATCHDOG_WARNING);      
       }
-      
-      // set the taxonomy for this node
-      //  tripal_feature_set_taxonomy($node, $feature_id);
-      
       $i++;
     }
   }

+ 2 - 2
tripal_feature/theme/tripal_feature/tripal_feature_relationships.tpl.php

@@ -46,7 +46,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
           // link the feature to it's node
           $feature_name = $object->record->object_id->name;
           if (property_exists($object->record, 'nid')) {
-            $feature_name = "<a href=\"" . url("node/" . $object->record->nid) . "\" target=\"_blank\">" . $object->record->object_id->name . "</a>";
+            $feature_name = l($feature_name, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
           }
           // link the organism to it's node
           $organism = $object->record->object_id->organism_id;
@@ -104,7 +104,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
           // link the feature to it's node
           $feature_name = $subject->record->subject_id->name;
           if (property_exists($subject->record, 'nid')) {
-            $feature_name = "<a href=\"" . url("node/" . $subject->record->nid) . "\" target=\"_blank\">" . $subject->record->subject_id->name . "</a>";
+            $feature_name = l($feature_name, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
           }
           // link the organism to it's node
           $organism = $subject->record->subject_id->organism_id;

+ 0 - 10
tripal_feature/theme/tripal_feature_help.tpl.php

@@ -1,13 +1,3 @@
- <h3>Tripal Feature Quick Links:</h3>
-  <ul>
-   <li><a href="<?php print url("find/sequences") ?>">Retrieve Sequences</a></li>
-   <li><a href="<?php print url("admin/tripal/tripal_feature/configuration") ?>">Feature Configuration</a></li>
-   <li><a href="<?php print url("admin/tripal/tripal_feature/fasta_loader") ?>">Import a multi-FASTA file</a></li>
-   <li><a href="<?php print url("admin/tripal/tripal_feature/gff3_load") ?>">Import a GFF3 file</a></li>
-   <li><a href="<?php print url("admin/tripal/tripal_feature/sync") ?>">Sync Features</a></li>
-   <li><a href="<?php print url("admin/tripal/tripal_feature/delete") ?>">Delete Features</a></li>
- </ul>
-
   <h3>Module Description:</h3>
   <p>The Tripal Feature module provides a new feature content type and interface for genomic features. </p>
 

+ 1 - 1
tripal_feature/theme/tripal_organism/tripal_organism_feature_browser.tpl.php

@@ -99,7 +99,7 @@ if ($enabled) {
         'header' => $headers,
         'rows' => $rows,
         'attributes' => array(
-          'id' => 'tripal_feature-table-analyses',
+          'id' => 'tripal_organism-table-features',
         ),
         'sticky' => FALSE,
         'caption' => '',

+ 4 - 4
tripal_organism/includes/organism_sync.inc

@@ -175,6 +175,7 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
       $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);
@@ -186,12 +187,11 @@ function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
         }
       }
       else {
-        print "Failed to insert organism $organism->common_name\n";
+        watchdog('torg_sync', "Unable to create organism node. ID: %org_id, Name: %name.",
+          array('%org_id' => $organism->organism_id, '%name' => $organism->genus . ' ' . $organism->species), 
+          WATCHDOG_WARNING);
       }
     }
-    else {
-      print "Skipped $organism->common_name\n";
-    }
   }
   return $page_content;
 }

+ 5 - 2
tripal_organism/includes/tripal_organism.admin.inc

@@ -42,8 +42,11 @@ function tripal_organism_admin() {
 
   $form = array();
 
-  get_tripal_organism_admin_form_reindex_set($form);
-  get_tripal_organism_admin_form_taxonomy_set($form);
+  $form['nothing'] = array(
+    '#markup' => t('There are currently no settings to configure.')
+  );
+  //get_tripal_organism_admin_form_reindex_set($form);
+  //get_tripal_organism_admin_form_taxonomy_set($form);
 
   return system_settings_form($form);
 }

+ 9 - 10
tripal_organism/tripal_organism.module

@@ -106,15 +106,6 @@ function tripal_organism_menu() {
    'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/chado/tripal_organism/help'] = array(
-   'title' => 'Help',
-   'description' => "A description of the Tripal Organism module including a short description of it's usage.",
-   'page callback' => 'theme',
-   'page arguments' => array('tripal_organism_help'),
-   'access arguments' => array('adminster tripal organism'),
-   'type' => MENU_LOCAL_TASK,
-  );
-
   $items['admin/tripal/chado/tripal_organism/configuration'] = array(
    'title' => 'Settings',
    'description' => 'Manage integration of Chado organisms including associated features',
@@ -140,7 +131,15 @@ function tripal_organism_menu() {
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
-
+  
+  $items['admin/tripal/chado/tripal_organism/help'] = array(
+    'title' => 'Help',
+    'description' => "A description of the Tripal Organism module including a short description of it's usage.",
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_organism_help'),
+    'access arguments' => array('adminster tripal organism'),
+    'type' => MENU_LOCAL_TASK,
+  );
   return $items;
 }
 

+ 89 - 59
tripal_pub/includes/pub_sync.inc

@@ -3,32 +3,58 @@
  *
  */
 function tripal_pub_sync_form() {
-
-  $form['sync_all'] = array(
-    '#type' => 'item',
-    '#value' => t('Syncing a publication will create a Drupal page for every publicatoin record in the Chado database. Click the button below to sync all publications in Chado that currently are not already synced with Drupal.'),
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync')
+  );
+  $form['sync']['sync_all'] = array(
+    '#markup' => t('<p>Syncing a publication will create a Drupal page for every publicatoin record in the Chado database. Click the button below to sync all publications in Chado that currently are not already synced with Drupal.</p>'),
   );
 
-
-
-  $form['submit'] = array(
+  $form['sync']['submit'] = array(
     '#type' => 'submit',
     '#weight' => 10,
     '#value' => t('Sync Publications')
   );
 
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#markup' => t("<p>With Drupal and chado residing in different databases ".
+        "it is possible that nodes in Drupal and publications in Chado become ".
+        "\"orphaned\".  This can occur if an pub node in Drupal is ".
+        "deleted but the corresponding chado pub is not and/or vice ".
+        "versa. Click the button below to resolve these discrepancies.</p>"),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned publications'),
+    '#weight' => 2,
+  );
+  
   return $form;
 }
 
-
 /*
  *
  */
 function tripal_pub_sync_form_submit($form, $form_state) {
   global $user;    //needed to make the current users details available so access of user id is available
-  $job_args = array();
-  $job_id = tripal_add_job('Sync Publications', 'tripal_pub', 'tripal_pub_sync_pubs', $job_args, $user->uid);
-
+  if ($form_state['values']['op'] == t('Sync Publications')) {
+    $job_args = array();
+    $job_id = tripal_add_job('Sync Publications', 'tripal_pub', 'tripal_pub_sync_pubs', $job_args, $user->uid);
+    
+  }
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
+    $job_args = array();
+    tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
+    'tripal_pub_cleanup', $job_args, $user->uid);
+  }
 }
 /**
  *
@@ -36,7 +62,8 @@ function tripal_pub_sync_form_submit($form, $form_state) {
  * @ingroup tripal_pub
  */
 function tripal_pub_sync_pubs($job_id = NULL) {
-
+  global $user;
+  
   // get the list of pubs that have not yet been synced
   // and ignore the default 'NULL' pub. we don't want
   // to sync that one.
@@ -48,60 +75,63 @@ function tripal_pub_sync_pubs($job_id = NULL) {
   ";
   $results = chado_query($sql);
 
-
+  // We'll use the following SQL statement for checking if the pub
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_pub} WHERE pub_id = :pub_id";
+  
   while ($pub = $results->fetchObject()) {
-    $node = tripal_pub_sync_pub($pub);
+
+    // check if this pub already exists in the drupal database. if it
+    // does then skip this pub and go to the next one.
+    if (!db_query($sql, array(':pub_id' => $pub->pub_id))->fetchObject()) {
+      
+      if(!$pub->pyear) {
+        watchdog('tpub_sync', "Skipping pub without published year: %title.", 
+          array('%title' => $pub->title), WATCHDOG_WARNING);
+        return FALSE;
+      }
+    
+      $new_node = new stdClass();
+      $new_node->pub_id      = $pub->pub_id;
+      $new_node->type        = 'chado_pub';
+      $new_node->uid         = $user->uid;
+      $new_node->title       = substr($pub->title, 0 ,255); // node titles can't be longer than 255 characters
+      $new_node->pubtitle    = $pub->title;
+      $new_node->pyear       = $pub->pyear;
+      $new_node->uniquename  = $pub->uniquename;
+      $new_node->type_id     = $pub->type_id;
+      $new_node->series_name = $pub->series_name;
+    
+      $form = array(); // dummy variable
+      $form_state = array(); // dummy variable
+      node_validate($new_node, $form, $form_state);
+      if (!form_get_errors()) {
+        $node = node_submit($new_node);
+        node_save($node);
+        if ($node->nid) {
+          print "Added $new_node->title\n";
+        }
+      }
+      else {
+        watchdog('tpub_sync', "Unable to create publication node. ID: %pub_id, Title: %title",
+          array('%pub_id' => $pub->pub_id, '%title' => $pub->title), WATCHDOG_WARNING);
+      }
+    }
   }
 }
+
 /**
- * @param $pub
- *   A publication object
+ * Remove orphaned drupal nodes
  *
- * @return
- *   A new Drupal node object on success. FALSE on failure
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_sync_pub($pub) {
-  global $user;
+function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
 
-  if(!$pub->pyear) {
-    watchdog('tpub_sync', "Skipping pub without published year: %title.", 
-      array('%title' => $pub->title), WATCHDOG_WARNING);
-    return FALSE;
-  }
+  return tripal_core_clean_orphaned_nodes('pub', $job_id);
 
-  $new_node = new stdClass();
-  $new_node->pub_id      = $pub->pub_id;
-  $new_node->type        = 'chado_pub';
-  $new_node->uid         = $user->uid;
-  $new_node->title       = substr($pub->title, 0 ,255); // node titles can't be longer than 255 characters
-  $new_node->pubtitle    = $pub->title;
-  $new_node->pyear       = $pub->pyear;
-  $new_node->uniquename  = $pub->uniquename;
-  $new_node->type_id     = $pub->type_id;
-  $new_node->series_name = $pub->series_name;
-
-  node_validate($new_node);
-  $errors = form_get_errors();
-  if (!$errors) {
-    $node = node_submit($new_node);
-    node_save($node);
-    if ($node->nid) {
-      print "Added " . $pub->pub_id . "\n";
-    }
-    else {
-      watchdog('tpub_sync', "Unable to create publication node: %title.", 
-        array('%title' => $pub->title), WATCHDOG_ERROR);
-      return FALSE;
-    }
-  }
-  // if there are form errors then we need to reset the form errors cache, print a message and return
-  else {
-    form_set_error(NULL,'',TRUE);
-    watchdog('tpub_sync', "Unable to create publication node: %title\n%errs",
-      array('%title' => $pub->title, '%errs' => print_r($errors, TRUE)), WATCHDOG_ERROR);
-    return FALSE;
-  }
-  return $node;
-}
+}

+ 62 - 141
tripal_pub/includes/tripal_pub.admin.inc

@@ -41,41 +41,67 @@ function tripal_pub_admin_pub_view() {
  */
 function tripal_pub_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 publications
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_pub')) {
-    $active_jobs = TRUE;
-  }
-
-  // add the field set for syncing publications
-  if (!$active_jobs) {
-    get_tripal_pub_admin_form_select_search_list($form);
-    get_tripal_pub_admin_form_importing_set($form);
-    get_tripal_pub_admin_form_default_type($form);
-    get_tripal_pub_admin_form_cleanup_set($form);
-  }
-  else {
-    $form['notice'] = array(
-     '#type' => 'fieldset',
-     '#title' => t('Publication Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-        '#value' => t('Currently, publication management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
-    );
+  
+  // -----------------------------------------
+  // add in the fields for selecting which fields are used when search for pubs
+  $form['searching'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Searching Options'),
+    '#description' => t("The list of checkboxes below indicate which fields a user 
+      can search with when using the publication search tool.  Check the fields that you want 
+      to allow users to search with.  Click the 'Save configuration' button below to save changes."),
+  );
+  
+  // get publication properties list
+  $properties = array();
+  $properties[] = 'Any Field';
+  $sql = "
+    SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
+    FROM {cvtermpath} CVTP
+      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
+    WHERE CV.name = 'tripal_pub' and
+      (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
+      NOT CVTS.is_obsolete = 1
+    ORDER BY CVTS.name ASC
+  ";
+  $prop_types = chado_query($sql);
+  while ($prop = $prop_types->fetchObject()) {
+    $properties[$prop->cvterm_id] = $prop->name;
   }
+  $form['searching']['allowed_search_fields'] = array(
+    '#type'    => 'checkboxes',
+    '#options' => $properties,
+    '#prefix'  => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
+    '#suffix'  => '</div>',
+    '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
+  );
 
-  return system_settings_form($form);
-}
-
-/**
- *
- * @param $form
- */
-function get_tripal_pub_admin_form_default_type(&$form) {
+  // -----------------------------------------
+  // add the field set for syncing publications 
+  $form['import'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Import Settings'),
+    '#description' => t('During import, Tripal will attempt to find duplicate publications,
+       and will not try to insert a publication that already exists in the database.  It can
+       find duplicates using the title, year, series name (e.g. Journal Name) and media type
+       (e.g. Journal Article etc.).
+       There are several options for how to find a duplicate publication.  Choose the
+       option that best suits your needs.'),
+  );
+  $form['import']['import_duplicate_check'] = array(
+    '#type' => 'radios',
+    '#title' => t('Unique Constraint'),
+    '#options' => array(
+      'title_year' => t('Title and Year'),
+      'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
+      'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
+    ),
+    '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
+  );
 
+  // -----------------------------------------
   // get the list of publication types.  In the Tripal publication
   // ontologies these are all grouped under the term 'Publication Type'
   // we want the default to be 'Journal Article'
@@ -110,99 +136,15 @@ function get_tripal_pub_admin_form_default_type(&$form) {
     '#type' => 'select',
     '#title' => t('Publication Type'),
     '#options' => $pub_types,
-    '#description' => t('Please set a default publiation type used for manual entry of a new publication.  This is useful in the event that someone is manually adding the same
-      publication repetitively'),
+    '#description' => t('Please set a default publiation type used for manual entry of a new 
+      publication.  This is useful in the event that someone is manually adding the same
+      publication type repetitively'),
     '#default_value' => $d_type_id
   );
-}
-/**
- *
- *
- * @ingroup tripal_pub
- */
-function get_tripal_pub_admin_form_importing_set(&$form) {
-  $form['import'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Import Settings')
-  );
-  $form['import']['import_duplicate_check'] = array(
-    '#type' => 'radios',
-    '#title' => t('Unique Constraint'),
-    '#options' => array(
-      'title_year' => t('Title and Year'),
-      'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
-      'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
-    ),
-    '#description' => t('During import, Tripal will attempt to find duplicate publications.
-       There are several options for how to find a duplicate publication.  Choose the
-       option that best suits your needs.'),
-    '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
-  );
-}
 
-/**
- *
- *
- * @ingroup tripal_pub
- */
-function get_tripal_pub_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 publications in Chado become ".
-        "\"orphaned\".  This can occur if an pub node in Drupal is ".
-        "deleted but the corresponding chado pub 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 publications'),
-    '#weight' => 2,
-  );
+  return system_settings_form($form);
 }
 
-/**
- *
- *
- * @ingroup tripal_pub
- */
-function get_tripal_pub_admin_form_select_search_list(&$form) {
-  $form['searching'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Searching Options')
-  );
-  // get publication properties list
-  $properties = array();
-  $properties[] = 'Any Field';
-  $sql = "
-    SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
-    FROM {cvtermpath} CVTP
-      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and
-      (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
-      NOT CVTS.is_obsolete = 1
-    ORDER BY CVTS.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  $form['searching']['allowed_search_fields'] = array(
-     '#type'    => 'checkboxes',
-     '#options' => $properties,
-     '#description'   => t("Please select the publication details that users can search by in the publication search form.  If none are selected then all fields will be available to the user."),
-     '#prefix'  => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
-     '#suffix'  => '</div>',
-     '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
-  );
-}
 
 /**
  *
@@ -227,29 +169,8 @@ function tripal_pub_admin_validate($form, &$form_state) {
   $default_type = $form_state['values']['type_id'];
   variable_set('tripal_pub_default_type', $default_type);
 
-  // -------------------------------------
-  // Submit the Cleanup Job if selected
-  if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
-    tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
-       'tripal_pub_cleanup', $job_args, $user->uid);
-  }
 }
 
-/**
- * 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_pub
- */
-function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
-
-  return tripal_core_clean_orphaned_nodes('pub', $job_id);
-
-}
 
 /**
  *

+ 76 - 58
tripal_pub/theme/tripal_pub/tripal_pub_authors.tpl.php

@@ -31,64 +31,82 @@ if (count($authors) > 0) {
 
 if ($has_contacts) { ?>
   <div id="tripal_pub-pubauthors-box" class="tripal_pub-info-box tripal-info-box">
-    <div class="tripal_pub-info-box-title tripal-info-box-title">Authors</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">Additional information about authors:</div>
-    <table id="tripal_pubauthor_<?php print $rank?>-table" class="tripal_pub-table tripal-table tripal-table-horz"><?php 
-      $rank = 1;
-      foreach ($authors as $author) {
-         
-        // expand the author to include the contact information linked via the pubauthor_contact table
-        $contact = $author->pubauthor_contact[0]->contact_id;
-        $options = array(
-          'return_array' => 1,
-          'include_fk' => array(
-            'type_id' => 1,       
-          ),      
-        );
-        $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
-        $properties = $contact->contactprop;
-        $options = array('order_by' => array('rank' => 'ASC'));
-        $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options); 
-        
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($rank % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>            
-        <tr class="<?php print $class?>">
-          <td><?php print $rank?></td>
-          <?php
-          // now build the table for display the authors and their information 
-          if ($contact->nid) {?>
-            <td><?php print l($author->givennames . " " . $author->surname, 'node/' . $contact->nid) ?></td><?php
+    <div class="tripal_pub-info-box-title tripal-info-box-title">Author Details</div>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">Additional information about authors:</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('', '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();
+    
+    $rank = 1;
+    foreach ($authors as $author) {
+       
+      // expand the author to include the contact information linked via the pubauthor_contact table
+      $contact = $author->pubauthor_contact[0]->contact_id;
+      $options = array(
+        'return_array' => 1,
+        'include_fk' => array(
+          'type_id' => 1,       
+        ),      
+      );
+      $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
+      $properties = $contact->contactprop;
+      $options = array('order_by' => array('rank' => 'ASC'));
+      $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options); 
+      
+      // link the contact to it's node if one exists
+      $contact_name = $author->givennames . " " . $author->surname;
+      if (property_exists($contact, 'nid')) {
+        $contact_name = l($contact_name, 'node/' . $contact->nid);
+      }
+      
+      // Get some additional details about this contact if they exists.
+      $details = '';
+      if (is_array($properties)) {
+        foreach ($properties as $property) {
+          // skip the description and name properties
+          if ($property->type_id->name == "contact_description" or
+              $property->type_id->name == "Surname" or
+              $property->type_id->name == "Given Name" or
+              $property->type_id->name == "First Initials" or
+              $property->type_id->name == "Suffix") {
+            continue;
           }
-          else {?>
-            <td><?php print $author->givennames . " " . $author->surname ?></td><?php
-          } ?>
-          <td> 
-            <table class="tripal-subtable"><?php 
-              if (is_array($properties)) {          
-                foreach ($properties as $property) {
-                  // skip the description and name properties
-                  if ($property->type_id->name == "contact_description" or
-                      $property->type_id->name == "Surname" or
-                      $property->type_id->name == "Given Name" or
-                      $property->type_id->name == "First Initials" or
-                      $property->type_id->name == "Suffix") {
-                    continue;
-                  }?>
-                  <tr>
-                    <td><?php print $property->type_id->name ?></td>
-                    <td>:</td>
-                    <td><?php print $property->value ?></td>
-                  </tr><?php
-                  $i++; 
-                } 
-              }?> 
-            </table>
-          </td>
-        </tr><?php 
-        $rank++;
-      }?>
-    </table>
+          $details .= "<br>" . $property->type_id->name . " : " .  $property->value;
+        }
+      }
+      
+      $rows[] = array(
+        $rank,
+        $contact_name . $details,
+      );
+      $rank++;
+    }
+    
+    // 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_pub-table-contacts',
+      ),
+      '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      
 }

+ 72 - 36
tripal_pub/theme/tripal_pub/tripal_pub_featuremaps.tpl.php

@@ -2,15 +2,22 @@
 $pub = $variables['node']->pub;
 $featuremaps = array();
 
-// expand the pub object to include the records from the pub_dbxref table
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$featuremap_pager_id = 5;
+// get the featuremaps that are associated with this publication.  But we only
+// want 25 and we want a pager to let the user cycle between pages of featuremaps.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of featuremaps
 
-// get the genotypes from the featuremap_genotype table
+$element = 1;        // an index to specify the pager this must be unique amongst all pub templates
+$num_per_page = 25;  // the number of featuremaps to show per page$num_results_per_page = 25; 
+
+// get the featuremaps from the featuremap_pub table
 $options = array(  
   'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $featuremap_pager_id),
+  'pager' => array(
+    'limit'   => $num_per_page, 
+    'element' => $element
+  ),
 );
 
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'featuremap_pub', $options);
@@ -21,40 +28,69 @@ if (count($featuremap_pubs) > 0 ) {
   }
 }
 
-// create the pager.  
-global $pager_total_items;
-$featuremap_pager = theme('pager', array(), $num_results_per_page, $featuremap_pager_id, array('block' => 'featuremaps'));
-$total_featuremaps = $pager_total_items[$featuremap_pager_id];
-
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
 
 if(count($featuremaps) > 0){ ?>
   <div id="tripal_pub-featuremaps-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Maps</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_featuremaps) ?> map(s):</div>
-    <table id="tripal_pub-featuremap-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Map Name</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($featuremaps as $featuremap){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($featuremap->nid) { 
-              print l($featuremap->name, 'node/' . $featuremap->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $featuremap->name;
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $featuremap_pager ?>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> maps:</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('Map 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 ($featuremaps as $featuremap){
+       $featuremap_name = $featuremap->name;
+       if (property_exists($featuremap, 'nid')) {
+         $featuremap_name = l($featuremap_name, 'node/' . $featuremap->nid, array('attributes' => array('target' => '_blank')));
+       }
+       
+       $rows[] = array(
+         $featuremap_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_pub-table-featuremaps',
+      ),
+      '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);
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'featuremaps'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $element,
+      'parameters' => array(
+        'block' => 'featuremaps'
+      ),
+      'quantity' => $num_per_page,
+    );
+    print theme_pager($pager); ?>
   </div><?php 
 }?>
 

+ 74 - 38
tripal_pub/theme/tripal_pub/tripal_pub_features.tpl.php

@@ -2,15 +2,22 @@
 $pub = $variables['node']->pub;
 $features = array();
 
-// expand the pub object to include the records from the pub_dbxref table
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$feature_pager_id = 5;
+// get the features that are associated with this publication.  But we only
+// want 25 and we want a pager to let the user cycle between pages of features.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of features
 
-// get the genotypes from the feature_genotype table
+$element = 2;        // an index to specify the pager this must be unique amongst all pub templates
+$num_per_page = 25;  // the number of features to show per page$num_results_per_page = 25; 
+
+// get the features from the feature_pub table
 $options = array(  
   'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $feature_pager_id),
+  'pager' => array(
+    'limit'   => $num_per_page, 
+    'element' => $element
+  ),
 );
 
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'feature_pub', $options);
@@ -21,42 +28,71 @@ if (count($feature_pubs) > 0 ) {
   }
 }
 
-// create the pager.  
-global $pager_total_items;
-$feature_pager = theme('pager', array(), $num_results_per_page, $feature_pager_id, array('block' => 'features'));
-$total_features = $pager_total_items[$feature_pager_id];
-
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
 
 if(count($features) > 0){ ?>
   <div id="tripal_pub-features-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Features</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_features) ?> features:</div>
-    <table id="tripal_pub-feature-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Feature Name</th>
-        <th>Type</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($features as $feature){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($feature->nid) { 
-              print l($feature->name, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $feature->name;
-            } ?>
-          </td>
-          <td><?php print $feature->type_id->name ?></td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $feature_pager ?>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> features:</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('Feature Name', 'Uniquenaem', 'Type');
+    
+    // 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 ($features as $feature){
+       $feature_name = $feature->name;
+       if (property_exists($feature, 'nid')) {
+         $feature_name = l($feature_name, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
+       }
+       
+       $rows[] = array(
+         $feature_name,
+         $feature->uniquename,
+         $feature->type_id->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_pub-table-features',
+      ),
+      '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);
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'features'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $element,
+      'parameters' => array(
+        'block' => 'features'
+      ),
+      'quantity' => $num_per_page,
+    );
+    print theme_pager($pager); ?>
   </div><?php 
 }?>
 

+ 77 - 40
tripal_pub/theme/tripal_pub/tripal_pub_libraries.tpl.php

@@ -2,15 +2,22 @@
 $pub = $variables['node']->pub;
 $libraries = array();
 
-// expand the pub object to include the records from the pub_dbxref table
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$library_pager_id = 5;
+// get the libraries that are associated with this publication.  But we only
+// want 25 and we want a pager to let the user cycle between pages of libraries.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of libraries
 
-// get the genotypes from the library_genotype table
+$element = 3;        // an index to specify the pager this must be unique amongst all pub templates
+$num_per_page = 25;  // the number of libraries to show per page$num_results_per_page = 25; 
+
+// get the libraries from the library_pub table
 $options = array(  
   'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $library_pager_id),
+  'pager' => array(
+    'limit'   => $num_per_page, 
+    'element' => $element
+  ),
 );
 
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'library_pub', $options);
@@ -21,44 +28,74 @@ if (count($library_pubs) > 0 ) {
   }
 }
 
-// create the pager.  
-global $pager_total_items;
-$library_pager = theme('pager', array(), $num_results_per_page, $library_pager_id, array('block' => 'libraries'));
-$total_libraries = $pager_total_items[$library_pager_id];
-
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
 
 if(count($libraries) > 0){ ?>
   <div id="tripal_pub-libraries-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Libraries</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_libraries) ?> libraries:</div>
-    <table id="tripal_pub-library-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Library Name</th>
-        <th>Species</th>
-        <th>Type</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($libraries as $library){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($library->nid) { 
-              print l($library->name, 'node/' . $library->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $library->name;
-            } ?>
-          </td>
-          <td><?php print $library->type_id->name ?></td>
-          <td><?php print $library->organism_id->genus ?> <?php print $library->organism_id->species ?></td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $library_pager ?>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> libraries:</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('Library Name', 'Unique Name', 'Organism');
+    
+    // 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 ($libraries as $library){
+       $library_name = $library->name;
+       if (property_exists($library, 'nid')) {
+         $library_name = l($library_name, 'node/' . $library->nid, array('attributes' => array('target' => '_blank')));
+       }
+       $organism = '<i>' . $library->organism_id->genus . ' ' . $library->organism_id->species . '</i>';
+       if (property_exists($library->organism_id, 'nid')) {
+         $organism = l($organism, 'node/' . $library->organism_id->nid, array('attributes' => array('target' => '_blank')));
+       }
+       $rows[] = array(
+         $library_name,
+         $library->uniquename,
+         $organism,
+       );
+    }
+    // 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_pub-table-libraries',
+      ),
+      '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);
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'libraries'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $element,
+      'parameters' => array(
+        'block' => 'libraries'
+      ),
+      'quantity' => $num_per_page,
+    );
+    print theme_pager($pager); ?>
   </div><?php 
 }?>
 

+ 76 - 36
tripal_pub/theme/tripal_pub/tripal_pub_projects.tpl.php

@@ -2,15 +2,22 @@
 $pub = $variables['node']->pub;
 $projects = array();
 
-// expand the pub object to include the records from the pub_dbxref table
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$project_pager_id = 5;
+// get the features that are associated with this publication.  But we only
+// want 25 and we want a pager to let the user cycle between pages of features.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of features
 
-// get the genotypes from the project_genotype table
+$element = 4;        // an index to specify the pager this must be unique amongst all pub templates
+$num_per_page = 25;  // the number of projects to show per page$num_results_per_page = 25; 
+
+// get the projects from the project_pub table
 $options = array(  
   'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $project_pager_id),
+  'pager' => array(
+    'limit'   => $num_per_page, 
+    'element' => $element
+  ),
 );
 
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'project_pub', $options);
@@ -21,40 +28,73 @@ if (count($project_pubs) > 0 ) {
   }
 }
 
-// create the pager.  
-global $pager_total_items;
-$project_pager = theme('pager', array(), $num_results_per_page, $project_pager_id, array('block' => 'projects'));
-$total_projects = $pager_total_items[$project_pager_id];
-
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
 
 if(count($projects) > 0){ ?>
   <div id="tripal_pub-projects-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Projects</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_projects) ?> projects:</div>
-    <table id="tripal_pub-project-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Project Name</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($projects as $project){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($project->nid) { 
-              print l($project->name, 'node/' . $project->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $project->name;
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $project_pager ?>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> projects:</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('Project Name', 'Description');
+    
+    // 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 ($projects as $project){
+       $project_name = $project->name;
+       if (property_exists($project, 'nid')) {
+         $project_name = l($project_name, 'node/' . $project->nid, array('attributes' => array('target' => '_blank')));
+       }
+       $description =  substr($project->description, 0, 200);
+       if (strlen($project->description) > 200) {
+         $description .= "... " . l("[more]", 'node/' . $project->nid, array('attributes' => array('target' => '_blank')));
+       } 
+       $rows[] = array(
+         $project_name,
+         $description
+       );
+    }
+    // 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_pub-table-projects',
+      ),
+      '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);
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'projects'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $element,
+      'parameters' => array(
+        'block' => 'projects'
+      ),
+      'quantity' => $num_per_page,
+    );
+    print theme_pager($pager); ?>
   </div><?php 
 }?>
 

+ 59 - 49
tripal_pub/theme/tripal_pub/tripal_pub_properties.tpl.php

@@ -24,54 +24,64 @@ if (is_array($pubprops)) {
   }
 }
 // we'll keep track of the keywords so we can lump them into a single row
-$keywords = array(); ?>
+$keywords = array(); 
+
+if (count($properties)) { ?>
   <div id="tripal_pub-properties-box" class="tripal_pub-info-box tripal-info-box">
-    <div class="tripal_pub-info-box-title tripal-info-box-title">More Details</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">Additional details for this publication include:</div>
-    <table class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Property Name</th>
-        <th>Value</th>
-      </tr> <?php
-      if (count($properties) > 0) {
-        $i = 0;
-        foreach ($properties as $property) {
-          if ($property->type_id->name == 'Keywords') {
-            $keywords[] = $property->value;
-            continue;
-          }
-          $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-          if ($i % 2 == 0 ) {
-             $class = 'tripal_pub-table-odd-row tripal-table-even-row';
-          }
-          $i++; 
-          ?>
-          <tr class="<?php print $class ?>">
-            <td nowrap><?php print $property->type_id->name ?></td>
-            <td><?php print $property->value ?></td>
-          </tr><?php 
-        } 
-        if (count($keywords) > 0) {
-          $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-          if ($i % 2 == 0 ) {
-             $class = 'tripal_pub-table-odd-row tripal-table-even-row';
-          }
-          $i++; 
-          ?>
-          <tr class="<?php print $class ?>">
-            <td nowrap>Keywords</td>
-            <td><?php print implode(', ', $keywords) ?></td>
-          </tr><?php   
-        }
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if ($i % 2 == 0 ) {
-           $class = 'tripal_pub-table-odd-row tripal-table-even-row';
-        }
-      } ?>
-    <tr class="<?php print $class ?>">
-      <td>Internal ID</td>
-      <td style="text-align:justify;"><?php print $pub->pub_id; ?></td>
-    </tr>
-  </table> 
-</div> <?php
+    <div class="tripal_pub-info-box-title tripal-info-box-title">Additional Properties</div>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">Additional details for this publication include:</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');
+    
+    // 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();
+    
+    $keywords = array();
+    foreach ($properties as $property) {
+      // each keyword is stored as a seperate properties. We want to show them
+      // only in a single field not as a bunc of individual properties, so when we see one, 
+      // save it in an array for later and down't add it yet to the table yet.
+      if ($property->type_id->name == 'Keywords') {
+        $keywords[] = $property->value;
+        continue;
+      }
+      $rows[] = array(
+        $property->type_id->name,
+        $property->value
+      );
+    }
+    // now add in a single row for all keywords
+    if (count($keywords) > 0) {
+      $rows[] = array(
+        'Keywords',
+        implode(', ', $keywords),
+      );
+    } 
 
+    // 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_pub-table-properties',
+      ),
+      '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
+}

+ 54 - 38
tripal_pub/theme/tripal_pub/tripal_pub_references.tpl.php

@@ -1,11 +1,13 @@
 <?php
 $pub = $variables['node']->pub;
-$references = array();
+
 
 // expand the pub object to include the records from the pub_dbxref table
 $options = array('return_array' => 1);
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'pub_dbxref', $options);
 $pub_dbxrefs = $pub->pub_dbxref;
+
+$references = array();
 if (count($pub_dbxrefs) > 0 ) {
   foreach ($pub_dbxrefs as $pub_dbxref) {    
     $references[] = $pub_dbxref->dbxref_id;
@@ -15,42 +17,56 @@ if (count($pub_dbxrefs) > 0 ) {
 if(count($references) > 0){ ?>
   <div id="tripal_pub-references-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Cross References</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication is also available in the following databases:</div>
-    <table id="tripal_pub-references-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Dababase</th>
-        <th>Accession</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($references as $dbxref){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($dbxref->db_id->url) { 
-              print l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . '<br>' . $dbxref->db_id->description;             
-            } 
-            else { 
-              print $dbxref->db_id->name . '<br>' . $dbxref->db_id->description;
-            } ?>
-          </td>
-          <td> <?php 
-            if ($dbxref->db_id->urlprefix) { 
-              print l($dbxref->db_id->name . ':' . $dbxref->accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $dbxref->db_id->name . ':' . $dbxref->accession; 
-            }
-            if ($dbxref->is_primary) {
-              print " <i>(primary cross-reference)</i>";
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication is also available in the following databases:</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('Database', 'Accession');
+    
+    // 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 ($references as $dbxref){
+      $database = $dbxref->db_id->name . ': ' . $dbxref->db_id->description;
+      if ($dbxref->db_id->url) {
+        $database = l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . ': ' . $dbxref->db_id->description; 
+      }
+      $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
+      if ($dbxref->db_id->urlprefix) {
+        $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+      }
+      if (property_exists($dbxref, 'is_primary')) {
+        $accession .= " <i>(primary cross-reference)</i>";
+      }
+      
+      $rows[] = array(
+        $database,
+        $accession
+      );
+    }
+    // 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_pub-table-references',
+      ),
+      '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 
-}?>
+}
 

+ 138 - 69
tripal_pub/theme/tripal_pub/tripal_pub_relationships.tpl.php

@@ -1,81 +1,150 @@
 <?php
-// this template does not follow the typical Tripal API. Normally
-// variables are expanded using the tripal_core_expand_chado_vars API
-// function call, but expanding the relationships table does not yeild
-// a meaningful order to the data.  Therefore, relationships are preprocessed
-// into an array named 'all_relationships', which is used in the template below.
-
+/* Typically in a Tripal template, the data needed is retrieved using a call to
+ * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * of the pub relationships for this node, the following function call would be made:
+ * 
+ *   $pub = tripal_core_expand_chado_vars($pub,'table','pub_relationship');
+ * 
+ * However, this function call can be extremely slow when there are numerous relationships.
+ * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * all data following the foreign key relationships tree.  Therefore, to speed retrieval
+ * of data, a special variable is provided to this template:
+ * 
+ *   $pub->all_relationships;
+ *   
+ * This variable is an array with two sub arrays with the keys 'object' and 'subject'.  The array with
+ * key 'object' contains relationships where the pub is the object, and the array with
+ * the key 'subject' contains relationships where the pub is the subject
+ */
 $pub = $variables['node']->pub;
 
 $all_relationships = $pub->all_relationships;
 $object_rels = $all_relationships['object'];
 $subject_rels = $all_relationships['subject'];
 
-// make the pub type a bit more human readable
-$pub_type =  preg_replace("/_/", ' ', $pub->type_id->name);
-
-if (count($object_rels) > 0 or count($subject_rels) > 0) {
-?>
+if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
   <div id="tripal_pub-relationships-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Relationships</div>
-    <!--  <div class="tripal_pub-info-box-desc tripal-info-box-desc"></div> --><?php
+    <div class="tripal_pub-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 $pub->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> pub(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('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 ($objects as $object){
+          // link the pub to it's node
+          $title = $object->record->object_id->title;
+          if (property_exists($object->record, 'nid')) {
+            $title = l($title, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
+          }
+          
+          // get the citation
+          $values = array(
+            'pub_id' => $object->record->object_id->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');
+          
+          $rows[] = array(
+            $title . '<br>' . htmlspecialchars($citation->value),
+          ); 
+         } 
+         // 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_pub-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
+       }
+    }
     
-      // first add in the subject relationships.  
-      foreach ($subject_rels as $rel_type => $rels){
-         // make the type a bit more human readable
-         $rel_type = preg_replace("/_/", ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through each parent   
-         foreach ($rels as $obj_type => $objects){?>
-           <p>This pub is a <b><?php print $rel_type ?></b> of the following pub(s):
-           <table id="tripal_pub-relationships_as_object-table" class="tripal_pub-table tripal-table tripal-table-horz">
-             <tr>
-               <th>pub Name</th>
-             </tr> <?php
-             foreach ($objects as $object){ ?>
-               <tr>
-                 <td><?php 
-                    if ($object->nid) {
-                      print "<a href=\"" . url("node/" . $object->nid) . "\" target=\"_blank\">" . $object->title . "</a>";
-                    }
-                    else {
-                      print $object->name;
-                    } ?>
-                 </td>
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      }
-      
-      // second add in the object relationships.  
-      foreach ($object_rels as $rel_type => $rels){
-         // make the type more human readable
-         $rel_type = preg_replace('/_/', ' ', $rel_type);
-         $rel_type = preg_replace("/^is/", '', $rel_type);
-         // iterate through the children         
-         foreach ($rels as $subject_type => $subjects){?>
-           <p>The following pubs are a <b><?php print $rel_type ?></b> of this pub:
-           <table id="tripal_pub-relationships_as_object-table" class="tripal_pub-table tripal-table tripal-table-horz">
-             <tr>
-               <th>Title</th>
-             </tr> <?php
-             foreach ($subjects as $subject){ ?>
-               <tr>
-                 <td><?php 
-                    if ($subject->nid) {
-                      print "<a href=\"" . url("node/" . $subject->nid) . "\" target=\"_blank\">" . $subject->title . "</a>";
-                    }
-                    else {
-                      print $subject->name;
-                    } ?>
-                 </td>
-               </tr> <?php
-             } ?>
-             </table>
-             </p><br><?php
-         }
-      } ?>
+    // 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> pub(s) are <?php print $rel_type ?> this <?php print $pub->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('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 ($subjects as $subject){
+          // link the pub to it's node
+          $title = $subject->record->subject_id->title;
+          if (property_exists($subject->record, 'nid')) {
+            $title = l($title, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
+          }
+          
+          // get the citation
+          $values = array(
+            'pub_id' => $subject->record->subject_id->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');
+          
+          $rows[] = array(
+            $title . '<br>' . htmlspecialchars($citation->value),
+          );
+         } 
+         // 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_pub-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
+       }
+    }?>
   </div> <?php
 }

+ 74 - 38
tripal_pub/theme/tripal_pub/tripal_pub_stocks.tpl.php

@@ -2,15 +2,22 @@
 $pub = $variables['node']->pub;
 $stocks = array();
 
-// expand the pub object to include the records from the pub_dbxref table
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$stock_pager_id = 5;
+// get the stocks that are associated with this publication.  But we only
+// want 25 and we want a pager to let the user cycle between pages of stocks.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of stocks
 
-// get the genotypes from the stock_genotype table
+$element = 5;        // an index to specify the pager this must be unique amongst all pub templates
+$num_per_page = 25;  // the number of stocks to show per page$num_results_per_page = 25; 
+
+// get the stocks from the stock_pub table
 $options = array(  
   'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $stock_pager_id),
+  'pager' => array(
+    'limit'   => $num_per_page, 
+    'element' => $element
+  ),
 );
 
 $pub = tripal_core_expand_chado_vars($pub, 'table', 'stock_pub', $options);
@@ -21,42 +28,71 @@ if (count($stock_pubs) > 0 ) {
   }
 }
 
-// create the pager.  
-global $pager_total_items;
-$stock_pager = theme('pager', array(), $num_results_per_page, $stock_pager_id, array('block' => 'stocks'));
-$total_stocks = $pager_total_items[$stock_pager_id];
-
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
 
 if(count($stocks) > 0){ ?>
   <div id="tripal_pub-stocks-box" class="tripal_pub-info-box tripal-info-box">
     <div class="tripal_pub-info-box-title tripal-info-box-title">Stocks</div>
-    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_stocks) ?> stocks:</div>
-    <table id="tripal_pub-stock-table" class="tripal_pub-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Stock Name</th>
-        <th>Type</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($stocks as $stock){         
-        $class = 'tripal_pub-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_pub-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($stock->nid) { 
-              print l($stock->name, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $stock->name;
-            } ?>
-          </td>
-          <td><?php print $stock->type_id->name ?></td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $stock_pager ?>
+    <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> stocks:</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('Stock Name', 'Uniquenaem', 'Type');
+    
+    // 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 ($stocks as $stock){
+       $stock_name = $stock->name;
+       if (property_exists($stock, 'nid')) {
+         $stock_name = l($stock_name, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
+       }
+       
+       $rows[] = array(
+         $stock_name,
+         $stock->uniquename,
+         $stock->type_id->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_pub-table-stocks',
+      ),
+      '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);
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'stocks'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $element,
+      'parameters' => array(
+        'block' => 'stocks'
+      ),
+      'quantity' => $num_per_page,
+    );
+    print theme_pager($pager); ?>
   </div><?php 
 }?>
 

+ 0 - 9
tripal_pub/theme/tripal_pub_help.tpl.php

@@ -1,13 +1,4 @@
 <br />
-<h3>Tripal Publication Quick Links</h3>
-<ul>
-	<li><?php print l('Search for Publications', 'find/publications') ?></li>
-	<li><?php print l('Configuration', 'admin/tripal/tripal_pub/configuration') ?></li>
-	<li><?php print l('Sync Publications', 'admin/tripal/tripal_pub/sync') ?></li>
-	<li><?php print l('List of Importers', 'admin/tripal/tripal_pub/import_list') ?></li>
-	<li><?php print l('Add a New Importer', 'admin/tripal/tripal_pub/import/new') ?></li>
-</ul>
-
 <h3>Module Description:</h3>
 <p>The Tripal Publication Module provides the functionality for adding,
 editing, deleting viewing and bulk importing of publications. This

+ 47 - 20
tripal_pub/tripal_pub.module

@@ -218,29 +218,14 @@ function tripal_pub_theme($existing, $type, $theme, $path) {
       'path' => "$core_path/theme",
     ),
     // node templates
-    'tripal_pub_base' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_pub_base',
-      'path' => "$path/theme/tripal_pub",
-    ),
-    'tripal_pub_properties' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_pub_properties',
-      'path' => "$path/theme/tripal_pub",
-    ),
     'tripal_pub_authors' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_pub_authors',
       'path' => "$path/theme/tripal_pub",
     ),
-    'tripal_pub_references' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_pub_references',
-      'path' => "$path/theme/tripal_pub",
-    ),
-    'tripal_pub_relationships' => array(
+    'tripal_pub_base' => array(
       'arguments' => array('node' => NULL),
-      'template' => 'tripal_pub_relationships',
+      'template' => 'tripal_pub_base',
       'path' => "$path/theme/tripal_pub",
     ),
     'tripal_pub_featuremaps' => array(
@@ -263,6 +248,21 @@ function tripal_pub_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_pub_projects',
       'path' => "$path/theme/tripal_pub",
     ),
+    'tripal_pub_properties' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_pub_properties',
+      'path' => "$path/theme/tripal_pub",
+    ),
+    'tripal_pub_references' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_pub_references',
+      'path' => "$path/theme/tripal_pub",
+    ),
+    'tripal_pub_relationships' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_pub_relationships',
+      'path' => "$path/theme/tripal_pub",
+    ),
     'tripal_pub_stocks' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_pub_stocks',
@@ -273,7 +273,7 @@ function tripal_pub_theme($existing, $type, $theme, $path) {
     'tripal_pub_help' => array(
       'template' => 'tripal_pub_help',
       'arguments' =>  array(NULL),
-      'path' => $path,
+      'path' => "$path/theme",
     ),
 
     // themed forms
@@ -840,7 +840,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   // query, therefore we will manually perform the query
   $sql = "
     SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
-    FROM pub_relationship PR
+    FROM {pub_relationship} PR
       INNER JOIN {pub} P            ON PR.object_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id   = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id     = CP.pub_id
@@ -849,7 +849,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   $as_subject = chado_query($sql, array(':subject_id' => $pub->pub_id));
   $sql = "
     SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
-    FROM pub_relationship PR
+    FROM {pub_relationship} PR
       INNER JOIN {pub} P            ON PR.subject_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id    = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id      = CP.pub_id
@@ -927,9 +927,36 @@ function tripal_pub_node_view($node, $view_mode, $langcode) {
     case 'chado_pub':
       // Show feature browser and counts
       if ($view_mode == 'full') {
+        $node->content['tripal_pub_authors'] = array(
+          '#value' => theme('tripal_pub_authors', array('node' => $node)),
+        );
         $node->content['tripal_pub_base'] = array(
           '#value' => theme('tripal_pub_base', array('node' => $node)),
         );
+        $node->content['tripal_pub_featuremaps'] = array(
+          '#value' => theme('tripal_pub_featuremaps', array('node' => $node)),
+        );
+        $node->content['tripal_pub_features'] = array(
+          '#value' => theme('tripal_pub_features', array('node' => $node)),
+        );
+        $node->content['tripal_pub_libraries'] = array(
+          '#value' => theme('tripal_pub_libraries', array('node' => $node)),
+        );
+        $node->content['tripal_pub_projects'] = array(
+          '#value' => theme('tripal_pub_projects', array('node' => $node)),
+        );
+        $node->content['tripal_pub_properties'] = array(
+          '#value' => theme('tripal_pub_properties', array('node' => $node)),
+        );
+        $node->content['tripal_pub_references'] = array(
+          '#value' => theme('tripal_pub_references', array('node' => $node)),
+        );
+        $node->content['tripal_pub_relationships'] = array(
+          '#value' => theme('tripal_pub_relationships', array('node' => $node)),
+        );
+        $node->content['tripal_pub_stocks'] = array(
+          '#value' => theme('tripal_pub_stocks', array('node' => $node)),
+        );
       }
       if ($view_mode == 'teaser') {
         $node->content['tripal_pub_teaser'] = array(