本文整理汇总了PHP中CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的具体用法?PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer怎么用?PHP CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact_Utils
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
//.........这里部分代码省略.........
$params['contact_sub_type'] = 'null';
} else {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'], TRUE)) {
// we'll need to fix tests to handle this
// CRM-7925
CRM_Core_Error::fatal(ts('The Contact Sub Type does not match the Contact type for this record'));
}
if (is_array($params['contact_sub_type'])) {
$params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
} else {
$params['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . trim($params['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
}
}
} else {
// Reset the value.
// CRM-101XX.
$params['contact_sub_type'] = 'null';
}
// Fixed contact source.
if (isset($params['contact_source'])) {
$params['source'] = $params['contact_source'];
}
// Fix for preferred communication method.
$prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
if ($prefComm && is_array($prefComm)) {
unset($params['preferred_communication_method']);
$newPref = array();
foreach ($prefComm as $k => $v) {
if ($v) {
$newPref[$k] = $v;
}
}
$prefComm = $newPref;
if (is_array($prefComm) && !empty($prefComm)) {
$prefComm = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($prefComm)) . CRM_Core_DAO::VALUE_SEPARATOR;
$contact->preferred_communication_method = $prefComm;
} else {
$contact->preferred_communication_method = '';
}
}
$allNull = $contact->copyValues($params);
$contact->id = CRM_Utils_Array::value('contact_id', $params);
if ($contact->contact_type == 'Individual') {
$allNull = FALSE;
// Format individual fields.
CRM_Contact_BAO_Individual::format($params, $contact);
} elseif ($contact->contact_type == 'Household') {
if (isset($params['household_name'])) {
$allNull = FALSE;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
}
} elseif ($contact->contact_type == 'Organization') {
if (isset($params['organization_name'])) {
$allNull = FALSE;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
}
}
$privacy = CRM_Utils_Array::value('privacy', $params);
if ($privacy && is_array($privacy) && !empty($privacy)) {
$allNull = FALSE;
foreach (self::$_commPrefs as $name) {
$contact->{$name} = CRM_Utils_Array::value($name, $privacy, FALSE);
}
}
// Since hash was required, make sure we have a 0 value for it (CRM-1063).
// @todo - does this mean we can remove this block?
// Fixed in 1.5 by making hash optional, only do this in create mode, not update.
if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
$allNull = FALSE;
$contact->hash = md5(uniqid(rand(), TRUE));
}
// Even if we don't need $employerId, it's important to call getFieldValue() before
// the contact is saved because we want the existing value to be cached.
// createCurrentEmployerRelationship() needs the old value not the updated one. CRM-10788
$employerId = empty($contact->id) ? NULL : CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id');
if (!$allNull) {
$contact->save();
CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
}
if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) {
// Create current employer.
$newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
$newContact = FALSE;
if (empty($params['contact_id'])) {
$newContact = TRUE;
}
if ($newEmployer) {
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
} else {
if ($employerId) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
}
}
}
// Update cached employer name.
if ($contact->contact_type == 'Organization') {
CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
}
return $contact;
}
示例2: add
/**
* takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function add(&$params)
{
$contact =& new CRM_Contact_DAO_Contact();
if (empty($params)) {
return;
}
//fixed contact source
if (isset($params['contact_source'])) {
$params['source'] = $params['contact_source'];
}
//fix for preferred communication method
$prefComm = CRM_Utils_Array::value('preferred_communication_method', $params);
if ($prefComm && is_array($prefComm)) {
unset($params['preferred_communication_method']);
$newPref = array();
foreach ($prefComm as $k => $v) {
if ($v) {
$newPref[$k] = $v;
}
}
$prefComm = $newPref;
if (is_array($prefComm) && !empty($prefComm)) {
$prefComm = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($prefComm)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
$contact->preferred_communication_method = $prefComm;
} else {
$contact->preferred_communication_method = '';
}
}
$allNull = $contact->copyValues($params);
$contact->id = CRM_Utils_Array::value('contact_id', $params);
if ($contact->contact_type == 'Individual') {
$allNull = false;
//format individual fields
require_once "CRM/Contact/BAO/Individual.php";
CRM_Contact_BAO_Individual::format($params, $contact);
} else {
if ($contact->contact_type == 'Household') {
if (isset($params['household_name'])) {
$allNull = false;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, '');
}
} else {
if ($contact->contact_type == 'Organization') {
if (isset($params['organization_name'])) {
$allNull = false;
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
}
}
}
}
// privacy block
$privacy = CRM_Utils_Array::value('privacy', $params);
if ($privacy && is_array($privacy) && !empty($privacy)) {
$allNull = false;
foreach (self::$_commPrefs as $name) {
$contact->{$name} = CRM_Utils_Array::value($name, $privacy, false);
}
}
// since hash was required, make sure we have a 0 value for it, CRM-1063
// fixed in 1.5 by making hash optional
// only do this in create mode, not update
if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) {
$allNull = false;
$contact->hash = md5(uniqid(rand(), true));
}
if (!$allNull) {
$contact->save();
require_once 'CRM/Core/BAO/Log.php';
CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id);
}
if ($contact->contact_type == 'Individual' && array_key_exists('current_employer', $params)) {
// create current employer
if ($params['current_employer']) {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $params['current_employer']);
} else {
//unset if employer id exits
if ($employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id')) {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
}
}
}
//update cached employee name
if ($contact->contact_type == 'Organization') {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id);
//.........这里部分代码省略.........