task action related fixes - counts / stats
authorDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Thu, 13 Mar 2014 06:37:59 +0000 (12:07 +0530)
committerDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Thu, 13 Mar 2014 06:37:59 +0000 (12:07 +0530)
CRM/Contribute/Form/Task.php
CRM/Contribute/Form/Task/PDFLetterCommon.php

index acb80d794ba29f9b4d9d2f686a3e563d021e1bad..c2143001d82a27e9d3aae3b710a209c1f59b1ba8 100644 (file)
@@ -74,6 +74,20 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form {
    */
   public $_contactIds;
 
+  /**
+   * The array that holds all the mapping contribution and contact ids
+   *
+   * @var array
+   */
+  protected $_contributionContactIds = array();
+
+  /**
+   * The flag to tell if there are soft credits included
+   *
+   * @var boolean
+   */
+  public $_includesSoftCredits = FALSE;
+
   /**
    * build all the data structures needed to build the form
    *
@@ -110,15 +124,25 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form {
         $sortOrder = $form->get( CRM_Utils_Sort::SORT_ORDER );
       }
 
+      $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
       $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
         CRM_Contact_BAO_Query::MODE_CONTRIBUTE
       );
-      $query->_distinctComponentClause = ' civicrm_contribution.id';
-      $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
-
+      if ($form->_includesSoftCredits) {
+        $contactIds = $contributionContactIds = array();
+        $query->_rowCountClause = " count(civicrm_contribution.id)";
+        $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
+      } else {
+        $query->_distinctComponentClause = ' civicrm_contribution.id';
+        $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
+      }
       $result = $query->searchQuery(0, 0, $sortOrder);
       while ($result->fetch()) {
         $ids[] = $result->contribution_id;
+        if ($form->_includesSoftCredits) {
+          $contactIds[$result->contact_id] = $result->contact_id;
+          $contributionContactIds["{$result->contact_id}-{$result->contribution_id}"] = $result->contribution_id;
+        }
       }
       $form->assign('totalSelectedContributions', $form->get('rowCount'));
     }
@@ -128,6 +152,10 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form {
 
       $form->assign('totalSelectedContributions', count($ids));
     }
+    if ($form->_includesSoftCredits && !empty($contactIds)) {
+      $form->_contactIds = $contactIds;
+      $form->_contributionContactIds = $contributionContactIds;
+    }
 
     $form->_contributionIds = $form->_componentIds = $ids;
 
@@ -156,9 +184,12 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form {
    * since its used for things like send email
    */
   public function setContactIDs() {
-    $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_contributionIds,
-      'civicrm_contribution'
-    );
+    if (!$this->_includesSoftCredits) {
+      $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent(
+        $this->_contributionIds,
+        'civicrm_contribution'
+      );
+    }
   }
 
   /**
index fde999f342c490e131ef27fbae91813f549e0acc..cdb34c43a0a1aacf34befee84e23fdf14f9c32c4 100644 (file)
@@ -29,10 +29,19 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF
     $skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
     $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
 
-    foreach ($form->getVar('_contributionIds') as $item => $contributionId) {
+    $contributionIDs = $form->getVar('_contributionIds');
+    if ($form->_includesSoftCredits) {
+      $contributionIDs = $form->getVar('_contributionContactIds');
+    }
 
+    foreach ($contributionIDs as $item => $contributionId) {
       // get contact information
-      $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
+      if ($form->_includesSoftCredits) {
+        list($contactId) = explode('-', $item);
+        $contactId = (int) $contactId;
+      } else {
+        $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
+      }
       $params = array('contact_id' => $contactId);
 
       list($contact) = CRM_Utils_Token::getTokenDetails($params,