本文整理汇总了PHP中CRM_Dedupe_Finder类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Dedupe_Finder类的具体用法?PHP CRM_Dedupe_Finder怎么用?PHP CRM_Dedupe_Finder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Dedupe_Finder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_dwutils_get_deduped_contact
function civicrm_dwutils_get_deduped_contact($params) {
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
$fields = array();
foreach($params as $key => $value) {
if(strncmp($key, 'fields_', 7) == 0) {
$new_key = str_replace('fields_', '', $key);
$fields[$new_key] = 1;
unset($params[$key]);
}
}
print_r($fields);
$contact_id = CRM_Utils_Array::value( 0, $ids );
$contact_result =& CRM_Contact_BAO_Contact::createProfileContact( $params, $fields, $contact_id );
return $contact_result;
}
示例2: testDupesByParams
public function testDupesByParams()
{
// make dupe checks based on based on following contact sets:
// FIRST - LAST - EMAIL
// ---------------------------------
// robin - hood - robin@example.com
// robin - hood - hood@example.com
// robin - dale - robin@example.com
// little - dale - dale@example.com
// will - dale - dale@example.com
// will - dale - will@example.com
// will - dale - will@example.com
// contact data set
// FIXME: move create params to separate function
$params = array(array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual'), array('first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual'));
$count = 1;
// TODO: This is not an API test!!
foreach ($params as $param) {
$param['version'] = 3;
$contact = civicrm_api('contact', 'create', $param);
$params = array('contact_id' => $contact['id'], 'street_address' => 'Ambachtstraat 23', 'location_type_id' => 1, 'version' => 3);
$result = civicrm_api('address', 'create', $params);
$contactIds[$count++] = $contact['id'];
}
// verify that all contacts have been created separately
$this->assertEquals(count($contactIds), 7, 'Check for number of contacts.');
$dao = new CRM_Dedupe_DAO_RuleGroup();
$dao->contact_type = 'Individual';
$dao->used = 'General';
$dao->is_default = 1;
$dao->find(TRUE);
$fields = array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'street_address' => 'Ambachtstraat 23');
$errorScope = CRM_Core_TemporaryErrorScope::useException();
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'General');
// Check with default Individual-General rule
$this->assertEquals(count($ids), 2, 'Check Individual-General rule for dupesByParams().');
// delete all created contacts
foreach ($contactIds as $contactId) {
Contact::delete($contactId);
}
}
示例3: checkDuplicateContacts
/**
* Function to that checks for duplicate contacts
*
* @param array $fields fields array which are submitted
* @param array $error error message array
* @param int $contactID contact id
* @param string $contactType contact type
*/
static function checkDuplicateContacts(&$fields, &$errors, $contactID, $contactType)
{
// if this is a forced save, ignore find duplicate rule
if (!CRM_Utils_Array::value('_qf_Contact_upload_duplicate', $fields)) {
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $contactType);
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, 'Fuzzy', array($contactID));
if ($ids) {
$viewUrls = array();
$editUrls = array();
require_once 'CRM/Contact/BAO/Contact/Utils.php';
list($viewUrls, $editUrls, $mergeUrl) = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, true, true, $contactID);
$viewUrl = implode(', ', $viewUrls);
$editUrl = implode(', ', $editUrls);
$errors['_qf_default'] = ts('One matching contact was found.', array('count' => count($editUrls), 'plural' => '%count matching contacts were found.'));
$errors['_qf_default'] .= '<br />';
$errors['_qf_default'] .= ts('If you need to verify if this is the same contact, click here - %1 - to VIEW the existing contact in a new tab.', array(1 => $viewUrl, 'count' => count($viewUrls), 'plural' => 'If you need to verify whether one of these is the same contact, click here - %1 - to VIEW the existing contact in a new tab.'));
$errors['_qf_default'] .= '<br />';
$errors['_qf_default'] .= ts('If you know the record you are creating is a duplicate, click here - %1 - to EDIT the original record instead.', array(1 => $editUrl));
$errors['_qf_default'] .= '<br />';
//allow to merge with matching contact, CRM-3160
if (!empty($mergeUrl)) {
$errors['_qf_default'] .= ts('If you know the record you are editing is a duplicate, click here - %1 - to MERGE with the existing record instead.', array(1 => $mergeUrl));
$errors['_qf_default'] .= '<br />';
}
$errors['_qf_default'] .= ts('If you are sure this is NOT a duplicate, click the "Save Matching Contact" button (this button is located at the bottom of the Contact Details section below).');
// let smarty know that there are duplicates
$template =& CRM_Core_Smarty::singleton();
$template->assign('isDuplicate', 1);
} else {
if (CRM_Utils_Array::value('_qf_Contact_refresh_dedupe', $fields)) {
// add a session message for no matching contacts
CRM_Core_Session::setStatus('No matching contact found.');
}
}
}
}
示例4: formRule
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param CRM_Core_Form $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self->_values);
if (CRM_Utils_Array::value('auto_renew', $fields) && CRM_Utils_Array::value('payment_processor_id', $fields) == 0) {
$errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.');
}
if (!empty($fields['selectMembership']) && $fields['selectMembership'] != 'no_thanks' || !empty($fields['priceSetId']) && $self->_useForMember) {
$isTest = $self->_action & CRM_Core_Action::PREVIEW ? TRUE : FALSE;
$lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $isTest, TRUE);
$membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
$unallowedOrgs = array();
foreach (array_keys($lifeMember) as $memTypeId) {
$unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
}
}
//check for atleast one pricefields should be selected
if (!empty($fields['priceSetId']) && empty($self->_ccid)) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$check = array();
$membershipIsActive = TRUE;
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && empty($fields["price_{$priceField->id}"]) && array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
$otherAmount = $priceField->id;
} elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = CRM_Utils_Rule::cleanMoney($fields["price_{$priceField->id}"]);
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
$check[] = $priceField->id;
}
}
$currentMemberships = NULL;
if ($membershipIsActive) {
$is_test = $self->_mode != 'live' ? 1 : 0;
$memContactID = $self->_membershipContactID;
// For anonymous user check using dedupe rule
// if user has Cancelled Membership
if (!$memContactID) {
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$memContactID = CRM_Utils_Array::value(0, $ids);
}
$currentMemberships = CRM_Member_BAO_Membership::getContactsCancelledMembership($memContactID, $is_test);
$errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
if (!is_array($fields['price_' . $fieldKey]) && isset($fieldValue['options'][$fields['price_' . $fieldKey]])) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]]) && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
}
} else {
if (is_array($fields['price_' . $fieldKey])) {
foreach (array_keys($fields['price_' . $fieldKey]) as $key) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$key]) && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])));
}
}
}
}
}
}
}
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required'] && $self->_values['amount_block_is_active']) {
$membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
//.........这里部分代码省略.........
示例5: processFormSubmission
//.........这里部分代码省略.........
$behalfOrganization[$block][$newKey] = $val;
}
}
}
unset($params['onbehalf_location']);
}
if (!empty($params['onbehalf[image_URL]'])) {
$behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
}
}
// check for profile double opt-in and get groups to be subscribed
$subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
// since we are directly adding contact to group lets unset it from mailing
if (!empty($addToGroups)) {
foreach ($addToGroups as $groupId) {
if (isset($subscribeGroupIds[$groupId])) {
unset($subscribeGroupIds[$groupId]);
}
}
}
foreach ($addToGroups as $k) {
if (array_key_exists($k, $subscribeGroupIds)) {
unset($addToGroups[$k]);
}
}
if (empty($contactID)) {
$dupeParams = $params;
if (!empty($dupeParams['onbehalf'])) {
unset($dupeParams['onbehalf']);
}
if (!empty($dupeParams['honor'])) {
unset($dupeParams['honor']);
}
$dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$contactID = CRM_Utils_Array::value(0, $ids);
// Fetch default greeting id's if creating a contact
if (!$contactID) {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if (!isset($params[$greeting])) {
$params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
}
}
}
$contactType = NULL;
} else {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $contactType, TRUE);
// Make the contact ID associated with the contribution available at the Class level.
// Also make available to the session.
//@todo consider handling this in $this->getContactID();
$this->set('contactID', $contactID);
$this->_contactID = $contactID;
//get email primary first if exist
$subscriptionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscriptionEmail['email']) {
$subscriptionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
}
// If onbehalf-of-organization contribution / signup, add organization
示例6: createCurrentEmployerRelationship
/**
* Create Current employer relationship for a individual.
*
* @param int $contactID
* Contact id of the individual.
* @param $organization
* (id or name).
* @param int $previousEmployerID
* @param bool $newContact
*
*/
public static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL, $newContact = FALSE)
{
//if organization name is passed. CRM-15368,CRM-15547
if ($organization && !is_numeric($organization)) {
$organizationParams['organization_name'] = $organization;
$dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupeParams['check_permission'] = FALSE;
$dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
if (is_array($dupeIDs) && !empty($dupeIDs)) {
// we should create relationship only w/ first org CRM-4193
foreach ($dupeIDs as $orgId) {
$organization = $orgId;
break;
}
} else {
//create new organization
$newOrg = array('contact_type' => 'Organization', 'organization_name' => $organization);
$org = CRM_Contact_BAO_Contact::create($newOrg);
$organization = $org->id;
}
}
if ($organization && is_numeric($organization)) {
$cid = array('contact' => $contactID);
// get the relationship type id of "Employee of"
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
}
// create employee of relationship
$relationshipParams = array('is_active' => TRUE, 'relationship_type_id' => $relTypeId . '_a_b', 'contact_check' => array($organization => TRUE));
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::legacyCreateMultiple($relationshipParams, $cid);
// In case we change employer, clean previous employer related records.
if (!$previousEmployerID && !$newContact) {
$previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id');
}
if ($previousEmployerID && $previousEmployerID != $organization) {
self::clearCurrentEmployer($contactID, $previousEmployerID);
}
// set current employer
self::setCurrentEmployer(array($contactID => $organization));
$relationshipParams['relationship_ids'] = $relationshipIds;
// Handle related memberships. CRM-3792
self::currentEmployerRelatedMembership($contactID, $organization, $relationshipParams, $duplicate, $previousEmployerID);
}
}
示例7: _woocommerce_civicrm_add_update_contact
function _woocommerce_civicrm_add_update_contact($cid, $order)
{
if (!civicrm_wp_initialize()) {
return;
}
$action = 'create';
//try {
$contact = array();
if ($cid != 0) {
try {
$params = array('contact_id' => $cid, 'return' => array('id', 'source', 'first_name', 'last_name'));
$contact = civicrm_api3('contact', 'getsingle', $params);
} catch (CiviCRM_Exception $e) {
CRM_Core_Error::debug_log_message('Not able to find contact');
return FALSE;
}
}
// Create contact
// Prepare array to update contact via civi API.
$email = '';
$fname = '';
$lname = '';
$cid = '';
if (!empty($order->shipping_email)) {
$email = $order->shipping_email;
$fname = $order->shipping_first_name;
$lname = $order->shipping_last_name;
} else {
$email = $order->billing_email;
$fname = $order->billing_first_name;
$lname = $order->billing_last_name;
}
// Try to get contact Id using dedupe
$contact['first_name'] = $fname;
$contact['last_name'] = $lname;
$contact['email'] = $email;
$dedupeParams = CRM_Dedupe_Finder::formatParams($contact, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised');
if ($ids) {
$cid = $ids['0'];
$action = 'update';
}
$contact['sort_name'] = "{$lname}, {$fname}";
$contact['display_name'] = "{$fname} {$lname}";
if (!$cid) {
$contact['contact_type'] = 'Individual';
}
if (isset($contact['contact_subtype'])) {
unset($contact['contact_subtype']);
}
if (empty($contact['source'])) {
$contact['source'] = 'Woocommerce purchase';
}
//CRM_Core_Error::debug_var('Contact', $contact);
// Create contact or update existing contact.
//if ($contact_status == 'new' && !$contact_info['values'][$cid]['first_name'] && !$contact_info['values'][$cid]['last_name']) {
try {
$result = civicrm_api3('contact', 'create', $contact);
$cid = $result['id'];
$name = trim($contact['display_name']);
$name = !empty($name) ? $contact['display_name'] : $cid;
$admin_url = get_admin_url();
$contact_url = "<a href='" . $admin_url . "admin.php?page=CiviCRM&q=civicrm/contact/view&reset=1&cid=" . $cid . "'>View</a>";
// Add order note
if ($action == 'update') {
$note = 'CiviCRM Contact Updated - ' . $contact_url;
} else {
$note = 'Created new CiviCRM Contact - ' . $contact_url;
}
$order->add_order_note($note);
} catch (Exception $e) {
CRM_Core_Error::debug_log_message('Not able to create/update contact');
return FALSE;
}
//}
//$loc_types = $GLOBALS["WooCommerceCiviCRMLocationTypes"];
$woocommerce_billing = $loc_types['woocommerce-billing'];
$woocommerce_shipping = $loc_types['woocommerce-shipping'];
$civicrm_billing = get_option('woocommerce_civicrm_billing_location_type_id', 5);
$civicrm_shipping = get_option('woocommerce_civicrm_shipping_location_type_id', 1);
try {
$existing_addresses = civicrm_api3('address', 'get', array('contact_id' => $cid));
$existing_addresses = $existing_addresses['values'];
$existing_phones = civicrm_api3('phone', 'get', array('contact_id' => $cid));
$existing_phones = $existing_phones['values'];
$shipping_address = $billing_address = array('contact_id' => $cid);
$address_types = array('billing', 'shipping');
foreach ($address_types as $address_type) {
// Process Phone
$phone_exists = FALSE;
if (!empty($order->{$address_type . '_phone'})) {
$phone = array('phone_type_id' => 1, 'location_type_id' => ${'civicrm_' . $address_type}, 'phone' => $order->{$address_type . '_phone'}, 'contact_id' => $cid);
foreach ($existing_phones as $existing_phone) {
if ($existing_phone['location_type_id'] == ${'civicrm_' . $address_type}) {
$phone['id'] = $existing_phone['id'];
}
if ($existing_phone['phone'] == $phone['phone']) {
$phone_exists = TRUE;
}
//.........这里部分代码省略.........
示例8: postProcess
/**
* Form submission of petition signature.
*/
public function postProcess()
{
$tag_name = Civi::settings()->get('tag_unconfirmed');
if ($tag_name) {
// Check if contact 'email confirmed' tag exists, else create one
// This should be in the petition module initialise code to create a default tag for this
$tag_params['name'] = $tag_name;
$tag_params['version'] = 3;
$tag = civicrm_api('tag', 'get', $tag_params);
if ($tag['count'] == 0) {
//create tag
$tag_params['description'] = $tag_name;
$tag_params['is_reserved'] = 1;
$tag_params['used_for'] = 'civicrm_contact';
$tag = civicrm_api('tag', 'create', $tag_params);
}
$this->_tagId = $tag['id'];
}
// export the field values to be used for saving the profile form
$params = $this->controller->exportValues($this->_name);
$session = CRM_Core_Session::singleton();
// format params
$params['last_modified_id'] = $session->get('userID');
$params['last_modified_date'] = date('YmdHis');
if ($this->_action & CRM_Core_Action::ADD) {
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
if (isset($this->_surveyId)) {
$params['sid'] = $this->_surveyId;
}
if (isset($this->_contactId)) {
$params['contactId'] = $this->_contactId;
}
// if logged in user, skip dedupe
if ($this->_loggedIn) {
$ids[0] = $this->_contactId;
} else {
// dupeCheck - check if contact record already exists
// code modified from api/v2/Contact.php-function civicrm_contact_check_params()
$params['contact_type'] = $this->_ctype;
//TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working
// ignore soft deleted contacts
//$params['is_deleted'] = 0;
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
$dedupeParams['check_permission'] = '';
//dupesByParams($params, $ctype, $level = 'Unsupervised', $except = array())
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']);
}
$petition_params['id'] = $this->_surveyId;
$petition = array();
CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition);
switch (count($ids)) {
case 0:
//no matching contacts - create a new contact
// Add a source for this new contact
$params['source'] = ts('Petition Signature') . ' ' . $this->petition['title'];
if ($this->petition['bypass_confirm']) {
// send thank you email directly, bypassing confirmation
$this->_sendEmailMode = self::EMAIL_THANK;
// Set status for signature activity to completed
$params['statusId'] = 2;
} else {
$this->_sendEmailMode = self::EMAIL_CONFIRM;
// Set status for signature activity to scheduled until email is verified
$params['statusId'] = 1;
}
break;
case 1:
$this->_contactId = $params['contactId'] = $ids[0];
// check if user has already signed this petition - redirects to Thank You if true
$this->redirectIfSigned($params);
if ($this->petition['bypass_confirm']) {
// send thank you email directly, bypassing confirmation
$this->_sendEmailMode = self::EMAIL_THANK;
// Set status for signature activity to completed
$params['statusId'] = 2;
break;
}
// dedupe matched single contact, check for 'unconfirmed' tag
if ($tag_name) {
$tag = new CRM_Core_DAO_EntityTag();
$tag->entity_id = $this->_contactId;
$tag->tag_id = $this->_tagId;
if (!$tag->find()) {
// send thank you email directly, the user is known and validated
$this->_sendEmailMode = self::EMAIL_THANK;
// Set status for signature activity to completed
$params['statusId'] = 2;
} else {
// send email verification email
$this->_sendEmailMode = self::EMAIL_CONFIRM;
// Set status for signature activity to scheduled until email is verified
$params['statusId'] = 1;
}
}
break;
//.........这里部分代码省略.........
示例9: run
//.........这里部分代码省略.........
}
$this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $sourceParams, FALSE, NULL, FALSE));
//reload from cache table
$cacheKeyString = "merge {$contactType}";
$cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
$cacheKeyString .= $gid ? "_{$gid}" : '_0';
$stats = CRM_Dedupe_Merger::getMergeStatsMsg($cacheKeyString);
if ($stats) {
CRM_Core_Session::setStatus($stats);
// reset so we not displaying same message again
CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
}
$join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND\n pn.entity_id2 = de.contact_id2 )";
$where = "de.id IS NULL";
if ($context == 'conflicts') {
$where .= " AND pn.is_selected = 1";
}
$this->_mainContacts = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);
if (empty($this->_mainContacts)) {
if ($context == 'conflicts') {
// if the current screen was intended to list only selected contacts, move back to full dupe list
$sourceParams = 'reset=1&action=update';
if ($gid) {
$sourceParams .= "&gid={$gid}";
}
if ($rgid) {
$sourceParams .= "&rgid={$rgid}";
}
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $sourceParams));
}
if ($gid) {
$foundDupes = $this->get("dedupe_dupes_{$gid}");
if (!$foundDupes) {
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid);
}
$this->set("dedupe_dupes_{$gid}", $foundDupes);
} elseif (!empty($contactIds)) {
$foundDupes = $this->get("search_dedupe_dupes_{$gid}");
if (!$foundDupes) {
$foundDupes = CRM_Dedupe_Finder::dupes($rgid, $contactIds);
}
$this->get("search_dedupe_dupes_{$gid}", $foundDupes);
} else {
$foundDupes = $this->get('dedupe_dupes');
if (!$foundDupes) {
$foundDupes = CRM_Dedupe_Finder::dupes($rgid);
}
$this->set('dedupe_dupes', $foundDupes);
}
if (!$foundDupes) {
$ruleGroup = new CRM_Dedupe_BAO_RuleGroup();
$ruleGroup->id = $rgid;
$ruleGroup->find(TRUE);
$session = CRM_Core_Session::singleton();
$session->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroup->name)), ts('None Found'), 'info');
$url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1');
if ($context == 'search') {
$url = $session->readUserContext();
}
CRM_Utils_System::redirect($url);
} else {
$cids = array();
foreach ($foundDupes as $dupe) {
$cids[$dupe[0]] = 1;
$cids[$dupe[1]] = 1;
}
示例10: _civicrm_api3_contact_check_params
/**
* Check parameters passed in.
*
* This function is on it's way out.
*
* @param array $params
* @param bool $dupeCheck
*
* @return null
* @throws API_Exception
* @throws CiviCRM_API3_Exception
*/
function _civicrm_api3_contact_check_params(&$params, $dupeCheck)
{
switch (strtolower(CRM_Utils_Array::value('contact_type', $params))) {
case 'household':
civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
break;
case 'organization':
civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
break;
case 'individual':
civicrm_api3_verify_one_mandatory($params, NULL, array('first_name', 'last_name', 'email', 'display_name'));
break;
}
// Fixme: This really needs to be handled at a lower level. @See CRM-13123
if (isset($params['preferred_communication_method'])) {
$params['preferred_communication_method'] = CRM_Utils_Array::implodePadded($params['preferred_communication_method']);
}
if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'])) {
throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
}
}
if ($dupeCheck) {
// check for record already existing
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
// CRM-6431
// setting 'check_permission' here means that the dedupe checking will be carried out even if the
// person does not have permission to carry out de-dupes
// this is similar to the front end form
if (isset($params['check_permission'])) {
$dedupeParams['check_permission'] = $params['check_permission'];
}
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Unsupervised', array());
if (count($ids) > 0) {
throw new API_Exception("Found matching contacts: " . implode(',', $ids), "duplicate", array("ids" => $ids));
}
}
// The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability
if (!empty($params['current_employer'])) {
$organizationParams = array('organization_name' => $params['current_employer']);
$dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupParams['check_permission'] = FALSE;
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Supervised');
// check for mismatch employer name and id
if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
throw new API_Exception('Employer name and Employer id Mismatch');
}
// show error if multiple organisation with same name exist
if (empty($params['employer_id']) && count($dupeIds) > 1) {
throw new API_Exception('Found more than one Organisation with same Name.');
}
if ($dupeIds) {
$params['employer_id'] = $dupeIds[0];
} else {
$result = civicrm_api3('Contact', 'create', array('organization_name' => $params['current_employer'], 'contact_type' => 'Organization'));
$params['employer_id'] = $result['id'];
}
}
return NULL;
}
示例11: checkRegistration
/**
* Method to check if the user is already registered for the event
* and if result found redirect to the event info page
*
* @param array $fields the input form values(anonymous user)
* @param array $self event data
* @param boolean $isAdditional treat isAdditional participants a bit differently
* @param boolean $returnContactId just find and return the contactID match to use
* @param boolean $useDedupeRules force usage of dedupe rules
*
* @return void
* @access public
*/
static function checkRegistration($fields, &$self, $isAdditional = FALSE, $returnContactId = FALSE, $useDedupeRules = FALSE)
{
// CRM-3907, skip check for preview registrations
// CRM-4320 participant need to walk wizard
if (!$returnContactId && ($self->_mode == 'test' || $self->_allowConfirmation)) {
return FALSE;
}
$contactID = NULL;
$session = CRM_Core_Session::singleton();
if (!$isAdditional) {
$contactID = $self->getContactID();
}
if (!$contactID && is_array($fields) && $fields) {
//CRM-6996
//as we are allowing w/ same email address,
//lets check w/ other contact params.
if ($self->_values['event']['allow_same_participant_emails']) {
$params = $fields;
$level = $isAdditional ? 'Supervised' : 'Unsupervised';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
// disable permission based on cache since event registration is public page/feature.
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', $level);
$contactID = CRM_Utils_Array::value(0, $ids);
} else {
foreach ($fields as $fieldname => $fieldvalue) {
if (substr($fieldname, 0, 6) == 'email-') {
$emailString = trim($fieldvalue);
if (!empty($emailString)) {
$match = CRM_Contact_BAO_Contact::matchContactOnEmail($emailString, 'Individual');
if (!empty($match)) {
$contactID = $match->contact_id;
}
}
}
}
}
}
if ($returnContactId) {
// CRM-7377
// return contactID if contact already exists
return $contactID;
}
if ($contactID) {
$participant = new CRM_Event_BAO_Participant();
$participant->contact_id = $contactID;
$participant->event_id = $self->_values['event']['id'];
if (!empty($fields['participant_role']) && is_numeric($fields['participant_role'])) {
$participant->role_id = $fields['participant_role'];
} else {
$participant->role_id = $self->_values['event']['default_role_id'];
}
$participant->is_test = 0;
$participant->find();
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
while ($participant->fetch()) {
if (array_key_exists($participant->status_id, $statusTypes)) {
if (!$isAdditional && !$self->_values['event']['allow_same_participant_emails']) {
$registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$self->_values['event']['id']}&cid=0");
if ($self->_pcpId) {
$registerUrl .= '&pcpId=' . $self->_pcpId;
}
$status = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
$session->setStatus($status, ts('Oops.'), 'alert');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$self->_values['event']['id']}&noFullMsg=true");
if ($self->_action & CRM_Core_Action::PREVIEW) {
$url .= '&action=preview';
}
if ($self->_pcpId) {
$url .= '&pcpId=' . $self->_pcpId;
}
CRM_Utils_System::redirect($url);
}
if ($isAdditional) {
$status = ts("It looks like this participant is already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.");
$session->setStatus($status, ts('Oops.'), 'alert');
return $participant->id;
}
}
}
}
}
示例12: postProcess
/**
* Function to process the form
*
* @access public
*
* @return None
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->getName());
if (!$this->_contactID && isset($params['cms_create_account'])) {
foreach ($params as $key => $value) {
if (substr($key, 0, 5) == 'email' && !empty($value)) {
list($fieldName, $locTypeId) = CRM_Utils_System::explode('-', $key, 2);
$isPrimary = 0;
if ($locTypeId == 'Primary') {
$locTypeDefault = CRM_Core_BAO_LocationType::getDefault();
$locTypeId = NULL;
if ($locTypeDefault) {
$locTypeId = $locTypeDefault->id;
}
$isPrimary = 1;
}
$params['email'] = array();
$params['email'][1]['email'] = $value;
$params['email'][1]['location_type_id'] = $locTypeId;
$params['email'][1]['is_primary'] = $isPrimary;
}
}
}
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Unsupervised');
if ($ids) {
$this->_contactID = $ids['0'];
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID);
$this->set('contactID', $contactID);
if (!empty($params['email'])) {
$params['email'] = $params['email'][1]['email'];
}
CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email');
}
示例13: createHonorContact
/**
* Function to create is honor of
*
* @param array $params associated array of fields (by reference)
* @param int $honorId honor Id
* @param array $honorParams any params that should be send to the create function
*
* @return contact id
*/
static function createHonorContact(&$params, $honorId = NULL, $honorParams = array())
{
$honorParams = array_merge(array('first_name' => $params['honor_first_name'], 'last_name' => $params['honor_last_name'], 'prefix_id' => $params['honor_prefix_id'], 'email-Primary' => $params['honor_email']), $honorParams);
if (!$honorId) {
$honorParams['email'] = $params['honor_email'];
$dedupeParams = CRM_Dedupe_Finder::formatParams($honorParams, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$honorId = CRM_Utils_Array::value(0, $ids);
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($honorParams, CRM_Core_DAO::$_nullArray, $honorId);
return $contactID;
}
示例14: createCurrentEmployerRelationship
/**
* Create Current employer relationship for a individual
*
* @param int $contactID contact id of the individual
* @param string $organization it can be name or id of organization
*
* @access public
* @static
*/
static function createCurrentEmployerRelationship($contactID, $organization)
{
require_once 'CRM/Contact/BAO/Relationship.php';
$organizationId = null;
// if organization id is passed.
if (is_numeric($organization)) {
$organizationId = $organization;
} else {
$orgName = explode('::', $organization);
trim($orgName[0]);
$organizationParams = array();
$organizationParams['organization_name'] = $orgName[0];
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
$dedupeParams['check_permission'] = false;
$dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Fuzzy');
if (is_array($dupeIDs) && !empty($dupeIDs)) {
// we should create relationship only w/ first org CRM-4193
foreach ($dupeIDs as $orgId) {
$organizationId = $orgId;
break;
}
} else {
//create new organization
$newOrg = array('contact_type' => 'Organization', 'organization_name' => trim($orgName[0]));
$org = CRM_Contact_BAO_Contact::add($newOrg);
$organizationId = $org->id;
}
}
if ($organizationId) {
$cid = array('contact' => $contactID);
// get the relationship type id of "Employee of"
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
}
// create employee of relationship
$relationshipParams = array('is_active' => true, 'relationship_type_id' => $relTypeId . '_a_b', 'contact_check' => array($organizationId => true));
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid);
// In case we change employer, clean prveovious employer related records.
$previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id');
if ($previousEmployerID && $previousEmployerID != $organizationId) {
self::clearCurrentEmployer($contactID, $previousEmployerID);
}
// set current employer
self::setCurrentEmployer(array($contactID => $organizationId));
// handle related meberships. CRM-3792
self::currentEmployerRelatedMembership($contactID, $organizationId, $relationshipParams, $duplicate);
}
}
示例15: postProcess
/**
* @todo per totten's suggestion, wrap all these writes in a transaction;
* see http://wiki.civicrm.org/confluence/display/CRMDOC43/Transaction+Reference
*/
function postProcess()
{
$cid = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM'], NULL);
$values = $this->controller->exportValues();
$profileFields = array();
foreach ($this->getProfileIDs() as $profileID) {
$profileFields += CRM_Core_BAO_UFGroup::getFields($profileID);
}
$profileValues = array_intersect_key($values, $profileFields);
$activityValues = array_diff_key($values, $profileValues);
// Search for duplicate
if (!$cid) {
$dedupeParams = CRM_Dedupe_Finder::formatParams($profileValues, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
if ($ids) {
$cid = $ids[0];
}
}
$cid = CRM_Contact_BAO_Contact::createProfileContact($profileValues, $profileFields, $cid);
$activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create');
$projectNeeds = array();
foreach ($this->_needs as $need) {
$activityValues['volunteer_need_id'] = $need['id'];
$activityValues['activity_date_time'] = CRM_Utils_Array::value('start_time', $need);
$activityValues['assignee_contact_id'] = $cid;
$activityValues['is_test'] = $this->_mode === 'test' ? 1 : 0;
// below we assume that volunteers are always signing up only themselves;
// for now this is a safe assumption, but we may need to revisit this.
$activityValues['source_contact_id'] = $cid;
// Set status to Available if user selected Flexible Need, else set to Scheduled.
if (CRM_Utils_Array::value('is_flexible', $need)) {
$activityValues['status_id'] = CRM_Utils_Array::key('Available', $activity_statuses);
} else {
$activityValues['status_id'] = CRM_Utils_Array::key('Scheduled', $activity_statuses);
}
$activityValues['time_scheduled_minutes'] = CRM_Utils_Array::value('duration', $need);
CRM_Volunteer_BAO_Assignment::createVolunteerActivity($activityValues);
if (!array_key_exists($need['project_id'], $projectNeeds)) {
$projectNeeds[$need['project_id']] = array();
}
$need['role'] = $need['role_label'];
$need['description'] = $need['role_description'];
$need['duration'] = CRM_Utils_Array::value('duration', $need);
$projectNeeds[$need['project_id']][$need['id']] = $need;
}
// Send confirmation email to volunteer
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($cid);
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
if ($email) {
$tplParams = $this->prepareTplParams($projectNeeds);
$sendTemplateParams = array('contactId' => $cid, 'from' => "{$domainEmailName} <" . $domainEmailAddress . ">", 'groupName' => 'msg_tpl_workflow_volunteer', 'isTest' => $this->_mode === 'test', 'toName' => $displayName, 'toEmail' => $email, 'tplParams' => array("volunteer_projects" => $tplParams), 'valueName' => 'volunteer_registration');
$bcc = array();
foreach ($tplParams as $data) {
foreach ($data['contacts'] as $manager) {
$bcc[$manager['contact_id']] = "{$manager['display_name']} <{$manager['email']}>";
}
}
if (count($bcc)) {
$sendTemplateParams['bcc'] = implode(', ', $bcc);
}
CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
}
$statusMsg = ts('You are scheduled to volunteer. Thank you!', array('domain' => 'org.civicrm.volunteer'));
CRM_Core_Session::setStatus($statusMsg, '', 'success');
CRM_Utils_System::redirect($this->_destination);
}