Browse Source

Added wrappers for all default views sort handlers -not yet tested

Lacey Sanderson 13 năm trước cách đây
mục cha
commit
cb44dc5e16

+ 12 - 12
base/tripal_analysis/views/analysis.views.inc

@@ -84,7 +84,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -102,7 +102,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -125,7 +125,7 @@ function retrieve_analysis_views_data() {
 	    'handler' => 'views_handler_filter_numeric',
 	  ),
 	  'sort' => array(
-	    'handler' => 'views_handler_sort',
+	    'handler' => 'chado_views_handler_sort',
 	  ),
 	);
 	
@@ -168,7 +168,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_chado_select_string',
@@ -191,7 +191,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -210,7 +210,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_chado_select_string',
@@ -229,7 +229,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_chado_select_string',
@@ -248,7 +248,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_chado_select_string',
@@ -266,7 +266,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -285,7 +285,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -304,7 +304,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort',
+      'handler' => 'chado_views_handler_sort',
     ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
@@ -323,7 +323,7 @@ function retrieve_analysis_views_data() {
       'click sortable' => TRUE,
     ),
     'sort' => array(
-      'handler' => 'views_handler_sort_date',
+      'handler' => 'chado_views_handler_sort_date',
     ),
   );
 

+ 21 - 1
base/tripal_core/tripal_core.views.inc

@@ -93,7 +93,8 @@ function tripal_core_views_handlers() {
      ),
 
      
-     // Wrappers for Default Views Handlers
+     // Wrappers for Default Views Handlers-----
+     // Field Handlers
      'chado_views_handler_field' => array(
       'parent' => 'views_handler_field'
      ),
@@ -118,6 +119,25 @@ function tripal_core_views_handlers() {
      'chado_views_handler_field_numeric' => array(
       'parent' => 'views_handler_field_numeric'
      ),
+     'chado_views_handler_sort' => array(
+      'parent' => 'views_handler_sort',
+     ),
+     // Sort Handlers
+     'chado_views_handler_sort' => array(
+      'parent' => 'views_handler_sort'
+     ),     
+     'chado_views_handler_sort_date' => array(
+      'parent' => 'views_handler_sort_date'
+     ), 
+     'chado_views_handler_sort_formula' => array(
+      'parent' => 'views_handler_sort_formula'
+     ), 
+     'chado_views_handler_sort_menu_hierarchy' => array(
+      'parent' => 'views_handler_sort_menu_hierarchy'
+     ), 
+     'chado_views_handler_sort_random' => array(
+      'parent' => 'views_handler_sort_random'
+     ), 
    ),
  );
 }

+ 1 - 2
base/tripal_core/views/handlers/chado_views_handler_sort.inc

@@ -41,8 +41,7 @@ class chado_views_handler_sort extends views_handler_sort {
     
     // if not then add the sort
     if (!$this->aggregated) {
-      $this->ensure_my_table();
-      $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
+      parent::query();
     }
     
   }

+ 49 - 0
base/tripal_core/views/handlers/chado_views_handler_sort_date.inc

@@ -0,0 +1,49 @@
+<?php
+
+class chado_views_handler_sort extends views_handler_sort_date {
+
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    
+    $form['msg'] = array(
+      '#type' => 'item',
+      '#value' => '<b>Sorting of aggregated fields only works for PostgreSQL 9.0+. This is due to lack of support at the database level. With lower postgreSQL versions, no sorting is applied.</b>'
+    );
+
+    parent::options_form($form, $form_state);
+  }
+  
+  /**
+   * Adds the sort to the query only if the field isn't aggregated
+   * If the field is aggregated then the sort has to be applied at the join handler level
+   */
+  function query () {
+    
+    // Determine if the current field is part of an aggregated table
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+    
+    // One day when the aggregated sort will work (ie: Postgresql 9.0+)
+    // it will need to be applied in join handler
+    // thus tell join handler about the sort
+    $table['join']->sort[] = array(
+      'table' => $table['alias'],
+      'field' => $this->options['field'],
+      'order' => $this->options['order']
+    );
+    
+    
+    // if not then add the sort
+    if (!$this->aggregated) {
+      parent::query();
+    }
+    
+  }
+  
+}

+ 49 - 0
base/tripal_core/views/handlers/chado_views_handler_sort_formula.inc

@@ -0,0 +1,49 @@
+<?php
+
+class chado_views_handler_sort extends views_handler_sort_formula {
+
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    
+    $form['msg'] = array(
+      '#type' => 'item',
+      '#value' => '<b>Sorting of aggregated fields only works for PostgreSQL 9.0+. This is due to lack of support at the database level. With lower postgreSQL versions, no sorting is applied.</b>'
+    );
+
+    parent::options_form($form, $form_state);
+  }
+  
+  /**
+   * Adds the sort to the query only if the field isn't aggregated
+   * If the field is aggregated then the sort has to be applied at the join handler level
+   */
+  function query () {
+    
+    // Determine if the current field is part of an aggregated table
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+    
+    // One day when the aggregated sort will work (ie: Postgresql 9.0+)
+    // it will need to be applied in join handler
+    // thus tell join handler about the sort
+    $table['join']->sort[] = array(
+      'table' => $table['alias'],
+      'field' => $this->options['field'],
+      'order' => $this->options['order']
+    );
+    
+    
+    // if not then add the sort
+    if (!$this->aggregated) {
+      parent::query();
+    }
+    
+  }
+  
+}

+ 49 - 0
base/tripal_core/views/handlers/chado_views_handler_sort_menu_hierarchy.inc

@@ -0,0 +1,49 @@
+<?php
+
+class chado_views_handler_sort extends views_handler_sort_menu_hierarchy {
+
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    
+    $form['msg'] = array(
+      '#type' => 'item',
+      '#value' => '<b>Sorting of aggregated fields only works for PostgreSQL 9.0+. This is due to lack of support at the database level. With lower postgreSQL versions, no sorting is applied.</b>'
+    );
+
+    parent::options_form($form, $form_state);
+  }
+  
+  /**
+   * Adds the sort to the query only if the field isn't aggregated
+   * If the field is aggregated then the sort has to be applied at the join handler level
+   */
+  function query () {
+    
+    // Determine if the current field is part of an aggregated table
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+    
+    // One day when the aggregated sort will work (ie: Postgresql 9.0+)
+    // it will need to be applied in join handler
+    // thus tell join handler about the sort
+    $table['join']->sort[] = array(
+      'table' => $table['alias'],
+      'field' => $this->options['field'],
+      'order' => $this->options['order']
+    );
+    
+    
+    // if not then add the sort
+    if (!$this->aggregated) {
+      parent::query();
+    }
+    
+  }
+  
+}

+ 49 - 0
base/tripal_core/views/handlers/chado_views_handler_sort_random.inc

@@ -0,0 +1,49 @@
+<?php
+
+class chado_views_handler_sort extends views_handler_sort_random {
+
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    
+    $form['msg'] = array(
+      '#type' => 'item',
+      '#value' => '<b>Sorting of aggregated fields only works for PostgreSQL 9.0+. This is due to lack of support at the database level. With lower postgreSQL versions, no sorting is applied.</b>'
+    );
+
+    parent::options_form($form, $form_state);
+  }
+  
+  /**
+   * Adds the sort to the query only if the field isn't aggregated
+   * If the field is aggregated then the sort has to be applied at the join handler level
+   */
+  function query () {
+    
+    // Determine if the current field is part of an aggregated table
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+    
+    // One day when the aggregated sort will work (ie: Postgresql 9.0+)
+    // it will need to be applied in join handler
+    // thus tell join handler about the sort
+    $table['join']->sort[] = array(
+      'table' => $table['alias'],
+      'field' => $this->options['field'],
+      'order' => $this->options['order']
+    );
+    
+    
+    // if not then add the sort
+    if (!$this->aggregated) {
+      parent::query();
+    }
+    
+  }
+  
+}