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
}
}
- /**
- * 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;
- }
-
}
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