Tripal v1.0 (6.x-1.0)
chado_views_handler_filter_numeric.inc
Go to the documentation of this file.
00001 <?php
00002 
00011 class chado_views_handler_filter_numeric extends views_handler_filter_numeric {
00012 
00016   function options_form(&$form, &$form_state) {
00017     $form['msg'] = array(
00018       '#type' => 'item',
00019       '#value' => '<b>If this filter applies to a table that is aggregated, additionally options may be ignored.</b>'
00020     );
00021 
00022     parent::options_form($form, $form_state);
00023 
00024     $form['agg'] = array(
00025       '#type' => 'fieldset',
00026       '#title' => 'Apply to fields that are aggregated'
00027     );
00028 
00029     $form['agg']['records_with'] = array(
00030       '#type' => 'checkbox',
00031       '#title' => t('Filter base table records'),
00032       '#description' => t('Filters %base_table to only those with the value in the aggregate array.', array('%base_table' => $this->view->base_table)),
00033       '#default_value' => (isset($this->options['agg']['records_with'])) ? $this->options['agg']['records_with'] : TRUE,
00034     );
00035 
00036     $form['agg']['aggregates_with'] = array(
00037       '#type' => 'checkbox',
00038       '#title' => t('Filter aggregates displayed'),
00039       '#description' => t('Filters the aggregates shown based on the value. Doesn\'t affect the number of %base_table records.', array('%base_table' => $this->view->base_table)),
00040       '#default_value' => (isset($this->options['agg']['aggregates_with'])) ? $this->options['agg']['aggregates_with'] : TRUE,
00041     );
00042 
00043   }
00044 
00049   function query() {
00050 
00051     // make optional
00052     // if it is not set or empty then don't restrict the query
00053     if (!$this->value) {
00054       return;
00055     }
00056 
00057     $this->ensure_my_table();
00058 
00059     $table = $this->query->get_table_info($this->table);
00060     if (preg_match('/aggregator/', $table['join']->definition['handler'])) {
00061       $this->aggregated = TRUE;
00062     }
00063     else {
00064       $this->aggregated = FALSE;
00065     }
00066 
00067     if (!$this->aggregated) {
00068       parent::query();
00069     }
00070     else {
00071 
00072       // Only base records with value in the aggregated field
00073       // This doesn't restrict the items in the aggregate field
00074       $this->ensure_my_table();
00075       $field = "$this->table_alias.$this->real_field";
00076       if ($this->options['agg']['records_with']) {
00077         $where = "'%s' = ANY($field)";
00078         $this->query->add_where($this->options['group'], $where, $this->value);
00079       }
00080 
00081       // To restrict the items in the aggregate...
00082       // Tell the join handler about the filter
00083       // so it can be done in the join query
00084       if ($this->options['agg']['aggregates_with']) {
00085         $table['join']->filter[] = $field . " = '" . $this->value . "'";
00086       }
00087     }
00088 
00089   }
00090 
00091 }
 All Classes Files Functions Variables