00001 <?php 00002 00019 class views_handler_field_boolean extends views_handler_field { 00020 function option_definition() { 00021 $options = parent::option_definition(); 00022 $options['type'] = array('default' => 'yes-no'); 00023 $options['not'] = array('definition bool' => 'reverse'); 00024 00025 return $options; 00026 } 00027 00028 function init(&$view, &$options) { 00029 parent::init($view, $options); 00030 00031 $default_formats = array( 00032 'yes-no' => array(t('Yes'), t('No')), 00033 'true-false' => array(t('True'), t('False')), 00034 'on-off' => array(t('On'), t('Off')), 00035 'enabled-disabled' => array(t('Enabled'), t('Disabled')), 00036 'unicode-yes-no' => array('✔', '✖'), 00037 ); 00038 $output_formats = isset($this->definition['output formats']) ? $this->definition['output formats'] : array(); 00039 $this->formats = array_merge($default_formats, $output_formats); 00040 } 00041 00042 function options_form(&$form, &$form_state) { 00043 foreach ($this->formats as $key => $item) { 00044 $options[$key] = implode('/', $item); 00045 } 00046 00047 $form['type'] = array( 00048 '#type' => 'select', 00049 '#title' => t('Output format'), 00050 '#options' => $options, 00051 '#default_value' => $this->options['type'], 00052 ); 00053 $form['not'] = array( 00054 '#type' => 'checkbox', 00055 '#title' => t('Reverse'), 00056 '#description' => t('If checked, true will be displayed as false.'), 00057 '#default_value' => $this->options['not'], 00058 ); 00059 parent::options_form($form, $form_state); 00060 } 00061 00062 function render($values) { 00063 $value = $this->get_value($values); 00064 if (!empty($this->options['not'])) { 00065 $value = !$value; 00066 } 00067 00068 if (isset($this->formats[$this->options['type']])) { 00069 return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1]; 00070 } 00071 else { 00072 return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1]; 00073 } 00074 } 00075 }