Merge pull request #13948 from civicrm/5.12
[civicrm-core.git] / CRM / Report / Form.php
index 0fc3f9f40826a499a4c479c79f086b79ac42e3db..56e056fb3f4c85e8a9541d22368b44312e38cc2c 100644 (file)
@@ -2070,6 +2070,10 @@ class CRM_Report_Form extends CRM_Core_Form {
         break;
     }
 
+    //dev/core/544 Add report support for multiple contact subTypes
+    if ($field['name'] == 'contact_sub_type' && $clause) {
+      $clause = $this->whereSubtypeClause($field, $value, $op);
+    }
     if (!empty($field['group']) && $clause) {
       $clause = $this->whereGroupClause($field, $value, $op);
     }
@@ -2088,6 +2092,27 @@ class CRM_Report_Form extends CRM_Core_Form {
     return $clause;
   }
 
+  /**
+   * Get SQL where clause for contact subtypes
+   * @param string $field
+   * @param mixed $value
+   * @param string $op SQL Operator
+   *
+   * @return string
+   */
+  public function whereSubtypeClause($field, $value, $op) {
+    $clause = '( ';
+    $subtypeFilters = count($value);
+    for ($i = 0; $i < $subtypeFilters; $i++) {
+      $clause .= "{$field['dbAlias']} LIKE '%$value[$i]%'";
+      if ($i !== ($subtypeFilters - 1)) {
+        $clause .= " OR ";
+      }
+    }
+    $clause .= ' )';
+    return $clause;
+  }
+
   /**
    * Get SQL where clause for a date field.
    *