当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_BAO_CustomField::getNameFromID方法代码示例

本文整理汇总了PHP中CRM_Core_BAO_CustomField::getNameFromID方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomField::getNameFromID方法的具体用法?PHP CRM_Core_BAO_CustomField::getNameFromID怎么用?PHP CRM_Core_BAO_CustomField::getNameFromID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_BAO_CustomField的用法示例。


在下文中一共展示了CRM_Core_BAO_CustomField::getNameFromID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: civicrm_api3_custom_value_get

/**
 * Use this API to get existing custom values for an entity.
 *
 * @param array $params
 *   Array specifying the entity_id.
 *   Optionally include entity_type param, i.e. 'entity_type' => 'Activity'
 *   If no entity_type is supplied, it will be determined based on the fields you request.
 *   If no entity_type is supplied and no fields are specified, 'Contact' will be assumed.
 *   Optionally include the desired custom data to be fetched (or else all custom data for this entity will be returned)
 *   Example: 'entity_id' => 123, 'return.custom_6' => 1, 'return.custom_33' => 1
 *   If you do not know the ID, you may use group name : field name, for example 'return.foo_stuff:my_field' => 1
 *
 * @throws API_Exception
 * @return array
 */
function civicrm_api3_custom_value_get($params)
{
    $getParams = array('entityID' => $params['entity_id'], 'entityType' => CRM_Utils_Array::value('entity_table', $params, ''));
    if (strstr($getParams['entityType'], 'civicrm_')) {
        $getParams['entityType'] = ucfirst(substr($getParams['entityType'], 8));
    }
    unset($params['entity_id'], $params['entity_table']);
    foreach ($params as $id => $param) {
        if ($param && substr($id, 0, 6) == 'return') {
            $id = substr($id, 7);
            list($c, $i) = CRM_Utils_System::explode('_', $id, 2);
            if ($c == 'custom' && is_numeric($i)) {
                $names['custom_' . $i] = 'custom_' . $i;
                $id = $i;
            } else {
                // Lookup names if ID was not supplied
                list($group, $field) = CRM_Utils_System::explode(':', $id, 2);
                $id = CRM_Core_BAO_CustomField::getCustomFieldID($field, $group);
                if (!$id) {
                    continue;
                }
                $names['custom_' . $id] = 'custom_' . $i;
            }
            $getParams['custom_' . $id] = 1;
        }
    }
    $result = CRM_Core_BAO_CustomValueTable::getValues($getParams);
    if ($result['is_error']) {
        if ($result['error_message'] == "No values found for the specified entity ID and custom field(s).") {
            $values = array();
            return civicrm_api3_create_success($values, $params, 'CustomValue');
        } else {
            throw new API_Exception($result['error_message']);
        }
    } else {
        $entity_id = $result['entityID'];
        unset($result['is_error'], $result['entityID']);
        // Convert multi-value strings to arrays
        $sp = CRM_Core_DAO::VALUE_SEPARATOR;
        foreach ($result as $id => $value) {
            if (strpos($value, $sp) !== FALSE) {
                $value = explode($sp, trim($value, $sp));
            }
            $idArray = explode('_', $id);
            if ($idArray[0] != 'custom') {
                continue;
            }
            $fieldNumber = $idArray[1];
            $customFieldInfo = CRM_Core_BAO_CustomField::getNameFromID($fieldNumber);
            $info = array_pop($customFieldInfo);
            // id is the index for returned results
            if (empty($idArray[2])) {
                $n = 0;
                $id = $fieldNumber;
            } else {
                $n = $idArray[2];
                $id = $fieldNumber . "." . $idArray[2];
            }
            if (!empty($params['format.field_names'])) {
                $id = $info['field_name'];
            } else {
                $id = $fieldNumber;
            }
            $values[$id]['entity_id'] = $getParams['entityID'];
            if (!empty($getParams['entityType'])) {
                $values[$id]['entity_table'] = $getParams['entityType'];
            }
            //set 'latest' -useful for multi fields but set for single for consistency
            $values[$id]['latest'] = $value;
            $values[$id]['id'] = $id;
            $values[$id][$n] = $value;
        }
        return civicrm_api3_create_success($values, $params, 'CustomValue');
    }
}
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:90,代码来源:CustomValue.php


注:本文中的CRM_Core_BAO_CustomField::getNameFromID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。