Skip to content

Commit

Permalink
Remove hacky metadata handling for phone & im
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 19, 2018
1 parent 435ac5a commit 847abb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
7 changes: 6 additions & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
);

Expand Down
6 changes: 1 addition & 5 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
25 changes: 7 additions & 18 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

}
Expand Down

0 comments on commit 847abb8

Please sign in to comment.