From be274d8ad290a7c5654add70af32db08a0667811 Mon Sep 17 00:00:00 2001 From: Edsel Date: Mon, 13 Apr 2015 19:56:58 +0530 Subject: [PATCH] CIVI-28 Rewrote filtering for contribution and membership search results --- CRM/Contact/BAO/Query.php | 7 +++++++ CRM/Contribute/Selector/Search.php | 3 --- CRM/Financial/BAO/FinancialType.php | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index cd69b39b1e..f28c61a68b 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -493,6 +493,13 @@ class CRM_Contact_BAO_Query { $this->selectClause(); $this->_whereClause = $this->whereClause(); + if (array_key_exists('civicrm_contribution', $this->_whereTables)) { + $component = 'contribution'; + } + if (array_key_exists('civicrm_membership', $this->_whereTables)) { + $component = 'membership'; + } + CRM_Financial_BAO_FinancialType::buildPermissionedClause($this->_whereClause, $component); $this->_fromClause = self::fromClause($this->_tables, NULL, NULL, $this->_primaryLocation, $this->_mode); $this->_simpleFromClause = self::fromClause($this->_whereTables, NULL, NULL, $this->_primaryLocation, $this->_mode); diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 00159b7d92..9d5fba445d 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -365,9 +365,6 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C ); $checkLineItem = FALSE; $row = array(); - if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { - continue; - } // Now check for lineItems $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id); foreach ($lineItems as $items) { diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index fe739fe36f..e15903a4db 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -234,12 +234,22 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { return $membershipTypes; } - public static function buildPermissionedClause(&$whereClauses) { - self::getAvailableFinancialTypes($financialType); - foreach ($financialType as $id => $type) { - $ids[] = $id; + public static function buildPermissionedClause(&$whereClauses, $component = NULL) { + self::getAvailableFinancialTypes($types); + if (is_array($whereClauses)) { + $whereClauses[] = ' financial_type_id IN (' . implode(',' , array_keys($types)) .')'; + } + else { + if ($component == 'contribution') { + $column = "financial_type_id"; + } + if ($component == 'membership') { + $types = array(); + self::getAvailableMembershipTypes($types, 'view'); + $column = "membership_type_id"; + } + $whereClauses .= " AND civicrm_{$component}.{$column} IN (". implode(',' , array_keys($types)) .")"; } - $whereClauses[] = ' financial_type_id IN (' . implode(',' , $ids) .')'; } public static function checkPermissionedLineItems($id, $op, $force = TRUE) { -- 2.25.1