$processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator);
$returnProperties = array();
- $selectedPaymentFields = FALSE;
- // @todo - this variable is overwritten later - it should be wholly definable in the processor fn.
- $paymentTableId = $processor->getPaymentTableID();
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
// Warning - this imProviders var is used in a somewhat fragile way - don't rename it
if ($fieldName == 'event_id') {
$returnProperties['event_id'] = 1;
}
- elseif (
- $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;
}
else {
$returnProperties = $processor->getDefaultReturnProperties();
}
+ // @todo - we are working towards this being entirely a property of the processor
+ $processor->setReturnProperties($returnProperties);
+ $paymentTableId = $processor->getPaymentTableID();
if ($mergeSameAddress) {
//make sure the addressee fields are selected
$addPaymentHeader = FALSE;
$paymentDetails = array();
- if ($processor->isExportPaymentFields() || $selectedPaymentFields) {
+ if ($processor->isExportPaymentFields()) {
// get payment related in for event and members
$paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
//get all payment headers.
// If we haven't selected specific payment fields, load in all the
// payment headers.
- if (!$selectedPaymentFields) {
+ if (!$processor->isExportSpecifiedPaymentFields()) {
$paymentHeaders = self::componentPaymentFields();
if (!empty($paymentDetails)) {
$addPaymentHeader = TRUE;
// for CRM-3157 purposes
$i18n = CRM_Core_I18n::singleton();
- list($outputColumns, $headerRows, $sqlColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor, $relationQuery, $selectedPaymentFields);
+ list($outputColumns, $headerRows, $sqlColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor);
$limitReached = FALSE;
while (!$limitReached) {
self::fetchRelationshipDetails($relDAO, $value, $field, $row);
}
else {
- $row[$field] = self::getTransformedFieldValue($field, $iterationDAO, $fieldValue, $i18n, $metadata, $selectedPaymentFields, $paymentDetails, $paymentTableId);
+ $row[$field] = self::getTransformedFieldValue($field, $iterationDAO, $fieldValue, $i18n, $metadata, $paymentDetails, $processor);
}
}
// data will already be in $row. Otherwise, add payment related
// information, if appropriate.
if ($addPaymentHeader) {
- if (!$selectedPaymentFields) {
+ if (!$processor->isExportSpecifiedPaymentFields()) {
if ($processor->isExportPaymentFields()) {
$paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails);
if (!is_array($paymentData) || empty($paymentData)) {
* @param $details
* @param $sqlColumns
*/
- public static function writeDetailsToTable($tableName, &$details, &$sqlColumns) {
+ public static function writeDetailsToTable($tableName, $details, $sqlColumns) {
if (empty($details)) {
return;
}
$sqlClause = array();
- foreach ($details as $dontCare => $row) {
+ foreach ($details as $row) {
$id++;
$valueString = array($id);
- foreach ($row as $dontCare => $value) {
+ foreach ($row as $value) {
if (empty($value)) {
$valueString[] = "''";
}
*
* @return string
*/
- public static function createTempTable(&$sqlColumns) {
+ public static function createTempTable($sqlColumns) {
//creating a temporary table for the search result that need be exported
$exportTempTable = CRM_Utils_SQL_TempTable::build()->setDurable()->setCategory('export')->getName();
* @param array|string $value
* @param array $phoneTypes
* @param array $imProviders
- * @param string $relationQuery
- * @param array $selectedPaymentFields
+ *
* @return array
*/
- public static function setHeaderRows($field, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders, $relationQuery, $selectedPaymentFields) {
+ public static function setHeaderRows($field, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders) {
$queryFields = $processor->getQueryFields();
// Split campaign into 2 fields for id and title
elseif ($processor->isRelationshipTypeKey($field)) {
foreach ($value as $relationField => $relationValue) {
// below block is same as primary block (duplicate)
- if (isset($relationQuery[$field]->_fields[$relationField]['title'])) {
- if ($relationQuery[$field]->_fields[$relationField]['name'] == 'name') {
+ if (isset($queryFields[$relationField]['title'])) {
+ if ($queryFields[$relationField]['name'] == 'name') {
$headerName = $field . '-' . $relationField;
}
else {
$headerName = $field . '-' . 'current_employer';
}
else {
- $headerName = $field . '-' . $relationQuery[$field]->_fields[$relationField]['name'];
+ $headerName = $field . '-' . $queryFields[$relationField]['name'];
}
}
foreach (array_keys($val) as $fld) {
$type = explode('-', $fld);
- $hdr = "{$ltype}-" . $relationQuery[$field]->_fields[$type[0]]['title'];
+ $hdr = "{$ltype}-" . $queryFields[$type[0]]['title'];
if (!empty($type[1])) {
if (CRM_Utils_Array::value(0, $type) == 'phone') {
}
self::manipulateHeaderRows($headerRows);
}
- elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) {
+ elseif ($processor->isExportPaymentFields() && array_key_exists($field, self::componentPaymentFields())) {
$headerRows[] = CRM_Utils_Array::value($field, self::componentPaymentFields());
}
else {
*
* @param array $returnProperties
* @param \CRM_Export_BAO_ExportProcessor $processor
- * @param string $relationQuery
- * @param array $selectedPaymentFields
+ *
* @return array
* - outputColumns Array of columns to be exported. The values don't matter but the key must match the
* alias for the field generated by BAO_Query object.
* - b) this code is old & outdated. Submit your answers to circular bin or better
* yet find a way to comment them for posterity.
*/
- public static function getExportStructureArrays($returnProperties, $processor, $relationQuery, $selectedPaymentFields) {
+ public static function getExportStructureArrays($returnProperties, $processor) {
$metadata = $headerRows = $outputColumns = $sqlColumns = array();
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
foreach ($returnProperties as $key => $value) {
if ($key != 'location' || !is_array($value)) {
$outputColumns[$key] = $value;
- list($headerRows, $sqlColumns) = self::setHeaderRows($key, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders, $relationQuery, $selectedPaymentFields);
+ list($headerRows, $sqlColumns) = self::setHeaderRows($key, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders);
}
else {
foreach ($value as $locationType => $locationFields) {
$metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders';
}
self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName);
- list($headerRows, $sqlColumns) = self::setHeaderRows($outputFieldName, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders, $relationQuery, $selectedPaymentFields);
+ list($headerRows, $sqlColumns) = self::setHeaderRows($outputFieldName, $headerRows, $sqlColumns, $processor, $value, $phoneTypes, $imProviders);
if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') {
$metadata[$daoFieldName] = array('context' => 'country');
}
* @param $fieldValue
* @param $i18n
* @param $metadata
- * @param $selectedPaymentFields
* @param $paymentDetails
- * @param string $paymentTableId
+ *
+ * @param \CRM_Export_BAO_ExportProcessor $processor
+ *
* @return string
*/
- protected static function getTransformedFieldValue($field, $iterationDAO, $fieldValue, $i18n, $metadata, $selectedPaymentFields, $paymentDetails, $paymentTableId) {
+ protected static function getTransformedFieldValue($field, $iterationDAO, $fieldValue, $i18n, $metadata, $paymentDetails, $processor) {
if ($field == 'id') {
return $iterationDAO->contact_id;
}
}
}
- elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) {
+ elseif ($processor->isExportSpecifiedPaymentFields() && array_key_exists($field, self::componentPaymentFields())) {
+ $paymentTableId = $processor->getPaymentTableID();
$paymentData = CRM_Utils_Array::value($iterationDAO->$paymentTableId, $paymentDetails);
$payFieldMapper = array(
'componentPaymentField_total_amount' => 'total_amount',