Tripal v1.0 (6.x-1.0)
views_handler_filter_chado_boolean.inc
Go to the documentation of this file.
00001 <?php
00002 
00011 class views_handler_filter_chado_boolean extends views_handler_filter_boolean_operator {
00016   function init(&$view, $options) {
00017     parent::init($view, $options);
00018 
00019     $results = tripal_core_chado_select($this->table, array($this->field), array());
00020     $this->boolean_type_tf = FALSE;
00021     if (preg_match('/[tf]/', $results[0]->{$this->field})) {
00022       $this->boolean_type_tf = TRUE;
00023     }
00024 
00025   }
00026 
00032   function get_value_options() {
00033 
00034     if ($this->boolean_type_tf) {
00035       if (isset($this->definition['type'])) {
00036         if ($this->definition['type'] == 'yes-no') {
00037           $this->value_options = array('t' => t('Yes'), 'f' => t('No'));
00038         }
00039         if ($this->definition['type'] == 'on-off') {
00040           $this->value_options = array('t' => t('On'), 'f' => t('Off'));
00041         }
00042       }
00043 
00044       // Provide a fallback if the above didn't set anything.
00045       if (!isset($this->value_options)) {
00046         $this->value_options = array('t' => t('True'), 'f' => t('False'));
00047       }
00048     }
00049     else { //end of t/f boolean
00050       if (isset($this->definition['type'])) {
00051         if ($this->definition['type'] == 'yes-no') {
00052           $this->value_options = array(1 => t('Yes'), 0 => t('No'));
00053         }
00054         if ($this->definition['type'] == 'on-off') {
00055           $this->value_options = array(1 => t('On'), 0 => t('Off'));
00056         }
00057       }
00058 
00059       // Provide a fallback if the above didn't set anything.
00060       if (!isset($this->value_options)) {
00061         $this->value_options = array(1 => t('True'), 0 => t('False'));
00062       }
00063     } //end of 0/1 boolean
00064   }
00065 
00066   function query() {
00067     $this->ensure_my_table();
00068 
00069     $where = "$this->table_alias.$this->real_field ";
00070 
00071     if ($this->boolean_type_tf) {
00072       if (preg_match('/f/', $this->value)) {
00073         $where .= "= 'f'";
00074       }
00075       else {
00076         $where .= "= 't'";
00077       }
00078       $this->query->add_where($this->options['group'], $where);
00079     }
00080     else {
00081       if (empty($this->value)) {
00082         $where .= '= 0';
00083         if ($this->accept_null) {
00084           $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)";
00085         }
00086       }
00087       else {
00088         $where .= '<> 0';
00089       }
00090       $this->query->add_where($this->options['group'], $where);
00091     }
00092   }
00093 }
 All Classes Files Functions Variables