function testAddSmart() { $checkParams = $params = array('title' => 'Group Dos', 'description' => 'Group Two', 'visibility' => 'User and User Admin Only', 'is_active' => 1, 'formValues' => array('sort_name' => 'Adams')); $group = CRM_Contact_BAO_Group::createSmartGroup($params); unset($checkParams['formValues']); $this->assertDBCompareValues('CRM_Contact_DAO_Group', array('id' => $group->id), $checkParams); }
/** * Get list of groups. */ public static function getGroupList() { $params = $_GET; if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; $params['rp'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); CRM_Utils_JSON::output($groups); } else { $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); $optionalParameters = array('parentsOnly' => 'Integer', 'showOrgInfo' => 'Boolean'); $params += CRM_Core_Page_AJAX::validateParams(array(), $optionalParameters); // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), // go ahead with flat hierarchy, CRM-12225 if (empty($groups)) { $groupsAccessible = CRM_Core_PseudoConstant::group(); $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params); if (!empty($groupsAccessible) && $parentsOnly) { // recompute group list with flat hierarchy $params['parentsOnly'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } CRM_Utils_JSON::output($groups); } }
/** * 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'))); }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { // text for sort_name or email criteria $config = CRM_Core_Config::singleton(); $label = empty($config->includeEmailInName) ? ts('Name') : ts('Name or Email'); $this->add('text', 'sort_name', $label); $searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options'); $shortCuts = array(); //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form // this is loaded onto then replace with something like '__' & test $separator = CRM_Core_DAO::VALUE_SEPARATOR; if (!empty($searchOptions['contactType'])) { $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator); $this->add('select', 'contact_type', ts('is...'), $contactTypes, FALSE, array('class' => 'crm-select2')); } if (!empty($searchOptions['groups'])) { // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, ' ', TRUE); // add select for groups $group = array('' => ts('- any group -')) + $groupHierarchy; $this->add('select', 'group', ts('in'), $group, FALSE, array('class' => 'crm-select2')); } if (!empty($searchOptions['tags'])) { // tag criteria if (!empty($this->_tag)) { $tag = array('' => ts('- any tag -')) + $this->_tag; $this->add('select', 'tag', ts('with'), $tag, FALSE, array('class' => 'crm-select2')); } } parent::buildQuickForm(); }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { // text for sort_name or email criteria $config = CRM_Core_Config::singleton(); $label = empty($config->includeEmailInName) ? ts('Name') : ts('Name or Email'); $this->add('text', 'sort_name', $label); $searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options'); if (!empty($searchOptions['contactType'])) { $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements(); $this->add('select', 'contact_type', ts('is...'), $contactTypes); } if (!empty($searchOptions['groups'])) { // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, ' ', TRUE); // add select for groups $group = array('' => ts('- any group -')) + $groupHierarchy; $this->_groupElement =& $this->addElement('select', 'group', ts('in'), $group); } if (!empty($searchOptions['tags'])) { // tag criteria if (!empty($this->_tag)) { $tag = array('' => ts('- any tag -')) + $this->_tag; $this->_tagElement =& $this->addElement('select', 'tag', ts('with'), $tag); } } parent::buildQuickForm(); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { // get the list of all the groups if ($this->_context == 'user') { $onlyPublicGroups = CRM_Utils_Request::retrieve('onlyPublicGroups', 'Boolean', $this, FALSE); $allGroups = CRM_Core_PseudoConstant::staticGroup($onlyPublicGroups); } else { $allGroups = CRM_Core_PseudoConstant::group(); } // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($allGroups, NULL, ' ', TRUE); // get the list of groups contact is currently in ("Added") or unsubscribed ("Removed"). $currentGroups = CRM_Contact_BAO_GroupContact::getGroupList($this->_contactId); // Remove current groups from drowdown options ($groupSelect) if (is_array($currentGroups)) { // Compare array keys, since the array values (group title) in $groupList may have extra spaces for indenting child groups $groupSelect = array_diff_key($groupHierarchy, $currentGroups); } else { $groupSelect = $groupHierarchy; } $groupSelect = array('' => ts('- select group -')) + $groupSelect; if (count($groupSelect) > 1) { $session = CRM_Core_Session::singleton(); // user dashboard if (strstr($session->readUserContext(), 'user')) { $msg = ts('Join a Group'); } else { $msg = ts('Add to a group'); } $this->add('select', 'group_id', '', $groupSelect, TRUE, array('class' => 'crm-select2 crm-action-menu action-icon-plus', 'placeholder' => $msg)); $this->addButtons(array(array('type' => 'next', 'name' => ts('Add'), 'isDefault' => TRUE))); } }
function buildQuickForm() { // Contact $this->add('hidden', 'contact_id', ts('Contact id'), '', true); // get the list of all the groups $allGroups = CRM_Core_PseudoConstant::group(); // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($allGroups, NULL, ' ', TRUE); // get the list of groups contact is currently in ("Added") or unsubscribed ("Removed"). $currentGroups = CRM_Contact_BAO_GroupContact::getGroupList($this->_contactId); // Remove current groups from drowdown options ($groupSelect) if (is_array($currentGroups)) { // Compare array keys, since the array values (group title) in $groupList may have extra spaces for indenting child groups $groupSelect = array_diff_key($groupHierarchy, $currentGroups); } else { $groupSelect = $groupHierarchy; } $groupSelect = array('' => ts('- select group -')) + $groupSelect; if (count($groupSelect) > 1) { $session = CRM_Core_Session::singleton(); $msg = ts('Add to a group'); $this->add('select', 'group_id', $msg, $groupSelect, false); $this->addButtons(array(array('type' => 'submit', 'name' => ts('Opslaan / Volgende'), 'isDefault' => TRUE))); // export form elements $this->assign('elementNames', $this->getRenderableElementNames()); } parent::buildQuickForm(); }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = array(); $params = array(); $params = array('saved_search_id' => $this->_id); CRM_Contact_BAO_Group::retrieve($params, $defaults); return $defaults; }
function testForceMailchimpToCiviSync() { $mailchimp_export_url = __DIR__ . '/../../../sample_mailchimp_export.txt'; $mailchimp_export_url = 'file:///' . realpath($mailchimp_export_url); $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group testForceMailchimpToCiviSync'); $mailchimp_members = CRM_CiviMailchimp_Form_Sync::forceMailchimpToCiviSync($mailchimp_export_url, $mailchimp_sync_setting); $contacts = CRM_Contact_BAO_Group::getGroupContacts($mailchimp_sync_setting->civicrm_group_id); $this->assertCount(3, $mailchimp_members); $this->assertCount(3, $contacts); }
/** * Delete a saved search. * * @param int $id * Id of saved search. */ public function delete($id) { // first delete the group associated with this saved search $group = new CRM_Contact_DAO_Group(); $group->saved_search_id = $id; if ($group->find(TRUE)) { CRM_Contact_BAO_Group::discard($group->id); } $savedSearch = new CRM_Contact_DAO_SavedSearch(); $savedSearch->id = $id; $savedSearch->is_active = 0; $savedSearch->save(); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { // add the email address $this->add('text', 'email', ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'), TRUE); $this->addRule('email', ts("Please enter a valid email address."), 'email'); if (!$this->_groupID) { // create a selector box of all public groups $groupTypeCondition = CRM_Contact_BAO_Group::groupTypeCondition('Mailing'); $query = "\nSELECT id, title, description\n FROM civicrm_group\n WHERE ( saved_search_id = 0\n OR saved_search_id IS NULL )\n AND visibility != 'User and User Admin Only'\n AND {$groupTypeCondition}\nORDER BY title"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); $rows = array(); while ($dao->fetch()) { $row = array(); $row['id'] = $dao->id; $row['title'] = $dao->title; $row['description'] = $dao->description; $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $row['id']; $this->addElement('checkbox', $row['checkbox'], NULL, NULL); $rows[] = $row; } if (empty($rows)) { CRM_Core_Error::fatal(ts('There are no public mailing list groups to display.')); } $this->assign('rows', $rows); $this->addFormRule(array('CRM_Mailing_Form_Subscribe', 'formRule')); } $addCaptcha = TRUE; // if recaptcha is not configured, then dont add it // CRM-11316 Only enable ReCAPTCHA for anonymous visitors $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if (empty($config->recaptchaPublicKey) || empty($config->recaptchaPrivateKey) || $contactID) { $addCaptcha = FALSE; } else { // if this is POST request and came from a block, // lets add recaptcha only if already present // gross hack for now if (!empty($_POST) && !array_key_exists('recaptcha_challenge_field', $_POST)) { $addCaptcha = FALSE; } } if ($addCaptcha) { // add captcha $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); $this->assign('isCaptcha', TRUE); } $this->addButtons(array(array('type' => 'next', 'name' => ts('Subscribe'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Get list of groups. * * @return array */ public static function getGroupList() { $params = $_REQUEST; if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; $params['rp'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); CRM_Utils_JSON::output($groups); } else { $sortMapper = array(0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), // go ahead with flat hierarchy, CRM-12225 if (empty($groups)) { $groupsAccessible = CRM_Core_PseudoConstant::group(); $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params); if (!empty($groupsAccessible) && $parentsOnly) { // recompute group list with flat hierarchy $params['parentsOnly'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } $iFilteredTotal = $iTotal = $params['total']; $selectorElements = array('group_name', 'count', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class'); if (empty($params['showOrgInfo'])) { unset($selectorElements[6]); } //add setting so this can be tested by unit test //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function if (!empty($params['is_unit_test'])) { return array($groups, $iFilteredTotal); } CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } }
/** * Takes an associative array and creates a campaign object. * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Campaign_DAO_Campaign */ public static function create(&$params) { if (empty($params)) { return NULL; } if (!CRM_Utils_Array::value('id', $params)) { if (!CRM_Utils_Array::value('created_id', $params)) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } if (!CRM_Utils_Array::value('created_date', $params)) { $params['created_date'] = date('YmdHis'); } if (!CRM_Utils_Array::value('name', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64); } CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params); } else { CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params); } $campaign = new CRM_Campaign_DAO_Campaign(); $campaign->copyValues($params); $campaign->save(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign); } else { CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign); } /* Create the campaign group record */ $groupTableName = CRM_Contact_BAO_Group::getTableName(); if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) { foreach ($params['groups']['include'] as $entityId) { $dao = new CRM_Campaign_DAO_CampaignGroup(); $dao->campaign_id = $campaign->id; $dao->entity_table = $groupTableName; $dao->entity_id = $entityId; $dao->group_type = 'Include'; $dao->save(); $dao->free(); } } //store custom data if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id); } return $campaign; }
/** * Get list of groups. * * @return array */ public static function getGroupList() { $params = $_GET; if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; $params['rp'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); CRM_Utils_JSON::output($groups); } else { $sortMapper = array(); $columns = CRM_Utils_Array::value('columns', $params, array()); foreach ($columns as $key => $value) { $sortMapper[$key] = $value['data']; } $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), // go ahead with flat hierarchy, CRM-12225 if (empty($groups)) { $groupsAccessible = CRM_Core_PseudoConstant::group(); $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params); if (!empty($groupsAccessible) && $parentsOnly) { // recompute group list with flat hierarchy $params['parentsOnly'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } //add setting so this can be tested by unit test //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function if (!empty($params['is_unit_test'])) { return array($groups['data'], $params['total']); } CRM_Utils_JSON::output($groups); } }
static function getGroupList() { $params = $_REQUEST; if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; $params['rp'] = 25; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); echo json_encode($groups); CRM_Utils_System::civiExit(); } else { $sortMapper = array(0 => 'groups.title', 1 => 'groups.id', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), // go ahead with flat hierarchy, CRM-12225 if (empty($groups)) { $groupsAccessible = CRM_Core_PseudoConstant::group(); $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params); if (!empty($groupsAccessible) && $parentsOnly) { // recompute group list with flat hierarchy $params['parentsOnly'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } $iFilteredTotal = $iTotal = $params['total']; $selectorElements = array('group_name', 'group_id', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class'); if (empty($params['showOrgInfo'])) { unset($selectorElements[6]); } echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); } }
/** * Get list of groups. */ public static function getGroupList() { $params = $_GET; if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; $params['rp'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); CRM_Utils_JSON::output($groups); } else { $sortMapper = array(); $columns = CRM_Utils_Array::value('columns', $params, array()); foreach ($columns as $key => $value) { $sortMapper[$key] = $value['data']; } $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case), // go ahead with flat hierarchy, CRM-12225 if (empty($groups)) { $groupsAccessible = CRM_Core_PseudoConstant::group(); $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params); if (!empty($groupsAccessible) && $parentsOnly) { // recompute group list with flat hierarchy $params['parentsOnly'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } CRM_Utils_JSON::output($groups); } }
static function updateCiviGroup(&$params, $op, $groupType = NULL) { $abort = false; $params['version'] = 3; $params['id'] = CRM_Bridge_OG_Utils::groupID($params['source'], $params['title'], $abort); if ($op == 'add') { if ($groupType) { $params['group_type'] = $groupType; } $group = civicrm_api('group', 'create', $params); if (!civicrm_error($group)) { $params['group_id'] = $group['id']; } } else { // do this only if we have a valid id if ($params['id']) { CRM_Contact_BAO_Group::discard($params['id']); $params['group_id'] = $params['id']; } } unset($params['id']); }
/** * Test to check contact reference field */ public function testContactReference() { //create group $groupId1 = $this->groupCreate(); $groupId2 = $this->groupCreate(array('name' => 'Test Group 2', 'domain_id' => 1, 'title' => 'New Test Group2 Created', 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only')); $contactIds = array(); foreach (array($groupId1, $groupId2) as $groupId) { $this->groupContactCreate($groupId); $contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId)); } $contactIds = CRM_Utils_Array::collect('contact_id', $contactIds); // create custom group with contact reference field $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group')); $params = array('custom_group_id' => $customGroup['id'], 'name' => 'Worker_Lookup', 'label' => 'Worker Lookup', 'filter' => "action=lookup&group={$groupId1},{$groupId2}", 'html_type' => 'Autocomplete-Select', 'data_type' => 'ContactReference', 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1); $customField = $this->callAPISuccess('custom_field', 'create', $params); $_GET = array('id' => $customField['id'], 'is_unit_test' => TRUE); $contactList = CRM_Contact_Page_AJAX::contactReference(); $contactList = CRM_Utils_Array::collect('id', $contactList); //assert each returned contact id to be present in group contact foreach ($contactList as $contactId) { $this->assertTrue(in_array($contactId, $contactIds)); } }
static function updateCiviGroup(&$params, $op, $groupType = null) { $abort = $op == 'delete' ? true : false; $params['id'] = CRM_Bridge_OG_Utils::groupID($params['source'], $params['title'], $abort); if ($op == 'add') { require_once 'api/v2/Group.php'; if ($groupType) { $params['group_type'] = $groupType; } $group = civicrm_group_add($params); if (!civicrm_error($group)) { $params['group_id'] = $group['result']; } } else { // do this only if we have a valid id if ($params['id']) { require_once 'CRM/Contact/BAO/Group.php'; CRM_Contact_BAO_Group::discard($params['id']); $params['group_id'] = $params['id']; } } unset($params['id']); }
/** * takes an associative array and creates a campaign object * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Campaign_DAO_Campaign object * @access public * @static */ static function create(&$params) { if (empty($params)) { return; } if (!CRM_Utils_Array::value('id', $params)) { if (!CRM_Utils_Array::value('created_id', $params)) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } if (!CRM_Utils_Array::value('created_date', $params)) { $params['created_date'] = date('YmdHis'); } if (!CRM_Utils_Array::value('name', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64); } } $campaign = new CRM_Campaign_DAO_Campaign(); $campaign->copyValues($params); $campaign->save(); /* Create the campaign group record */ $groupTableName = CRM_Contact_BAO_Group::getTableName(); require_once 'CRM/Campaign/DAO/CampaignGroup.php'; $dao = new CRM_Campaign_DAO_CampaignGroup(); if (CRM_Utils_Array::value('include', $params['groups']) && is_array($params['groups']['include'])) { foreach ($params['groups']['include'] as $entityId) { $dao->reset(); $dao->campaign_id = $campaign->id; $dao->entity_table = $groupTableName; $dao->entity_id = $entityId; $dao->group_type = 'include'; $dao->save(); } } return $campaign; }
static function getGroupList() { $sortMapper = array(0 => 'groups.title', 1 => 'groups.id', 2 => '', 3 => 'groups.group_type', 4 => 'groups.visibility'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $params = $_POST; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get group list $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $iFilteredTotal = $iTotal = $params['total']; $selectorElements = array('group_name', 'group_id', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class'); if (!CRM_Utils_Array::value('showOrgInfo', $params)) { unset($selectorElements[5]); } echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
public function postProcess() { $values = $this->controller->exportValues($this->_name); $groups = array(); foreach (array('name', 'group_id', 'is_sms') as $n) { if (!empty($values[$n])) { $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; $ids = array(); if ($this->get('mailing_id')) { // don't create a new mass sms 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_MailingGroup(); $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); // also compute the recipients and store them in the mailing recipients table CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, TRUE, FALSE, 'sms'); $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) { $status = ts("Your Mass SMS has been saved."); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); $url = CRM_Utils_System::url('civicrm/mailing', 'reset=1&sms=1'); return $this->controller->setDestination($url); } }
/** * 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); }
/** * @param $groupInfo * @param null $sort * @param null $showLinks * @param bool $returnOnlyCount * @param int $offset * @param int $rowCount * * @return array */ static function getGlobalContacts(&$groupInfo, $sort = NULL, $showLinks = NULL, $returnOnlyCount = FALSE, $offset = 0, $rowCount = 25) { $globalContacts = array(); $settingsProcessor = new CRM_Case_XMLProcessor_Settings(); $settings = $settingsProcessor->run(); if (!empty($settings)) { $groupInfo['name'] = $settings['groupname']; if ($groupInfo['name']) { $searchParams = array('name' => $groupInfo['name']); $results = array(); CRM_Contact_BAO_Group::retrieve($searchParams, $results); if ($results) { $groupInfo['id'] = $results['id']; $groupInfo['title'] = $results['title']; $params = array(array('group', 'IN', array($groupInfo['id'] => 1), 0, 0)); $return = array('contact_id' => 1, 'sort_name' => 1, 'display_name' => 1, 'email' => 1, 'phone' => 1); list($globalContacts) = CRM_Contact_BAO_Query::apiQuery($params, $return, NULL, $sort, $offset, $rowCount, TRUE, $returnOnlyCount); if ($returnOnlyCount) { return $globalContacts; } if ($showLinks) { foreach ($globalContacts as $idx => $contact) { $globalContacts[$idx]['sort_name'] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contact['contact_id']}") . '">' . $contact['sort_name'] . '</a>'; } } } } } return $globalContacts; }
/** * Build the common elements between the search/advanced form. */ public function buildQuickForm() { parent::buildQuickForm(); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array(); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { $className = $this->_modeValue['taskClassName']; $tasks += $className::permissionedTaskTitles($permission, FALSE); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // CRM-11788, we might want to do this for all of search where force=1 $formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues); $getQFKey = CRM_Utils_Array::value('qfKey', $_GET); $postQFKey = CRM_Utils_Array::value('qfKey', $_POST); if ($formQFKey && empty($getQFKey) && empty($postQFKey)) { $url = CRM_Utils_System::makeURL('qfKey') . $formQFKey; CRM_Utils_System::redirect($url); } $permissionForGroup = FALSE; if (!empty($this->_groupID)) { // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $permissionForGroup = TRUE; } // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_groupID])) { $this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title'); } // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', $permissionForGroup); } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_amtgID])) { $this->assign('permissionedForGroup', FALSE); $this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title'); } // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'crm-form-submit')); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all'); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); } $selectedContactIds = array(); $qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues); // We use ajax to handle selections only if the search results component_mode is set to "contacts" if ($qfKeyParam && ($this->get('component_mode') <= 1 || $this->get('component_mode') == 7)) { $this->addClass('crm-ajax-selection-form'); $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $rows = $this->get('rows'); if (is_array($rows)) { $this->addRowSelectors($rows); } }
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) { //get the hidden smart group id. $ssId = $this->get('ssID'); $session = CRM_Core_Session::singleton(); $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')); require_once 'CRM/Contact/BAO/Group.php'; 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') 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 require_once 'CRM/Contact/DAO/Group.php'; 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'); } require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids); $this->set('mailing_id', $mailing->id); $count = CRM_Mailing_BAO_Mailing::getRecipientsCount(true, false, $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'; } else { if ($this->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } else { if ($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); CRM_Utils_System::redirect($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'); CRM_Utils_System::redirect($url); } } }
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); } } }
/** * Get options for a given field. * @see CRM_Core_DAO::buildOptions * * @param string $fieldName * @param string $context * @see CRM_Core_DAO::buildOptionsContext * @param array $props * whatever is known about this dao object. * * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { $params = array(); $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); // Sort group list by hierarchy // TODO: This will only work when api.entity is "group_contact". What about others? if (($fieldName == 'group' || $fieldName == 'group_id') && ($context == 'search' || $context == 'create')) { $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE); } return $options; }
/** * This method populates the civicrm_group_contact table */ private function addGroup() { // add the 3 groups first foreach ($this->sampleData['group'] as $groupName) { $group = new CRM_Contact_BAO_Group(); $group->name = $group->title = $groupName; $group->group_type = "12"; $group->visibility = 'Public Pages'; $group->is_active = 1; $group->save(); $group->buildClause(); $group->save(); } // 60 are for newsletter for ($i = 0; $i < 60; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // newsletter subscribers $groupContact->group_id = 2; $groupContact->contact_id = $this->Individual[$i]; // always add members $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 15 volunteers for ($i = 0; $i < 15; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // Volunteers $groupContact->group_id = 3; $groupContact->contact_id = $this->Individual[$i + 60]; // membership status $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 8 advisory board group for ($i = 0; $i < 8; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // advisory board group $groupContact->group_id = 4; $groupContact->contact_id = $this->Individual[$i * 7]; // membership status $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } //In this function when we add groups that time we are cache the contact fields //But at the end of setup we are appending sample custom data, so for consistency //reset the cache. CRM_Core_BAO_Cache::deleteGroup('contact fields'); }
/** * Load the smart group cache for a saved search. * * @param object $group * The smart group that needs to be loaded. * @param bool $force * Should we force a search through. */ public static function load(&$group, $force = FALSE) { $groupID = $group->id; $savedSearchID = $group->saved_search_id; if (array_key_exists($groupID, self::$_alreadyLoaded) && !$force) { return; } // grab a lock so other processes don't compete and do the same query $lock = Civi::lockManager()->acquire("data.core.group.{$groupID}"); if (!$lock->isAcquired()) { // this can cause inconsistent results since we don't know if the other process // will fill up the cache before our calling routine needs it. // however this routine does not return the status either, so basically // its a "lets return and hope for the best" return; } self::$_alreadyLoaded[$groupID] = 1; // we now have the lock, but some other process could have actually done the work // before we got here, so before we do any work, lets ensure that work needs to be // done // we allow hidden groups here since we dont know if the caller wants to evaluate an // hidden group if (!$force && !self::shouldGroupBeRefreshed($groupID, TRUE)) { $lock->release(); return; } $sql = NULL; $idName = 'id'; $customClass = NULL; if ($savedSearchID) { $ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID); // rectify params to what proximity search expects if there is a value for prox_distance // CRM-7021 if (!empty($ssParams)) { CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams); } $returnProperties = array(); if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) { $fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID); $returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv); } if (isset($ssParams['customSearchID'])) { // if custom search // we split it up and store custom class // so temp tables are not destroyed if they are used // hence customClass is defined above at top of function $customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID); $searchSQL = $customClass->contactIDs(); $searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL); if (!strstr($searchSQL, 'WHERE')) { $searchSQL .= " WHERE ( 1 ) "; } $idName = 'contact_id'; } else { $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID); // CRM-17075 using the formValues in this way imposes extra logic and complexity. // we have the where_clause and where tables stored in the saved_search table // and should use these rather than re-processing the form criteria (which over-works // the link between the form layer & the query layer too). // It's hard to think of when you would want to use anything other than return // properties = array('contact_id' => 1) here as the point would appear to be to // generate the list of contact ids in the group. // @todo review this to use values in saved_search table (preferably for 4.8). $query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, NULL, FALSE, FALSE, 1, TRUE, TRUE, FALSE, CRM_Utils_Array::value('display_relationship_type', $formValues), CRM_Utils_Array::value('operator', $formValues, 'AND')); $query->_useDistinct = FALSE; $query->_useGroupBy = FALSE; $searchSQL = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, TRUE, TRUE, NULL, NULL, NULL, TRUE); } $groupID = CRM_Utils_Type::escape($groupID, 'Integer'); $sql = $searchSQL . " AND contact_a.id NOT IN (\n SELECT contact_id FROM civicrm_group_contact\n WHERE civicrm_group_contact.status = 'Removed'\n AND civicrm_group_contact.group_id = {$groupID} ) "; } if ($sql) { $sql = preg_replace("/^\\s*SELECT/", "SELECT {$groupID} as group_id, ", $sql); } // lets also store the records that are explicitly added to the group // this allows us to skip the group contact LEFT JOIN $sqlB = "\nSELECT {$groupID} as group_id, contact_id as {$idName}\nFROM civicrm_group_contact\nWHERE civicrm_group_contact.status = 'Added'\n AND civicrm_group_contact.group_id = {$groupID} "; $groupIDs = array($groupID); self::remove($groupIDs); $processed = FALSE; $tempTable = 'civicrm_temp_group_contact_cache' . rand(0, 2000); foreach (array($sql, $sqlB) as $selectSql) { if (!$selectSql) { continue; } $insertSql = "CREATE TEMPORARY TABLE {$tempTable} ({$selectSql});"; $processed = TRUE; CRM_Core_DAO::executeQuery($insertSql); CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)\n SELECT DISTINCT {$idName}, group_id FROM {$tempTable}\n "); CRM_Core_DAO::executeQuery(" DROP TEMPORARY TABLE {$tempTable}"); } self::updateCacheTime($groupIDs, $processed); if ($group->children) { //Store a list of contacts who are removed from the parent group $sql = "\nSELECT contact_id\nFROM civicrm_group_contact\nWHERE civicrm_group_contact.status = 'Removed'\nAND civicrm_group_contact.group_id = {$groupID} "; $dao = CRM_Core_DAO::executeQuery($sql); $removed_contacts = array(); while ($dao->fetch()) { $removed_contacts[] = $dao->contact_id; } $childrenIDs = explode(',', $group->children); foreach ($childrenIDs as $childID) { $contactIDs = CRM_Contact_BAO_Group::getMember($childID, FALSE); //Unset each contact that is removed from the parent group foreach ($removed_contacts as $removed_contact) { unset($contactIDs[$removed_contact]); } $values = array(); foreach ($contactIDs as $contactID => $dontCare) { $values[] = "({$groupID},{$contactID})"; } self::store($groupIDs, $values); } } $lock->release(); }