return $returnValues;
}
- }
-}
+ /**
+ * convert the pseudo constants id's to their names
+ * @param reference parameter $dao
+ */
+ function convertToPseudoNames(&$dao) {
+ if (empty($this->_pseudoConstantsSelect)) {
+ return;
+ }
+
+ $values = array();
+ foreach ($this->_pseudoConstantsSelect as $key => $value) {
+ if (CRM_Utils_Array::value('sorting', $this->_pseudoConstantsSelect[$key])) {
+ continue;
+ }
+
+ if (property_exists($dao, $value['idCol'])) {
+ $val = $dao->$value['idCol'];
+
+ if (CRM_Utils_System::isNull($val)) {
+ $dao->$key = NULL;
+ continue;
+ }
+
+ if ($baoName = CRM_Utils_Array::value('bao', $value, NULL)) {
+ $dao->$key = CRM_Core_PseudoConstant::getLabel($baoName, $value['pseudoField'], $val);
+ }
+ elseif ($value['pseudoField'] == 'state_province_abbreviation') {
+ $dao->$key = CRM_Core_PseudoConstant::stateProvinceAbbreviation($val);
+ }
+ else {
+ $labels = CRM_Core_OptionGroup::values($value['pseudoField']);
+ $dao->$key = $labels[$val];
+ }
+ $values[$key] = $dao->$key;
+ }
+ }
+ return $values;
+ }
+
+ /*
+ * include pseudo fields LEFT JOIN
+ * @param $sort can be a object or string
+ *
+ */
+ function includePseudoFieldsJoin($sort) {
+ if (!$sort || empty($this->_pseudoConstantsSelect)) {
+ return;
+ }
+ $sort = is_string($sort) ? $sort : $sort->orderBy();
+ $present = array();
+
+ foreach ($this->_pseudoConstantsSelect as $name => $value) {
+ if (CRM_Utils_Array::value('table', $value)) {
+ $regex = "/({$value['table']}\.|{$name})/";
+ if (preg_match($regex, $sort)) {
+ $this->_elemnt[$value['element']] = 1;
+ $this->_select[$value['element']] = $value['select'];
+ $this->_pseudoConstantsSelect[$name]['sorting'] = 1;
+ $present[$value['table']] = $value['join'];
+ }
+ }
+ }
+ $presentSimpleFrom = $present;
+
+ if (array_key_exists('civicrm_worldregion', $this->_whereTables) &&
+ array_key_exists('civicrm_country', $presentSimpleFrom)) {
+ unset($presentSimpleFrom['civicrm_country']);
+ }
+ if (array_key_exists('civicrm_worldregion', $this->_tables) &&
+ array_key_exists('civicrm_country', $present)) {
+ unset($present['civicrm_country']);
+ }
+
+ $presentClause = $presentSimpleFromClause = NULL;
+ if (!empty($present)) {
+ $presentClause = implode(' ', $present);
+ }
+ if (!empty($presentSimpleFrom)) {
+ $presentSimpleFromClause = implode(' ', $presentSimpleFrom);
+ }
+
+ $this->_fromClause = $this->_fromClause . $presentClause;
+ $this->_simpleFromClause = $this->_simpleFromClause . $presentSimpleFromClause;
+
+ return array($presentClause, $presentSimpleFromClause);
+ }
++}