From c21a9b7f94a9df2d4f29647388efd9f96b32a7c0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Dec 2015 16:24:15 -0500 Subject: [PATCH] CRM-17646 - Refactor out CRM_Core_BAO_CustomOption::getOptionLabel --- CRM/Core/BAO/CustomField.php | 58 -------------------------------- CRM/Core/BAO/CustomOption.php | 62 ----------------------------------- CRM/Utils/Token.php | 7 +++- 3 files changed, 6 insertions(+), 121 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 6914096be7..1efdbcba64 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1178,64 +1178,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { return self::formatDisplayValue($value, self::$displayInfoCache[$fieldId], $contactId); } - /** - * Legacy display value formatter. - * - * @deprecated - * - * @param string $value - * @param array $option - * @param string $html_type - * @param string $data_type - * @param int $contactID - * @param int $fieldID - * - * @return array|mixed|null|string - */ - public static function getDisplayValueCommon( - $value, - $option, - $html_type, - $data_type, - $contactID = NULL, - $fieldID = NULL - ) { - - if ($fieldID && - (($html_type == 'Radio' && $data_type != 'Boolean') || - ($html_type == 'Autocomplete-Select' && $data_type != 'ContactReference') || - $html_type == 'Select' || - $html_type == 'CheckBox' || - $html_type == 'AdvMulti-Select' || - $html_type == 'Multi-Select' - ) - ) { - CRM_Utils_Hook::customFieldOptions($fieldID, $option); - } - - if ($data_type == 'Boolean') { - $option = CRM_Core_SelectValues::boolean(); - } - - if ($data_type == 'Country') { - $option = CRM_Core_PseudoConstant::country(FALSE, FALSE); - } - - if ($data_type == 'StateProvince') { - $option = CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE); - } - - $field = array( - 'id' => $fieldID, - 'html_type' => $html_type, - 'data_type' => $data_type, - 'options' => $option, - ); - - return self::formatDisplayValue($value, $field, $contactID); - } - - /** * Lower-level logic for rendering a custom field value * diff --git a/CRM/Core/BAO/CustomOption.php b/CRM/Core/BAO/CustomOption.php index 0e7fe31a74..6c44541c83 100644 --- a/CRM/Core/BAO/CustomOption.php +++ b/CRM/Core/BAO/CustomOption.php @@ -213,68 +213,6 @@ class CRM_Core_BAO_CustomOption { return $options; } - /** - * Returns the option label for a custom field with a specific value. Handles all - * custom field data and html types - * - * @param int $fieldId - * the custom field ID. - * @pram $value string the value (typically from the DB) of this custom field - * @param $value - * @param string $htmlType - * the html type of the field (optional). - * @param string $dataType - * the data type of the field (optional). - * - * @return string - * the label to display for this custom field - */ - public static function getOptionLabel($fieldId, $value, $htmlType = NULL, $dataType = NULL) { - if (!$fieldId) { - return NULL; - } - - if (!$htmlType || !$dataType) { - $sql = " -SELECT html_type, data_type -FROM civicrm_custom_field -WHERE id = %1 -"; - $params = array(1 => array($fieldId, 'Integer')); - $dao = CRM_Core_DAO::executeQuery($sql, $params); - if ($dao->fetch()) { - $htmlType = $dao->html_type; - $dataType = $dao->data_type; - } - else { - CRM_Core_Error::fatal(); - } - } - - $options = NULL; - switch ($htmlType) { - case 'CheckBox': - case 'Multi-Select': - case 'AdvMulti-Select': - case 'Select': - case 'Radio': - case 'Autocomplete-Select': - if (!in_array($dataType, array( - 'Boolean', - 'ContactReference', - )) - ) { - $options = self::valuesByID($fieldId); - } - } - - return CRM_Core_BAO_CustomField::getDisplayValueCommon($value, - $options, - $htmlType, - $dataType - ); - } - /** * Delete Option. * diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index c0e4f214de..8e28f658b7 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -326,6 +326,11 @@ class CRM_Utils_Token { /** * Replace all the org-level tokens in $str * + * @fixme: This function appears to be broken, as it depends on + * nonexistant method: CRM_Core_BAO_CustomValue::getContactValues() + * Marking as deprecated until this is fixed + * @deprecated + * * @param string $str * The string with tokens to be replaced. * @param object $org @@ -369,7 +374,7 @@ class CRM_Utils_Token { } foreach ($cv as $cvFieldID => $value) { if ($cvFieldID == $cfID) { - $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value); + $value = CRM_Core_BAO_CustomField::displayValue($value, $cfID); break; } } -- 2.25.1