Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00011 class chado_views_handler_filter_boolean_operator extends views_handler_filter_boolean_operator { 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 == 'All') { 00054 return; 00055 } 00056 00057 $this->ensure_my_table(); 00058 00059 // determine whether it is aggregated or not 00060 $table = $this->query->get_table_info($this->table); 00061 if (preg_match('/aggregator/', $table['join']->definition['handler'])) { 00062 $this->aggregated = TRUE; 00063 } 00064 else { 00065 $this->aggregated = FALSE; 00066 } 00067 00068 // check if its a t/f or 1/0 boolean 00069 $check = db_fetch_object(db_query("SELECT %s as val FROM %s LIMIT 1", $this->real_field, $this->table)); 00070 if (preg_match('/^[tTfF]/', $check->val)) { 00071 $true = 't'; 00072 $false = 'f'; 00073 } 00074 else { 00075 $true = 1; 00076 $false = 0; 00077 } 00078 00079 if (!$this->aggregated) { 00080 00081 // Only base records with value in the aggregated field 00082 // This doesn't restrict the items in the aggregate field 00083 if ($this->options['agg']['records_with']) { 00084 $where = "$this->table_alias.$this->real_field "; 00085 if (empty($this->value)) { 00086 $where .= "= '" . $false . "'"; 00087 if ($this->accept_null) { 00088 $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; 00089 } 00090 } 00091 else { 00092 if (!empty($this->definition['use equal'])) { 00093 $where .= "= '" . $true . "'"; 00094 } 00095 else { 00096 $where .= "<> '" . $false . "'"; 00097 } 00098 } 00099 $this->query->add_where($this->options['group'], $where); 00100 } 00101 00102 // To restrict the items in the aggregate... 00103 // Tell the join handler about the filter 00104 // so it can be done in the join query 00105 if ($this->options['agg']['aggregates_with']) { 00106 //Do nothing b/c it's not aggregated! 00107 } 00108 } 00109 else { 00110 00111 // Only base records with value in the aggregated field 00112 // This doesn't restrict the items in the aggregate field 00113 $this->ensure_my_table(); 00114 $field = "$this->table_alias.$this->real_field"; 00115 if ($this->options['agg']['records_with']) { 00116 $where = "'%s' = ANY($field)"; 00117 if ($this->value) { 00118 $this->query->add_where($this->options['group'], $where, $true); 00119 } 00120 else { 00121 $this->query->add_where($this->options['group'], $where, $false); 00122 } 00123 } 00124 00125 // To restrict the items in the aggregate... 00126 // Tell the join handler about the filter 00127 // so it can be done in the join query 00128 if ($this->options['agg']['aggregates_with']) { 00129 if ($this->value) { 00130 $table['join']->filter[] = $field . " = '" . $true . "'"; 00131 } 00132 else { 00133 $table['join']->filter[] = $field . " = '" . $false . "'"; 00134 } 00135 } 00136 } 00137 00138 } 00139 00140 }