Browse Source

Changed chado pager to use instead of . Also moved tripal_feature_featurepos template to featuremap module where it belongs

Stephen Ficklin 11 years ago
parent
commit
04218d9d98

+ 23 - 3
tripal_core/api/tripal_core.chado_query.api.inc

@@ -1355,7 +1355,7 @@ function chado_query($sql, $args = array()) {
  * @param $limit
  *   The number of query results to display per page.
  * @param $element
- *   An optional integer to distinguish between multiple pagers on one page.
+ *   An numeric identifier used to distinguish between multiple pagers on one page.
  * @param $count_query
  *   An SQL query used to count matching records.
  *
@@ -1366,10 +1366,10 @@ function chado_query($sql, $args = array()) {
  * @ingroup tripal_chado_query_api
  */
 function chado_pager_query($query, $args, $limit, $element, $count_query = '') {
-
   // get the page and offset for the pager
   $page = isset($_GET['page']) ? $_GET['page'] : '0';
   $offset = $limit * $page;
+  $q = $_GET['q'];
 
   // Construct a count query if none was given.
   if (!isset($count_query)) {
@@ -1387,7 +1387,7 @@ function chado_pager_query($query, $args, $limit, $element, $count_query = '') {
   $total_records = $results->fetchField();
 
   // set a session variable for storing the total number of records
-  $_SESSION['chado_pager'][$element]['total_records'] = $total_records;
+  $GLOBALS['chado_pager'][$q][$element]['total_records'] = $total_records;
 
   pager_default_initialize($total_records, $limit, $element);
 
@@ -1395,6 +1395,26 @@ function chado_pager_query($query, $args, $limit, $element, $count_query = '') {
   $results = chado_query($query, $args);
   return $results;
 }
+/**
+ * A function to retrieve the total number of records for a pager that
+ * was generated using the chado_pager_query() function
+ * 
+ * @param $element
+ *   The $element argument that was passed to the chado_pager_query function
+ *   
+ * @ingroup tripal_chado_query_api
+ */
+function chado_pager_get_count($element) {
+  $q = $_GET['q'];
+  
+  if (array_key_exists($q, $_SESSION['chado_pager']) and 
+      array_key_exists($element, $_SESSION['chado_pager'][$q])) {
+    return $GLOBALS['chado_pager'][$q][$element]['total_records'];
+  }
+  else {
+    return 0;
+  }
+}
 
 /**
  * Gets the value of a foreign key relationship

+ 0 - 5
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -864,11 +864,6 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
           '#tripal_toc_title' => 'Overview',
           '#weight' => -100,
         );
-        $node->content['tripal_feature_featurepos'] = array(
-          '#markup' => theme('tripal_feature_featurepos', array('node' => $node)),
-          '#tripal_toc_id'    => 'featurepos',
-          '#tripal_toc_title' => 'Maps',
-        );
         $node->content['tripal_feature_properties'] = array(
           '#markup' => theme('tripal_feature_properties', array('node' => $node)),
           '#tripal_toc_id'    => 'properties',

+ 0 - 5
tripal_feature/tripal_feature.module

@@ -245,11 +245,6 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_base',
       'path' => "$path/theme/tripal_feature",
     ),
-    'tripal_feature_featurepos' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_featurepos',
-      'path' => "$path/theme/tripal_feature",
-    ),
     'tripal_feature_sequence' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_feature_sequence',

+ 9 - 0
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -524,5 +524,14 @@ function tripal_featuremap_node_view($node, $view_mode, $langcode) {
         );
       }
       break;
+    case 'chado_feature':
+      if ($view_mode == 'full') {
+        $node->content['tripal_feature_featurepos'] = array(
+          '#markup' => theme('tripal_feature_featurepos', array('node' => $node)),
+          '#tripal_toc_id'    => 'featurepos',
+          '#tripal_toc_title' => 'Maps',
+        );
+      }
+      break;
   }
 }

+ 3 - 2
tripal_feature/theme/tripal_feature/tripal_feature_featurepos.tpl.php → tripal_featuremap/theme/tripal_feature/tripal_feature_featurepos.tpl.php

@@ -32,10 +32,11 @@ $feature = tripal_core_expand_chado_vars($feature, 'table', 'featurepos', $optio
 // because the featurepos table has  FK relationships with map_feature_id and feature_id with the feature table 
 // the function call above will try to expand both and will create an array of matches for each FK.
 // we only want to show the map that this feature belongs to
-$map_positions = $feature->featurepos->feature_id;
+$map_positions = $feature->featurepos->map_feature_id;
+dpm($feature);
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$featurepos_pager_id]['total_records'];
+$total_records = chado_pager_get_count($featurepos_pager_id);
 
 
 if(count($map_positions) > 0){ ?>

+ 1 - 1
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_featurepos.tpl.php

@@ -34,7 +34,7 @@ $feature_positions = $featuremap->featurepos;
 
 
 // the total number of records for the paged query is stored in a session variable
-$total_features = $_SESSION['chado_pager'][$featurepos_pager_id]['total_records'];
+$total_features = chado_pager_get_count($featurepos_pager_id);
 
 
 if(count($feature_positions) > 0){ ?>

+ 7 - 0
tripal_featuremap/tripal_featuremap.module

@@ -217,6 +217,13 @@ function tripal_featuremap_theme($existing, $type, $theme, $path) {
       'variables' =>  array(NULL),
       'path' => "$path/theme/tripal_featuremap",
     ),
+    
+    // templates for the chado_feature node type
+    'tripal_feature_featurepos' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_feature_featurepos',
+      'path' => "$path/theme/tripal_feature",
+    ),
   );
   return $items;
 }

+ 1 - 1
tripal_genetic/theme/tripal_feature/tripal_feature_genotypes.tpl.php

@@ -40,7 +40,7 @@ $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype',
 $feature_genotypes = $feature->feature_genotype->feature_id;
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$feature_pager_id]['total_records'];
+$total_records = chado_pager_get_count($feature_pager_id);
 
 // now iterate through the feature genotypes and print a paged table.
 if (count($feature_genotypes) > 0) {?>

+ 1 - 1
tripal_genetic/theme/tripal_stock/tripal_stock_genotypes.tpl.php

@@ -30,7 +30,7 @@ $stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_genotype', $optio
 $stock_genotypes = $stock->stock_genotype;
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$stock_pager_id]['total_records'];
+$total_records = chado_pager_get_count($stock_pager_id);
 
 // now iterate through the stock genotypes and print a paged table.
 if (count($stock_genotypes) > 0) {?>

+ 1 - 1
tripal_natural_diversity/theme/tripal_feature/tripal_feature_nd_genotypes.tpl.php

@@ -63,7 +63,7 @@ $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype',
 $feature_genotypes = $feature->feature_genotype->feature_id;
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$feature_pager_id]['total_records'];
+$total_records = chado_pager_get_count($feature_pager_id);
 
 // now iterate through the feature genotypes and print a paged table.
 if (count($feature_genotypes) > 0) { ?>

+ 1 - 1
tripal_natural_diversity/theme/tripal_stock/tripal_stock_nd_genotypes.tpl.php

@@ -98,7 +98,7 @@ if (count($nd_experiment_stocks) > 0) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$stock_pager_id]['total_records'];
+$total_records = chado_pager_get_count($stock_pager_id);
 
 // now iterate through the feature genotypes and print a paged table.
 if (count($genotypes) > 0) { ?>

+ 1 - 1
tripal_pub/includes/tripal_pub.pub_search.inc

@@ -41,7 +41,7 @@ function tripal_pub_search_page() {
     // get the list of publications from the remote database using the search criteria.
     $pubs = tripal_pub_get_search_results($search_array, $limit);
     $page = isset($_GET['page']) ? $_GET['page'] : '0';
-    $total_records = $_SESSION['chado_pager'][0]['total_records'];
+    $total_records = chado_pager_get_count(0);
     $total_pages = (int) ($total_records / $limit) + 1;
 
     // iterate through the results and construct the table displaying the publications

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

@@ -29,7 +29,7 @@ if (count($featuremap_pubs) > 0 ) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+$total_records = chado_pager_get_count($element);
 
 if(count($featuremaps) > 0){ ?>
   <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> maps:</div> <?php 

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

@@ -29,7 +29,7 @@ if (count($feature_pubs) > 0 ) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+$total_records = chado_pager_get_count($element);
 
 if(count($features) > 0){ ?>
   <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> features:</div> <?php 

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

@@ -29,7 +29,7 @@ if (count($library_pubs) > 0 ) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+$total_records = chado_pager_get_count($element);
 
 if(count($libraries) > 0){ ?>
   <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> libraries:</div> <?php 

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

@@ -29,7 +29,7 @@ if (count($project_pubs) > 0 ) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+$total_records = chado_pager_get_count($element);
 
 if(count($projects) > 0){ ?>
   <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> projects:</div> <?php 

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

@@ -29,7 +29,7 @@ if (count($stock_pubs) > 0 ) {
 }
 
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+$total_records = chado_pager_get_count($element);
 
 if(count($stocks) > 0){ ?>
   <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> stocks:</div> <?php 

+ 1 - 1
tripal_stock/theme/tripal_organism/tripal_organism_stocks.tpl.php

@@ -24,7 +24,7 @@ $stocks = $organism->stock;
 
 // create the pager.  
 // the total number of records for the paged query is stored in a session variable
-$total_records = $_SESSION['chado_pager'][$pager_id]['total_records'];
+$total_records = chado_pager_get_count($pager_id);
 
  
 if (count($stocks) > 0) { ?>