From f639bf2f89e5c306190c9e2d1b5bb274b841cc94 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Mon, 4 Feb 2019 21:04:56 +0000 Subject: [PATCH] use name and label to retrive ID --- api/v3/Contact.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/api/v3/Contact.php b/api/v3/Contact.php index ed3a8158b4..e2781de714 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -430,13 +430,15 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) { } if (isset($params['group'])) { $groups = $params['group']; - $allGroups = CRM_Contact_BAO_GroupContact::buildOptions('group_id', 'validate'); + $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; } -- 2.25.1