CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Solved Drupal 7 Views custom field checkboxes views get or'd rather than and'd
Pages: [1]

Author Topic: Solved Drupal 7 Views custom field checkboxes views get or'd rather than and'd  (Read 1624 times)

bouton

  • Guest
Solved Drupal 7 Views custom field checkboxes views get or'd rather than and'd
November 18, 2011, 03:37:04 am
I created a view which displays a custom field with multiple choices. It works well and lists them all as it should. However, regardless of how I set it in the views filter criteria - either as an 'and'...  or as an 'or'... it always 'or-d' the items together.
For example
Organization 1
  Custom field = keyword: values = talk, lecture, training
Organization 2
   Custom field = keyword: values = talk, lecture
Results I expected to get
Filter with keyword talk - get Organization 1 AND Organization 2
Filter with additional keyword training get Organization 1  (because Organization 2 does not have keyword=training)
So the view query should have filtered down to Organization 1 but as I said it "or'd" them so I always got Organization 1 AND Organization 2.

I tracked the problem down to the op_simple function in civicrm_handler_filter_custom_option.inc where the "glue" variable was the reverse of what I wanted.

Code: [Select]
// negated operator uses AND, positive uses OR
$op = ($this->operator == 'in') ? 'LIKE' : 'NOT LIKE';
$glue = ($this->operator == 'in') ? 'AND ' : 'OR ';
 //   $glue = ($this->operator == 'in') ? 'OR ' : 'AND '; //this is wrong for me AND is no longer needed in Drupal 7
         foreach ($this->value as $value){
             $clauses[] = "$this->table_alias.$this->real_field " . $op . " '%" . $sep . $value . $sep . "%' ";
         }
this filter handler was also was written for Drupal 6. Drupal 7 views now has and/or integrated into it so it no longer needs the 'glue'.
Discussion with the original author confirms this.

I have created a patch and filed a bug. My first patch - so be gentle.
http://issues.civicrm.org/jira/browse/CRM-9211
« Last Edit: December 01, 2011, 01:24:57 am by bouton »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Solved Drupal 7 Views custom field checkboxes views get or'd rather than and'd

This forum was archived on 2017-11-26.