diff --git modules/views/handlers/views_handler_filter_boolean_operator.inc modules/views/handlers/views_handler_filter_boolean_operator.inc index 7385c79..fb527f5 100644 --- modules/views/handlers/views_handler_filter_boolean_operator.inc +++ modules/views/handlers/views_handler_filter_boolean_operator.inc @@ -15,12 +15,17 @@ class views_handler_filter_boolean_operator extends views_handler_filter { var $no_single = TRUE; // Don't display empty space where the operator would be. var $no_operator = TRUE; + // Whether to accept NULL as a false value or not + 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']; + } $this->value_options = NULL; parent::construct(); } @@ -123,6 +128,18 @@ class views_handler_filter_boolean_operator extends views_handler_filter { function query() { $this->ensure_my_table(); - $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . (empty($this->value) ? '=' : '<>') . " 0"); + + $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 { + $where .= '<> 0'; + } + $this->query->add_where($this->options['group'], $where); } } diff --git modules/views/handlers/views_handler_filter_boolean_operator_string.inc modules/views/handlers/views_handler_filter_boolean_operator_string.inc index 2bea616..09b5c23 100644 --- modules/views/handlers/views_handler_filter_boolean_operator_string.inc +++ modules/views/handlers/views_handler_filter_boolean_operator_string.inc @@ -12,6 +12,17 @@ class views_handler_filter_boolean_operator_string extends views_handler_filter_boolean_operator { function query() { $this->ensure_my_table(); - $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . (empty($this->value) ? '=' : '<>') . " ''"); + $where = "$this->table_alias.$this->real_field "; + + if (empty($this->value)) { + $where .= "= ''"; + if ($this->accept_null) { + $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; + } + } + else { + $where .= "<> ''"; + } + $this->query->add_where($this->options['group'], $where); } } diff --git modules/views/modules/user/views_handler_filter_user_current.inc modules/views/modules/user/views_handler_filter_user_current.inc index 8108528..58f4034 100644 --- modules/views/modules/user/views_handler_filter_user_current.inc +++ modules/views/modules/user/views_handler_filter_user_current.inc @@ -12,6 +12,17 @@ class views_handler_filter_user_current extends views_handler_filter_boolean_ope function query() { $this->ensure_my_table(); - $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . (empty($this->value) ? '!=' : '=') . " ***CURRENT_USER***"); + $where = "$this->table_alias.$this->real_field "; + + if (empty($this->value)) { + $where .= '<> ***CURRENT_USER***'; + if ($this->accept_null) { + $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; + } + } + else { + $where .= '= ***CURRENT_USER***'; + } + $this->query->add_where($this->options['group'], $where); } }