Skip to content
Snippets Groups Projects
Unverified Commit 7d6d923d authored by eileen's avatar eileen :8ball: Committed by GitHub
Browse files

Merge pull request #13327 from pradpnayak/SerarchView

Used buildoptions function to get all groups
parents 90b7caa5 f639bf2f
Branches
Tags
No related merge requests found
......@@ -430,13 +430,15 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
}
if (isset($params['group'])) {
$groups = $params['group'];
$allGroups = CRM_Core_PseudoConstant::group();
$groupsByTitle = CRM_Core_PseudoConstant::group();
$groupsByName = CRM_Contact_BAO_GroupContact::buildOptions('group_id', 'validate');
$allGroups = array_merge(array_flip($groupsByTitle), array_flip($groupsByName));
if (is_array($groups) && in_array(key($groups), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
// Get the groups array.
$groupsArray = $groups[key($groups)];
foreach ($groupsArray as &$group) {
if (!is_numeric($group) && array_search($group, $allGroups)) {
$group = array_search($group, $allGroups);
if (!is_numeric($group) && !empty($allGroups[$group])) {
$group = $allGroups[$group];
}
}
// Now reset the $groups array with the ids not the titles.
......@@ -445,17 +447,17 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
// handle format like 'group' => array('title1', 'title2').
elseif (is_array($groups)) {
foreach ($groups as $k => &$group) {
if (!is_numeric($group) && array_search($group, $allGroups)) {
$group = array_search($group, $allGroups);
if (!is_numeric($group) && !empty($allGroups[$group])) {
$group = $allGroups[$group];
}
if (!is_numeric($k) && array_search($k, $allGroups)) {
if (!is_numeric($k) && !empty($allGroups[$k])) {
unset($groups[$k]);
$groups[array_search($k, $allGroups)] = $group;
$groups[$allGroups[$k]] = $group;
}
}
}
elseif (!is_numeric($groups) && array_search($groups, $allGroups)) {
$groups = array_search($groups, $allGroups);
elseif (!is_numeric($groups) && !empty($allGroups[$groups])) {
$groups = $allGroups[$groups];
}
$params['group'] = $groups;
}
......
......@@ -3842,6 +3842,31 @@ class api_v3_ContactTest extends CiviUnitTestCase {
$this->assertEquals(array('external_identifier'), $result['values']['UI_external_identifier']);
}
/**
* API test to retrieve contact from group having different group title and name.
*/
public function testContactGetFromGroup() {
$groupId = $this->groupCreate([
'name' => 'Test_Group',
'domain_id' => 1,
'title' => 'New Test Group Created',
'description' => 'New Test Group Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
]);
$contact = $this->callAPISuccess('contact', 'create', $this->_params);
$groupContactCreateParams = array(
'contact_id' => $contact['id'],
'group_id' => $groupId,
'status' => 'Pending',
);
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
$this->CallAPISuccess('Contact', 'getcount', [
'group' => "Test_Group",
]);
}
public function testSmartGroupsForRelatedContacts() {
$rtype1 = $this->callAPISuccess('relationship_type', 'create', array(
"name_a_b" => uniqid() . " Child of",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment