more fixes for CRM-17286
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 12 Oct 2015 09:42:37 +0000 (15:12 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 12 Oct 2015 09:42:37 +0000 (15:12 +0530)
CRM/Contact/BAO/Query.php
CRM/Contribute/BAO/Query.php

index 002d42873f7ea4c6350f2c6c09f2c9d4bdc3356a..426e15d5715797aaba984f5c31b58986958ca7dd 100644 (file)
@@ -820,6 +820,11 @@ class CRM_Contact_BAO_Query {
                 $this->_pseudoConstantsSelect[$tName]['select'] = "{$field['where']} as `$name`";
                 $this->_pseudoConstantsSelect[$tName]['element'] = $name;
               }
+              elseif (strpos($name, 'contribution_soft_credit') !== FALSE ) {
+                if (CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->_params)) {
+                  $this->_select[$name] = "{$field['where']} as `$name`";
+                }
+              }
               else {
                 $this->_select[$name] = "{$field['where']} as `$name`";
               }
index 927d33cd06e449e079042ad1a12a527262fc489e..0e0ff8d2e7dc8da0c7733079255f4acdcd7aade0 100644 (file)
@@ -154,12 +154,14 @@ class CRM_Contribute_BAO_Query {
     }
 
     // LCD 716
+    $includeSoftCredits = self::isSoftCreditOptionEnabled($query->_params);
     if (!empty($query->_returnProperties['contribution_soft_credit_name'])) {
-      $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name";
+      if ($includeSoftCredits) {
+        $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name";
+        // also include contact id. Will help build hyperlinks
+        $query->_select['contribution_soft_credit_contact_id'] = "civicrm_contact_d.id as contribution_soft_credit_contact_id";
+      }
       $query->_element['contribution_soft_credit_name'] = 1;
-
-      // also include contact id. Will help build hyperlinks
-      $query->_select['contribution_soft_credit_contact_id'] = "civicrm_contact_d.id as contribution_soft_credit_contact_id";
       $query->_element['contribution_soft_credit_contact_id'] = 1;
 
       $query->_tables['civicrm_contribution'] = 1;
@@ -174,21 +176,27 @@ class CRM_Contribute_BAO_Query {
     }
 
     if (!empty($query->_returnProperties['contribution_soft_credit_amount'])) {
-      $query->_select['contribution_soft_credit_amount'] = "civicrm_contribution_soft.amount as contribution_soft_credit_amount";
+      if ($includeSoftCredits) {
+        $query->_select['contribution_soft_credit_amount'] = "civicrm_contribution_soft.amount as contribution_soft_credit_amount";
+      }
       $query->_element['contribution_soft_credit_amount'] = 1;
       $query->_tables['civicrm_contribution'] = 1;
       $query->_tables['civicrm_contribution_soft'] = 1;
     }
 
     if (!empty($query->_returnProperties['contribution_soft_credit_type'])) {
-      $query->_select['contribution_soft_credit_type'] = "contribution_softcredit_type.label as contribution_soft_credit_type";
+      if ($includeSoftCredits) {
+        $query->_select['contribution_soft_credit_type'] = "contribution_softcredit_type.label as contribution_soft_credit_type";
+      }
       $query->_element['contribution_soft_credit_type'] = 1;
       $query->_tables['civicrm_contribution'] = 1;
       $query->_tables['contribution_softcredit_type'] = 1;
     }
 
     if (!empty($query->_returnProperties['contribution_soft_credit_contribution_id'])) {
-      $query->_select['contribution_soft_credit_contribution_id'] = "civicrm_contribution_soft.contribution_id as contribution_soft_credit_contribution_id";
+      if ($includeSoftCredits) {
+        $query->_select['contribution_soft_credit_contribution_id'] = "civicrm_contribution_soft.contribution_id as contribution_soft_credit_contribution_id";
+      }
       $query->_element['contribution_soft_credit_contribution_id'] = 1;
       $query->_tables['civicrm_contribution'] = 1;
       $query->_tables['civicrm_contribution_soft'] = 1;