/** * Returns the option label for a custom field with a specific value. Handles all * custom field data and html types * * @param $fieldId int the custom field ID * @pram $value string the value (typically from the DB) of this custom field * @param $htmlType string the html type of the field (optional) * @param $dataType string the data type of the field (optional) * * @return string the label to display for this custom field * @static * @access public */ static function getOptionLabel($fieldId, $value, $htmlType = NULL, $dataType = NULL) { if (!$fieldId) { return NULL; } if (!$htmlType || !$dataType) { $sql = "\nSELECT html_type, data_type\nFROM civicrm_custom_field\nWHERE id = %1\n"; $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); }
static function getOptionLabel($fieldId, $value, $htmlType = null, $dataType = null) { if (!$fieldId) { return null; } if (!$htmlType || !$dataType) { $sql = "\nSELECT html_type, data_type\nFROM civicrm_custom_field\nWHERE id = %1\n"; $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': if ($dataType != 'Boolean') { $options =& self::valuesByID($fieldId); } } require_once 'CRM/Core/BAO/CustomField.php'; return CRM_Core_BAO_CustomField::getDisplayValueCommon($value, $options, $htmlType, $dataType); }