本文整理汇总了PHP中CRM_Core_DAO_CustomField::copyValues方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO_CustomField::copyValues方法的具体用法?PHP CRM_Core_DAO_CustomField::copyValues怎么用?PHP CRM_Core_DAO_CustomField::copyValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO_CustomField
的用法示例。
在下文中一共展示了CRM_Core_DAO_CustomField::copyValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
//.........这里部分代码省略.........
} else {
if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']])) {
$params['default_value'] = $params['option_value'][$params['default_option']];
}
}
break;
}
$transaction = new CRM_Core_Transaction();
// create any option group & values if required
if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money'))) {
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name');
//CRM-16659: if option_value then create an option group for this custom field.
if ($params['option_type'] == 1 && (empty($params['option_group_id']) || !empty($params['option_value']))) {
// first create an option group for this custom group
$optionGroup = new CRM_Core_DAO_OptionGroup();
$optionGroup->name = "{$columnName}_" . date('YmdHis');
$optionGroup->title = $params['label'];
$optionGroup->is_active = 1;
$optionGroup->save();
$params['option_group_id'] = $optionGroup->id;
if (!empty($params['option_value']) && is_array($params['option_value'])) {
foreach ($params['option_value'] as $k => $v) {
if (strlen(trim($v))) {
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->option_group_id = $optionGroup->id;
$optionValue->label = $params['option_label'][$k];
$optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
switch ($params['data_type']) {
case 'Money':
$optionValue->value = CRM_Utils_Rule::cleanMoney($v);
break;
case 'Int':
$optionValue->value = intval($v);
break;
case 'Float':
$optionValue->value = floatval($v);
break;
default:
$optionValue->value = trim($v);
}
$optionValue->weight = $params['option_weight'][$k];
$optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], FALSE);
$optionValue->save();
}
}
}
}
}
// check for orphan option groups
if (!empty($params['option_group_id'])) {
if (!empty($params['id'])) {
self::fixOptionGroups($params['id'], $params['option_group_id']);
}
// if we do not have a default value
// retrieve it from one of the other custom fields which use this option group
if (empty($params['default_value'])) {
//don't insert only value separator as default value, CRM-4579
$defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']);
if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultValue))) {
$params['default_value'] = $defaultValue;
}
}
}
// since we need to save option group id :)
if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') {
$params['attributes'] = 'rows=4, cols=60';
}
$customField = new CRM_Core_DAO_CustomField();
$customField->copyValues($params);
$customField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE);
$customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
$customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
$customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE);
//CRM-15792 - Custom field gets disabled if is_active not set
$customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE);
$customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
$customField->save();
// make sure all values are present in the object for further processing
$customField->find(TRUE);
$triggerRebuild = CRM_Utils_Array::value('triggerRebuild', $params, TRUE);
//create/drop the index when we toggle the is_searchable flag
if (!empty($params['id'])) {
self::createField($customField, 'modify', $indexExist, $triggerRebuild);
} else {
if (!isset($origParams['column_name'])) {
$columnName .= "_{$customField->id}";
$params['column_name'] = $columnName;
}
$customField->column_name = $columnName;
$customField->save();
// make sure all values are present in the object
$customField->find(TRUE);
$indexExist = FALSE;
self::createField($customField, 'add', $indexExist, $triggerRebuild);
}
// complete transaction
$transaction->commit();
CRM_Utils_System::flushCache();
return $customField;
}
示例2: create
//.........这里部分代码省略.........
// also add the seperator before and after the value per new conventio (CRM-1604)
$params['default_value'] = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultArray) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
}
} else {
if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) {
$params['default_value'] = $params['option_value'][$params['default_option']];
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
// create any option group & values if required
if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money')) && !empty($params['option_value']) && is_array($params['option_value'])) {
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name');
if ($params['option_type'] == 1) {
// first create an option group for this custom group
require_once 'CRM/Core/BAO/OptionGroup.php';
$optionGroup = new CRM_Core_DAO_OptionGroup();
$optionGroup->name = "{$params['column_name']}_" . date('YmdHis');
$optionGroup->label = $params['label'];
$optionGroup->is_active = 1;
$optionGroup->save();
$params['option_group_id'] = $optionGroup->id;
require_once 'CRM/Core/BAO/OptionValue.php';
require_once 'CRM/Utils/String.php';
foreach ($params['option_value'] as $k => $v) {
if (strlen(trim($v))) {
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->option_group_id = $optionGroup->id;
$optionValue->label = $params['option_label'][$k];
$optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
switch ($params['data_type']) {
case 'Money':
require_once 'CRM/Utils/Rule.php';
$optionValue->value = number_format(CRM_Utils_Rule::cleanMoney($v), 2);
break;
case 'Int':
$optionValue->value = intval($v);
break;
case 'Float':
$optionValue->value = floatval($v);
break;
default:
$optionValue->value = trim($v);
}
$optionValue->weight = $params['option_weight'][$k];
$optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], false);
$optionValue->save();
}
}
}
}
// check for orphan option groups
if (CRM_Utils_Array::value('option_group_id', $params)) {
if (CRM_Utils_Array::value('id', $params)) {
self::fixOptionGroups($params['id'], $params['option_group_id']);
}
// if we dont have a default value
// retrive it from one of the other custom fields which use this option group
if (!CRM_Utils_Array::value('default_value', $params)) {
//don't insert only value separator as default value, CRM-4579
$defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']);
if (!CRM_Utils_System::isNull(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultValue))) {
$params['default_value'] = $defaultValue;
}
}
}
// since we need to save option group id :)
if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') {
$params['attributes'] = 'rows=4, cols=60';
}
$customField = new CRM_Core_DAO_CustomField();
$customField->copyValues($params);
$customField->is_required = CRM_Utils_Array::value('is_required', $params, false);
$customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, false);
$customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, false);
$customField->is_active = CRM_Utils_Array::value('is_active', $params, false);
$customField->is_view = CRM_Utils_Array::value('is_view', $params, false);
$customField->save();
// make sure all values are present in the object for further processing
$customField->find(true);
//create/drop the index when we toggle the is_searchable flag
if (CRM_Utils_Array::value('id', $params)) {
self::createField($customField, 'modify', $indexExist);
} else {
$customField->column_name .= "_{$customField->id}";
$customField->save();
// make sure all values are present in the object
$customField->find(true);
self::createField($customField, 'add');
}
// complete transaction
$transaction->commit();
// reset the cache
require_once 'CRM/Core/BAO/Cache.php';
CRM_Core_BAO_Cache::deleteGroup('contact fields');
// reset various static arrays used here
require_once 'CRM/Contact/BAO/Contact.php';
CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = self::$_importFields = null;
return $customField;
}