Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-9211

civicrm_handler_filter_custom_option op_simple has its and/or incorrect

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.0.0, 4.0.1, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6, 4.0.7
    • Fix Version/s: 4.3.0
    • Labels:

      Description

      The Drupal views integration module which allows for filtering on a custom field has the and/or mixed up when creating a query.

      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.

      // 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
              foreach ($this->value as $value)

      {             $clauses[] = "$this->table_alias.$this->real_field " . $op . " '%" . $sep . $value . $sep . "%' ";         }

      It 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 attached a patch. Note this is my first ever patch so forgive me if it is not what is needed. But you can see what the difference is.
      Thanks.

        Attachments

          Activity

            People

            • Assignee:
              jalama Jim Taylor
              Reporter:
              bouton K. Bouton
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 30 minutes
                30m
                Remaining:
                Remaining Estimate - 30 minutes
                30m
                Logged:
                Time Spent - Not Specified
                Not Specified