本文整理汇总了PHP中CRM_Contact_BAO_GroupContact::removeContactsFromGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_GroupContact::removeContactsFromGroup方法的具体用法?PHP CRM_Contact_BAO_GroupContact::removeContactsFromGroup怎么用?PHP CRM_Contact_BAO_GroupContact::removeContactsFromGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_GroupContact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_GroupContact::removeContactsFromGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess()
{
$groupId = $this->controller->exportValue('RemoveFromGroup', 'group_id');
$group = CRM_Core_PseudoConstant::group();
list($total, $removed, $notRemoved) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($this->_contactIds, $groupId);
$status = array(ts("%count contact removed from '%2'", array('count' => $removed, 'plural' => "%count contacts removed from '%2'", 2 => $group[$groupId])));
if ($notRemoved) {
$status[] = ts('1 contact was already not in this group', array('count' => $notRemoved, 'plural' => '%count contacts were already not in this group'));
}
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts("Removed Contact From Group", array('plural' => "Removed Contacts From Group", 'count' => $removed)), 'success', array('expires' => 0));
}
示例2: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
function postProcess()
{
$groupId = $this->controller->exportValue('RemoveFromGroup', 'group_id');
$group =& CRM_Core_PseudoConstant::group();
list($total, $removed, $notRemoved) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($this->_contactIds, $groupId);
$status = array(ts('Removed Contact(s) from %1', array(1 => $group[$groupId])), ts('Total Selected Contact(s): %1', array(1 => $total)));
if ($removed) {
$status[] = ts('Total Contact(s) removed from group: %1', array(1 => $removed));
}
if ($notRemoved) {
$status[] = ts('Total Contact(s) not in group: %1', array(1 => $notRemoved));
}
CRM_Core_Session::setStatus($status);
}
示例3: foreach
/**
* Create contact.
*
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param bool $fixAddress
* If we need to fix address.
* @param bool $invokeHooks
* If we need to invoke hooks.
*
* @param bool $skipDelete
* Unclear parameter, passed to website create
*
* @todo explain this parameter
*
* @throws Exception
* @return CRM_Contact_BAO_Contact|CRM_Core_Error
* Created or updated contribution object. We are deprecating returning an error in
* favour of exceptions
*/
public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE)
{
$contact = NULL;
if (empty($params['contact_type']) && empty($params['contact_id'])) {
return $contact;
}
$isEdit = TRUE;
if ($invokeHooks) {
if (!empty($params['contact_id'])) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params);
$isEdit = FALSE;
}
}
$config = CRM_Core_Config::singleton();
// CRM-6942: set preferred language to the current language if it’s unset (and we’re creating a contact).
if (empty($params['contact_id']) && empty($params['preferred_language'])) {
$params['preferred_language'] = $config->lcMessages;
}
// CRM-9739: set greeting & addressee if unset and we’re creating a contact.
if (empty($params['contact_id'])) {
foreach (self::$_greetingTypes as $greeting) {
if (empty($params[$greeting . '_id'])) {
if ($defaultGreetingTypeId = CRM_Contact_BAO_Contact_Utils::defaultGreeting($params['contact_type'], $greeting)) {
$params[$greeting . '_id'] = $defaultGreetingTypeId;
}
}
}
}
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
if (!$contact) {
// Not dying here is stupid, since we get into wierd situation and into a bug that
// is impossible to figure out for the user or for us
// CRM-7925
CRM_Core_Error::fatal();
}
$params['contact_id'] = $contact->id;
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
// Enabling multisite causes the contact to be added to the domain group.
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (!empty($domainGroupID)) {
if (!empty($params['group']) && is_array($params['group'])) {
$params['group'][$domainGroupID] = 1;
} else {
$params['group'] = array($domainGroupID => 1);
}
}
}
if (array_key_exists('group', $params)) {
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} elseif ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
// Add location Block data.
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//add website
CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete);
//get userID from session
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (!empty($params['note'])) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
//.........这里部分代码省略.........
示例4: manageCiviCRMGroupSubcription
static function manageCiviCRMGroupSubcription($contactID = array(), $requestData, $action)
{
CRM_Mailchimp_Utils::checkDebug('Start- CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $contactID= ', $contactID);
CRM_Mailchimp_Utils::checkDebug('Start- CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $requestData= ', $requestData);
CRM_Mailchimp_Utils::checkDebug('Start- CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $requestType= ', $action);
if (empty($contactID) || empty($requestData['list_id']) || empty($action)) {
return NULL;
}
$listID = $requestData['list_id'];
$groupContactRemoves = $groupContactAdditions = array();
// Deal with subscribe/unsubscribe.
// We need the CiviCRM membership group for this list.
$groups = CRM_Mailchimp_Utils::getGroupsToSync(array(), $listID, $membership_only = TRUE);
$allGroups = CRM_Mailchimp_Utils::getGroupsToSync(array(), $listID, $membership_only = FALSE);
if (!$groups) {
// This list is not mapped to a group in CiviCRM.
return NULL;
}
$_ = array_keys($groups);
$membershipGroupID = $_[0];
if ($action == 'subscribe') {
$groupContactAdditions[$membershipGroupID][] = $contactID;
} elseif ($action == 'unsubscribe') {
$groupContactRemoves[$membershipGroupID][] = $contactID;
$mcGroupings = array();
foreach (empty($requestData['merges']['GROUPINGS']) ? array() : $requestData['merges']['GROUPINGS'] as $grouping) {
foreach (explode(', ', $grouping['groups']) as $group) {
$mcGroupings[$grouping['id']][$group] = 1;
}
}
foreach ($allGroups as $groupID => $details) {
if ($groupID != $membershipGroupID && $details['is_mc_update_grouping']) {
if (!empty($mcGroupings[$details['grouping_id']][$details['group_name']])) {
$groupContactRemoves[$groupID][] = $contactID;
}
}
}
}
// Now deal with all the groupings that are mapped to CiviCRM groups for this list
// and that have the allow MC updates flag set.
/* Sample groupings from MC:
*
* [GROUPINGS] => Array(
* [0] => Array(
* [id] => 11365
* [name] => CiviCRM
* [groups] => special
* ))
* Re-map to mcGroupings[grouping_id][group_name] = 1;
*/
$mcGroupings = array();
foreach (empty($requestData['merges']['GROUPINGS']) ? array() : $requestData['merges']['GROUPINGS'] as $grouping) {
foreach (explode(', ', $grouping['groups']) as $group) {
$mcGroupings[$grouping['id']][$group] = 1;
}
}
$groups = CRM_Mailchimp_Utils::getGroupsToSync(array(), $listID, $membership_only = FALSE);
CRM_Mailchimp_Utils::checkDebug('Middle- CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $groups ', $groups);
CRM_Mailchimp_Utils::checkDebug('Middle- CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $mcGroupings ', $mcGroupings);
foreach ($groups as $groupID => $details) {
if ($groupID != $membershipGroupID && $details['is_mc_update_grouping']) {
// This is a group we allow updates for.
if (empty($mcGroupings[$details['grouping_id']][$details['group_name']])) {
$groupContactRemoves[$groupID][] = $contactID;
} else {
$groupContactAdditions[$groupID][] = $contactID;
}
}
}
// Add contacts to groups, if anything to do.
foreach ($groupContactAdditions as $groupID => $contactIDs) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIDs, $groupID, 'Admin', 'Added');
}
// Remove contacts from groups, if anything to do.
foreach ($groupContactRemoves as $groupID => $contactIDs) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIDs, $groupID, 'Admin', 'Removed');
}
CRM_Mailchimp_Utils::checkDebug('End - CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $groupContactRemoves ', $groupContactRemoves);
CRM_Mailchimp_Utils::checkDebug('End - CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $groupContactAdditions ', $groupContactAdditions);
CRM_Mailchimp_Utils::checkDebug('End - CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $contactID= ', $contactID);
CRM_Mailchimp_Utils::checkDebug('End - CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $requestData= ', $requestData);
CRM_Mailchimp_Utils::checkDebug('End - CRM_Mailchimp_Page_WebHook manageCiviCRMGroupSubcription $requestType= ', $action);
}
示例5: del
/**
* function to remove/ rejoin the group
*
* @param int $groupContactId id of crm_group_contact
* @param string $status this is the status that should be updated.
*
* $access public
*/
function del($groupContactId, $status)
{
$groupContact =& new CRM_Contact_DAO_GroupContact();
$groupId = CRM_Contact_BAO_GroupContact::getGroupId($groupContactId);
switch ($status) {
case 'i':
$groupStatus = 'Added';
break;
case 'p':
$groupStatus = 'Pending';
break;
case 'o':
$groupStatus = 'Removed';
break;
}
$contactID = array($this->_contactId);
$method = 'Admin';
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactID, $groupId, $method, $groupStatus);
}
示例6: testContactAddedToGroup
function testContactAddedToGroup()
{
$params = CRM_CiviMailchimp_UtilsTest::sampleContactParams();
$contact = CRM_Contact_BAO_Contact::create($params);
$mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test group testContactAddedToGroup');
// Test that the contact is not in the group (contactAddedToGroup returns TRUE)
$contact_added_to_group = CRM_CiviMailchimp_Utils::contactAddedToGroup($mailchimp_sync_setting->civicrm_group_id, $contact->id);
$this->assertTrue($contact_added_to_group);
// Test that the contact is in the group (contactAddedToGroup returns FALSE)
$contact_ids = array($contact->id);
CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $mailchimp_sync_setting->civicrm_group_id);
$contact_added_to_group = CRM_CiviMailchimp_Utils::contactAddedToGroup($mailchimp_sync_setting->civicrm_group_id, $contact->id);
$this->assertFalse($contact_added_to_group);
// Test that a status other than 'Added' returns TRUE
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contact_ids, $mailchimp_sync_setting->civicrm_group_id);
$contact_added_to_group = CRM_CiviMailchimp_Utils::contactAddedToGroup($mailchimp_sync_setting->civicrm_group_id, $contact->id);
$this->assertTrue($contact_added_to_group);
}
示例7: postProcess
/**
* Process the form after the input has been submitted and validated.
*
*
* @return void
*/
public function postProcess()
{
$params = $this->controller->exportValues();
$groupOption = CRM_Utils_Array::value('group_option', $params, NULL);
if ($groupOption) {
$groupParams = array();
$groupParams['title'] = $params['title'];
$groupParams['description'] = $params['description'];
$groupParams['visibility'] = "User and User Admin Only";
if (array_key_exists('group_type', $params) && is_array($params['group_type'])) {
$groupParams['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
} else {
$groupParams['group_type'] = '';
}
$groupParams['is_active'] = 1;
$createdGroup = CRM_Contact_BAO_Group::create($groupParams);
$groupID = $createdGroup->id;
$groupName = $groupParams['title'];
} else {
$groupID = $params['group_id'];
if (!isset($groupID)) {
$groupID = $this->_id;
}
$group = CRM_Core_PseudoConstant::group();
$groupName = $group[$groupID];
}
if (isset($groupID)) {
$selectedIDs = $params['availablePlayers'];
// First, remove any contacts before edit
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($this->_contactIds, $groupID);
list($total, $added, $notAdded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($selectedIDs, $groupID);
$status = array(ts('%count player added to team', array('count' => $added, 'plural' => '%count players added to team')));
if ($notAdded) {
$status[] = ts('%count player was already on team', array('count' => $notAdded, 'plural' => '%count players were already on team'));
}
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('Added Player to %1', array(1 => $groupName, 'count' => $added, 'plural' => 'Added Players to %1')), 'success', array('expires' => 0));
}
if ($this->_context === 'amtg') {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/tournament/team'));
//search', "reset=1&force=1"));
}
}
示例8: create
/**
* Takes an associative array and creates / removes
* contacts from the groups
*
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $contactId
* Contact id.
*
* @param bool $visibility
* @param string $method
*
* @return void
*/
public static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin')
{
$contactIds = array();
$contactIds[] = $contactId;
//if $visibility is true we are coming in via profile mean $method = 'Web'
$ignorePermission = FALSE;
if ($visibility) {
$ignorePermission = TRUE;
}
if ($contactId) {
$contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added', NULL, FALSE, $ignorePermission);
if (is_array($contactGroupList)) {
foreach ($contactGroupList as $key) {
$groupId = $key['group_id'];
$contactGroup[$groupId] = $groupId;
}
}
}
// get the list of all the groups
$allGroup = CRM_Contact_BAO_GroupContact::getGroupList(0, $visibility);
// this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
if (!is_array($params)) {
$params = array();
}
// this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
if (!isset($contactGroup) || !is_array($contactGroup)) {
$contactGroup = array();
}
// check which values has to be add/remove contact from group
foreach ($allGroup as $key => $varValue) {
if (!empty($params[$key]) && !array_key_exists($key, $contactGroup)) {
// add contact to group
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method);
} elseif (empty($params[$key]) && array_key_exists($key, $contactGroup)) {
// remove contact from group
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method);
}
}
}
示例9: create
/**
* takes an associative array and creates / removes
* contacts from the groups
*
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $contactId contact id
*
* @return none
* @access public
* @static
*/
static function create(&$params, $contactId, $visibility = false, $method = 'Admin')
{
$contactIds = array();
$contactIds[] = $contactId;
if ($contactId) {
$contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added');
if (is_array($contactGroupList)) {
foreach ($contactGroupList as $key) {
$groupId = $key['group_id'];
$contactGroup[$groupId] = $groupId;
}
}
}
// get the list of all the groups
$allGroup =& CRM_Contact_BAO_GroupContact::getGroupList(0, $visibility);
// this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
if (!is_array($params)) {
$params = array();
}
// this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
if (!isset($contactGroup) || !is_array($contactGroup)) {
$contactGroup = array();
}
// check which values has to be add/remove contact from group
foreach ($allGroup as $key => $varValue) {
if (CRM_Utils_Array::value($key, $params) && !array_key_exists($key, $contactGroup)) {
// add contact to group
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method);
} else {
if (!CRM_Utils_Array::value($key, $params) && array_key_exists($key, $contactGroup)) {
// remove contact from group
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method);
}
}
}
}
示例10: syncPullUpdates
/**
* New contacts from Mailchimp need bringing into CiviCRM.
*/
static function syncPullUpdates(CRM_Queue_TaskContext $ctx, $listID)
{
// Prepare the groups that we need to update
$stats[$listID]['added'] = $stats[$listID]['removed'] = 0;
// We need the membership group and any groups mapped to interest groupings with the allow MC updates option set.
$membership_group_id = FALSE;
$updatable_grouping_groups = array();
foreach (CRM_Mailchimp_Utils::getGroupsToSync(array(), $listID) as $groupID => $details) {
if (!$details['grouping_id']) {
$membership_group_id = $groupID;
} elseif ($details['is_mc_update_grouping']) {
// This group is one that we allow Mailchimp to update CiviCRM with.
$updatable_grouping_groups[$groupID] = $details;
}
}
// all Mailchimp table
$dao = CRM_Core_DAO::executeQuery("SELECT m.*, c.groupings c_groupings\n FROM tmp_mailchimp_push_m m\n LEFT JOIN tmp_mailchimp_push_c c ON m.email = c.email\n ;");
// Loop the $dao object creating/finding contacts in CiviCRM.
$groupContactRemoves = $groupContact = array();
while ($dao->fetch()) {
$params = array('FNAME' => $dao->first_name, 'LNAME' => $dao->last_name, 'EMAIL' => $dao->email);
// Update/create contact.
$contact_id = CRM_Mailchimp_Utils::updateContactDetails($params);
if ($contact_id) {
// Ensure the contact is in the membership group.
if (!$dao->c_groupings) {
// This contact was not found in the CiviCRM table.
// Therefore they are not in the membership group.
// (actually they could have an email problem as well, but that's OK).
// Add them into the membership group.
$groupContact[$membership_group_id][] = $contact_id;
$civi_groupings = array();
$stats[$listID]['added']++;
} else {
// This contact is in C and MC, but has differences.
// unpack the group membership from CiviCRM.
$civi_groupings = unserialize($dao->c_groupings);
}
// unpack the group membership reported by MC
$mc_groupings = unserialize($dao->groupings);
// Now sort out the grouping_groups for those we are supposed to allow updates for
foreach ($updatable_grouping_groups as $groupID => $details) {
// Should this person be in this grouping:group according to MC?
if (!empty($mc_groupings[$details['grouping_id']][$details['group_id']])) {
// They should be in this group.
if (empty($civi_groupings[$details['grouping_id']][$details['group_id']])) {
// But they're not! Plan to add them in.
$groupContact[$groupID][] = $contact_id;
}
} else {
// They should NOT be in this group.
if (!empty($civi_groupings[$details['grouping_id']][$details['group_id']])) {
// But they ARE. Plan to remove them.
$groupContactRemoves[$groupID][] = $contact_id;
}
}
}
}
}
// And now, what if a contact is not in the Mailchimp list? We must remove them from the membership group.
$dao = CRM_Core_DAO::executeQuery("SELECT c.contact_id\n FROM tmp_mailchimp_push_c c\n WHERE NOT EXISTS (\n SELECT m.email FROM tmp_mailchimp_push_m m WHERE m.email=c.email\n );");
// Loop the $dao object creating/finding contacts in CiviCRM.
while ($dao->fetch()) {
$groupContactRemoves[$membership_group_id][] = $dao->contact_id;
$stats[$listID]['removed']++;
}
// Log group contacts which are going to be added to CiviCRM
CRM_Core_Error::debug_var('Mailchimp $groupContact= ', $groupContact);
// FIXME: dirty hack setting a variable in session to skip post hook
require_once 'CRM/Core/Session.php';
$session = CRM_Core_Session::singleton();
$session->set('skipPostHook', 'yes');
if ($groupContact) {
// We have some contacts to add into groups...
foreach ($groupContact as $groupID => $contactIDs) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIDs, $groupID, 'Admin', 'Added');
}
}
// Log group contacts which are going to be removed from CiviCRM
CRM_Core_Error::debug_var('Mailchimp $groupContactRemoves= ', $groupContactRemoves);
if ($groupContactRemoves) {
// We have some contacts to add into groups...
foreach ($groupContactRemoves as $groupID => $contactIDs) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIDs, $groupID, 'Admin', 'Removed');
}
}
// FIXME: unset variable in session
$session->set('skipPostHook', '');
static::updatePullStats($stats);
// Finally, finish up by removing the two temporary tables
CRM_Core_DAO::executeQuery("DROP TABLE tmp_mailchimp_push_m;");
CRM_Core_DAO::executeQuery("DROP TABLE tmp_mailchimp_push_c;");
return CRM_Queue_Task::TASK_SUCCESS;
}
示例11: civicrm_group_contact_common
/**
*
* @param <type> $params
* @param <type> $op
*
* @return <type>
*/
function civicrm_group_contact_common(&$params, $op = 'add')
{
if (!is_array($params)) {
return civicrm_create_error(ts('input parameter should be an array'));
}
$contactIDs = array();
$groupIDs = array();
foreach ($params as $n => $v) {
if (substr($n, 0, 10) == 'contact_id') {
$contactIDs[] = $v;
} elseif (substr($n, 0, 8) == 'group_id') {
$groupIDs[] = $v;
}
}
if (empty($contactIDs)) {
return civicrm_create_error(ts('contact_id is a required field'));
}
if (empty($groupIDs)) {
return civicrm_create_error(ts('group_id is a required field'));
}
$method = CRM_Utils_Array::value('method', $params, 'API');
if ($op == 'add') {
$status = CRM_Utils_Array::value('status', $params, 'Added');
} elseif ($op == 'pending') {
$status = CRM_Utils_Array::value('status', $params, 'Pending');
} else {
$status = CRM_Utils_Array::value('status', $params, 'Removed');
}
$tracking = CRM_Utils_Array::value('tracking', $params);
require_once 'CRM/Contact/BAO/GroupContact.php';
$values = array('is_error' => 0);
if ($op == 'add' || $op == 'pending') {
$values['total_count'] = $values['added'] = $values['not_added'] = 0;
foreach ($groupIDs as $groupID) {
list($tc, $a, $na) = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIDs, $groupID, $method, $status, $tracking);
$values['total_count'] += $tc;
$values['added'] += $a;
$values['not_added'] += $na;
}
} else {
$values['total_count'] = $values['removed'] = $values['not_removed'] = 0;
foreach ($groupIDs as $groupID) {
list($tc, $r, $nr) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIDs, $groupID, $method, $status, $tracking);
$values['total_count'] += $tc;
$values['removed'] += $r;
$values['not_removed'] += $nr;
}
}
return $values;
}
示例12: del
/**
* function to remove/ rejoin the group
*
* @param int $groupContactId id of crm_group_contact
* @param string $status this is the status that should be updated.
*
* $access public
*/
static function del($groupContactId, $status, $contactID)
{
$groupId = CRM_Contact_BAO_GroupContact::getGroupId($groupContactId);
switch ($status) {
case 'i':
$groupStatus = 'Added';
break;
case 'p':
$groupStatus = 'Pending';
break;
case 'o':
$groupStatus = 'Removed';
break;
case 'd':
$groupStatus = 'Deleted';
break;
}
$groupNum = CRM_Contact_BAO_GroupContact::getContactGroup($contactID, 'Added', NULL, TRUE, TRUE);
if ($groupNum == 1 && $groupStatus == 'Removed' && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
CRM_Core_Session::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove'));
return FALSE;
}
$ids = array($contactID);
$method = 'Admin';
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if ($userID == $contactID) {
$method = 'Web';
}
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($ids, $groupId, $method, $groupStatus);
}
示例13: CRM_Core_Transaction
/**
* Function to create contact
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress if we need to fix address
* @param boolean $invokeHooks if we need to invoke hooks
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function &create(&$params, $fixAddress = true, $invokeHooks = true)
{
$contact = null;
if (!CRM_Utils_Array::value('contact_type', $params) && !CRM_Utils_Array::value('contact_id', $params)) {
return $contact;
}
$isEdit = true;
if ($invokeHooks) {
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('contact_id', $params)) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
$isEdit = false;
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
$params['contact_id'] = $contact->id;
if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
// in order to make sure that every contact must be added to a group (CRM-4613) -
require_once 'CRM/Core/BAO/Domain.php';
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('group', $params) && is_array($params['group'])) {
$grpFlp = array_flip($params['group']);
if (!array_key_exists(1, $grpFlp)) {
$params['group'][$domainGroupID] = 1;
}
} else {
$params['group'] = array($domainGroupID => 1);
}
}
if (array_key_exists('group', $params)) {
require_once 'CRM/Contact/BAO/GroupContact.php';
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} else {
if ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
}
//add location Block data
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//get userID from session
$session =& CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (CRM_Utils_Array::value('note', $params)) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => $note['subject'], 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
} else {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note'], 'subject' => CRM_Utils_Array::value('subject', $params), 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
}
// update the UF user_unique_id if that has changed
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::updateUFName($contact->id);
//.........这里部分代码省略.........
示例14: CRM_Core_Transaction
/**
* Function to create contact
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param boolean $fixAddress if we need to fix address
* @param boolean $invokeHooks if we need to invoke hooks
*
* @return object CRM_Contact_BAO_Contact object
* @access public
* @static
*/
static function &create(&$params, $fixAddress = true, $invokeHooks = true)
{
$contact = null;
if (!CRM_Utils_Array::value('contact_type', $params) && !CRM_Utils_Array::value('contact_id', $params)) {
return $contact;
}
$isEdit = true;
if ($invokeHooks) {
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('contact_id', $params)) {
CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
} else {
CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
$isEdit = false;
}
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
if (!$contact) {
// CRM_Core_Error::fatal( ts( 'THe contact was not created, not set up to handle error' ) );
}
$params['contact_id'] = $contact->id;
if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
// in order to make sure that every contact must be added to a group (CRM-4613) -
require_once 'CRM/Core/BAO/Domain.php';
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('group', $params) && is_array($params['group'])) {
$grpFlp = array_flip($params['group']);
if (!array_key_exists(1, $grpFlp)) {
$params['group'][$domainGroupID] = 1;
}
} else {
$params['group'] = array($domainGroupID => 1);
}
}
if (array_key_exists('group', $params)) {
require_once 'CRM/Contact/BAO/GroupContact.php';
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} else {
if ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
}
$config = CRM_Core_Config::singleton();
if (!$config->doNotResetCache) {
// Note: doNotResetCache flag is currently set by import contact process, since resetting and
// rebuilding cache could be expensive (for many contacts). We might come out with better
// approach in future.
// clear acl cache if any.
require_once 'CRM/ACL/BAO/Cache.php';
CRM_ACL_BAO_Cache::resetCache();
}
//add location Block data
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//get userID from session
$session =& CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (CRM_Utils_Array::value('note', $params)) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => $note['subject'], 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
} else {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
//.........这里部分代码省略.........
示例15: removeContactFromGroup
/**
* Remove a given contact from the group set to sync with the given
* Mailchimp list.
*/
static function removeContactFromGroup($contact, $mailchimp_list_id)
{
$contact_ids = array($contact->id);
$mailchimp_sync_settings = CRM_CiviMailchimp_BAO_SyncSettings::findByListId($mailchimp_list_id);
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contact_ids, $mailchimp_sync_settings->civicrm_group_id);
self::markContactAsNoBulkEmailsIfSettingEnabled($contact);
}