From 8cee0c709c6e70d34e55febfc3b92520d92eca24 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Dec 2015 14:42:28 -0500 Subject: [PATCH] CRM-17646 - Refactor out CRM_Core_BAO_CustomField::getDisplayValue --- CRM/Badge/BAO/Badge.php | 2 +- CRM/Case/XMLProcessor/Report.php | 5 +-- CRM/Contact/Form/Task/Label.php | 2 +- CRM/Contact/Form/Task/LabelCommon.php | 2 +- CRM/Contact/Selector.php | 3 +- CRM/Core/BAO/CustomField.php | 31 ------------------- CRM/Core/BAO/CustomQuery.php | 6 ++-- CRM/Core/BAO/UFGroup.php | 6 +--- CRM/Dedupe/Merger.php | 2 +- CRM/Event/BAO/Event.php | 3 +- CRM/Export/BAO/Export.php | 6 ++-- .../Page/MultipleRecordFieldsListing.php | 8 ++--- CRM/Profile/Selector/Listings.php | 3 +- CRM/Utils/Token.php | 4 +-- .../phpunit/CRM/Core/BAO/CustomFieldTest.php | 8 +---- 15 files changed, 18 insertions(+), 73 deletions(-) diff --git a/CRM/Badge/BAO/Badge.php b/CRM/Badge/BAO/Badge.php index 741b357f40..6c2da90afd 100644 --- a/CRM/Badge/BAO/Badge.php +++ b/CRM/Badge/BAO/Badge.php @@ -481,7 +481,7 @@ class CRM_Badge_BAO_Badge { $value = isset($dao->$key) ? $dao->$key : NULL; // Format custom fields if (strstr($key, 'custom_') && isset($value)) { - $value = CRM_Core_BAO_CustomField::getDisplayValue($value, substr($key, 7), $query->_options, $dao->contact_id); + $value = CRM_Core_BAO_CustomField::displayValue($value, substr($key, 7), $dao->contact_id); } $rows[$dao->participant_id][$key] = $value; } diff --git a/CRM/Case/XMLProcessor/Report.php b/CRM/Case/XMLProcessor/Report.php index 5f68f1f1db..dcb3ef9210 100644 --- a/CRM/Case/XMLProcessor/Report.php +++ b/CRM/Case/XMLProcessor/Report.php @@ -553,10 +553,7 @@ WHERE a.id = %1 if ($dao->fetch()) { $customGroup = array(); foreach ($typeValues[$tableName] as $columnName => $typeValue) { - $value = CRM_Core_BAO_CustomField::getDisplayValue($dao->$columnName, - $typeValue['fieldID'], - $options - ); + $value = CRM_Core_BAO_CustomField::displayValue($dao->$columnName, $typeValue['fieldID']); if (CRM_Utils_Array::value('type', $typeValue) == 'Date') { $value = $dao->$columnName; diff --git a/CRM/Contact/Form/Task/Label.php b/CRM/Contact/Form/Task/Label.php index 1ff219d514..6bd801bb60 100644 --- a/CRM/Contact/Form/Task/Label.php +++ b/CRM/Contact/Form/Task/Label.php @@ -229,7 +229,7 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task { foreach ($this->_contactIds as $value) { foreach ($custom as $cfID) { if (isset($details[0][$value]["custom_{$cfID}"])) { - $details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($details[0][$value]["custom_{$cfID}"], $cfID, $details[1]); + $details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[0][$value]["custom_{$cfID}"], $cfID); } } $contact = CRM_Utils_Array::value($value, $details['0']); diff --git a/CRM/Contact/Form/Task/LabelCommon.php b/CRM/Contact/Form/Task/LabelCommon.php index 00d44fd329..ddf5eefc85 100644 --- a/CRM/Contact/Form/Task/LabelCommon.php +++ b/CRM/Contact/Form/Task/LabelCommon.php @@ -162,7 +162,7 @@ class CRM_Contact_Form_Task_LabelCommon { foreach ($contactIDs as $value) { foreach ($custom as $cfID) { if (isset($details[$value]["custom_{$cfID}"])) { - $details[$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($details[$value]["custom_{$cfID}"], $cfID, $details[1]); + $details[$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[$value]["custom_{$cfID}"], $cfID); } } $contact = CRM_Utils_Array::value($value, $details); diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 2143bb8ccd..ec7d494423 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -663,10 +663,9 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se continue; } if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) { - $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue( + $row[$property] = CRM_Core_BAO_CustomField::displayValue( $result->$property, $cfID, - $this->_options, $result->contact_id ); } diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 6110650326..9f5560d9ac 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1171,37 +1171,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { return self::formatDisplayValue($value, self::$displayInfoCache[$fieldId], $contactId); } - /** - * Legacy display value getter. - * - * @deprecated - * - * @param mixed $value - * The custom field value. - * @param int $fieldID - * The custom field id. - * @param array $options - * The assoc array of option name/value pairs. - * @param int $contactID - * - * @return string - * the display value - */ - public static function getDisplayValue($value, $fieldID, &$options, $contactID = NULL) { - $option = &$options[$fieldID]; - $attributes = &$option['attributes']; - $html_type = $attributes['html_type']; - $data_type = $attributes['data_type']; - - return self::getDisplayValueCommon($value, - $option, - $html_type, - $data_type, - $contactID, - $fieldID - ); - } - /** * Legacy display value formatter. * diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index fd79201f58..6e7d831fae 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -341,15 +341,15 @@ SELECT label, value $qillValue = NULL; if (!is_array($value)) { $value = CRM_Core_DAO::escapeString(trim($value)); - $qillValue = CRM_Core_BAO_CustomField::getDisplayValue($value, $id, $this->_options); + $qillValue = CRM_Core_BAO_CustomField::displayValue($value, $id); } elseif (count($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { $op = key($value); - $qillValue = strstr($op, 'NULL') ? NULL : CRM_Core_BAO_CustomField::getDisplayValue($value[$op], $id, $this->_options); + $qillValue = strstr($op, 'NULL') ? NULL : CRM_Core_BAO_CustomField::displayValue($value[$op], $id); } else { $op = strstr($op, 'IN') ? $op : 'IN'; - $qillValue = CRM_Core_BAO_CustomField::getDisplayValue($value, $id, $this->_options); + $qillValue = CRM_Core_BAO_CustomField::displayValue($value, $id); } $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 1f52489a14..fdb4eda617 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -973,7 +973,6 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { } $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); - $options = &$query->_options; $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause); @@ -1166,10 +1165,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { } $params[$index] = $customVal; - $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, - $cfID, - $options - ); + $values[$index] = CRM_Core_BAO_CustomField::displayValue($customVal, $cfID); if ($field['data_type'] == 'ContactReference') { $params[$index] = $values[$index]; } diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index e97cac8cec..2933c41535 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1647,7 +1647,7 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m case 'Select Country': case 'Select State/Province': - $submitted[$key] = CRM_Core_BAO_CustomField::getDisplayValue($value, $fid, $cFields); + $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid); break; case 'CheckBox': diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index c155a9dc42..2ad3f680b1 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1664,9 +1664,8 @@ WHERE id = $cfID //take the custom field options $returnProperties = array($name => 1); $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); - $options = &$query->_options; if (!$skip) { - $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); + $displayValue = CRM_Core_BAO_CustomField::displayValue($customVal, $cfID); } //Hack since we dont have function to check empty. //FIXME in 2.3 using crmIsEmptyArray() diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 55a429edbd..e767e8f1ff 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1073,9 +1073,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c elseif (isset($fieldValue) && $fieldValue != '') { //check for custom data if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationField)) { - $row[$field . $relationField] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, - $relationQuery[$field]->_options - ); + $row[$field . $relationField] = CRM_Core_BAO_CustomField::displayValue($fieldValue, $cfID); } else { //normal relationship fields @@ -1107,7 +1105,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c ) { //check for custom data if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) { - $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options); + $row[$field] = CRM_Core_BAO_CustomField::displayValue($fieldValue, $cfID); } elseif (array_key_exists($field, $multipleSelectFields)) { //option group fixes diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index df62b037ff..20615f10b4 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -305,7 +305,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $customValue = &$val; if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) { // formatted date capture value capture - $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); + $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::displayValue($customValue, $fieldId); //set date and time format switch ($timeFormat) { @@ -325,11 +325,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { } else { // assign to $result - $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); - } - // FIXME: getDisplayValue should always return a string so why is this necessary? - if (!$customValue && $customValue !== '0') { - $customValue = ""; + $customValue = CRM_Core_BAO_CustomField::displayValue($customValue, $fieldId); } // Set field attributes to support crmEditable diff --git a/CRM/Profile/Selector/Listings.php b/CRM/Profile/Selector/Listings.php index 565ee4b958..f08cb8f373 100644 --- a/CRM/Profile/Selector/Listings.php +++ b/CRM/Profile/Selector/Listings.php @@ -612,9 +612,8 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR foreach ($names as $name) { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { - $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->$name, + $row[] = CRM_Core_BAO_CustomField::displayValue($result->$name, $cfID, - $this->_options, $result->contact_id ); } diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 71b1293b44..c0e4f214de 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1262,9 +1262,7 @@ class CRM_Utils_Token { foreach ($custom as $cfID) { if (isset($contactDetails[$contactID]["custom_{$cfID}"])) { - $contactDetails[$contactID]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($contactDetails[$contactID]["custom_{$cfID}"], - $cfID, $details[1] - ); + $contactDetails[$contactID]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($contactDetails[$contactID]["custom_{$cfID}"], $cfID); } } diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index 670845b9fd..fb5b509309 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -132,13 +132,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { $customFieldID1 = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup->id, 'id', 'custom_group_id', 'Database check for created CustomField.' ); - $options = array(); - $options[$customFieldID1]['attributes'] = array( - 'label' => 'testCountryFld1', - 'data_type' => 'Country', - 'html_type' => 'Select Country', - ); - $display = CRM_Core_BAO_CustomField::getDisplayValue($fields['default_value'], $customFieldID1, $options); + $display = CRM_Core_BAO_CustomField::displayValue($fields['default_value'], $customFieldID1); $this->assertEquals('UNITED STATES', $display, 'Confirm Country display Name'); -- 2.25.1