From 114a2c85063823318225017fc4eed86306bb733c Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Sun, 22 Jun 2014 15:47:39 -0700 Subject: [PATCH] CRM-14857 - provide option to add membership type and membership org filters to reports. ---------------------------------------- * CRM-14857: https://issues.civicrm.org/jira/browse/CRM-14857 --- CRM/Report/Form.php | 51 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index ad47a690a9..4c36019b8a 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -1,10 +1,10 @@ whereTagClause($field, $value, $op); } - + elseif (!empty($field['membership_org']) && $clause) { + $clause = $this->whereMembershipOrgClause($field, $value, $op); + } + elseif (!empty($field['membership_type']) && $clause) { + $clause = $this->whereMembershipTypeClause($field, $value, $op); + } return $clause; } @@ -2982,6 +2987,42 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND WHERE entity_table = 'civicrm_contact' AND {$clause} ) "; } + function whereMembershipOrgClause($field, $value, $op) { + $sqlOp = $this->getSQLOperator($op); + if (!is_array($value)) { + $value = array($value); + } + + $tmp_membership_org_sql_list = implode(', ', $value); + return " {$this->_aliases['civicrm_contact']}.id {$sqlOp} ( + SELECT DISTINCT mem.contact_id + FROM civicrm_membership mem + LEFT JOIN civicrm_membership_status mem_status ON mem.status_id = mem_status.id + LEFT JOIN civicrm_membership_type mt ON mem.membership_type_id = mt.id + WHERE mt.member_of_contact_id IN (".$tmp_membership_org_sql_list.") + AND mt.is_active = '1' + AND mem_status.is_current_member = '1' + AND mem_status.is_active = '1' ) "; + } + + function whereMembershipTypeClause($field, $value, $op) { + $sqlOp = $this->getSQLOperator($op); + if (!is_array($value)) { + $value = array($value); + } + + $tmp_membership_sql_list = implode(', ', $value); + return " {$this->_aliases['civicrm_contact']}.id {$sqlOp} ( + SELECT DISTINCT mem.contact_id + FROM civicrm_membership mem + LEFT JOIN civicrm_membership_status mem_status ON mem.status_id = mem_status.id + LEFT JOIN civicrm_membership_type mt ON mem.membership_type_id = mt.id + WHERE mem.membership_type_id IN (".$tmp_membership_sql_list.") + AND mt.is_active = '1' + AND mem_status.is_current_member = '1' + AND mem_status.is_active = '1' ) "; + } + /** * @param string $tableAlias */ -- 2.25.1