/** * 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'))); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ function postProcess() { $fileName = $this->controller->exportValue('UploadFile', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $newGroup = $this->controller->exportValue($this->_name, 'newGroup'); $newGroupName = $this->controller->exportValue($this->_name, 'newGroupName'); $newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc'); $groups = $this->controller->exportValue($this->_name, 'groups'); $allGroups = $this->get('groups'); $tagForContact = $this->controller->exportValue($this->_name, 'tag'); $allTags = $this->get('tag'); $seperator = ','; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocTypes = array(); $mapperPhoneTypes = array(); $mapperRelated = array(); $mapperRelatedContactType = array(); $mapperRelatedContactDetails = array(); $mapperRelatedContactLocType = array(); $mapperRelatedContactPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocTypes[$key] = $mapper[$key][1]; } else { $mapperLocTypes[$key] = null; } if (!is_numeric($mapper[$key][2])) { $mapperPhoneTypes[$key] = $mapper[$key][2]; } else { $mapperPhoneTypes[$key] = null; } 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); eval('$mapperRelatedContactType[$key] = $relationType->contact_type_' . $second . ';'); $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; $mapperRelatedContactPhoneType[$key] = $mapper[$key][3]; } else { $mapperRelated[$key] = null; $mapperRelatedContactType[$key] = null; $mapperRelatedContactDetails[$key] = null; $mapperRelatedContactLocType[$key] = null; $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')); } }
/** * 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(); } }
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; }
/** * 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)); }
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(); } } } else { // new mailing, so lets set the created_id $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids); $this->set('mailing_id', $mailing->id); $dedupeEmail = FALSE; if (isset($params['dedupe_email'])) { $dedupeEmail = $params['dedupe_email']; } // also compute the recipients and store them in the mailing recipients table CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, NULL, NULL, TRUE, $dedupeEmail); $count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id); $this->set('count', $count); $this->assign('count', $count); $this->set('groups', $groups); $this->set('mailings', $mailings); if ($qf_Group_submit) { //when user perform mailing from search context //redirect it to search result CRM-3711. $ssID = $this->get('ssID'); $context = $this->get('context'); if ($ssID && $this->_searchBasedMailing) { if ($this->_action == CRM_Core_Action::BASIC) { $fragment = 'search'; } elseif ($this->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } elseif ($this->_action == CRM_Core_Action::ADVANCED) { $fragment = 'search/advanced'; } else { $fragment = 'search/custom'; } $context = $this->get('context'); if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL)); CRM_Core_Session::setStatus($status); //replace user context to search. $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); return $this->controller->setDestination($url); } else { $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it."); CRM_Core_Session::setStatus($status); $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); return $this->controller->setDestination($url); } } }
/** * 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)); } } }
/** * @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; }
/** * 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'); }
/** * 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); }
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; }
/** * 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); }
static function createTestGroupAndSyncSettings($group_name, $mailchimp_list_id = 'MailchimpListsTestListA', $mailchimp_interest_groups = array()) { $group_params = array('name' => $group_name, 'title' => $group_name, 'domain_id' => 1, 'description' => 'New Test Group Created', 'is_active' => 1, 'visibility' => 'Public Pages', 'group_type' => array('1' => 1, '2' => 1)); $group = CRM_Contact_BAO_Group::create($group_params); $mailchimp_sync_setting = self::createTestSettings($group->id, $mailchimp_list_id, $mailchimp_interest_groups); return $mailchimp_sync_setting; }
/** * @return bool|null|object|string */ static function getGroupId() { static $groupID = NULL; if ($groupID) { return $groupID; } $domainGroupID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'domain_group_id'); $multisite = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled'); if ($domainGroupID) { $groupID = $domainGroupID; } elseif ($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', true); if (empty($groupID) && !empty($title)) { $groupParams = array('title' => $title, 'is_active' => 1, 'no_parent' => 1); $group = CRM_Contact_BAO_Group::create($groupParams); $groupID = $group->id; } } return $groupID ? $groupID : FALSE; }
/** * Defines a new group (static or query-based) * * @param array $params Associative array of parameters * @return object|null The new group BAO (if created) * @access public * @static */ function createGroup(&$params) { if (CRM_Utils_Array::value('saved_search_id', $params)) { $savedSearch =& new CRM_Contact_DAO_SavedSearch(); $savedSearch->domain_id = CRM_Core_Config::domainID(); $savedSearch->form_values = CRM_Utils_Array::value('formValues', $params); $savedSearch->is_active = 1; $savedSearch->id = $params['saved_search_id']; $savedSearch->save(); } return CRM_Contact_BAO_Group::create($params); }
/** * 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")); } }
/** * 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); }
/** * process the form after the input has been submitted and validated * * @access public * @return void */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = null; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder require_once "CRM/Core/BAO/Mapping.php"; if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search require_once "CRM/Contact/BAO/SavedSearch.php"; $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(true); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts('Your smart group has been saved as \'%1\'.', array(1 => $formValues['title']))); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } require_once 'CRM/Contact/BAO/Group.php'; $group =& CRM_Contact_BAO_Group::create($params); }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = NULL; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(TRUE); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; // Use the query parameters rather than the form values - these have already been assessed / converted // with the extra knowledge that the form has. // Note that we want to move towards a standardised way of saving the query that is not // an exact match for the form requirements & task the form layer with converting backwards and forwards. // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the // sql operator syntax at the query layer. $savedSearch->form_values = serialize($this->get('queryParams')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (isset($formValues['group_type']) && is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; //CRM-14190 $params['parents'] = $formValues['parents']; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); // CRM-9464 $this->_id = $savedSearch->id; //CRM-14190 if (!empty($formValues['parents'])) { CRM_Contact_BAO_GroupNestingCache::update(); } }
/** * Test case for add( ). */ public function testAddSimple() { $checkParams = $params = array('title' => 'Group Uno', 'description' => 'Group One', 'visibility' => 'User and User Admin Only', 'is_active' => 1); $group = CRM_Contact_BAO_Group::create($params); $this->assertDBCompareValues('CRM_Contact_DAO_Group', array('id' => $group->id), $checkParams); }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcessOld() { $doGeocodeAddress = $this->controller->exportValue('DataSource', 'doGeocodeAddress'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $newGroupName = $this->controller->exportValue($this->_name, 'newGroupName'); $newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc'); $groups = $this->controller->exportValue($this->_name, 'groups'); $allGroups = $this->get('groups'); $newTagName = $this->controller->exportValue($this->_name, 'newTagName'); $newTagDesc = $this->controller->exportValue($this->_name, 'newTagDesc'); $tag = $this->controller->exportValue($this->_name, 'tag'); $allTags = $this->get('tag'); $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocTypes = array(); $mapperPhoneTypes = array(); $mapperRelated = array(); $mapperRelatedContactType = array(); $mapperRelatedContactDetails = array(); $mapperRelatedContactLocType = array(); $mapperRelatedContactPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocTypes[$key] = $mapper[$key][1]; } else { $mapperLocTypes[$key] = NULL; } if (CRM_Utils_Array::value($key, $mapperKeys) == 'phone') { $mapperPhoneTypes[$key] = $mapper[$key][2]; } else { $mapperPhoneTypes[$key] = NULL; } 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); $fieldName = "contact_type_{$second}"; $mapperRelatedContactType[$key] = $relationType->{$fieldName}; $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; $mapperRelatedContactPhoneType[$key] = $mapper[$key][3]; } else { $mapperRelated[$key] = NULL; $mapperRelatedContactType[$key] = NULL; $mapperRelatedContactDetails[$key] = NULL; $mapperRelatedContactLocType[$key] = NULL; $mapperRelatedContactPhoneType[$key] = NULL; } } $parser = new CRM_Contact_Import_Parser_Contact($mapperKeys, $mapperLocTypes, $mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType, $mapperRelatedContactDetails, $mapperRelatedContactLocType, $mapperRelatedContactPhoneType); $mapFields = $this->get('fields'); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); 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); } $tableName = $this->get('importTableName'); //print "Running parser on table: $tableName<br/>"; $parser->run($tableName, $mapperFields, CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $this->get('primaryKeyName'), $this->get('statusFieldName'), $onDuplicate, $this->get('statusID'), $this->get('totalRowCount'), $doGeocodeAddress, CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'), $this->get('dedupe')); // 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('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] + $addRelCount[2], 'new' => $new); } $this->set('groupAdditions', $groupAdditions); } $newTagId = NULL; if ($newTagName) { /* Create a new Tag */ $tagParams = array('name' => $newTagName, 'title' => $newTagName, 'description' => $newTagDesc, 'is_active' => TRUE); $id = array(); $addedTag = CRM_Core_BAO_Tag::add($tagParams, $id); $tag[$addedTag->id] = 1; } //add Tag to Import if (is_array($tag)) { $tagAdditions = array(); foreach ($tag as $tagId => $val) { $addTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId); if (!empty($relatedContactIds)) { $addRelTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($relatedContactIds, $tagId); } $totalTagCount = $addTagCount[1] + $addRelTagCount[1]; if ($tagId == $addedTag->id) { $tagName = $newTagName; $new = TRUE; } else { $tagName = $allTags[$tagId]; $new = FALSE; } $tagAdditions[] = array('url' => CRM_Utils_System::url('civicrm/contact/search', 'reset=1&force=1&context=smog&id=' . $tagId), 'name' => $tagName, 'added' => $totalTagCount, 'notAdded' => $addTagCount[2] + $addRelTagCount[2], 'new' => $new); } $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(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } // there is no fileName since this is a sql import // so fudge it $config = CRM_Core_Config::singleton(); $errorFile = $config->uploadDir . "sqlImport.error.log"; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlparams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = NULL; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(TRUE); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (isset($formValues['group_type']) && is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; //CRM-14190 $params['parents'] = $formValues['parents']; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); // CRM-9464 $this->_id = $savedSearch->id; //CRM-14190 if (!empty($formValues['parents'])) { CRM_Contact_BAO_GroupNestingCache::update(); } }
/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { // saved search form values $formValues = $this->controller->exportValues(); $session = CRM_Core_Session::singleton(); //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); }
/** * process the form after the input has been submitted and validated * * @access public * @return void */ function postProcess() { // saved search form values $formValues = $this->controller->exportValues($this->_name); // save the search $savedSearch =& new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->domain_id = CRM_Core_Config::domainID(); $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->is_active = 1; $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts('Your smart group has been saved as "%1".', array(1 => $formValues['title']))); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['domain_id'] = CRM_Core_Config::domainID(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group =& CRM_Contact_BAO_Group::create($params); }