本文整理汇总了PHP中CRM_Contact_BAO_GroupContact::addContactsToGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_GroupContact::addContactsToGroup方法的具体用法?PHP CRM_Contact_BAO_GroupContact::addContactsToGroup怎么用?PHP CRM_Contact_BAO_GroupContact::addContactsToGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_GroupContact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_GroupContact::addContactsToGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
*
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
// before we proceed lets just check if this contact is already 'Added'
// if so, we should ignore this request and hence avoid sending multiple
// emails - CRM-11157
$details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
if ($details && $details->status == 'Added') {
// This contact is already subscribed
// lets return the group title
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
}
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(TRUE);
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
$mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
// send - ignore errors because the desired status change has already been successful
$unused_result = CRM_Utils_Mail::send($mailParams);
return $group->title;
}
示例2: testForceCiviToMailchimpSyncNullEmail
function testForceCiviToMailchimpSyncNullEmail()
{
$mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group testForceCiviToMailchimpSyncNullEmail');
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
unset($params['email']);
$contact = CRM_Contact_BAO_Contact::create($params);
$contact_ids = array($contact->id);
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $mailchimp_sync_setting->civicrm_group_id);
$contacts = CRM_CiviMailchimp_Form_Sync::forceCiviToMailchimpSync($mailchimp_sync_setting);
$mailchimp_api_subscribe = civimailchimp_static('mailchimp_api_subscribe');
$this->assertCount(0, $contacts);
$this->assertNull($mailchimp_api_subscribe);
}
示例3: testFindByContactId
function testFindByContactId()
{
$expected_mailchimp_sync_setting = self::createTestGroupAndSyncSettings('Test group testFindByContactId');
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
$contact = CRM_Contact_BAO_Contact::create($params);
$contact_ids = array($contact->id);
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $expected_mailchimp_sync_setting->civicrm_group_id);
$mailchimp_sync_settings = CRM_CiviMailchimp_BAO_SyncSettings::findByContactId($contact->id);
$mailchimp_sync_setting = $mailchimp_sync_settings[$expected_mailchimp_sync_setting->civicrm_group_id];
$this->assertEquals($expected_mailchimp_sync_setting->id, $mailchimp_sync_setting->id);
$this->assertEquals($expected_mailchimp_sync_setting->civicrm_group_id, $mailchimp_sync_setting->civicrm_group_id);
$this->assertEquals($expected_mailchimp_sync_setting->mailchimp_list_id, $mailchimp_sync_setting->mailchimp_list_id);
$this->assertEquals($expected_mailchimp_sync_setting->mailchimp_interest_groups, $mailchimp_sync_setting->mailchimp_interest_groups);
}
示例4: crm_subscribe_group_contacts
/**
* subscribe contacts to a group
*
* @param CRM_Contact $group A valid group object (passed by reference).
* @param array $contacts An array of one or more valid Contact objects (passed by reference).
*
*
* @return null if success or CRM_Error (db error or contacts were not valid)
*
* @access public
*/
function crm_subscribe_group_contacts(&$group, $contacts)
{
_crm_initialize();
if (!is_array($contacts)) {
return _crm_error('$contacts is not Array ');
}
if (!is_a($group, 'CRM_Contact_BAO_Group') && !is_a($group, 'CRM_Contact_DAO_Group')) {
return _crm_error('Invalid group object passed in');
}
foreach ($contacts as $contact) {
if (!isset($contact->id)) {
return _crm_error('Invalid contact object passed in');
}
$contactID[] = $contact->id;
}
$status = 'Pending';
$method = 'Email';
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactID, $group->id, $method, $status);
return null;
}
示例5: array
/**
* Register a subscription event. Create a new contact if one does not
* already exist.
*
* @param int $group_id
* The group id to subscribe to.
* @param string $email
* The email address of the (new) contact.
* @param int $contactId
* Currently used during event registration/contribution.
* Specifically to avoid linking group to wrong duplicate contact
* during event registration.
* @param string $context
*
* @return int|null
* $se_id The id of the subscription event, null on failure
*/
public static function &subscribe($group_id, $email, $contactId = NULL, $context = NULL)
{
// CRM-1797 - allow subscription only to public groups
$params = array('id' => (int) $group_id);
$defaults = array();
$contact_id = NULL;
$success = NULL;
$bao = CRM_Contact_BAO_Group::retrieve($params, $defaults);
if ($bao && substr($bao->visibility, 0, 6) != 'Public' && $context != 'profile') {
return $success;
}
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$email = $strtolower($email);
// process the query only if no contactId
if ($contactId) {
$contact_id = $contactId;
} else {
/* First, find out if the contact already exists */
$query = "\n SELECT DISTINCT contact_a.id as contact_id\n FROM civicrm_contact contact_a\nLEFT JOIN civicrm_email ON contact_a.id = civicrm_email.contact_id\n WHERE civicrm_email.email = %1 AND contact_a.is_deleted = 0";
$params = array(1 => array($email, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
$id = array();
// lets just use the first contact id we got
if ($dao->fetch()) {
$contact_id = $dao->contact_id;
}
$dao->free();
}
$transaction = new CRM_Core_Transaction();
if (!$contact_id) {
require_once 'CRM/Utils/DeprecatedUtils.php';
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual', 'version' => 3);
$locationType = CRM_Core_BAO_LocationType::getDefault();
$value = array('email' => $email, 'location_type_id' => $locationType->id);
_civicrm_api3_deprecated_add_formatted_param($value, $formatted);
$formatted['onDuplicate'] = CRM_Import_Parser::DUPLICATE_SKIP;
$formatted['fixAddress'] = TRUE;
require_once 'api/api.php';
$contact = civicrm_api('contact', 'create', $formatted);
if (civicrm_error($contact)) {
return $success;
}
$contact_id = $contact['id'];
} elseif (!is_numeric($contact_id) && (int) $contact_id > 0) {
// make sure contact_id is numeric
return $success;
}
/* Get the primary email id from the contact to use as a hash input */
$dao = new CRM_Core_DAO();
$query = "\nSELECT civicrm_email.id as email_id\n FROM civicrm_email\n WHERE civicrm_email.email = %1\n AND civicrm_email.contact_id = %2";
$params = array(1 => array($email, 'String'), 2 => array($contact_id, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
if (!$dao->fetch()) {
CRM_Core_Error::fatal('Please file an issue with the backtrace');
return $success;
}
$se = new CRM_Mailing_Event_BAO_Subscribe();
$se->group_id = $group_id;
$se->contact_id = $contact_id;
$se->time_stamp = date('YmdHis');
$se->hash = substr(sha1("{$group_id}:{$contact_id}:{$dao->email_id}:" . time()), 0, 16);
$se->save();
$contacts = array($contact_id);
CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id);
$transaction->commit();
return $se;
}
示例6: add2group
/**
* @param int $groupID
*/
public function add2group($groupID)
{
if (is_numeric($groupID)) {
$sql = "\n{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy}\nORDER BY civicrm_contribution_total_amount_sum DESC\n) as abc {$this->_groupLimit}";
$dao = CRM_Core_DAO::executeQuery($sql);
$contact_ids = array();
// Add resulting contacts to group
while ($dao->fetch()) {
$contact_ids[$dao->civicrm_contact_id] = $dao->civicrm_contact_id;
}
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $groupID);
CRM_Core_Session::setStatus(ts("Listed contact(s) have been added to the selected group."), ts('Contacts Added'), 'success');
}
}
示例7: postProcess
/**
*
* @return void
*/
public function postProcess()
{
$contactID = array($this->_contactId);
$groupId = $this->controller->exportValue('GroupContact', 'group_id');
$method = $this->_context == 'user' ? 'Web' : 'Admin';
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if ($userID == $this->_contactId) {
$method = 'Web';
}
$groupContact = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactID, $groupId, $method);
if ($groupContact && $this->_context != 'user') {
$groups = CRM_Core_PseudoConstant::group();
CRM_Core_Session::setStatus(ts("Contact has been added to '%1'.", array(1 => $groups[$groupId])), ts('Added to Group'), 'success');
}
}
示例8: civicrm_api3_group_contact_update_status
/**
* Update group contact status.
*
* @deprecated - this should be part of create but need to know we aren't missing something
*
* @param array $params
*
* @return bool
* @throws \API_Exception
*/
function civicrm_api3_group_contact_update_status($params)
{
civicrm_api3_verify_mandatory($params, NULL, array('contact_id', 'group_id'));
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($params['contact_id']), $params['group_id'], CRM_Utils_Array::value('method', $params, 'API'), 'Added', CRM_Utils_Array::value('tracking', $params));
return TRUE;
}
示例9: add2group
/**
* @param $groupID
*/
function add2group($groupID) {
if (is_numeric($groupID) && isset($this->_aliases['civicrm_contact'])) {
$contact = CRM_Utils_Array::value('btn_group_contact', $this->_submitValues, 'civicrm_contact');
$select = "SELECT DISTINCT {$this->_aliases[$contact]}.id AS addtogroup_contact_id";
// $select = str_ireplace('SELECT SQL_CALC_FOUND_ROWS ', $select, $this->_select);
$sql = "{$select} {$this->_from} {$this->_where} AND {$this->_aliases[$contact]}.id IS NOT NULL {$this->_groupBy} {$this->_having} {$this->_orderBy}";
$sql = str_replace('WITH ROLLUP', '', $sql);
$dao = CRM_Core_DAO::executeQuery($sql);
$contact_ids = array();
// Add resulting contacts to group
while ($dao->fetch()) {
$contact_ids[$dao->addtogroup_contact_id] = $dao->addtogroup_contact_id;
}
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $groupID);
CRM_Core_Session::setStatus(ts("Listed contact(s) have been added to the selected group."));
}
}
示例10: sendEmail
/**
* takes an associative array and sends a thank you or email verification email
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @param $sendEmailMode
*
* @throws Exception
* @return void
@access public
* @static
*/
public static function sendEmail($params, $sendEmailMode)
{
/* sendEmailMode
* CRM_Campaign_Form_Petition_Signature::EMAIL_THANK
* connected user via login/pwd - thank you
* or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
* or login using fb connect - thank you + click to add msg to fb wall
*
* CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM
* send a confirmation request email
*/
// check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it
$petitionGroupName = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'petition_contacts', NULL, 'Petition Contacts');
$dao = new CRM_Contact_DAO_Group();
$dao->title = $petitionGroupName;
if (!$dao->find(TRUE)) {
$dao->is_active = 1;
$dao->visibility = 'User and User Admin Only';
$dao->save();
}
$group_id = $dao->id;
// get petition info
$petitionParams['id'] = $params['sid'];
$petitionInfo = array();
CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo);
if (empty($petitionInfo)) {
CRM_Core_Error::fatal('Petition doesn\'t exist.');
}
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$toName = CRM_Contact_BAO_Contact::displayName($params['contactId']);
$replyTo = "do-not-reply@{$emailDomain}";
// set additional general message template params (custom tokens to use in email msg templates)
// tokens then available in msg template as {$petition.title}, etc
$petitionTokens['title'] = $petitionInfo['title'];
$petitionTokens['petitionId'] = $params['sid'];
$tplParams['petition'] = $petitionTokens;
switch ($sendEmailMode) {
case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK:
// add this contact to the CIVICRM_PETITION_CONTACTS group
// Cannot pass parameter 1 by reference
$p = array($params['contactId']);
CRM_Contact_BAO_GroupContact::addContactsToGroup($p, $group_id, 'API');
if ($params['email-Primary']) {
CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title']));
}
break;
case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM:
// create mailing event subscription record for this contact
// this will allow using a hash key to confirm email address by sending a url link
$se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $params['email-Primary'], $params['contactId'], 'profile');
// require_once 'CRM/Core/BAO/Domain.php';
// $domain = CRM_Core_BAO_Domain::getDomain();
$config = CRM_Core_Config::singleton();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}";
$confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE);
$confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE, NULL, FALSE);
// set email specific message template params and assign to tplParams
$petitionTokens['confirmUrl'] = $confirmUrl;
$petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText;
$tplParams['petition'] = $petitionTokens;
if ($params['email-Primary']) {
CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl));
}
break;
}
}
示例11: postProcess
/**
*
* @access public
* @return None
*/
public function postProcess()
{
$contactID = array($this->_contactId);
$groupId = $this->controller->exportValue('GroupContact', 'group_id');
$method = 'Admin';
$method = $this->_context == 'user' ? 'Web' : 'Admin';
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if ($userID == $this->_contactId) {
$method = 'Web';
}
$groupContact = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactID, $groupId, $method);
if ($groupContact && $this->_context != 'user') {
CRM_Core_Session::setStatus(ts('Contact has been added to the selected group.'));
}
}
示例12: createSmartContactGroupForSearchContacts
/**
* TODO: Find a way to move this into CRM_Simplemail_Form_Task_SimpleMail::postProcess()
*
* Note: A lot of the logic in this method (for creating hidden and smart groups) is taken from
* CRM_Mailing_Form_Group::postProcess()
*
* @return null|string
* @throws Exception
*/
private static function createSmartContactGroupForSearchContacts()
{
$searchParams = simplemail_civicrm_getFromSessionScope('searchParams');
$contactIds = simplemail_civicrm_getFromSessionScope('contactIds');
$smartGroupId = NULL;
if ($contactIds) {
$resultSelectOption = $searchParams['radio_ts'];
// Only the ticked contacts in the search result need to be sent mailing - create a hidden group for them
if ($resultSelectOption == 'ts_sel') {
// create a static grp if only a subset of result set was selected:
$randID = md5(time());
$grpTitle = "Hidden Group {$randID}";
$grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
if (!$grpID) {
$groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1));
$group = CRM_Contact_BAO_Group::create($groupParams);
$grpID = $group->id;
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $group->id);
$newGroupTitle = "Hidden Group {$grpID}";
$groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle, 'group_type' => array('2' => 1));
$group = CRM_Contact_BAO_Group::create($groupParams);
}
// note at this point its a static group
$smartGroupId = $grpID;
} else {
// Get the saved search ID
$ssId = simplemail_civicrm_getFromSessionScope('ssId');
$formValues = simplemail_civicrm_getFromSessionScope('formValues');
$customSearchId = simplemail_civicrm_getFromSessionScope('customSearchId');
$context = simplemail_civicrm_getFromSessionScope('context');
$hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $formValues, 'saved_search_id' => $ssId, 'search_custom_id' => $customSearchId, 'search_context' => $context);
list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
// Set the saved search ID
if (!$ssId) {
if ($savedSearchId) {
simplemail_civicrm_addToSessionScope('ssId', $savedSearchId);
} else {
CRM_Core_Error::fatal();
}
}
}
}
simplemail_civicrm_addToSessionScope('smartGroupId', $smartGroupId);
}
示例13: _addRespondentToGroup
/**
* @param $contactIds
*
* @return array
*/
private function _addRespondentToGroup($contactIds)
{
$groupAdditions = array();
if (empty($contactIds)) {
return $groupAdditions;
}
$params = $this->controller->exportValues($this->_name);
$groups = CRM_Utils_Array::value('groups', $params, array());
$newGroupName = CRM_Utils_Array::value('newGroupName', $params);
$newGroupDesc = CRM_Utils_Array::value('newGroupDesc', $params);
$newGroupId = NULL;
//create new group.
if ($newGroupName) {
$grpParams = array('title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => TRUE);
$group = CRM_Contact_BAO_Group::create($grpParams);
$groups[] = $newGroupId = $group->id;
}
//add the respondents to groups.
if (is_array($groups)) {
$existingGroups = CRM_Core_PseudoConstant::group();
foreach ($groups as $groupId) {
$addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
$totalCount = CRM_Utils_Array::value(1, $addCount);
if ($groupId == $newGroupId) {
$name = $newGroupName;
$new = TRUE;
} else {
$name = $existingGroups[$groupId];
$new = FALSE;
}
if ($totalCount) {
$url = CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $groupId);
$groupAdditions[] = '<a href="' . $url . '">' . $name . '</a>';
}
}
}
return $groupAdditions;
}
示例14: createHiddenGroup
/**
* Given this task's list of targets, produce a hidden group.
*
* @return array
* Array(0 => int $groupID, 1 => int|NULL $ssID).
* @throws Exception
*/
public function createHiddenGroup()
{
// Did the user select "All" matches or cherry-pick a few records?
$searchParams = $this->controller->exportValues();
if ($searchParams['radio_ts'] == 'ts_sel') {
// Create a static group.
$randID = md5(time() . rand(1, 1000));
// groups require a unique name
$grpTitle = "Hidden Group {$randID}";
$grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
if (!$grpID) {
$groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1));
$group = CRM_Contact_BAO_Group::create($groupParams);
$grpID = $group->id;
CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id);
$newGroupTitle = "Hidden Group {$grpID}";
$groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle, 'group_type' => array('2' => 1));
$group = CRM_Contact_BAO_Group::create($groupParams);
}
// note at this point its a static group
return array($grpID, NULL);
} else {
// Create a smart group.
$ssId = $this->get('ssID');
$hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'));
list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
return array($smartGroupId, $savedSearchId);
}
}
示例15: _addImportedContactsToNewGroup
private function _addImportedContactsToNewGroup($contactIds, $newGroupName, $newGroupDesc)
{
$newGroupId = NULL;
if ($newGroupName) {
/* Create a new group */
$gParams = array('title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => TRUE);
$group = CRM_Contact_BAO_Group::create($gParams);
$this->_groups[] = $newGroupId = $group->id;
}
if (is_array($this->_groups)) {
$groupAdditions = array();
foreach ($this->_groups as $groupId) {
$addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
$totalCount = $addCount[1];
if ($groupId == $newGroupId) {
$name = $newGroupName;
$new = TRUE;
} else {
$name = $this->_allGroups[$groupId];
$new = FALSE;
}
$groupAdditions[] = array('url' => CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $groupId), 'name' => $name, 'added' => $totalCount, 'notAdded' => $addCount[2], 'new' => $new);
}
return $groupAdditions;
}
return FALSE;
}