diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 9e59eb0327d..cf009390818 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1553,9 +1553,14 @@ public static function &exportableFields($contactType = 'Individual', $status = $IMProvider = array( 'im_provider' => array( - 'name' => 'im_provider', + 'name' => 'provider_id', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'), + 'pseudoconstant' => [ + 'optionGroupName' => 'instant_messenger_service', + 'optionEditPath' => 'civicrm/admin/options/instant_messenger_service', + ], + 'bao' => 'CRM_Core_BAO_IM', ), ); diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 405387169e0..e77f813fd13 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1273,12 +1273,8 @@ public static function getExportStructureArrays($returnProperties, $processor) { if (!empty($type[1])) { $daoFieldName .= "-" . $type[1]; } - if ($type[0] == 'im_provider') { - // Warning: shame inducing hack. - $metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders'; - } $processor->addOutputSpecification($actualDBFieldName, NULL, $locationType, CRM_Utils_Array::value(1, $type)); - if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') { + if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') { $metadata[$daoFieldName] = array('context' => 'country'); } if ($actualDBFieldName == 'state_province') { diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 08f22767bba..67c9ad3f5a2 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -457,6 +457,9 @@ public function addOutputSpecification($key, $relationshipType = NULL, $location $this->outputSpecification[$index]['sql_key'] = $this->getMungedFieldName($index); $this->outputSpecification[$index]['sql_column'] = $this->getSqlColumnDefinition($index); + if (!isset($this->queryFields[$index]) && isset ($this->queryFields[$key])) { + $this->queryFields[$index] = $this->queryFields[$key]; + } if ($this->isHouseholdMergeRelationshipTypeKey($relationshipType)) { // Do not add to header row if we are only generating for merge reasons. $this->setColumnAsCalculationOnly($index); @@ -528,9 +531,6 @@ public function buildRow($query, $iterationDAO, $outputColumns, $metadata, $paym if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) { $fieldValue = $phoneTypes[$fieldValue]; } - elseif ($field == 'im_provider') { - $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); - } elseif (strstr($field, 'master_id')) { $masterAddressId = NULL; if (isset($iterationDAO->$field)) { @@ -649,26 +649,15 @@ public function getTransformedFieldValue($field, $iterationDAO, $fieldValue, $me return $i18n->crm_translate($fieldValue); default: - if (isset($metadata[$field])) { + if (isset($this->getQueryFields()[$field])) { + $spec = $this->getQueryFields()[$field]; // No I don't know why we do it this way & whether we could // make better use of pseudoConstants. if (!empty($metadata[$field]['context'])) { return $i18n->crm_translate($fieldValue, $metadata[$field]); } - if (!empty($metadata[$field]['pseudoconstant'])) { - // This is not our normal syntax for pseudoconstants but I am a bit loath to - // call an external function until sure it is not increasing php processing given this - // may be iterated 100,000 times & we already have the $imProvider var loaded. - // That can be next refactor... - // Yes - definitely feeling hatred for this bit of code - I know you will beat me up over it's awfulness - // but I have to reach a stable point.... - $varName = $metadata[$field]['pseudoconstant']['var']; - if ($varName === 'imProviders') { - return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $fieldValue); - } - if ($varName === 'phoneTypes') { - return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Phone', 'phone_type_id', $fieldValue); - } + if (!empty($spec['pseudoconstant'])) { + return CRM_Core_PseudoConstant::getLabel($spec['bao'], $spec['name'], $fieldValue); } }