From: Allen Shaw Date: Wed, 6 Mar 2013 17:56:05 +0000 (-0600) Subject: Fix CRM-12013. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d77aba4b5bb38ba615a8f81cf1b492128a91464d;p=civicrm-core.git Fix CRM-12013. --- diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index ed870f9bf4..d931339530 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -403,6 +403,16 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { if (($mappingType == 'Search Builder') || ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT)) { if (CRM_Core_Permission::access('CiviEvent')) { $fields['Participant'] = CRM_Event_BAO_Participant::exportableFields(); + //get the component payment fields + if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) { + require_once 'CRM/Export/BAO/Export.php'; + $componentPaymentFields = array(); + foreach (CRM_Export_BAO_Export::componentPaymentFields() as $payField => $payTitle) { + $componentPaymentFields[$payField] = array('title' => $payTitle); + } + $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields); + } + unset($fields['Participant']['participant_contact_id']); $compArray['Participant'] = ts('Participant'); } diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index f65b98291c..f3963e4e1a 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -76,7 +76,7 @@ class CRM_Export_BAO_Export { $queryOperator = 'AND' ) { $headerRows = $returnProperties = array(); - $primary = $paymentFields = FALSE; + $primary = $paymentFields = $selectedPaymentFields = FALSE; $origFields = $fields; $queryMode = $relationField = NULL; @@ -226,6 +226,14 @@ class CRM_Export_BAO_Export { if ($fieldName == 'event_id') { $returnProperties['event_title'] = 1; } + else if ( + $exportMode == CRM_Export_Form_Select::EVENT_EXPORT && + array_key_exists( $fieldName, self::componentPaymentFields()) + ) { + $selectedPaymentFields = true; + $paymentTableId = 'participant_id'; + $returnProperties[$fieldName] = 1; + } else { $returnProperties[$fieldName] = 1; @@ -568,20 +576,16 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $addPaymentHeader = FALSE; $paymentDetails = array(); - if ($paymentFields) { - //special return properties for event and members - $paymentHeaders = array( - 'total_amount' => ts('Total Amount'), - 'contribution_status' => ts('Contribution Status'), - 'received_date' => ts('Received Date'), - 'payment_instrument' => ts('Payment Instrument'), - 'transaction_id' => ts('Transaction ID'), - ); + if ($paymentFields || $selectedPaymentFields) { // get payment related in for event and members $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids); - if (!empty($paymentDetails)) { - $addPaymentHeader = TRUE; + //get all payment headers. + if (!$selectedPaymentFields) { + $paymentHeaders = self::componentPaymentFields(); + if (!empty($paymentDetails)) { + $addPaymentHeader = TRUE; + } } $nullContributionDetails = array_fill_keys(array_keys($paymentHeaders), NULL); } @@ -719,6 +723,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c } } } + elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) { + $headerRows[] = CRM_Utils_Array::value($field, self::componentPaymentFields()); + } else { $headerRows[] = $field; } @@ -956,6 +963,17 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $campIdFld = "{$field}_id"; $row[$field] = CRM_Utils_Array::value($dao->$campIdFld, $allCampaigns, ''); } + elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) { + $paymentData = CRM_Utils_Array::value($dao->$paymentTableId, $paymentDetails); + $payFieldMapper = array( + 'componentPaymentField_total_amount' => 'total_amount', + 'componentPaymentField_contribution_status' => 'contribution_status', + 'componentPaymentField_payment_instrument' => 'pay_instru', + 'componentPaymentField_transaction_id' => 'trxn_id', + 'componentPaymentField_received_date' => 'receive_date', + ); + $row[$field] = CRM_Utils_Array::value($payFieldMapper[$field], $paymentData, ''); + } else { // if field is empty or null $row[$field] = ''; @@ -979,8 +997,12 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $setHeader = FALSE; // add payment related information - if ($paymentFields && isset($paymentDetails[$row[$paymentTableId]])) { - $row = array_merge($row, $paymentDetails[$row[$paymentTableId]]); + if ($paymentFields) { + $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails); + if (!is_array($paymentData) || empty($paymentData)) { + $paymentData = $nullContributionDetails; + } + $row = array_merge($row, $paymentData); } elseif (!empty($paymentDetails)) { $row = array_merge($row, $nullContributionDetails); @@ -1800,5 +1822,22 @@ WHERE {$whereClause}"; } } } + + /** + * Build componentPayment fields. + */ + static function componentPaymentFields() { + static $componentPaymentFields; + if (!isset( $componentPaymentFields)) { + $componentPaymentFields = array( + 'componentPaymentField_total_amount' => ts('Total Amount'), + 'componentPaymentField_contribution_status' => ts('Contribution Status'), + 'componentPaymentField_received_date' => ts('Received Date'), + 'componentPaymentField_payment_instrument' => ts('Payment Instrument'), + 'componentPaymentField_transaction_id' => ts('Transaction ID'), + ); + } + return $componentPaymentFields; + } }