Browse Source

added support for chado field boolean filters.

Lacey Sanderson 9 years ago
parent
commit
8eec2fd932

+ 34 - 0
tripal_chado/includes/chado_views_handler_filter.inc

@@ -4,6 +4,40 @@
  * Contains views filter handlers that provide chado support.
  */
 
+/**
+ * Adds support for chado boolean filters.
+ */
+class chado_views_handler_filter_boolean extends views_handler_filter_boolean_operator {
+
+  /**
+   * {@inheritdoc}
+   */
+  function value_form(&$form, &$form_state) {
+    parent::value_form($form, $form_state);
+
+    // change the keys of the options so that this filter can be optional.
+    $form['value']['#options']['f'] = $form['value']['#options'][0];
+    $form['value']['#options']['t'] = $form['value']['#options'][1];
+    unset($form['value']['#options'][0], $form['value']['#options'][1]);
+ 
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function query() {
+
+    // Adds joins to chado_entity and the chado table this field is from.
+    $alias = _chado_views_add_table_joins($this);
+
+    // Booleans in chado are stored t/f.
+    $field = $alias .'.'. $this->definition['chado_field'];
+    if ($this->value) {
+      $this->query->add_where($this->options['group'], $field, $this->value, '=');
+    }
+  }
+}
+
 /**
  * Adds support for chado foreign key filters.
  */

+ 5 - 1
tripal_chado/tripal_chado.views.inc

@@ -124,7 +124,11 @@ function tripal_chado_add_field_views_data(&$data) {
         $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_fk';
         $data['tripal_entity'][ $field['field_name'] ]['filter']['foreign_key'] = $fk_defn;
       }
-
+      if ($field_defn['type'] == 'boolean') {
+        $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_boolean';
+        $data['tripal_entity'][ $field['field_name'] ]['filter']['label'] = $field['settings']['chado_column'];
+        $data['tripal_entity'][ $field['field_name'] ]['filter']['type'] = 'yes-no'; 
+      }
     }    
   }
 }