From 6e2de55de792de15d8f39afcf7859bfb17dcba87 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 17 Nov 2018 10:03:32 +1300 Subject: [PATCH] Move buildRow to processor class --- CRM/Export/BAO/Export.php | 100 +---------------------------- CRM/Export/BAO/ExportProcessor.php | 97 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 99 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 9425982570..30566387dd 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -471,7 +471,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c while ($iterationDAO->fetch()) { $count++; $rowsThisIteration++; - $row = self::buildRow($query, $iterationDAO, $processor, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId); + $row = $processor->buildRow($query, $iterationDAO, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId); // add component info // write the row to a file @@ -1623,102 +1623,4 @@ WHERE {$whereClause}"; } } - /** - * Build the row for output. - * - * @param \CRM_Contact_BAO_Query $query - * @param CRM_Core_DAO $iterationDAO - * @param \CRM_Export_BAO_ExportProcessor$processor - * @param array $outputColumns - * @param $metadata - * @param $paymentDetails - * @param $addPaymentHeader - * @param $paymentTableId - * - * @return array - */ - protected static function buildRow($query, $iterationDAO, $processor, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId) { - $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); - $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); - - $row = []; - $query->convertToPseudoNames($iterationDAO); - - //first loop through output columns so that we return what is required, and in same order. - foreach ($outputColumns as $field => $value) { - - // add im_provider to $dao object - if ($field == 'im_provider' && property_exists($iterationDAO, 'provider_id')) { - $iterationDAO->im_provider = $iterationDAO->provider_id; - } - - //build row values (data) - $fieldValue = NULL; - if (property_exists($iterationDAO, $field)) { - $fieldValue = $iterationDAO->$field; - // to get phone type from phone type id - if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) { - $fieldValue = $phoneTypes[$fieldValue]; - } - elseif ($field == 'provider_id' || $field == 'im_provider') { - $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); - } - elseif (strstr($field, 'master_id')) { - $masterAddressId = NULL; - if (isset($iterationDAO->$field)) { - $masterAddressId = $iterationDAO->$field; - } - // get display name of contact that address is shared. - $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId); - } - } - - if ($processor->isRelationshipTypeKey($field)) { - foreach (array_keys($value) as $property) { - if ($property === 'location') { - // @todo just undo all this nasty location wrangling! - foreach ($value['location'] as $locationKey => $locationFields) { - foreach (array_keys($locationFields) as $locationField) { - $fieldKey = str_replace(' ', '_', $locationKey . '-' . $locationField); - $row[$field . '_' . $fieldKey] = $processor->getRelationshipValue($field, $iterationDAO->contact_id, $fieldKey); - } - } - } - else { - $row[$field . '_' . $property] = $processor->getRelationshipValue($field, $iterationDAO->contact_id, $property); - } - } - } - else { - $row[$field] = $processor->getTransformedFieldValue($field, $iterationDAO, $fieldValue, $metadata, $paymentDetails); - } - } - - // If specific payment fields have been selected for export, payment - // data will already be in $row. Otherwise, add payment related - // information, if appropriate. - if ($addPaymentHeader) { - if (!$processor->isExportSpecifiedPaymentFields()) { - $nullContributionDetails = array_fill_keys(array_keys($processor->getPaymentHeaders()), NULL); - if ($processor->isExportPaymentFields()) { - $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); - } - } - } - //remove organization name for individuals if it is set for current employer - if (!empty($row['contact_type']) && - $row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row) - ) { - $row['organization_name'] = ''; - } - return $row; - } - } diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index e454a8c30e..22c0b00ff6 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -409,6 +409,103 @@ class CRM_Export_BAO_ExportProcessor { return array($query, $select, $from, $where, $having); } + /** + * Build the row for output. + * + * @param \CRM_Contact_BAO_Query $query + * @param CRM_Core_DAO $iterationDAO + * @param array $outputColumns + * @param $metadata + * @param $paymentDetails + * @param $addPaymentHeader + * @param $paymentTableId + * + * @return array + */ + public function buildRow($query, $iterationDAO, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId) { + $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); + $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); + + $row = []; + $query->convertToPseudoNames($iterationDAO); + + //first loop through output columns so that we return what is required, and in same order. + foreach ($outputColumns as $field => $value) { + + // add im_provider to $dao object + if ($field == 'im_provider' && property_exists($iterationDAO, 'provider_id')) { + $iterationDAO->im_provider = $iterationDAO->provider_id; + } + + //build row values (data) + $fieldValue = NULL; + if (property_exists($iterationDAO, $field)) { + $fieldValue = $iterationDAO->$field; + // to get phone type from phone type id + if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) { + $fieldValue = $phoneTypes[$fieldValue]; + } + elseif ($field == 'provider_id' || $field == 'im_provider') { + $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); + } + elseif (strstr($field, 'master_id')) { + $masterAddressId = NULL; + if (isset($iterationDAO->$field)) { + $masterAddressId = $iterationDAO->$field; + } + // get display name of contact that address is shared. + $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId); + } + } + + if ($this->isRelationshipTypeKey($field)) { + foreach (array_keys($value) as $property) { + if ($property === 'location') { + // @todo just undo all this nasty location wrangling! + foreach ($value['location'] as $locationKey => $locationFields) { + foreach (array_keys($locationFields) as $locationField) { + $fieldKey = str_replace(' ', '_', $locationKey . '-' . $locationField); + $row[$field . '_' . $fieldKey] = $this->getRelationshipValue($field, $iterationDAO->contact_id, $fieldKey); + } + } + } + else { + $row[$field . '_' . $property] = $this->getRelationshipValue($field, $iterationDAO->contact_id, $property); + } + } + } + else { + $row[$field] = $this->getTransformedFieldValue($field, $iterationDAO, $fieldValue, $metadata, $paymentDetails); + } + } + + // If specific payment fields have been selected for export, payment + // data will already be in $row. Otherwise, add payment related + // information, if appropriate. + if ($addPaymentHeader) { + if (!$this->isExportSpecifiedPaymentFields()) { + $nullContributionDetails = array_fill_keys(array_keys($this->getPaymentHeaders()), NULL); + if ($this->isExportPaymentFields()) { + $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); + } + } + } + //remove organization name for individuals if it is set for current employer + if (!empty($row['contact_type']) && + $row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row) + ) { + $row['organization_name'] = ''; + } + return $row; + } + /** * @param $field * @param $iterationDAO -- 2.25.1