diff --git a/includes/fivestar.field.inc b/includes/fivestar.field.inc index 46c41d2..68d05d1 100644 --- a/includes/fivestar.field.inc +++ b/includes/fivestar.field.inc @@ -129,7 +129,6 @@ function fivestar_field_delete($entity_type, $entity, $field, $instance, $langco * Implements hook_field_views_data(). */ function fivestar_field_views_data($field) { - $field_name = $field['field_name']; $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { // Add our handler to the rating views field. diff --git a/includes/fivestar_views_handler_filter_in_operator.inc b/includes/fivestar_views_handler_filter_in_operator.inc index 2aadcf4..3c969ac 100644 --- a/includes/fivestar_views_handler_filter_in_operator.inc +++ b/includes/fivestar_views_handler_filter_in_operator.inc @@ -49,6 +49,7 @@ class fivestar_views_handler_filter_in_operator extends views_handler_filter_in_ $has_nul = in_array(0, $this->value); $or_statement = db_or(); + $and_statement = db_and(); // Add regular condition if we have any values other than zero. if (count($this->value) > ($has_nul ? 1 : 0)) { $or_statement->condition("$this->table_alias.$this->real_field", array_values($this->value), $this->operator); @@ -56,11 +57,57 @@ class fivestar_views_handler_filter_in_operator extends views_handler_filter_in_ // Add zero condition if zero is in the values, or if it's not and the // operator is 'not in' (to also show 0 stars when "not in (1, 2)"). - if ($has_nul || $this->operator == 'not in') { - $nul_operator = (($this->operator == 'in') xor $has_nul) ? 'IS NOT NULL' : 'IS NULL'; - $or_statement->condition("$this->table_alias.$this->real_field", NULL, $nul_operator); + $selected_val_count = count(array_values($this->value)); + $first_element = reset($this->value); + // 'IN' Condition. + if ($this->operator == 'in') { + if ($selected_val_count == 1) { + if ($first_element == 0) { + $nul_operator = ($has_nul == 0) ? 'IS NOT NULL' : 'IS NULL'; + $or_statement->condition("$this->table_alias.$this->real_field", NULL, $nul_operator); + $this->query->add_where($this->options['group'], $or_statement); + } + if ($first_element != 0) { + $operator = 'IN'; + $and_statement->condition("$this->table_alias.$this->real_field", array_values($this->value), $operator); + $this->query->add_where($this->options['group'], $and_statement); + } + } + if ($selected_val_count > 1) { + if ($first_element == 0) { + $nul_operator = ($has_nul == 0) ? 'IS NOT NULL' : 'IS NULL'; + $or_statement->condition("$this->table_alias.$this->real_field", NULL, $nul_operator); + $this->query->add_where($this->options['group'], $or_statement); + } + if ($first_element != 0) { + $operator = 'IN'; + $and_statement->condition("$this->table_alias.$this->real_field", array_values($this->value), $operator); + $this->query->add_where($this->options['group'], $and_statement); + } + } + } + // 'NOT IN' Condition. + if ($this->operator == 'not in') { + if ($has_nul == 1) { + if ($selected_val_count == 1 && $first_element == 0) { + $nul_operator = 'IS NOT NULL'; + $and_statement->condition("$this->table_alias.$this->real_field", array_values($this->value), $nul_operator); + $this->query->add_where($this->options['group'], $and_statement); + } + if ($selected_val_count > 1 && $first_element == 0) { + $operator = 'NOT IN'; + $nul_operator = 'IS NOT NULL'; + $and_statement->condition("$this->table_alias.$this->real_field", array_values($this->value), $operator); + $and_statement->condition("$this->table_alias.$this->real_field", NULL, $nul_operator); + $this->query->add_where($this->options['group'], $and_statement); + } + } + if ($has_nul == 0) { + $nul_operator = 'IS NULL'; + $or_statement->condition("$this->table_alias.$this->real_field", NULL, $nul_operator); + $this->query->add_where($this->options['group'], $or_statement); + } } - - $this->query->add_where($this->options['group'], $or_statement); } + }