本文整理汇总了PHP中CRM_Utils_Array::crmReplaceKey方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array::crmReplaceKey方法的具体用法?PHP CRM_Utils_Array::crmReplaceKey怎么用?PHP CRM_Utils_Array::crmReplaceKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Array
的用法示例。
在下文中一共展示了CRM_Utils_Array::crmReplaceKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMultiRecordFieldList
/**
* Get list of Multi Record Fields.
*
*/
public static function getMultiRecordFieldList()
{
$params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
$params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
$params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
$contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
$obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
$obj->_pageViewType = 'customDataView';
$obj->_contactId = $params['cid'];
$obj->_customGroupId = $params['cgid'];
$obj->_contactType = $contactType;
$obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
$obj->_DTparams['rowCount'] = $params['rp'];
if (!empty($params['sortBy'])) {
$obj->_DTparams['sort'] = $params['sortBy'];
}
list($fields, $attributes) = $obj->browse();
// format params and add class attributes
$fieldList = array();
foreach ($fields as $id => $value) {
$field = array();
foreach ($value as $fieldId => &$fieldName) {
if (!empty($attributes[$fieldId][$id]['class'])) {
$fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
}
if (is_numeric($fieldId)) {
$fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
}
}
$field = $value;
array_push($fieldList, $field);
}
$totalRecords = !empty($obj->_total) ? $obj->_total : 0;
$multiRecordFields = array();
$multiRecordFields['data'] = $fieldList;
$multiRecordFields['recordsTotal'] = $totalRecords;
$multiRecordFields['recordsFiltered'] = $totalRecords;
if (!empty($_GET['is_unit_test'])) {
return $multiRecordFields;
}
CRM_Utils_JSON::output($multiRecordFields);
}
示例2: getMultiRecordFieldList
/**
* Get list of Multi Record Fields.
*
*/
public static function getMultiRecordFieldList()
{
$params = $_GET;
$offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
$rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 10;
$sortMapper = array();
foreach ($_GET['columns'] as $key => $value) {
$sortMapper[$key] = $value['data'];
}
$sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
$sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
$contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
$obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
$obj->_pageViewType = 'customDataView';
$obj->_contactId = $params['cid'];
$obj->_customGroupId = $params['cgid'];
$obj->_contactType = $contactType;
$obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
$obj->_DTparams['rowCount'] = $params['rp'];
if ($sort && $sortOrder) {
$sort = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $sort, 'column_name', 'label');
$obj->_DTparams['sort'] = $sort . ' ' . $sortOrder;
}
list($fields, $attributes) = $obj->browse();
// format params and add class attributes
$fieldList = array();
foreach ($fields as $id => $value) {
$field = array();
foreach ($value as $fieldId => &$fieldName) {
if (!empty($attributes[$fieldId][$id]['class'])) {
$fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
}
if (is_numeric($fieldId)) {
$fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'label');
CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
}
}
$field = $value;
array_push($fieldList, $field);
}
$totalRecords = !empty($obj->_total) ? $obj->_total : 0;
$multiRecordFields = array();
$multiRecordFields['data'] = $fieldList;
$multiRecordFields['recordsTotal'] = $totalRecords;
$multiRecordFields['recordsFiltered'] = $totalRecords;
CRM_Utils_JSON::output($multiRecordFields);
}
示例3: reformatProfileFields
/**
* This is function is used to format pseudo fields.
*
* @param array $fields
* Associated array of profile fields.
*
*/
public static function reformatProfileFields(&$fields)
{
//reformat fields array
foreach ($fields as $name => $field) {
//reformat phone and extension field
if (substr($field['name'], 0, 13) == 'phone_and_ext') {
$fieldSuffix = str_replace('phone_and_ext-', '', $field['name']);
// retain existing element properties and just update and replace key
CRM_Utils_Array::crmReplaceKey($fields, $name, "phone-{$fieldSuffix}");
$fields["phone-{$fieldSuffix}"]['name'] = "phone-{$fieldSuffix}";
$fields["phone-{$fieldSuffix}"]['where'] = 'civicrm_phone.phone';
// add additional phone extension field
$fields["phone_ext-{$fieldSuffix}"] = $field;
$fields["phone_ext-{$fieldSuffix}"]['title'] = $field['title'] . ' - ' . ts('Ext.');
$fields["phone_ext-{$fieldSuffix}"]['name'] = "phone_ext-{$fieldSuffix}";
$fields["phone_ext-{$fieldSuffix}"]['where'] = 'civicrm_phone.phone_ext';
$fields["phone_ext-{$fieldSuffix}"]['skipDisplay'] = 1;
//ignore required for extension field
$fields["phone_ext-{$fieldSuffix}"]['is_required'] = 0;
}
}
}
示例4: civicrm_api3_generic_setValue
/**
* Set a single value using the api.
*
* This function is called when no specific setvalue api exists.
* Params must contain at least id=xx & {one of the fields from getfields}=value
*
* @param array $apiRequest
*
* @throws API_Exception
* @return array
*/
function civicrm_api3_generic_setValue($apiRequest)
{
$entity = $apiRequest['entity'];
$params = $apiRequest['params'];
$id = $params['id'];
if (!is_numeric($id)) {
return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id"));
}
$field = CRM_Utils_String::munge($params['field']);
$value = $params['value'];
$fields = civicrm_api($entity, 'getFields', array('version' => 3, 'action' => 'create', "sequential"));
// getfields error, shouldn't happen.
if ($fields['is_error']) {
return $fields;
}
$fields = $fields['values'];
$isCustom = strpos($field, 'custom_') === 0;
// Trim off the id portion of a multivalued custom field name
$fieldKey = $isCustom && substr_count($field, '_') > 1 ? rtrim(rtrim($field, '1234567890'), '_') : $field;
if (!array_key_exists($fieldKey, $fields)) {
return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields)));
}
$def = $fields[$fieldKey];
$title = CRM_Utils_Array::value('title', $def, ts('Field'));
// Disallow empty values except for the number zero.
// TODO: create a utility for this since it's needed in many places
if (!empty($def['required']) || !empty($def['is_required'])) {
if ((empty($value) || $value === 'null') && $value !== '0' && $value !== 0) {
return civicrm_api3_create_error(ts('%1 is a required field.', array(1 => $title)), array("error_code" => "required", "field" => $field));
}
}
switch ($def['type']) {
case CRM_Utils_Type::T_FLOAT:
if (!is_numeric($value) && !empty($value) && $value !== 'null') {
return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN'));
}
break;
case CRM_Utils_Type::T_INT:
if (!CRM_Utils_Rule::integer($value) && !empty($value) && $value !== 'null') {
return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN'));
}
break;
case CRM_Utils_Type::T_STRING:
case CRM_Utils_Type::T_TEXT:
if (!CRM_Utils_Rule::xssString($value)) {
return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS'));
}
if (array_key_exists('maxlength', $def)) {
$value = substr($value, 0, $def['maxlength']);
}
break;
case CRM_Utils_Type::T_DATE:
$value = CRM_Utils_Type::escape($value, "Date", FALSE);
if (!$value) {
return civicrm_api3_create_error("Param '{$field}' is not a date. format YYYYMMDD or YYYYMMDDHHMMSS");
}
break;
case CRM_Utils_Type::T_BOOLEAN:
// Allow empty value for non-required fields
if ($value === '' || $value === 'null') {
$value = '';
} else {
$value = (bool) $value;
}
break;
default:
return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet (" . $def['type'] . "). Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED'));
}
$dao_name = _civicrm_api3_get_DAO($entity);
$params = array('id' => $id, $field => $value);
if ((!empty($def['pseudoconstant']) || !empty($def['option_group_id'])) && $value !== '' && $value !== 'null') {
_civicrm_api3_api_match_pseudoconstant($params[$field], $entity, $field, $def);
}
CRM_Utils_Hook::pre('edit', $entity, $id, $params);
// Custom fields
if ($isCustom) {
CRM_Utils_Array::crmReplaceKey($params, 'id', 'entityID');
// Treat 'null' as empty value. This is awful but the rest of the code supports it.
if ($params[$field] === 'null') {
$params[$field] = '';
}
CRM_Core_BAO_CustomValueTable::setValues($params);
CRM_Utils_Hook::post('edit', $entity, $id, CRM_Core_DAO::$_nullObject);
} elseif (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $params[$field])) {
$entityDAO = new $dao_name();
$entityDAO->copyValues($params);
CRM_Utils_Hook::post('edit', $entity, $entityDAO->id, $entityDAO);
} else {
return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})");
//.........这里部分代码省略.........