Skip to content

Commit

Permalink
Merge pull request #12484 from eileenmcnaughton/queryFields
Browse files Browse the repository at this point in the history
Export code tidy up Use queryFields rather than query. Look to stop passing around query.
  • Loading branch information
eileenmcnaughton authored Jul 16, 2018
2 parents 5e27028 + 3110c41 commit 07cdb0a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ public static function sqlColumnDefn($query, &$sqlColumns, $field) {
if (substr($field, -4) == '_a_b' || substr($field, -4) == '_b_a') {
return;
}
$queryFields = $query->_fields;

$fieldName = CRM_Utils_String::munge(strtolower($field), '_', 64);
if ($fieldName == 'id') {
Expand All @@ -1095,8 +1096,8 @@ public static function sqlColumnDefn($query, &$sqlColumns, $field) {

$lookUp = array('prefix_id', 'suffix_id');
// set the sql columns
if (isset($query->_fields[$field]['type'])) {
switch ($query->_fields[$field]['type']) {
if (isset($queryFields[$field]['type'])) {
switch ($queryFields[$field]['type']) {
case CRM_Utils_Type::T_INT:
case CRM_Utils_Type::T_BOOLEAN:
if (in_array($field, $lookUp)) {
Expand All @@ -1108,8 +1109,8 @@ public static function sqlColumnDefn($query, &$sqlColumns, $field) {
break;

case CRM_Utils_Type::T_STRING:
if (isset($query->_fields[$field]['maxlength'])) {
$sqlColumns[$fieldName] = "$fieldName varchar({$query->_fields[$field]['maxlength']})";
if (isset($queryFields[$field]['maxlength'])) {
$sqlColumns[$fieldName] = "$fieldName varchar({$queryFields[$field]['maxlength']})";
}
else {
$sqlColumns[$fieldName] = "$fieldName varchar(255)";
Expand Down Expand Up @@ -1156,12 +1157,12 @@ public static function sqlColumnDefn($query, &$sqlColumns, $field) {
}
else {
// set the sql columns for custom data
if (isset($query->_fields[$field]['data_type'])) {
if (isset($queryFields[$field]['data_type'])) {

switch ($query->_fields[$field]['data_type']) {
switch ($queryFields[$field]['data_type']) {
case 'String':
// May be option labels, which could be up to 512 characters
$length = max(512, CRM_Utils_Array::value('text_length', $query->_fields[$field]));
$length = max(512, CRM_Utils_Array::value('text_length', $queryFields[$field]));
$sqlColumns[$fieldName] = "$fieldName varchar($length)";
break;

Expand Down Expand Up @@ -1810,24 +1811,25 @@ public static function componentPaymentFields() {
*/
public static function setHeaderRows($field, $headerRows, $sqlColumns, $query, $value, $phoneTypes, $imProviders, $relationQuery, $selectedPaymentFields) {

$queryFields = $query->_fields;
// Split campaign into 2 fields for id and title
if (substr($field, -14) == 'campaign_title') {
$headerRows[] = ts('Campaign Title');
}
elseif (substr($field, -11) == 'campaign_id') {
$headerRows[] = ts('Campaign ID');
}
elseif (isset($query->_fields[$field]['title'])) {
$headerRows[] = $query->_fields[$field]['title'];
elseif (isset($queryFields[$field]['title'])) {
$headerRows[] = $queryFields[$field]['title'];
}
elseif ($field == 'phone_type_id') {
$headerRows[] = ts('Phone Type');
}
elseif ($field == 'provider_id') {
$headerRows[] = ts('IM Service Provider');
}
elseif (substr($field, 0, 5) == 'case_' && $query->_fields['case'][$field]['title']) {
$headerRows[] = $query->_fields['case'][$field]['title'];
elseif (substr($field, 0, 5) == 'case_' && $queryFields['case'][$field]['title']) {
$headerRows[] = $queryFields['case'][$field]['title'];
}
elseif (array_key_exists($field, self::$relationshipTypes)) {
foreach ($value as $relationField => $relationValue) {
Expand Down Expand Up @@ -1935,6 +1937,7 @@ public static function getExportStructureArrays($returnProperties, $query, $rela
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');

$queryFields = $query->_fields;
foreach ($returnProperties as $key => $value) {
if ($key != 'location' || !is_array($value)) {
$outputColumns[$key] = $value;
Expand All @@ -1946,7 +1949,7 @@ public static function getExportStructureArrays($returnProperties, $query, $rela
$type = explode('-', $locationFieldName);

$actualDBFieldName = $type[0];
$outputFieldName = $locationType . '-' . $query->_fields[$actualDBFieldName]['title'];
$outputFieldName = $locationType . '-' . $queryFields[$actualDBFieldName]['title'];
$daoFieldName = CRM_Utils_String::munge($locationType) . '-' . $actualDBFieldName;

if (!empty($type[1])) {
Expand Down

0 comments on commit 07cdb0a

Please sign in to comment.