Sfoglia il codice sorgente

Adjusted views_handler_filter_chado_select_String to not pull all records at once (makes things too slow) and to export the width of the select box to the admin

Stephen Ficklin 13 anni fa
parent
commit
cd4c9f0c50

+ 5 - 5
tripal_views/tripal_views_integration.inc

@@ -529,7 +529,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL){
             if($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial'){
                $default_field_handler = 'chado_views_handler_field_numeric';
             }
-            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type = 'varchar'){
+            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar'){
                $default_field_handler = 'chado_views_handler_field';
             }
             elseif($column_type == 'boolean'){
@@ -564,7 +564,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL){
             if($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial'){
                $default_filter_handler = 'chado_views_handler_filter_numeric';
             }
-            elseif(preg_match("/^character varying/",$column_type) or $column_type == 'char' or $column_type == 'text'){
+            elseif(preg_match("/^character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar'){
                $default_filter_handler = 'chado_views_handler_filter_string';
             }
             elseif($column_type == 'boolean'){
@@ -598,7 +598,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL){
             if($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial'){
                $default_sort_handler = 'chado_views_handler_sort';
             }
-            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text'){
+            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar'){
                $default_sort_handler = 'chado_views_handler_sort';
             }
             elseif($column_type == 'boolean'){
@@ -632,7 +632,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL){
             if($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial'){
                $default_argument_handler = 'views_handler_argument_numeric';
             }
-            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text'){
+            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar'){
                $default_argument_handler = 'views_handler_argument_string';
             }
             elseif($column_type == 'boolean'){
@@ -666,7 +666,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL){
             if($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial'){
                $default_relationship_handler = 'views_handler_relationship';
             }
-            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text'){
+            elseif(preg_match("/character varying/",$column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar'){
                $default_relationship_handler = 'views_handler_relationship';
             }
             elseif($column_type == 'boolean'){

+ 17 - 8
tripal_views/views/handlers/views_handler_filter_chado_select_string.inc

@@ -35,6 +35,14 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
       '#description' => t('Adds --Any-- to the available options.'),
       '#default_value' => (isset($this->options['optional'])) ? $this->options['optional'] : TRUE,
     );
+ 
+    $form['max_length'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Max Width'),
+      '#description' => t('Specify the maximum width of the select box'),
+      '#default_value' => (isset($this->options['max_length'])) ? $this->options['max_length'] : 40,
+
+    );
     
   }
   
@@ -57,14 +65,15 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
         //$options['<select '.$this->table.'>'] = '--None--';
         $options['All'] = '--Any--';
       }
-      $results = tripal_core_chado_select(
-        $this->table,
-        array($this->field),
-        array(),
-        array('order_by' => array($this->field => 'ASC'))
-      );
-      $max_length = 40;
-      foreach ($results as $r) {
+      $sql = "SELECT $this->field FROM $this->table ORDER BY $this->field ASC";
+      $previous_db = tripal_db_set_active('chado');  // use chado database
+      $results = db_query($sql);
+      tripal_db_set_active($previous_db);  // now use drupal database 
+      $max_length = $this->options['max_length'];
+      if(!$max_length){
+         $max_length = 40;
+      }
+      while($r = db_fetch_object($results)){
         if (strlen($r->{$this->field}) > $max_length) {
           $options[$r->{$this->field}] = substr($r->{$this->field},0,$max_length) . '...';
         } else {