Jelajahi Sumber

Fixed phenotype module to include the tripal_feature.phenotype.tpl.php template

Stephen Ficklin 11 tahun lalu
induk
melakukan
8bd0b15d71

+ 114 - 75
tripal_feature/theme/tripal_feature/tripal_feature_featurepos.tpl.php

@@ -3,14 +3,19 @@
 // expand the feature object to include the records from the featurepos table
 // specify the number of features to show by default and the unique pager ID
 $num_results_per_page = 25; 
-$featurepos_pager_id = 0;
+$featurepos_pager_id = 20;
 
 // get the maps associated with this feature
 $feature = $variables['node']->feature;
 $options = array(  
   'return_array' => 1,
-  'order_by' => array('map_feature_id' => 'ASC'),
-  'pager' => array('limit' => $num_results_per_page, 'element' => $featurepos_pager_id),
+  'order_by' => array(
+    'map_feature_id' => 'ASC'
+  ),
+  'pager' => array(
+    'limit' => $num_results_per_page, 
+    'element' => $featurepos_pager_id
+  ),
   'include_fk' => array(
     'map_feature_id' => array(
       'type_id' => 1,
@@ -29,83 +34,117 @@ $feature = tripal_core_expand_chado_vars($feature, 'table', 'featurepos', $optio
 // we only want to show the map that this feature belongs to
 $map_positions = $feature->featurepos->feature_id;
 
-// create the pager.  
-$featurepos_pager = theme('pager', array(), $num_results_per_page, $featurepos_pager_id, array('block' => 'featurepos'));
+// 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'];
 
 
 if(count($map_positions) > 0){ ?>
   <div id="tripal_feature-featurepos-box" class="tripal_feature-info-box tripal-info-box">
     <div class="tripal_feature-info-box-title tripal-info-box-title">Maps</div>
-    <div class="tripal_feature-info-box-desc tripal-info-box-desc">This feature is contained in the following maps:</div>
-    <table id="tripal_feature-featurepos-table" class="tripal_feature-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Map Name</th>
-        <th>Landmark</th>
-        <th>Type</th>
-        <th>Position</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($map_positions as $position){
-        $map_feature = $position->map_feature_id;
+    <div class="tripal_feature-info-box-desc tripal-info-box-desc">This feature is contained in the following <?php print number_format($total_records) ?> map(s):</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', 'Landmark', 'Type', 'Position');
+    
+    // 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();
+
+    // iterate through our map positions    
+    foreach ($map_positions as $position){
+      $map_feature = $position->map_feature_id;
+
+      // check if there are any values in the featureposprop table for the start and stop
+      $mappos = $position->mappos;
+      $options = array(
+        'return_array' => 1,
+        'include_fk' => array(
+          'type_id' => 1,            
+        ),
+      );
+      $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
+      $featureposprop = $position->featureposprop;
+      $start = '';
+      $stop = '';
+      if (is_array($featureposprop)) {
+        foreach ($featureposprop as $index => $property) {
+           if ($property->type_id->name == 'start') {
+             $start = $property->value;
+           }
+           if ($property->type_id->name == 'stop') {
+             $stop = $property->value;
+           }
+        }      
+      }  
+      if ($start and $stop and $start != $stop) {
+        $mappos = "$start-$stop";
+      }
+      if ($start and !$stop) {
+        $mappos = $start;
+      }
+      if ($start and $stop and $start == $stop) {
+        $mappos = $start;
+      }
+      
+      // get the map name feature
+      $map_name =  $position->featuremap_id->name;
+      if (property_exists($position->featuremap_id, 'nid')) {
+        $map_name = l($map_name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
+      }
+      
+      
+      // get the landmark
+      $landmark = $map_feature->name;
+      if (property_exists($map_feature, 'nid')) {
+        $landmark =  l($landmark, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
+      }
+      
+      $rows[] = array(
+        $map_name,
+        $landmark,
+        $map_feature->type_id->name,
+        $mappos . ' ' . $position->featuremap_id->unittype_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_feature-table-featurepos',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
 
-        // check if there are any values in the featureposprop table for the start and stop
-        $mappos = $position->mappos;
-        $options = array(
-          'return_array' => 1,
-          'include_fk' => array(
-            'type_id' => 1,            
-          ),
-        );
-        $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
-        $featureposprop = $position->featureposprop;
-        if (is_array($featureposprop)) {
-          foreach ($featureposprop as $index => $property) {
-             if ($property->type_id->name == 'start') {
-               $start = $property->value;
-             }
-             if ($property->type_id->name == 'stop') {
-               $stop = $property->value;
-             }
-          }      
-        }  
-        if ($start and $stop and $start != $stop) {
-          $mappos = "$start-$stop";
-        }
-        if ($start and !$stop) {
-          $mappos = $start;
-        }
-        if ($start and $stop and $start == $stop) {
-          $mappos = $start;
-        }
-        
-        $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_feature-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($position->featuremap_id->nid) { 
-              print l($position->featuremap_id->name, 'node/' . $position->featuremap_id->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $position->featuremap_id->name;
-            } ?>
-          </td>
-          <td> <?php 
-            if ($map_feature->nid) { 
-              print l($map_feature->name, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $map_feature->name;
-            } ?>
-          </td>          
-          <td><?php print $map_feature->type_id->name ?></td>
-          <td><?php print $mappos ?> <?php print $position->featuremap_id->unittype_id->name ?> </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $featurepos_pager ?>
-  </div><?php 
+    // 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' => $featurepos_pager_id,
+      'parameters' => array(
+        'block' => 'featurepos'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager); ?>
+  </div> <?php 
 }?>
 

+ 2 - 7
tripal_feature/tripal_feature.module

@@ -340,11 +340,6 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_synonyms',
       'path' => "$path/theme/tripal_feature",
     ),
-    'tripal_feature_phenotypes' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_feature_phenotypes',
-      'path' => "$path/theme/tripal_feature",
-    ),
     'tripal_feature_references' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_feature_references',
@@ -1386,8 +1381,8 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
         $node->content['tripal_feature_base'] = array(
           '#value' => theme('tripal_feature_base', array('node' => $node)),
         );
-        $node->content['tripal_feature_phenotypes'] = array(
-          '#value' => theme('tripal_feature_phenotypes', array('node' => $node)),
+        $node->content['tripal_feature_featurepos'] = array(
+          '#value' => theme('tripal_feature_featurepos', array('node' => $node)),
         );
         $node->content['tripal_feature_properties'] = array(
           '#value' => theme('tripal_feature_properties', array('node' => $node)),

+ 22 - 10
tripal_feature/theme/tripal_feature/tripal_feature_phenotypes.tpl.php → tripal_phenotype/theme/tripal_feature/tripal_feature.phenotypes.tpl.php

@@ -15,14 +15,8 @@ $options = array(
 $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_phenotype', $options);
 $feature_phenotypes = $feature->feature_phenotype;
 
-if(count($feature_phenotypes) > 0){ 
+if(count($feature_phenotypes) > 0){ ?>
   
-  // expand the text fields
-  $options = array('return_array' => 1);
-  $feature = tripal_core_expand_chado_vars($feature, 'field', 'phenotype.value', $options);
-  $feature = tripal_core_expand_chado_vars($feature, 'field', 'phenotype.uniquename', $options);
-  $feature = tripal_core_expand_chado_vars($feature, 'field', 'phenotype.name', $options); ?>
-
   <div id="tripal_feature-phenotypes-box" class="tripal_feature-info-box tripal-info-box">
     <div class="tripal_feature-info-box-title tripal-info-box-title">Phenotypes</div>
     <div class="tripal_feature-info-box-desc tripal-info-box-desc">The feature is associated with the following phenotypes</div><?php
@@ -37,13 +31,31 @@ if(count($feature_phenotypes) > 0){
     // can be found here:
     // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
     $rows = array();
-    foreach ($feature_phenotypes as $index => $feature_phenotype){
+    
+    // iterate through the feature_phenotype records
+    foreach ($feature_phenotypes as $feature_phenotype){
+      $phenotype = $feature_phenotype->phenotype_id;
+      
+      // expand the text fields
+      $options = array('return_array' => 1);
+      $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.value', $options);
+      $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.uniquename', $options);
+      $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.name', $options); 
+      
+      // get the phenotype value. If the value is qualitative the cvalue_id will link to a type. 
+      // If quantitative we use the value column
+      $phen_value = $phenotype->value . '<br>';
+      if ($phenotype->cvalue_id) {
+        $phen_value .= ucwords(preg_replace('/_/', ' ', $phenotype->cvalue_id->name)) . '<br>';
+      }
+      
+      $phen_value = $phenotype->cvalue_id ? $phenotype->cvalue_id->name : $phenotype->value;
       $phenotype = $feature_phenotype->phenotype_id;
       $rows[] = array(
         $phenotype->attr_id->name,
         $phenotype->observable_id->name,
-        $phenotype->cvalue_id ? $phenotype->cvalue_id->name : $phenotype->value,
-        $phenotype->assay_id
+        $phen_value,
+        $phenotype->assay_id->name
       );
     } 
     // the $table array contains the headers and rows array as well as other

+ 0 - 0
tripal_phenotype/theme/tripal_phenotype_help.tpl.php → tripal_phenotype/theme/tripal_phenotype.help.tpl.php


+ 23 - 1
tripal_phenotype/tripal_phenotype.module

@@ -62,8 +62,13 @@ function tripal_phenotype_theme($existing, $type, $theme, $path) {
   $core_path = drupal_get_path('module', 'tripal_core');
 
   $items = array(
+    'tripal_feature_phenotypes' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature.phenotypes',
+      'path' => "$path/theme/tripal_feature",
+    ),
     'tripal_phenotype_help' => array(
-      'template' => 'tripal_phenotype_help',
+      'template' => 'tripal_phenotype.help',
       'variables' =>  array(NULL),
       'path' => "$path/theme",
     ),
@@ -113,4 +118,21 @@ function tripal_phenotype_admin_phenotypes_listing() {
   }
 
   return $output;
+}
+
+/**
+ *
+ * @ingroup tripal_phenotype
+ */
+function tripal_phenotype_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'chado_feature':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_feature_phenotypes'] = array(
+          '#value' => theme('tripal_feature_phenotypes', array('node' => $node)),
+        );
+      }
+      break;
+  }
 }