Tripal v1.0 (6.x-1.0)
chado_views_handler_filter_float.inc
Go to the documentation of this file.
00001 <?php
00002 
00011 class chado_views_handler_filter_float extends views_handler_filter_float {
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 AND !is_array($this->value)) {
00054       return;
00055     }
00056     elseif (is_array($this->value)) {
00057       $tmp = array_filter($this->value);
00058       if (!$tmp) {
00059         return;
00060       }
00061     }
00062 
00063     $this->ensure_my_table();
00064 
00065     $table = $this->query->get_table_info($this->table);
00066     if (preg_match('/aggregator/', $table['join']->definition['handler'])) {
00067       $this->aggregated = TRUE;
00068     }
00069     else {
00070       $this->aggregated = FALSE;
00071     }
00072 
00073     if (!$this->aggregated) {
00074       parent::query();
00075     }
00076     else {
00077 
00078       // Only base records with value in the aggregated field
00079       // This doesn't restrict the items in the aggregate field
00080       $this->ensure_my_table();
00081       $field = "$this->table_alias.$this->real_field";
00082       if ($this->options['agg']['records_with']) {
00083         $where = "'%s' = ANY($field)";
00084         $this->query->add_where($this->options['group'], $where, $this->value);
00085       }
00086 
00087       // To restrict the items in the aggregate...
00088       // Tell the join handler about the filter
00089       // so it can be done in the join query
00090       if ($this->options['agg']['aggregates_with']) {
00091         $table['join']->filter[] = $field . " = '" . $this->value . "'";
00092       }
00093     }
00094 
00095   }
00096 
00097 }
 All Classes Files Functions Variables