CIVI-28 Rewrote filtering for contribution and membership search results
authorEdsel <edsel.lopez@jmaconsulting.biz>
Mon, 13 Apr 2015 14:26:58 +0000 (19:56 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 21 Sep 2015 10:42:44 +0000 (16:12 +0530)
CRM/Contact/BAO/Query.php
CRM/Contribute/Selector/Search.php
CRM/Financial/BAO/FinancialType.php

index cd69b39b1ecc639db6a83aa2215c712c72f79678..f28c61a68b60fcdb57f30350f6bd06b576974dd8 100644 (file)
@@ -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);
index 00159b7d9207810a4052de91a29d5a3b805c24b3..9d5fba445d0f9a3f6c319df58f05e09310420542 100644 (file)
@@ -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) { 
index fe739fe36f922ea1b0afbf147c38023fca063436..e15903a4dbcec08fb3fbc4dd54c89462443eb321 100644 (file)
@@ -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) {