CIVI-28 Rewrote filtering for contribution and membership search results
[civicrm-core.git] / CRM / Contribute / Selector / Search.php
index 32d153ebb2ced809d573b7fbffdfe0845fc59bbd..9d5fba445d0f9a3f6c319df58f05e09310420542 100644 (file)
@@ -358,7 +358,38 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
 
     while ($result->fetch()) {
+      $links = self::links($componentId,
+          $componentAction,
+          $qfKey,
+          $componentContext
+      );
+      $checkLineItem = FALSE;
       $row = array();
+      // Now check for lineItems
+      $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id);
+      foreach ($lineItems as $items) { 
+        if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
+          $checkLineItem = TRUE;
+          break;
+        }
+        if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
+          unset($links[CRM_Core_Action::UPDATE]);
+          break;
+        }
+        if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
+          unset($links[CRM_Core_Action::DELETE]);
+          break;
+        }
+      }
+      if ($checkLineItem) {
+        continue;
+      }
+      if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
+        unset($links[CRM_Core_Action::UPDATE]);
+      }
+      if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
+        unset($links[CRM_Core_Action::DELETE]);
+      }
       // the columns we are interested in
       foreach (self::$_properties as $property) {
         if (property_exists($result, $property)) {
@@ -395,11 +426,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
       );
 
       $row['action'] = CRM_Core_Action::formLink(
-        self::links($componentId,
-          $componentAction,
-          $qfKey,
-          $componentContext
-        ),
+        $links,
         $mask, $actions,
         ts('more'),
         FALSE,