本文整理汇总了PHP中CRM_Contact_BAO_Group::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Group::create方法的具体用法?PHP CRM_Contact_BAO_Group::create怎么用?PHP CRM_Contact_BAO_Group::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Group
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Group::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRemoveFromParentSmartGroup
/**
* Allow removing contact from a parent group even if contact is in
* a child group. (CRM-8858)
*/
function testRemoveFromParentSmartGroup()
{
// Create smart group $parent
$params = array('name' => 'Deceased Contacts', 'title' => 'Deceased Contacts', 'is_active' => 1, 'formValues' => array('is_deceased' => 1));
$parent = CRM_Contact_BAO_Group::createSmartGroup($params);
$this->registerTestObjects(array($parent));
// Create group $child in $parent
$params = array('name' => 'Child Group', 'title' => 'Child Group', 'is_active' => 1, 'parents' => array($parent->id => 1));
$child = CRM_Contact_BAO_Group::create($params);
$this->registerTestObjects(array($child));
// Create $c1, $c2, $c3
$deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3);
// Add $c1, $c2, $c3 to $child
foreach ($deceased as $contact) {
$result = $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contact->id, 'group_id' => $child->id));
}
// GroupContactCache::load()
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), $parent->id);
// Remove $c1 from $parent
$result = civicrm_api('group_contact', 'create', array('contact_id' => $deceased[0]->id, 'group_id' => $parent->id, 'status' => 'Removed', 'version' => '3'));
$this->assertAPISuccess($result);
// Assert $c1 not in $parent
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(array($deceased[1]->id, $deceased[2]->id), $parent->id);
// Assert $c1 still in $child
$this->assertDBQuery(1, 'select count(*) from civicrm_group_contact where group_id=%1 and contact_id=%2 and status=%3', array(1 => array($child->id, 'Integer'), 2 => array($deceased[0]->id, 'Integer'), 3 => array('Added', 'String')));
}
示例2: civicrm_api3_group_create
/**
* create/update group
*
* This API is used to create new group or update any of the existing
* In case of updating existing group, id of that particular grop must
* be in $params array. Either id or name is required field in the
* $params array
*
* @param array $params (referance) Associative array of property
* name/value pairs to insert in new 'group'
*
* @return array returns id of the group created if success,
* error message otherwise
*@example GroupCreate.php
*{@getfields group_create}
* @access public
*/
function civicrm_api3_group_create($params)
{
$group = CRM_Contact_BAO_Group::create($params);
if (is_null($group)) {
return civicrm_api3_create_error('Group not created');
} else {
$values = array();
_civicrm_api3_object_to_array_unique_fields($group, $values[$group->id]);
return civicrm_api3_create_success($values, $params, 'group', 'create', $group);
}
}
示例3: civicrm_group_add
/**
* create/update group
*
* This API is used to create new group or update any of the existing
* In case of updating existing group, id of that particular grop must
* be in $params array. Either id or name is required field in the
* $params array
*
* @param array $params (referance) Associative array of property
* name/value pairs to insert in new 'group'
*
* @return array returns id of the group created if success,
* error message otherwise
*
* @access public
*/
function civicrm_group_add(&$params)
{
_civicrm_initialize();
if (is_null($params) || !is_array($params) || empty($params)) {
return civicrm_create_error('Required parameter missing');
}
if (!CRM_Utils_Array::value('title', $params)) {
return civicrm_create_error('Required parameter title missing');
}
$group = CRM_Contact_BAO_Group::create($params);
if (is_null($group)) {
return civicrm_create_error('Group not created');
} else {
return civicrm_create_success($group);
}
}
示例4: 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);
}
}
示例5: postProcess
//.........这里部分代码省略.........
$mapperRelatedContactPhoneType[$key] = null;
}
}
$parser =& new CRM_Import_Parser_Contact($mapperKeys, $mapperLocTypes, $mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType, $mapperRelatedContactDetails, $mapperRelatedContactLocType, $mapperRelatedContactPhoneType);
$mapFields = $this->get('fields');
$locationTypes = CRM_Core_PseudoConstant::locationType();
$phoneTypes = CRM_Core_SelectValues::phoneType();
foreach ($mapper as $key => $value) {
$header = array();
list($id, $first, $second) = explode('_', $mapper[$key][0]);
if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
$relationType =& new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(true);
$header[] = $relationType->name_a_b;
$header[] = ucwords(str_replace("_", " ", $mapper[$key][1]));
if (isset($mapper[$key][2])) {
$header[] = $locationTypes[$mapper[$key][2]];
}
if (isset($mapper[$key][3])) {
$header[] = $phoneTypes[$mapper[$key][3]];
}
} else {
if (isset($mapFields[$mapper[$key][0]])) {
$header[] = $mapFields[$mapper[$key][0]];
if (isset($mapper[$key][1])) {
$header[] = $locationTypes[$mapper[$key][1]];
}
if (isset($mapper[$key][2])) {
$header[] = $phoneTypes[$mapper[$key][2]];
}
}
}
$mapperFields[] = implode(' - ', $header);
}
$parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_IMPORT_PARSER_MODE_IMPORT, $this->get('contactType'), $onDuplicate);
// add the new contacts to selected groups
$contactIds =& $parser->getImportedContacts();
// add the new related contacts to selected groups
$relatedContactIds =& $parser->getRelatedImportedContacts();
$this->set('relatedCount', count($relatedContactIds));
$newGroupId = null;
//changed below if-statement "if ($newGroup) {" to "if ($newGroupName) {"
if ($newGroupName) {
/* Create a new group */
$gParams = array('domain_id' => CRM_Core_Config::domainID(), 'name' => $newGroupName, 'title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => true);
$group =& CRM_Contact_BAO_Group::create($gParams);
$groups[] = $newGroupId = $group->id;
}
if (is_array($groups)) {
$groupAdditions = array();
foreach ($groups as $groupId) {
$addCount =& CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
if (!empty($relatedContactIds)) {
$addRelCount =& CRM_Contact_BAO_GroupContact::addContactsToGroup($relatedContactIds, $groupId);
}
$totalCount = $addCount[1] + $addRelCount[1];
if ($groupId == $newGroupId) {
$name = $newGroupName;
$new = true;
} else {
$name = $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);
}
$this->set('groupAdditions', $groupAdditions);
}
if (is_array($tagForContact)) {
$tagAddition = array();
require_once "CRM/Core/BAO/EntityTag.php";
foreach ($tagForContact as $tagId => $selected) {
$taggedContacts = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId);
$tagName = $allTags[$tagId];
$tagAdditions[] = array('name' => $tagName, 'added' => $taggedContacts[1], 'notAdded' => $taggedContacts[2]);
}
$this->set('tagAdditions', $tagAdditions);
}
// add all the necessary variables to the form
$parser->set($this, CRM_IMPORT_PARSER_MODE_IMPORT);
// check if there is any error occured
$errorStack =& CRM_Core_Error::singleton();
$errors = $errorStack->getErrors();
$errorMessage = array();
$config =& CRM_Core_Config::singleton();
if (is_array($errors)) {
foreach ($errors as $key => $value) {
$errorMessage[] = $value['message'];
}
$errorFile = $fileName . '.error.log';
if ($fd = fopen($errorFile, 'w')) {
fwrite($fd, implode('\\n', $errorMessage));
}
fclose($fd);
$this->set('errorFile', $errorFile);
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=1'));
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=2'));
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=4'));
}
}
示例6: postProcess
/**
* Process the form when submitted.
*/
public function postProcess()
{
CRM_Utils_System::flushCache('CRM_Core_DAO_Group');
$updateNestingCache = FALSE;
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Group::discard($this->_id);
CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $this->_title)), ts('Group Deleted'), 'success');
$updateNestingCache = TRUE;
} else {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$params['is_active'] = CRM_Utils_Array::value('is_active', $this->_groupValues, 1);
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_groupOrganizationID)) {
$params['group_organization'] = $this->_groupOrganizationID;
}
$params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
$groupTypeIds = array();
$groupType = CRM_Utils_Array::value('group_type', $params);
if (is_array($groupType)) {
foreach ($groupType as $type => $selected) {
if ($selected) {
$groupTypeIds[] = $type;
}
}
}
$params['group_type'] = $groupTypeIds;
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Group');
$group = CRM_Contact_BAO_Group::create($params);
//Remove any parent groups requested to be removed
if (!empty($this->_groupValues['parents'])) {
$parentGroupIds = explode(',', $this->_groupValues['parents']);
foreach ($parentGroupIds as $parentGroupId) {
if (isset($params["remove_parent_group_{$parentGroupId}"])) {
CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
$updateNestingCache = TRUE;
}
}
}
CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)), ts('Group Saved'), 'success');
// Add context to the session, in case we are adding members to the group
if ($this->_action & CRM_Core_Action::ADD) {
$this->set('context', 'amtg');
$this->set('amtgID', $group->id);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
}
}
// update the nesting cache
if ($updateNestingCache) {
CRM_Contact_BAO_GroupNestingCache::update();
}
}
示例7: getGroupId
static function getGroupId()
{
static $groupID = null;
if ($groupID) {
return $groupID;
}
if (defined('CIVICRM_DOMAIN_GROUP_ID') && CIVICRM_DOMAIN_GROUP_ID) {
$groupID = CIVICRM_DOMAIN_GROUP_ID;
} else {
if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
// create a group with that of domain name
$title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'name');
$groupID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $title, 'id', 'title');
if (empty($groupID) && !empty($title)) {
$groupParams = array('title' => $title, 'is_active' => 1, 'no_parent' => 1);
require_once 'CRM/Contact/BAO/Group.php';
$group = CRM_Contact_BAO_Group::create($groupParams);
$groupID = $group->id;
}
}
}
return $groupID ? $groupID : false;
}
示例8: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
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'];
$group = CRM_Core_PseudoConstant::group();
$groupName = $group[$groupID];
}
list($total, $added, $notAdded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $groupID);
$status = array(ts('%count contact added to group', array('count' => $added, 'plural' => '%count contacts added to group')));
if ($notAdded) {
$status[] = ts('%count contact was already in group', array('count' => $notAdded, 'plural' => '%count contacts were already in group'));
}
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('Added Contact to %1', array(1 => $groupName, 'count' => $added, 'plural' => 'Added Contacts to %1')), 'success', array('expires' => 0));
}
示例9: postProcess
public function postProcess()
{
$values = $this->controller->exportValues($this->_name);
//build hidden smart group. when user want to send mailing
//through search contact-> more action -> send Mailing. CRM-3711
$groups = array();
if ($this->_searchBasedMailing && $this->_contactIds) {
$session = CRM_Core_Session::singleton();
if ($this->_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($this->_contactIds, $group->id);
$newGroupTitle = "Hidden Group {$grpID}";
$groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle);
$group = CRM_Contact_BAO_Group::create($groupParams);
}
// note at this point its a static group
$smartGroupId = $grpID;
} else {
//get the hidden smart group id.
$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);
//set the saved search id.
if (!$ssId) {
if ($savedSearchId) {
$this->set('ssID', $savedSearchId);
} else {
CRM_Core_Error::fatal();
}
}
}
//get the base group for this mailing, CRM-3711
$groups['base'] = array($values['baseGroup']);
$values['includeGroups'][] = $smartGroupId;
}
foreach (array('name', 'group_id', 'search_id', 'search_args', 'campaign_id', 'dedupe_email') as $n) {
if (CRM_Utils_Array::value($n, $values)) {
$params[$n] = $values[$n];
}
}
$qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
$this->set('name', $params['name']);
$inGroups = $values['includeGroups'];
$outGroups = $values['excludeGroups'];
$inMailings = $values['includeMailings'];
$outMailings = $values['excludeMailings'];
if (is_array($inGroups)) {
foreach ($inGroups as $key => $id) {
if ($id) {
$groups['include'][] = $id;
}
}
}
if (is_array($outGroups)) {
foreach ($outGroups as $key => $id) {
if ($id) {
$groups['exclude'][] = $id;
}
}
}
$mailings = array();
if (is_array($inMailings)) {
foreach ($inMailings as $key => $id) {
if ($id) {
$mailings['include'][] = $id;
}
}
}
if (is_array($outMailings)) {
foreach ($outMailings as $key => $id) {
if ($id) {
$mailings['exclude'][] = $id;
}
}
}
$session = CRM_Core_Session::singleton();
$params['groups'] = $groups;
$params['mailings'] = $mailings;
if ($this->get('mailing_id')) {
$ids = array();
// don't create a new mailing if already exists
$ids['mailing_id'] = $this->get('mailing_id');
$groupTableName = CRM_Contact_BAO_Group::getTableName();
$mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
// delete previous includes/excludes, if mailing already existed
foreach (array('groups', 'mailings') as $entity) {
$mg = new CRM_Mailing_DAO_Group();
$mg->mailing_id = $ids['mailing_id'];
$mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
$mg->find();
while ($mg->fetch()) {
$mg->delete();
}
//.........这里部分代码省略.........
示例10: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
function postProcess()
{
if ($this->_action & CRM_CORE_ACTION_DELETE) {
CRM_Contact_BAO_Group::discard($this->_id);
CRM_Core_Session::setStatus(ts('The Group "%1" has been deleted.', array(1 => $this->_title)));
} else {
// store the submitted values in an array
$params = $this->exportValues();
$params['domain_id'] = CRM_Core_Config::domainID();
$params['is_active'] = 1;
if ($this->_action & CRM_CORE_ACTION_UPDATE) {
$params['id'] = $this->_id;
}
$group =& CRM_Contact_BAO_Group::create($params);
// do the updates/inserts
CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params);
CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, 'Group', $group->id);
CRM_Core_Session::setStatus(ts('The Group "%1" has been saved.', array(1 => $group->title)));
/*
* Add context to the session, in case we are adding members to the group
*/
if ($this->_action & CRM_CORE_ACTION_ADD) {
$this->set('context', 'amtg');
$this->set('amtgID', $group->id);
$session =& CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
}
}
}
示例11: _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;
}
示例12: testContactSearchByParentGroup
/**
* Test case for contact search: CRM-6706, CRM-6586 Parent Group search should return contacts from child groups too.
*/
public function testContactSearchByParentGroup()
{
// create a parent group
// TODO: This is not an API test!!
$groupParams1 = array('title' => 'Parent Group', 'description' => 'Parent Group', 'visibility' => 'User and User Admin Only', 'parents' => '', 'is_active' => 1);
$parentGroup = CRM_Contact_BAO_Group::create($groupParams1);
// create a child group
$groupParams2 = array('title' => 'Child Group', 'description' => 'Child Group', 'visibility' => 'User and User Admin Only', 'parents' => $parentGroup->id, 'is_active' => 1);
$childGroup = CRM_Contact_BAO_Group::create($groupParams2);
// Create a contact within parent group
$parentContactParams = array('first_name' => 'Parent1 Fname', 'last_name' => 'Parent1 Lname', 'group' => array($parentGroup->id => 1));
$parentContact = Contact::createIndividual($parentContactParams);
// create a contact within child dgroup
$childContactParams = array('first_name' => 'Child1 Fname', 'last_name' => 'Child2 Lname', 'group' => array($childGroup->id => 1));
$childContact = Contact::createIndividual($childContactParams);
// Check if searching by parent group returns both parent and child group contacts
$searchParams = array('group' => $parentGroup->id, 'version' => 3);
$result = civicrm_api('contact', 'get', $searchParams);
$validContactIds = array($parentContact, $childContact);
$resultContactIds = array();
foreach ($result['values'] as $k => $v) {
$resultContactIds[] = $v['contact_id'];
}
$this->assertEquals(2, count($resultContactIds), 'Check the count of returned values');
$this->assertEquals(array(), array_diff($validContactIds, $resultContactIds), 'Check that the difference between two arrays should be blank array');
// Check if searching by child group returns just child group contacts
$searchParams = array('group' => $childGroup->id, 'version' => 3);
$result = civicrm_api('contact', 'get', $searchParams);
$validChildContactIds = array($childContact);
$resultChildContactIds = array();
foreach ($result['values'] as $k => $v) {
$resultChildContactIds[] = $v['contact_id'];
}
$this->assertEquals(1, count($resultChildContactIds), 'Check the count of returned values');
$this->assertEquals(array(), array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array');
}
示例13: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
public function postProcess()
{
$updateNestingCache = false;
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Group::discard($this->_id);
CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $this->_title)));
$updateNestingCache = true;
} else {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$params['is_active'] = 1;
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_groupOrganizationID)) {
$params['group_organization'] = $this->_groupOrganizationID;
}
$customFields = CRM_Core_BAO_CustomField::getFields('Group');
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Group');
require_once 'CRM/Contact/BAO/Group.php';
$group =& CRM_Contact_BAO_Group::create($params);
/*
* Remove any parent groups requested to be removed
*/
if (CRM_Utils_Array::value('parents', $this->_groupValues)) {
$parentGroupIds = explode(',', $this->_groupValues['parents']);
foreach ($parentGroupIds as $parentGroupId) {
if (isset($params["remove_parent_group_{$parentGroupId}"])) {
CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
$updateNestingCache = true;
}
}
}
CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)));
/*
* Add context to the session, in case we are adding members to the group
*/
if ($this->_action & CRM_Core_Action::ADD) {
$this->set('context', 'amtg');
$this->set('amtgID', $group->id);
$session =& CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
}
}
// update the nesting cache
if ($updateNestingCache) {
require_once 'CRM/Contact/BAO/GroupNestingCache.php';
CRM_Contact_BAO_GroupNestingCache::update();
}
require_once 'CRM/Utils/Recent.php';
// add the recently added group
CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', null, null);
}
示例14: _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;
}
示例15: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
$params = $this->controller->exportValues();
$groupOption = $params['group_option'];
if ($groupOption) {
$groupParams = array();
$groupParams['title'] = $params['title'];
$groupParams['description'] = $params['description'];
$groupParams['visibility'] = "User and User Admin Only";
if (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;
require_once 'CRM/Contact/BAO/Group.php';
$createdGroup =& CRM_Contact_BAO_Group::create($groupParams);
$groupID = $createdGroup->id;
$groupName = $groupParams['title'];
} else {
$groupID = $params['group_id'];
$group =& CRM_Core_PseudoConstant::group();
$groupName = $group[$groupID];
}
list($total, $added, $notAdded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $groupID);
$status = array(ts('Added Contact(s) to %1', array(1 => $groupName)), ts('Total Selected Contact(s): %1', array(1 => $total)));
if ($added) {
$status[] = ts('Total Contact(s) added to group: %1', array(1 => $added));
}
if ($notAdded) {
$status[] = ts('Total Contact(s) already in group: %1', array(1 => $notAdded));
}
$status = implode('<br/>', $status);
CRM_Core_Session::setStatus($status);
}