Skip to content
Snippets Groups Projects
Unverified Commit 75c2638e authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #14814 from eileenmcnaughton/reg515

dev/report/15 Add fix and tests for contact subtype report filter
parents ac7af202 5f13f94f
No related branches found
No related tags found
No related merge requests found
......@@ -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.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment