From b719f00020a5e58b6c9bbd4a5a641dd8518ac515 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Fri, 2 Aug 2013 19:53:02 +0530 Subject: [PATCH] CRM-12639-improvements : code improvements which also fixes the failing tests https://test.civicrm.org/job/CiviCRM-master-git/LABEL=debian6,SUITE=api_v3_AllTests/397/ --- CRM/Contact/BAO/Query.php | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 4c7d959606..40bcd8d876 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4081,10 +4081,10 @@ civicrm_relationship.start_date > {$today} return array($noRows,NULL); } $val = $query->store($dao); - $convertedVals = $query->convertToPseudoNames($dao); + $convertedVals = $query->convertToPseudoNames($dao, TRUE); if (!empty($convertedVals)) { - $val = array_merge($val, $convertedVals); + $val = array_merge_recursive($val, $convertedVals); } $values[$dao->contact_id] = $val; } @@ -5033,11 +5033,10 @@ AND displayRelType.is_active = 1 * convert the pseudo constants id's to their names * @param reference parameter $dao */ - function convertToPseudoNames(&$dao) { + function convertToPseudoNames(&$dao, $return = FALSE) { if (empty($this->_pseudoConstantsSelect)) { return; } - $values = array(); foreach ($this->_pseudoConstantsSelect as $key => $value) { if (CRM_Utils_Array::value('sorting', $this->_pseudoConstantsSelect[$key])) { @@ -5049,10 +5048,8 @@ AND displayRelType.is_active = 1 if (CRM_Utils_System::isNull($val)) { $dao->$key = NULL; - continue; } - - if ($baoName = CRM_Utils_Array::value('bao', $value, NULL)) { + elseif ($baoName = CRM_Utils_Array::value('bao', $value, NULL)) { $dao->$key = CRM_Core_PseudoConstant::getLabel($baoName, $value['pseudoField'], $val); } elseif ($value['pseudoField'] == 'state_province_abbreviation') { @@ -5062,7 +5059,25 @@ AND displayRelType.is_active = 1 $labels = CRM_Core_OptionGroup::values($value['pseudoField']); $dao->$key = $labels[$val]; } - $values[$key] = $dao->$key; + + // return converted values in array format + if ($return) { + if (strpos($key, '-') !== FALSE) { + $keyVal = explode('-', $key); + $current = &$values; + $lastElement = array_pop($keyVal); + foreach ($keyVal as $v) { + if (!array_key_exists($v, $current)) { + $current[$v] = array(); + } + $current = &$current[$v]; + } + $current[$lastElement] = $dao->$key; + } + else { + $values[$key] = $dao->$key; + } + } } } return $values; -- 2.25.1