本文整理匯總了PHP中CRM_Contact_DAO_Contact::free方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Contact_DAO_Contact::free方法的具體用法?PHP CRM_Contact_DAO_Contact::free怎麽用?PHP CRM_Contact_DAO_Contact::free使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Contact_DAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_DAO_Contact::free方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processNormalization
static function processNormalization($fromContactId, $toContactId)
{
$processInfo = array('name' => 0, 'phone' => 0, 'address' => 0);
if (empty($fromContactId) || empty($toContactId)) {
return $processInfo;
}
$contactIds = range($fromContactId, $toContactId);
$normalization = CRM_Utils_Normalize::singleton();
$formattedContactIds = $formattedPhoneIds = $formattedAddressIds = array();
foreach ($contactIds as $contactId) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $contactId;
if ($contact->find()) {
$params = array('id' => $contactId, 'contact_id' => $contactId);
$orgContactValues = array();
CRM_Contact_BAO_Contact::retrieve($params, $orgContactValues);
//update contacts name fields.
$formatNameValues = array();
foreach ($normalization->getNameFields() as $field) {
$nameValue = CRM_Utils_Array::value($field, $orgContactValues);
if (empty($nameValue)) {
continue;
}
$formatNameValues[$field] = $nameValue;
}
if (!empty($formatNameValues)) {
$formatNameValues['contact_type'] = $orgContactValues['contact_type'];
$formattedNameValues = $formatNameValues;
//format name values
$normalization->normalize_contact($formattedNameValues);
//check formatted diff, only update if there is difference.
$formatDiff = array_diff($formatNameValues, $formattedNameValues);
if (!empty($formatDiff)) {
$formattedNameValues['id'] = $formattedNameValues['contact_id'] = $orgContactValues['id'];
$formattedNameValues['contact_type'] = $orgContactValues['contact_type'];
$contactUpdated = CRM_Contact_BAO_Contact::add($formattedNameValues);
if ($contactUpdated->id) {
$formattedContactIds[$contactUpdated->id] = $contactUpdated->id;
}
$contactUpdated->free();
}
}
//update phone fields.
if (isset($orgContactValues['phone']) && is_array($orgContactValues['phone'])) {
foreach ($orgContactValues['phone'] as $cnt => $orgPhoneValues) {
if (!isset($orgPhoneValues['id']) || empty($orgPhoneValues['id']) || empty($orgPhoneValues['phone'])) {
continue;
}
$formattedPhoneValues = $orgPhoneValues;
//format phone fields
$normalization->normalize_phone($formattedPhoneValues);
//do check for formatted difference, than only update.
$formattedDiff = array_diff_assoc($orgPhoneValues, $formattedPhoneValues);
if (!empty($formattedDiff)) {
$phoneUpdated = CRM_Core_BAO_Phone::add($formattedPhoneValues);
if ($phoneUpdated->id) {
$formattedPhoneIds[$phoneUpdated->id] = $phoneUpdated->id;
}
$phoneUpdated->free();
}
}
}
//update address.
if (isset($orgContactValues['address']) && is_array($orgContactValues['address'])) {
foreach ($orgContactValues['address'] as $cnt => $orgAddressValues) {
if (!isset($orgAddressValues['id']) || empty($orgAddressValues['id'])) {
continue;
}
$formattedAddressValues = $orgAddressValues;
//format addrees fields
$normalization->normalize_address($formattedAddressValues);
//do check for formatted difference, than only update.
$formattedDiff = array_diff($orgAddressValues, $formattedAddressValues);
if (!empty($formattedDiff)) {
$addressUpdated = CRM_Core_BAO_Address::add($formattedAddressValues, FALSE);
if ($addressUpdated->id) {
$formattedAddressIds[$addressUpdated->id] = $addressUpdated->id;
}
$addressUpdated->free();
}
}
}
}
$contact->free();
}
$processInfo = array('name' => $formattedContactIds, 'phone' => $formattedPhoneIds, 'address' => $formattedAddressIds);
return $processInfo;
}