Browse Source

Views Select cvterm filter: added back in the where clauses

Lacey Sanderson 10 years ago
parent
commit
0096a1fb26

+ 8 - 6
tripal_views/views/handlers/tripal_views_handler_filter_select_cvterm.inc

@@ -39,9 +39,10 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
         $sql = "
           WITH RECURSIVE t AS (
             SELECT MIN(cv_id) AS col FROM {!table}
+              " . ($where == '' ? '' : "WHERE " . $where) . "
             UNION ALL
-            SELECT (SELECT MIN(cv_id) FROM {!table} WHERE cv_id > col)
-            FROM t WHERE col IS NOT NULL
+            SELECT (SELECT MIN(cv_id) FROM {!table} WHERE cv_id > col " . ($where == '' ? '' : " AND " . $where) . ")
+              FROM t WHERE col IS NOT NULL
           )
           SELECT cv_id, name
             FROM {cv}
@@ -60,17 +61,18 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
             SELECT MIN(cvterm.cv_id) AS col
               FROM {!table} filter_table
               LEFT JOIN {cvterm} ON filter_table.!field=cvterm.cvterm_id
+              " . ($where == '' ? '' : "WHERE " . $where) . "
             UNION ALL
             SELECT (
                 SELECT MIN(cv_id)
                 FROM {!table} filter_table
                 LEFT JOIN {cvterm} ON filter_table.!field=cvterm.cvterm_id
-                WHERE cv_id > col
+                WHERE cv_id > col " . ($where == '' ? '' : " AND " . $where) . "
               )
               FROM t WHERE col IS NOT NULL
           )
           SELECT cv_id, name
-            FROM chado.cv
+            FROM {cv}
             WHERE cv_id IN (SELECT col FROM t where col IS NOT NULL)
             ORDER BY cv.name ASC";
         $sql = format_string($sql, array('!table' => $this->table, '!field' => $this->field));
@@ -98,7 +100,7 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
       $where_clauses = $this->get_select_option_where();
       $where = '';
       if (!empty($where_clauses)) {
-        $where = ' AND ' . implode(' AND ', $where_clauses);
+        $where = implode(' AND ', $where_clauses);
       }
 
       // Using a "Loose Index Scan" to get a list of all the cvterms used
@@ -107,7 +109,7 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
         WITH RECURSIVE t AS (
           SELECT MIN(!field) AS col FROM {!table} " . ($where == '' ? '' : "WHERE " . $where) . "
           UNION ALL
-          SELECT (SELECT MIN(!field) FROM {!table} WHERE !field > col " . $where . ")
+          SELECT (SELECT MIN(!field) FROM {!table} WHERE !field > col " . ($where == '' ? '' : " AND " . $where) . ")
           FROM t WHERE col IS NOT NULL
         )
         SELECT cvterm_id, name

+ 14 - 0
tripal_views/views/handlers/tripal_views_handler_filter_select_string.inc

@@ -64,6 +64,11 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
       'bool' => TRUE,
       'export' => TRUE
     );
+    $options['show_all'] = array(
+      'default' => FALSE,
+      'bool' => TRUE,
+      'export' => TRUE
+    );
     $options['max_length'] = array(
       'default' => 40,
       'export' => TRUE
@@ -172,6 +177,13 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
       '#default_value' => $this->options['values_form_type'],
     );
 
+    $form['show_all'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show All'),
+      '#description' => t('When selected all terms from the controlled vocaulbary used by the table will be shown where the default is to only show those that are used.'),
+      '#default_value' => $this->options['show_all'],
+    );
+
     $form['select_multiple'] = array(
       '#type' => 'checkbox',
       '#title' => t('Select Multiple'),
@@ -212,6 +224,7 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
     $this->options['select_multiple'] = $form_state['values']['options']['select_multiple'];
     $this->options['select_optional'] = $form_state['values']['options']['select_optional'];
     $this->options['max_length'] = $form_state['values']['options']['max_length'];
+    $this->options['show_all'] = $form_state['values']['options']['show_all'];
   }
 
   /**
@@ -222,6 +235,7 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
     $this->options['select_multiple'] = FALSE;
     $this->options['select_optional'] = FALSE;
     $this->options['max_length'] = 40;
+    $this->options['show_all'] = FALSE;
   }
 
   /**