本文整理汇总了PHP中CRM_Core_BAO_CustomValueTable::setValues方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomValueTable::setValues方法的具体用法?PHP CRM_Core_BAO_CustomValueTable::setValues怎么用?PHP CRM_Core_BAO_CustomValueTable::setValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomValueTable
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomValueTable::setValues方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCustomGroupMultipleOldFormat
public function testCustomGroupMultipleOldFormat()
{
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate(array('is_multiple' => 1));
$fields = array('custom_group_id' => $customGroup['id'], 'dataType' => 'String', 'htmlType' => 'Text');
$customField = $this->customFieldCreate($fields);
$params = array('entityID' => $contactID, "custom_{$customField['id']}" => 'First String');
CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array('entityID' => $contactID, "custom_{$customField['id']}" => 1);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params["custom_{$customField['id']}"], $result["custom_{$customField['id']}_1"]);
$this->assertEquals($params['entityID'], $result['entityID']);
$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
示例2: testCustomGroupMultipleOldFormate
public function testCustomGroupMultipleOldFormate()
{
$params = array();
$contactID = Contact::createIndividual();
$customGroup = Custom::createGroup($params, 'Individual', TRUE);
$fields = array('groupId' => $customGroup->id, 'dataType' => 'String', 'htmlType' => 'Text');
$customField = Custom::createField($params, $fields);
$params = array('entityID' => $contactID, "custom_{$customField->id}" => 'First String');
$error = CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array('entityID' => $contactID, "custom_{$customField->id}" => 1);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params["custom_{$customField->id}"], $result["custom_{$customField->id}_1"]);
$this->assertEquals($params['entityID'], $result['entityID']);
Custom::deleteField($customField);
Custom::deleteGroup($customGroup);
Contact::delete($contactID);
}
示例3: testCustomGroupMultiple
public function testCustomGroupMultiple()
{
$params = array();
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
$fields = array('custom_group_id' => $customGroup['id'], 'data_type' => 'String', 'html_type' => 'Text');
$customField = $this->customFieldCreate($fields);
$params = array('entityID' => $contactID, 'custom_' . $customField['id'] . '_-1' => 'First String');
$error = CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array('entityID' => $contactID, 'custom_' . $customField['id'] => 1);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
$this->assertEquals($params['entityID'], $result['entityID']);
$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
示例4: testSetGetValuesYesNoRadio
/**
* Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio
*/
public function testSetGetValuesYesNoRadio()
{
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate(array('is_multiple' => 1));
//create Custom Field of type YesNo(Boolean) Radio
$fields = array('custom_group_id' => $customGroup['id'], 'data_type' => 'Boolean', 'html_type' => 'Radio', 'default_value' => '');
$customField = $this->customFieldCreate($fields);
// Retrieve the field ID for sample custom field 'test_Boolean'
$params = array('label' => 'test_Boolean');
$field = array();
//get field Id
CRM_Core_BAO_CustomField::retrieve($params, $field);
$fieldID = $customField['id'];
// valid boolean value '1' for Boolean Radio
$yesNo = '1';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo);
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the YesNo radio value is stored
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the boolean value is stored for contact ' . $contactID);
// Now set YesNo radio to an invalid boolean value and try to reset
$badYesNo = '20';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo);
CRM_Core_TemporaryErrorScope::useException();
$message = NULL;
try {
CRM_Core_BAO_CustomValueTable::setValues($params);
} catch (Exception $e) {
$message = $e->getMessage();
}
$errorScope = NULL;
// Check that an exception has been thrown
$this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed');
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID);
// Cleanup
$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
示例5: civicrm_api3_custom_value_create
/**
* Sets custom values for an entity.
*
* @param array $params
* Expected keys are in format custom_fieldID:recordID or custom_groupName:fieldName:recordID.
*
* @example:
* @code
* // entity ID. You do not need to specify entity type, we figure it out based on the fields you're using
* 'entity_id' => 123,
* // (omitting :id) inserts or updates a field in a single-valued group
* 'custom_6' => 'foo',
* // custom_24 is checkbox or multiselect, so pass items as an array
* 'custom_24' => array('bar', 'baz'),
* // in this case custom_33 is part of a multi-valued group, and we're updating record id 5
* 'custom_33:5' => value,
* // inserts new record in multi-valued group
* 'custom_33:-1' => value,
* // inserts another new record in multi-valued group
* 'custom_33:-2' => value,
* // you can use group_name:field_name instead of ID
* 'custom_some_group:my_field' => 'myinfo',
* // updates record ID 8 in my_other_field in multi-valued some_big_group
* 'custom_some_big_group:my_other_field:8' => 'myinfo',
* @endcode
*
* @throws Exception
* @return array
* ['values' => TRUE] or ['is_error' => 1, 'error_message' => 'what went wrong']
*/
function civicrm_api3_custom_value_create($params)
{
// @todo it's not clear where the entity_table is used as CRM_Core_BAO_CustomValueTable::setValues($create)
// didn't seem to use it
// so not clear if it's relevant
if (!empty($params['entity_table']) && substr($params['entity_table'], 0, 7) == 'civicrm') {
$params['entity_table'] = substr($params['entity_table'], 8, 7);
}
$create = array('entityID' => $params['entity_id']);
// Translate names and
//Convert arrays to multi-value strings
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
foreach ($params as $id => $param) {
if (is_array($param)) {
$param = $sp . implode($sp, $param) . $sp;
}
list($c, $id) = CRM_Utils_System::explode('_', $id, 2);
if ($c != 'custom') {
continue;
}
list($i, $n, $x) = CRM_Utils_System::explode(':', $id, 3);
if (is_numeric($i)) {
$key = $i;
$x = $n;
} else {
// Lookup names if ID was not supplied
$key = CRM_Core_BAO_CustomField::getCustomFieldID($n, $i);
if (!$key) {
continue;
}
}
if ($x && is_numeric($x)) {
$key .= '_' . $x;
}
$create['custom_' . $key] = $param;
}
$result = CRM_Core_BAO_CustomValueTable::setValues($create);
if ($result['is_error']) {
throw new Exception($result['error_message']);
}
return civicrm_api3_create_success(TRUE, $params, 'CustomValue');
}
示例6: moveAllBelongings
//.........这里部分代码省略.........
}
}
}
// **** Do file custom fields related migrations
// FIXME: move this someplace else (one of the BAOs) after discussing
// where to, and whether CRM_Core_BAO_File::deleteFileReferences() shouldn't actually,
// like, delete a file...
if (!isset($customFiles)) {
$customFiles = array();
}
foreach ($customFiles as $customId) {
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
// get the contact_id -> file_id mapping
$fileIds = array();
$sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
$dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
while ($dao->fetch()) {
$fileIds[$dao->entity_id] = $dao->file_id;
}
$dao->free();
// delete the main contact's file
if (!empty($fileIds[$mainId])) {
CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId);
}
// move the other contact's file to main contact
//NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
if (CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")) {
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
} else {
$sql = "INSERT INTO {$tableName} ( entity_id, {$columnName} ) VALUES ( {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
if (CRM_Core_DAO::singleValueQuery("\n SELECT id\n FROM civicrm_entity_file\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}")) {
$sql = "\n UPDATE civicrm_entity_file\n SET entity_id = {$mainId}\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}";
} else {
$sql = "\n INSERT INTO civicrm_entity_file ( entity_table, entity_id, file_id )\n VALUES ( '{$tableName}', {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
}
// move view only custom fields CRM-5362
$viewOnlyCustomFields = array();
foreach ($submitted as $key => $value) {
$fid = (int) substr($key, 7);
if (array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])) {
$viewOnlyCustomFields[$key] = $value;
}
}
// special case to set values for view only, CRM-5362
if (!empty($viewOnlyCustomFields)) {
$viewOnlyCustomFields['entityID'] = $mainId;
CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
}
// **** Delete other contact & update prev-next caching
$otherParams = array('contact_id' => $otherId, 'id' => $otherId, 'version' => 3);
if (CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts')) {
// if ext id is submitted then set it null for contact to be deleted
if (!empty($submitted['external_identifier'])) {
$query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
CRM_Core_DAO::executeQuery($query);
}
civicrm_api('contact', 'delete', $otherParams);
CRM_Core_BAO_PrevNextCache::deleteItem($otherId);
}
// FIXME: else part
/* else { */
/* CRM_Core_Session::setStatus( ts('Do not have sufficient permission to delete duplicate contact.') ); */
/* } */
// CRM-15681 merge sub_types
if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) {
if ($main_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['main_details'])) {
$submitted['contact_sub_type'] = array_unique(array_merge($main_sub_types, $other_sub_types));
} else {
$submitted['contact_sub_type'] = $other_sub_types;
}
}
// **** Update contact related info for the main contact
if (!empty($submitted)) {
$submitted['contact_id'] = $mainId;
//update current employer field
if ($currentEmloyerId = CRM_Utils_Array::value('current_employer_id', $submitted)) {
if (!CRM_Utils_System::isNull($currentEmloyerId)) {
$submitted['current_employer'] = $submitted['current_employer_id'];
} else {
$submitted['current_employer'] = '';
}
unset($submitted['current_employer_id']);
}
//CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
if (!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])) {
$submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
}
if (!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])) {
$submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
}
CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $mainId);
unset($submitted);
}
CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject);
return TRUE;
}
示例7: 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})");
//.........这里部分代码省略.........
示例8: postProcess
//.........这里部分代码省略.........
//for checkbox and m-select format w/ VALUE_SEPERATOR
if (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select'))) {
$submitted[$key] = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $mergeValue) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
} else {
$submitted[$key] = $mergeValue;
}
}
} else {
if (in_array($htmlType, array('Multi-Select Country', 'Multi-Select State/Province'))) {
//we require submitted values should be in array format
if ($value) {
$mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
//hack to remove null values from array.
$mergeValue = array();
foreach ($mergeValueArray as $k => $v) {
if ($v != '') {
$mergeValue[] = $v;
}
}
$submitted[$key] = $mergeValue;
}
}
}
break;
default:
break;
}
}
}
// handle the related tables
if (isset($moveTables)) {
CRM_Dedupe_Merger::moveContactBelongings($this->_cid, $this->_oid, $moveTables, $tableOperations);
}
// move file custom fields
// FIXME: move this someplace else (one of the BAOs) after discussing
// where to, and whether CRM_Core_BAO_File::delete() shouldn't actually,
// like, delete a file...
require_once 'CRM/Core/BAO/File.php';
require_once 'CRM/Core/DAO/CustomField.php';
require_once 'CRM/Core/DAO/CustomGroup.php';
require_once 'CRM/Core/DAO/EntityFile.php';
require_once 'CRM/Core/Config.php';
if (!isset($customFiles)) {
$customFiles = array();
}
foreach ($customFiles as $customId) {
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
// get the contact_id -> file_id mapping
$fileIds = array();
$sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$this->_cid}, {$this->_oid})";
$dao =& CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
while ($dao->fetch()) {
$fileIds[$dao->entity_id] = $dao->file_id;
}
$dao->free();
// delete the main contact's file
if (!empty($fileIds[$this->_cid])) {
CRM_Core_BAO_File::delete($fileIds[$this->_cid], $this->_cid, $customId);
}
// move the other contact's file to main contact
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$this->_oid]} WHERE entity_id = {$this->_cid}";
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
$sql = "UPDATE civicrm_entity_file SET entity_id = {$this->_cid} WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$this->_oid]}";
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
}
// move view only custom fields CRM-5362
$viewOnlyCustomFields = array();
foreach ($submitted as $key => $value) {
$fid = (int) substr($key, 7);
if (array_key_exists($fid, $cFields) && CRM_Utils_Array::value('is_view', $cFields[$fid]['attributes'])) {
$viewOnlyCustomFields[$key] = $value;
}
}
//special case to set values for view only, CRM-5362
if (!empty($viewOnlyCustomFields)) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
$viewOnlyCustomFields['entityID'] = $this->_cid;
CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
}
// move other's belongings and delete the other contact
CRM_Dedupe_Merger::moveContactBelongings($this->_cid, $this->_oid);
$otherParams = array('contact_id' => $this->_oid);
if (CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts')) {
// if ext id is submitted then set it null for contact to be deleted
if (CRM_Utils_Array::value('external_identifier', $submitted)) {
$query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$this->_oid}";
CRM_Core_DAO::executeQuery($query);
}
civicrm_contact_delete($otherParams);
} else {
CRM_Core_Session::setStatus(ts('Do not have sufficient permission to delete duplicate contact.'));
}
if (isset($submitted)) {
$submitted['contact_id'] = $this->_cid;
CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $this->_cid);
}
CRM_Core_Session::setStatus(ts('The contacts have been merged.'));
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_cid}");
CRM_Utils_System::redirect($url);
}
示例9: civicrm_api3_custom_value_create
/**
* Sets custom values for an entity.
*
*
* @param $params expected keys are in format custom_fieldID:recordID or custom_groupName:fieldName:recordID
* for example:
// entity ID. You do not need to specify entity type, we figure it out based on the fields you're using
* 'entity_id' => 123,
// (omitting :id) inserts or updates a field in a single-valued group
* 'custom_6' => 'foo',
// custom_24 is checkbox or multiselect, so pass items as an array
* 'custom_24' => array('bar', 'baz'),
// in this case custom_33 is part of a multi-valued group, and we're updating record id 5
* 'custom_33:5' => value,
// inserts new record in multi-valued group
* 'custom_33:-1' => value,
// inserts another new record in multi-valued group
* 'custom_33:-2' => value,
// you can use group_name:field_name instead of ID
* 'custom_some_group:my_field => 'myinfo',
// updates record ID 8 in my_other_field in multi-valued some_big_group
* 'custom_some_big_group:my_other_field:8 => 'myinfo',
*
*
* @return array('values' => TRUE) or array('is_error' => 1, 'error_message' => 'what went wrong')
*
* @access public
*
*/
function civicrm_api3_custom_value_create($params)
{
civicrm_api3_verify_mandatory($params, NULL, array('entity_id'));
if (substr($params['entity_table'], 0, 7) == 'civicrm') {
$params['entity_table'] = substr($params['entity_table'], 8, 7);
}
$create = array('entityID' => $params['entity_id']);
// Translate names and
//Convert arrays to multi-value strings
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
foreach ($params as $id => $param) {
if (is_array($param)) {
$param = $sp . implode($sp, $param) . $sp;
}
list($c, $id) = explode('_', $id, 2);
if ($c != 'custom') {
continue;
}
list($i, $n, $x) = explode(':', $id);
if (is_numeric($i)) {
$key = $i;
$x = $n;
} else {
// Lookup names if ID was not supplied
$key = CRM_Core_BAO_CustomField::getCustomFieldID($n, $i);
if (!$key) {
continue;
}
}
if ($x && is_numeric($x)) {
$key .= '_' . $x;
}
$create['custom_' . $key] = $param;
}
$result = CRM_Core_BAO_CustomValueTable::setValues($create);
if ($result['is_error']) {
return civicrm_api3_create_error($result['error_message']);
}
return civicrm_api3_create_success(TRUE, $params);
}
示例10: moveAllBelongings
//.........这里部分代码省略.........
}
$submitted[$key] = $mergeValue;
}
}
break;
default:
break;
}
}
}
// **** Do file custom fields related migrations
// FIXME: move this someplace else (one of the BAOs) after discussing
// where to, and whether CRM_Core_BAO_File::deleteFileReferences() shouldn't actually,
// like, delete a file...
if (!isset($customFiles)) {
$customFiles = array();
}
foreach ($customFiles as $customId) {
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
// get the contact_id -> file_id mapping
$fileIds = array();
$sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$fileIds[$dao->entity_id] = $dao->file_id;
}
$dao->free();
// delete the main contact's file
if (!empty($fileIds[$mainId])) {
CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId);
}
// move the other contact's file to main contact
//NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
if (CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")) {
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
} else {
$sql = "INSERT INTO {$tableName} ( entity_id, {$columnName} ) VALUES ( {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql);
if (CRM_Core_DAO::singleValueQuery("\n SELECT id\n FROM civicrm_entity_file\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}")) {
$sql = "\n UPDATE civicrm_entity_file\n SET entity_id = {$mainId}\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}";
} else {
$sql = "\n INSERT INTO civicrm_entity_file ( entity_table, entity_id, file_id )\n VALUES ( '{$tableName}', {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql);
}
// move view only custom fields CRM-5362
$viewOnlyCustomFields = array();
foreach ($submitted as $key => $value) {
$fid = (int) substr($key, 7);
if (array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])) {
$viewOnlyCustomFields[$key] = $value;
}
}
// special case to set values for view only, CRM-5362
if (!empty($viewOnlyCustomFields)) {
$viewOnlyCustomFields['entityID'] = $mainId;
CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
}
if (!$checkPermissions || CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts')) {
// if ext id is submitted then set it null for contact to be deleted
if (!empty($submitted['external_identifier'])) {
$query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
CRM_Core_DAO::executeQuery($query);
}
civicrm_api3('contact', 'delete', array('id' => $otherId));
}
// CRM-15681 merge sub_types
if ($other_sub_types = CRM_Utils_Array::value('contact_sub_type', $migrationInfo['other_details'])) {
if ($main_sub_types = CRM_Utils_Array::value('contact_sub_type', $migrationInfo['main_details'])) {
$submitted['contact_sub_type'] = array_unique(array_merge($main_sub_types, $other_sub_types));
} else {
$submitted['contact_sub_type'] = $other_sub_types;
}
}
// **** Update contact related info for the main contact
if (!empty($submitted)) {
$submitted['contact_id'] = $mainId;
//update current employer field
if ($currentEmloyerId = CRM_Utils_Array::value('current_employer_id', $submitted)) {
if (!CRM_Utils_System::isNull($currentEmloyerId)) {
$submitted['current_employer'] = $submitted['current_employer_id'];
} else {
$submitted['current_employer'] = '';
}
unset($submitted['current_employer_id']);
}
//CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
if (!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])) {
$submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
}
if (!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])) {
$submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
}
CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $mainId);
}
CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject);
self::createMergeActivities($mainId, $otherId);
return TRUE;
}
示例11: hrrecruitment_civicrm_postProcess
/**
* Implementation of hook_civicrm_postProcess
*
* @params string $formName - the name of the form
* object $form - reference to the form object
* @return void
*/
function hrrecruitment_civicrm_postProcess($formName, &$form)
{
if ($formName == 'CRM_Case_Form_Activity') {
if (!empty($form->_submitValues['evaluationProfile']) && isset($_POST['new_activity_id'])) {
//Save evaluation profile fields
$pID = $form->_submitValues['evaluationProfile'];
$profileContactType = CRM_Core_BAO_UFGroup::getContactType($pID);
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $profileContactType);
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
$applicantID = $form->_currentlyViewedContactId;
if (count($ids)) {
$applicantID = CRM_Utils_Array::value(0, $ids);
}
$applicantID = CRM_Contact_BAO_Contact::createProfileContact($form->_submitValues, CRM_Core_DAO::$_nullArray, $applicantID, NULL, $pID);
//set custom fields values
$profileFields = CRM_Core_BAO_UFGroup::getFields($form->_submitValues['evaluationProfile']);
foreach ($profileFields as $profileFieldKey => $profileFieldVal) {
$params = array("entityID" => $_POST['new_activity_id'], $profileFieldKey => $form->_submitValues[$profileFieldKey]);
CRM_Core_BAO_CustomValueTable::setValues($params);
}
}
}
}
示例12: testSetGetValuesYesNoRadio
function testSetGetValuesYesNoRadio()
{
$params = array();
$contactID = Contact::createIndividual();
//create Custom Group
$customGroup = Custom::createGroup($params, 'Individual', true);
//create Custom Field of type YesNo(Boolean) Radio
$fields = array('groupId' => $customGroup->id, 'dataType' => 'Boolean', 'htmlType' => 'Radio');
$customField = Custom::createField($params, $fields);
// Retrieve the field ID for sample custom field 'test_Boolean'
$params = array('label' => 'test_Boolean');
$field = array();
//get field Id
require_once 'CRM/Core/BAO/CustomField.php';
CRM_Core_BAO_CustomField::retrieve($params, $field);
$fieldID = $field['id'];
// valid boolean value '1' for Boolean Radio
$yesNo = '1';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo);
require_once 'CRM/Core/BAO/CustomValueTable.php';
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the YesNo radio value is stored
$values = array();
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
$this->assertEquals($values['custom_1_1'], $yesNo, 'Verify that the date value is stored for contact ' . $contactID);
// Now set YesNo radio to an invalid boolean value and try to reset
$badYesNo = '20';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo);
require_once 'CRM/Core/BAO/CustomValueTable.php';
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
// Check that the error flag is set AND that custom date value has not been modified
$this->assertEquals($result['is_error'], $yesNo, 'Verify that is_error = 1 when bad boolen value is passed.');
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['custom_1_1'], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID);
// Cleanup
Custom::deleteField($customField);
Custom::deleteGroup($customGroup);
Contact::delete($contactID);
}