Unverified Commit a9edd337 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub

Merge pull request #14764 from elisseck/dev/report/15

dev/report/15 Add fix and tests for contact subtype report filter
parents d1ee2fbb 2fdf00e9
......@@ -2129,12 +2129,30 @@ class CRM_Report_Form extends CRM_Core_Form {
* @return string
*/
public function whereSubtypeClause($field, $value, $op) {
// Get the correct SQL operator.
switch ($op) {
case 'notin':
$op = 'nhas';
$clauseSeparator = 'AND';
break;
case 'in':
$op = 'has';
$clauseSeparator = 'OR';
break;
}
$sqlOp = $this->getSQLOperator($op);
$clause = '( ';
$subtypeFilters = count($value);
for ($i = 0; $i < $subtypeFilters; $i++) {
$clause .= "{$field['dbAlias']} LIKE '%$value[$i]%'";
if ($i !== ($subtypeFilters - 1)) {
$clause .= " OR ";
if ($sqlOp == 'IS NULL' || $sqlOp == 'IS NOT NULL') {
$clause .= "{$field['dbAlias']} $sqlOp";
}
else {
for ($i = 0; $i < $subtypeFilters; $i++) {
$clause .= "{$field['dbAlias']} $sqlOp '%$value[$i]%'";
if ($i !== ($subtypeFilters - 1)) {
$clause .= " $clauseSeparator ";
}
}
}
$clause .= ' )';
......
......@@ -1123,6 +1123,44 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
$this->assertEquals(1, $rows['count']);
}
/**
* Test contact subtype filter on summary report.
*
* @throws \CRM_Core_Exception
*/
public function testContactSubtypeNotNull() {
$this->individualCreate(['contact_sub_type' => ['Student', 'Parent']]);
$this->individualCreate();
$rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contact/summary',
'contact_sub_type_op' => 'nnll',
'contact_sub_type_value' => [],
'contact_type_op' => 'eq',
'contact_type_value' => 'Individual',
]);
$this->assertEquals(1, $rows['count']);
}
/**
* Test contact subtype filter on summary report.
*
* @throws \CRM_Core_Exception
*/
public function testContactSubtypeNull() {
$this->individualCreate(['contact_sub_type' => ['Student', 'Parent']]);
$this->individualCreate();
$rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contact/summary',
'contact_sub_type_op' => 'nll',
'contact_sub_type_value' => [],
'contact_type_op' => 'eq',
'contact_type_value' => 'Individual',
]);
$this->assertEquals(1, $rows['count']);
}
/**
* Test PCP report to ensure total donors and total committed is accurate.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment