本文整理汇总了PHP中CRM_Mailing_Event_BAO_Subscribe::commonSubscribe方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Mailing_Event_BAO_Subscribe::commonSubscribe方法的具体用法?PHP CRM_Mailing_Event_BAO_Subscribe::commonSubscribe怎么用?PHP CRM_Mailing_Event_BAO_Subscribe::commonSubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Mailing_Event_BAO_Subscribe
的用法示例。
在下文中一共展示了CRM_Mailing_Event_BAO_Subscribe::commonSubscribe方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
//.........这里部分代码省略.........
if (!empty($dupeParams['onbehalf'])) {
unset($dupeParams['onbehalf']);
}
$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
$contact_id = CRM_Utils_Array::value(0, $ids);
// Fetch default greeting id's if creating a contact
if (!$contact_id) {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if (!isset($params[$greeting])) {
$params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
}
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups, NULL, NULL, TRUE);
} else {
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, 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
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
// If onbehalf-of-organization contribution / signup, add organization
// and it's location.
if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
$ufFields = array();
foreach ($this->_fields['onbehalf'] as $name => $value) {
$ufFields[$name] = 1;
}
self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params, $ufFields);
} else {
if (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) {
// this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
// store current user id as related contact for later use for mailing / activity..
$this->_values['related_contact'] = $contactID;
$this->_params['related_contact'] = $contactID;
// swap contact like we do for on-behalf-org case, so parent/primary membership is affected
$contactID = $this->_membershipContactID;
}
}
// lets store the contactID in the session
// for things like tell a friend
$session = CRM_Core_Session::singleton();
if (!$session->get('userID')) {
$session->set('transaction.userID', $contactID);
} else {
$session->set('transaction.userID', NULL);
}
$this->_useForMember = $this->get('useForMember');
// store the fact that this is a membership and membership type is selected
$processMembership = FALSE;
if (!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks' || $this->_useForMember) {
$processMembership = TRUE;
示例2: processFormSubmission
//.........这里部分代码省略.........
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
// and it's location.
if (isset($this->_values['onbehalf_profile_id']) && isset($behalfOrganization['organization_name'])) {
$ufFields = array();
foreach ($this->_fields['onbehalf'] as $name => $value) {
$ufFields[$name] = 1;
}
self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params, $ufFields);
} elseif (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) {
// this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
// store current user id as related contact for later use for mailing / activity..
$this->_values['related_contact'] = $contactID;
$this->_params['related_contact'] = $contactID;
// swap contact like we do for on-behalf-org case, so parent/primary membership is affected
$contactID = $this->_membershipContactID;
}
// lets store the contactID in the session
// for things like tell a friend
$session = CRM_Core_Session::singleton();
if (!$session->get('userID')) {
$session->set('transaction.userID', $contactID);
} else {
$session->set('transaction.userID', NULL);
}
$this->_useForMember = $this->get('useForMember');
// store the fact that this is a membership and membership type is selected
if (!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks' || $this->_useForMember) {
if (!$this->_useForMember) {
$this->assign('membership_assign', TRUE);
$this->set('membershipTypeID', $this->_params['selectMembership']);
}
示例3: updateContactFields
/**
* Update contact fields.
*
* @param int $contactID
* @param array $params
* @param array $fields
* @param CRM_Core_Form $form
*
* @return int
*/
public static function updateContactFields($contactID, $params, $fields, &$form)
{
//add the contact to group, if add to group is selected for a
//particular uf group
// get the add to groups
$addToGroups = array();
if (!empty($form->_fields)) {
foreach ($form->_fields as $key => $value) {
if (!empty($value['add_to_group_id'])) {
$addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
}
}
}
// check for profile double opt-in and get groups to be subscribed
$subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
foreach ($addToGroups as $k) {
if (array_key_exists($k, $subscribeGroupIds)) {
unset($addToGroups[$k]);
}
}
// 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]);
}
}
}
if ($contactID) {
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
if (array_key_exists('contact_id', $params) && empty($params['contact_id'])) {
// we unset this here because the downstream function ignores the contactID we give it
// if it is set & it is difficult to understand the implications of 'fixing' this downstream
// but if we are passing a contact id into this function it's reasonable to assume we don't
// want it ignored
unset($params['contact_id']);
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, TRUE);
} else {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if (!isset($params[$greeting . '_id'])) {
$params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, NULL, $addToGroups, NULL, NULL, TRUE);
$form->set('contactID', $contactID);
}
//get email primary first if exist
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$form->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
return $contactID;
}
示例4: postProcess
//.........这里部分代码省略.........
if (!empty($addToGroupId)) {
//run same check whether group is a mailing list
$groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id');
$groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
//filter group of mailing type and unset it from params
if (in_array(2, $groupType) && !empty($result['email']) && CRM_Core_BAO_UFGroup::isProfileAddToGroupDoubleOptin()) {
if (!count($contactGroup)) {
//array of group id, subscribed by contact
$contactGroup = array();
if ($this->_id) {
$contactGroups = new CRM_Contact_DAO_GroupContact();
$contactGroups->contact_id = $this->_id;
$contactGroups->status = 'Added';
$contactGroups->find();
$contactGroup = array();
while ($contactGroups->fetch()) {
$contactGroup[] = $contactGroups->group_id;
$groupSubscribed[$contactGroups->group_id] = 1;
}
}
}
//if group is already subscribed , ignore it
$groupExist = CRM_Utils_Array::key($addToGroupId, $contactGroup);
if (!isset($groupExist)) {
$mailingType[] = $addToGroupId;
$addToGroupId = NULL;
}
} else {
// since we are directly adding contact to group lets unset it from mailing
if ($key = array_search($addToGroupId, $mailingType)) {
unset($mailingType[$key]);
}
}
}
if ($this->_grid) {
$params['group'] = $groupSubscribed;
}
// commenting below code, since we potentially
// triggered maximum name field formatting cases during CRM-4430.
// CRM-4343
// $params['preserveDBName'] = true;
$profileFields = $this->_fields;
if ($this->_mode & self::MODE_EDIT && $this->_activityId && $this->_isContactActivityProfile) {
$profileFields = $activityParams = array();
foreach ($this->_fields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
if (isset($params[$fieldName])) {
$activityParams[$fieldName] = $params[$fieldName];
}
if (isset($params['activity_date_time'])) {
$activityParams['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
}
if (!empty($params[$fieldName]) && isset($params["{$fieldName}_id"])) {
$activityParams[$fieldName] = $params["{$fieldName}_id"];
}
} else {
$profileFields[$fieldName] = $field;
}
}
if (!empty($activityParams)) {
$activityParams['version'] = 3;
$activityParams['id'] = $this->_activityId;
$activityParams['skipRecentView'] = TRUE;
civicrm_api('Activity', 'create', $activityParams);
}
}
if ($this->_multiRecord && $this->_recordId && $this->_multiRecordFields && $this->_recordExists) {
$params['customRecordValues'][$this->_recordId] = array_keys($this->_multiRecordFields);
}
$this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $profileFields, $this->_id, $addToGroupId, $this->_gid, $this->_ctype, TRUE);
//mailing type group
if (!empty($mailingType)) {
// we send in the contactID so we match the same groups and are exact, rather than relying on email
// CRM-8710
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile');
}
$ufGroups = array();
if ($this->_gid) {
$ufGroups[$this->_gid] = 1;
} elseif ($this->_mode == self::MODE_REGISTER) {
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
}
foreach ($ufGroups as $gId => $val) {
if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
$values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, NULL);
CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
}
}
//create CMS user (if CMS user option is selected in profile)
if (!empty($params['cms_create_account']) && $this->_mode == self::MODE_CREATE) {
$params['contactID'] = $this->_id;
if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error');
CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']);
$transaction->rollback();
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
}
}
$transaction->commit();
}
示例5: postProcess
/**
* Process the user submitted custom data values.
*
* @access public
* @return void
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->_name);
if ($this->_mode == self::MODE_REGISTER) {
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::setOverwrite(false);
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
//used to send subcribe mail to the group which user want.
//if the profile double option in is enabled
$mailingType = array();
$config =& CRM_Core_Config::singleton();
if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) {
$result = null;
foreach ($params as $name => $values) {
if (substr($name, 0, 6) == 'email-') {
$result['email'] = $values;
}
}
$groupSubscribed = array();
if (CRM_Utils_Array::value('email', $result)) {
require_once 'CRM/Contact/DAO/Group.php';
//array of group id, subscribed by contact
$contactGroup = array();
if ($this->_id) {
$contactGroups = new CRM_Contact_DAO_GroupContact();
$contactGroups->contact_id = $this->_id;
$contactGroups->status = 'Added';
$contactGroups->find();
$contactGroup = array();
while ($contactGroups->fetch()) {
$contactGroup[] = $contactGroups->group_id;
$groupSubscribed[$contactGroups->group_id] = 1;
}
}
foreach ($params['group'] as $key => $val) {
if (!$val) {
unset($params['group'][$key]);
continue;
}
$groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
$groupType = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($groupTypes, 1, -1));
//filter group of mailing type and unset it from params
if (in_array(2, $groupType)) {
//if group is already subscribed , ignore it
$groupExist = CRM_Utils_Array::key($key, $contactGroup);
if (!isset($groupExist)) {
$mailingType[] = $key;
unset($params['group'][$key]);
}
}
}
}
}
if ($this->_grid) {
$params['group'] = $groupSubscribed;
}
// commenting below code, since we potentially
// triggered maximum name field formatting cases during CRM-4430.
// CRM-4343
// $params['preserveDBName'] = true;
$this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true);
//mailing type group
if (!empty($mailingType)) {
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result);
}
require_once 'CRM/Core/BAO/UFGroup.php';
$ufGroups = array();
if ($this->_gid) {
$ufGroups[$this->_gid] = 1;
} else {
if ($this->_mode == self::MODE_REGISTER) {
$ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
}
}
foreach ($ufGroups as $gId => $val) {
if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
$values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, null);
CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
}
}
//create CMS user (if CMS user option is selected in profile)
if (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) {
$params['contactID'] = $this->_id;
require_once "CRM/Core/BAO/CMSUser.php";
if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'));
$transaction->rollback();
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
}
}
$transaction->commit();
//.........这里部分代码省略.........
示例6: postProcess
/**
*
* @return void
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->_name);
$groups = array();
if ($this->_groupID) {
$groups[] = $this->_groupID;
} else {
foreach ($params as $name => $dontCare) {
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
$groups[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
}
}
}
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($groups, $params);
}
示例7: updateContactFields
/**
* function to update contact fields
*
* @return void
* @access public
*/
public function updateContactFields($contactID, $params, $fields)
{
//add the contact to group, if add to group is selected for a
//particular uf group
// get the add to groups
$addToGroups = array();
if (!empty($this->_fields)) {
foreach ($this->_fields as $key => $value) {
if (CRM_Utils_Array::value('add_to_group_id', $value)) {
$addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
}
}
}
// check for profile double opt-in and get groups to be subscribed
require_once 'CRM/Core/BAO/UFGroup.php';
$subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
require_once "CRM/Contact/BAO/Contact.php";
if ($contactID) {
$ctype = CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $contactID, "contact_type");
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype);
} else {
// when we have allow_same_participant_emails = 1
// don't take email address in dedupe params - CRM-4886
// here we are making dedupe weak - so to make dedupe
// more effective please update individual 'Strict' rule.
$allowSameEmailAddress = CRM_Utils_Array::value('allow_same_participant_emails', $this->_values['event']);
require_once 'CRM/Dedupe/Finder.php';
//suppress "email-Primary" when allow_same_participant_emails = 1
if ($allowSameEmailAddress && ($email = CRM_Utils_Array::value('email-Primary', $params)) && CRM_Utils_Array::value('registered_by_id', $params)) {
//skip dedupe check only for additional participants
unset($params['email-Primary']);
}
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$contact_id = $ids[0];
if (isset($email)) {
$params['email-Primary'] = $email;
}
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups);
$this->set('contactID', $contactID);
}
//get email primary first if exist
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
return $contactID;
}
示例8: updateContactFields
/**
* function to update contact fields
*
* @return void
* @access public
*/
public function updateContactFields($contactID, $params, $fields)
{
//add the contact to group, if add to group is selected for a
//particular uf group
// get the add to groups
$addToGroups = array();
if (!empty($this->_fields)) {
foreach ($this->_fields as $key => $value) {
if (CRM_Utils_Array::value('add_to_group_id', $value)) {
$addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
}
}
}
// check for profile double opt-in and get groups to be subscribed
$subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
foreach ($addToGroups as $k) {
if (array_key_exists($k, $subscribeGroupIds)) {
unset($addToGroups[$k]);
}
}
// 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]);
}
}
}
if ($contactID) {
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, TRUE);
} else {
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if (!isset($params[$greeting . '_id'])) {
$params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, NULL, $addToGroups, NULL, NULL, TRUE);
$this->set('contactID', $contactID);
}
//get email primary first if exist
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
return $contactID;
}
示例9: updateContactFields
/**
* function to update contact fields
*
* @return void
* @access public
*/
public function updateContactFields($contactID, $params, $fields)
{
//add the contact to group, if add to group is selected for a
//particular uf group
// get the add to groups
$addToGroups = array();
if (!empty($this->_fields)) {
foreach ($this->_fields as $key => $value) {
if (CRM_Utils_Array::value('add_to_group_id', $value)) {
$addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
}
}
}
// check for profile double opt-in and get groups to be subscribed
require_once 'CRM/Core/BAO/UFGroup.php';
$subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
foreach ($addToGroups as $k) {
if (array_key_exists($k, $subscribeGroupIds)) {
unset($addToGroups[$k]);
}
}
// 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]);
}
}
}
require_once "CRM/Contact/BAO/Contact.php";
if ($contactID) {
$ctype = CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $contactID, "contact_type");
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype);
} else {
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, null, $addToGroups);
$this->set('contactID', $contactID);
}
//get email primary first if exist
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
return $contactID;
}
示例10: postProcess
//.........这里部分代码省略.........
}
if ($this->_mode == self::MODE_REGISTER) {
require_once 'CRM/Core/BAO/Address.php';
CRM_Core_BAO_Address::setOverwrite(false);
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
//used to send subcribe mail to the group which user want.
//if the profile double option in is enabled
$mailingType = array();
$config = CRM_Core_Config::singleton();
if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) {
$result = null;
foreach ($params as $name => $values) {
if (substr($name, 0, 6) == 'email-') {
$result['email'] = $values;
}
}
$groupSubscribed = array();
if (CRM_Utils_Array::value('email', $result)) {
require_once 'CRM/Contact/DAO/Group.php';
//array of group id, subscribed by contact
$contactGroup = array();
if ($this->_id) {
$contactGroups = new CRM_Contact_DAO_GroupContact();
$contactGroups->contact_id = $this->_id;
$contactGroups->status = 'Added';
$contactGroups->find();
$contactGroup = array();
while ($contactGroups->fetch()) {
$contactGroup[] = $contactGroups->group_id;
$groupSubscribed[$contactGroups->group_id] = 1;
}
}
foreach ($params['group'] as $key => $val) {
if (!$val) {
unset($params['group'][$key]);
continue;
}
$groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
$groupType = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($groupTypes, 1, -1));
//filter group of mailing type and unset it from params
if (in_array(2, $groupType)) {
//if group is already subscribed , ignore it
$groupExist = CRM_Utils_Array::key($key, $contactGroup);
if (!isset($groupExist)) {
$mailingType[] = $key;
unset($params['group'][$key]);
}
}
}
}
}
if (CRM_Utils_Array::value('add_to_group', $params)) {
$addToGroupId = $params['add_to_group'];
// since we are directly adding contact to group lets unset it from mailing
if ($key = array_search($addToGroupId, $mailingType)) {
unset($mailingType[$key]);
}
}
if ($this->_grid) {
$params['group'] = $groupSubscribed;
}
// commenting below code, since we potentially
// triggered maximum name field formatting cases during CRM-4430.
// CRM-4343
// $params['preserveDBName'] = true;
$this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true);
//mailing type group
if (!empty($mailingType)) {
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result);
}
require_once 'CRM/Core/BAO/UFGroup.php';
$ufGroups = array();
if ($this->_gid) {
$ufGroups[$this->_gid] = 1;
} else {
if ($this->_mode == self::MODE_REGISTER) {
$ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
}
}
foreach ($ufGroups as $gId => $val) {
if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
$values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, null);
CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
}
}
//create CMS user (if CMS user option is selected in profile)
if (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) {
$params['contactID'] = $this->_id;
require_once "CRM/Core/BAO/CMSUser.php";
if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'));
$transaction->rollback();
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
}
}
$transaction->commit();
}
示例11: postProcess
//.........这里部分代码省略.........
$behalfOrganization = array();
foreach (array('organization_name', 'organization_id', 'org_option') as $fld) {
if (array_key_exists($fld, $params)) {
$behalfOrganization[$fld] = $params[$fld];
unset($params[$fld]);
}
}
if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
foreach ($params['onbehalf_location'] as $block => $vals) {
$behalfOrganization[$block] = $vals;
}
unset($params['onbehalf_location']);
}
}
// check for profile double opt-in and get groups to be subscribed
require_once 'CRM/Core/BAO/UFGroup.php';
$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 (!isset($contactID)) {
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$dedupeParams['check_permission'] = false;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$contact_id = CRM_Utils_Array::value(0, $ids);
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups);
$this->set('contactID', $contactID);
} else {
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
$contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype);
}
//get email primary first if exist
$subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
if (!$subscribtionEmail['email']) {
$subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
}
// subscribing contact to groups
if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
}
// If onbehalf-of-organization contribution / signup, add organization
// and it's location.
if (isset($params['is_for_organization']) && isset($behalfOrganization['organization_name'])) {
self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params);
}
// lets store the contactID in the session
// for things like tell a friend
$session = CRM_Core_Session::singleton();
if (!$session->get('userID')) {
$session->set('transaction.userID', $contactID);
} else {
$session->set('transaction.userID', null);
}
// store the fact that this is a membership and membership type is selected
$processMembership = false;
if (CRM_Utils_Array::value('selectMembership', $membershipParams) && $membershipParams['selectMembership'] != 'no_thanks') {
$processMembership = true;
$this->assign('membership_assign', true);
$this->set('membershipTypeID', $this->_params['selectMembership']);
if ($this->_action & CRM_Core_Action::PREVIEW) {
$membershipParams['is_test'] = 1;
}
if ($this->_params['is_pay_later']) {
$membershipParams['is_pay_later'] = 1;
}
}
if ($processMembership) {
require_once 'CRM/Core/Payment/Form.php';
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, true);
// added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
if (isset($this->_params['related_contact'])) {
$membershipParams['cms_contactID'] = $this->_params['related_contact'];
} else {
$membershipParams['cms_contactID'] = $contactID;
}
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, $this, $premiumParams);
} else {
// at this point we've created a contact and stored its address etc
// all the payment processors expect the name and address to be in the
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
$contributionTypeId = $this->_values['contribution_type_id'];
require_once 'CRM/Contribute/BAO/Contribution/Utils.php';
CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $premiumParams, $contactID, $contributionTypeId, 'contribution');
}
}