From 0816f78c486829c5af80fbc6f17e56e6ac587fb6 Mon Sep 17 00:00:00 2001 From: Eli Lisseck Date: Mon, 26 Nov 2018 10:46:42 -0800 Subject: [PATCH] dev/core/544 add report support for filtering on multiple contact subtypes --- CRM/Report/Form.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 325eb064a4..37cf4013ba 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2055,6 +2055,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); } @@ -2073,6 +2077,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. * -- 2.25.1