Przeglądaj źródła

Added remaining chado filter wrappers -not tested

Lacey Sanderson 13 lat temu
rodzic
commit
e4fd96ec64

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

@@ -123,7 +123,25 @@ function tripal_core_views_handlers() {
      // Filter Handlers
      'chado_views_handler_filter_string' => array(
       'parent' => 'views_handler_filter_string',
-     ),     
+     ), 
+     'chado_views_handler_filter_boolean_operator_string' => array(
+      'parent' => 'views_handler_filter_boolean_operator_string',
+     ),
+     'chado_views_handler_filter_boolean_operator' => array(
+      'parent' => 'views_handler_filter_boolean_operator',
+     ),
+     'chado_views_handler_filter_date' => array(
+      'parent' => 'views_handler_filter_date',
+     ),
+     'chado_views_handler_filter_equality' => array(
+      'parent' => 'views_handler_filter_equality',
+     ),
+     'chado_views_handler_filter_float' => array(
+      'parent' => 'views_handler_filter_float',
+     ),
+     'chado_views_handler_filter_numeric' => array(
+      'parent' => 'views_handler_filter_numeric',
+     ),
      // Sort Handlers
      'chado_views_handler_sort' => array(
       'parent' => 'views_handler_sort'

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_boolean_operator.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_boolean_operator extends views_handler_filter_boolean_operator {
+
+  /**
+   * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_boolean_operator_string.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_boolean_operator_string extends views_handler_filter_boolean_operator_string {
+
+  /**
+   * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_date.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_date extends views_handler_filter_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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_equality.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_equality extends views_handler_filter_equality {
+
+  /**
+   * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_float.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_float extends views_handler_filter_float {
+
+  /**
+   * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 75 - 0
base/tripal_core/views/handlers/chado_views_handler_filter_numeric.inc

@@ -0,0 +1,75 @@
+<?php
+
+class chado_views_handler_filter_numeric extends views_handler_filter_numeric {
+
+  /**
+   * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
+    parent::options_form($form, $form_state);
+    
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter base table records'),
+      '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
+    );
+    
+    $form['agg']['aggregates_with'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Filter aggregates displayed'),
+      '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
+    );
+    
+  }
+  
+  /**
+   * If the table to be filtered is not aggregated uses the parent::query()
+   * However, if it is uses postgresql any() function to compare
+   */
+  function query () {
+    $this->ensure_my_table();
+    
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+
+    if (!$this->aggregated) {
+      parent::query();
+    } else {
+
+      // Only base records with value in the aggregated field
+      // This doesn't restrict the items in the aggregate field
+      $this->ensure_my_table();
+      $field = "$this->table_alias.$this->real_field";
+      if ($this->options['agg']['records_with']) {
+        $where = "'%s' = ANY($field)";
+        $this->query->add_where($this->options['group'], $where, $this->value);
+      }
+
+      // To restrict the items in the aggregate...
+      // Tell the join handler about the filter 
+      // so it can be done in the join query
+      if ($this->options['agg']['aggregates_with']) {
+        $table['join']->filter[] = $field ." = '". $this->value."'";
+      }    
+    }
+    
+  }
+  
+}

+ 16 - 6
base/tripal_core/views/handlers/chado_views_handler_filter_string.inc

@@ -6,20 +6,30 @@ class chado_views_handler_filter_string extends views_handler_filter_string {
    * 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>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
+    );
+    
     parent::options_form($form, $form_state);
     
-    $form['records_with'] = array(
+    $form['agg'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Apply to fields that are aggregated'
+    );
+    
+    $form['agg']['records_with'] = array(
       '#type' => 'checkbox',
       '#title' => t('Filter base table records'),
       '#description' => t('Filters '.$this->view->base_table.' to only those with the value in the aggregate array.'),
-      '#default_value' => ($this->options['records_with']) ? $this->options['records_with'] : TRUE,
+      '#default_value' => (isset($this->options['records_with'])) ? $this->options['records_with'] : TRUE,
     );
     
-    $form['aggregates_with'] = array(
+    $form['agg']['aggregates_with'] = array(
       '#type' => 'checkbox',
       '#title' => t('Filter aggregates displayed'),
       '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of '.$this->view->base_table.' records.'),
-      '#default_value' => ($this->options['aggregates_with']) ? $this->options['aggregates_with'] : TRUE,    
+      '#default_value' => (isset($this->options['aggregates_with'])) ? $this->options['aggregates_with'] : TRUE,    
     );
     
   }
@@ -47,7 +57,7 @@ class chado_views_handler_filter_string extends views_handler_filter_string {
       // This doesn't restrict the items in the aggregate field
       $this->ensure_my_table();
       $field = "$this->table_alias.$this->real_field";
-      if ($this->options['records_with']) {
+      if ($this->options['agg']['records_with']) {
         $where = "'%s' = ANY($field)";
         $this->query->add_where($this->options['group'], $where, $this->value);
       }
@@ -55,7 +65,7 @@ class chado_views_handler_filter_string extends views_handler_filter_string {
       // To restrict the items in the aggregate...
       // Tell the join handler about the filter 
       // so it can be done in the join query
-      if ($this->options['aggregates_with']) {
+      if ($this->options['agg']['aggregates_with']) {
         $table['join']->filter[] = $field ." = '". $this->value."'";
       }    
     }