views_handler_filter_boolean_operator.inc in Views (for Drupal 7) 6.2
File
handlers/views_handler_filter_boolean_operator.inc
View source
<?php
class views_handler_filter_boolean_operator extends views_handler_filter {
var $no_single = TRUE;
var $no_operator = TRUE;
var $accept_null = FALSE;
function construct() {
$this->value_value = t('True');
if (isset($this->definition['label'])) {
$this->value_value = $this->definition['label'];
}
if (isset($this->definition['accept null'])) {
$this->accept_null = (bool) $this->definition['accept null'];
}
else {
if (isset($this->definition['accept_null'])) {
$this->accept_null = (bool) $this->definition['accept_null'];
}
}
$this->value_options = NULL;
parent::construct();
}
function get_value_options() {
if (isset($this->definition['type'])) {
if ($this->definition['type'] == 'yes-no') {
$this->value_options = array(
1 => t('Yes'),
0 => t('No'),
);
}
if ($this->definition['type'] == 'on-off') {
$this->value_options = array(
1 => t('On'),
0 => t('Off'),
);
}
}
if (!isset($this->value_options)) {
$this->value_options = array(
1 => t('True'),
0 => t('False'),
);
}
}
function option_definition() {
$options = parent::option_definition();
$options['value']['default'] = FALSE;
return $options;
}
function operator_form(&$form, &$form_state) {
$form['operator'] = array();
}
function value_form(&$form, &$form_state) {
if (empty($this->value_options)) {
$this
->get_value_options();
}
if (!empty($form_state['exposed'])) {
$filter_form_type = 'select';
}
else {
$filter_form_type = 'radios';
}
$form['value'] = array(
'#type' => $filter_form_type,
'#title' => $this->value_value,
'#options' => $this->value_options,
'#default_value' => $this->value,
);
if (!empty($this->options['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (!isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
}
if (empty($form_state['exposed']) || !empty($this->options['optional'])) {
$any_label = variable_get('views_exposed_filter_any_label', 'old_any') == 'old_any' ? '<Any>' : t('- Any -');
if ($form['value']['#type'] != 'select') {
$any_label = check_plain($any_label);
}
$form['value']['#options'] = array(
'All' => $any_label,
) + $form['value']['#options'];
}
}
}
function value_validate($form, &$form_state) {
if ($form_state['values']['options']['value'] == 'All' && empty($form_state['values']['options']['expose']['optional'])) {
form_set_error('value', t('You must select a value unless this is an optional exposed filter.'));
}
}
function admin_summary() {
if (!empty($this->options['exposed'])) {
return t('exposed');
}
if (empty($this->value_options)) {
$this
->get_value_options();
}
return $this->value_options[!empty($this->value)];
}
function expose_options() {
parent::expose_options();
$this->options['expose']['operator'] = '';
$this->options['expose']['label'] = $this->value_value;
$this->options['expose']['optional'] = FALSE;
}
function query() {
$this
->ensure_my_table();
$where = "{$this->table_alias}.{$this->real_field} ";
if (empty($this->value)) {
$where .= '= 0';
if ($this->accept_null) {
$where = '(' . $where . " OR {$this->table_alias}.{$this->real_field} IS NULL)";
}
}
else {
if (!empty($this->definition['use equal'])) {
$where .= '= 1';
}
else {
$where .= '<> 0';
}
}
$this->query
->add_where($this->options['group'], $where);
}
}