From: Donald A. Lobo Date: Thu, 7 Mar 2013 21:11:08 +0000 (-0800) Subject: fix CRM-12052 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f828fa2c2e9695807b8c9e28107f1d25b4ac3a4d;p=civicrm-core.git fix CRM-12052 --- diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 4e82c340af..e21a768224 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -890,15 +890,21 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { /** * This function to get hierarchical list of groups (parent followed by children) * - * @param array $params associated array for params + * @param array $groupIDs array of group ids + * * @access public */ static function getGroupsHierarchy ( - $groupIds, + $groupIDs, $parents = NULL, $spacer = '', $titleOnly = FALSE ) { + if (empty($groupIDs)) { + return array(); + } + + $groupIdString = '(' . implode(',', array_keys($groupIDs)) . ')'; // // need to return id, title (w/ spacer), description, visibility @@ -908,10 +914,12 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { // Instead of recursively making mysql queries, we'll make one big // query and build the heirarchy with the algorithm below. $groups = array(); - $args = array(1 => array($groupIds, 'String')); - $query = "SELECT id, title, description, visibility, parents - FROM civicrm_group - WHERE id $groupIds"; + $args = array(1 => array($groupIdString, 'String')); + $query = " +SELECT id, title, description, visibility, parents +FROM civicrm_group +WHERE id IN $groupIdString +"; if ($parents) { // group can have > 1 parent so parents may be comma separated list (eg. '1,2,5'). We just grab and match on 1st parent. $parentArray = explode(',', $parents); @@ -982,9 +990,11 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { if ($titleOnly) { $groupsReturn[$key] = $value[0] . $value[1]; } else { - $groupsReturn[$key] = array('title' => $value[0] . $value[1], - 'description' => $allGroups[$key]['description'], - 'visibility' => $allGroups[$key]['visibility'],); + $groupsReturn[$key] = array( + 'title' => $value[0] . $value[1], + 'description' => $allGroups[$key]['description'], + 'visibility' => $allGroups[$key]['visibility'], + ); } } diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index 1a1fc24564..26767cccf2 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -85,7 +85,7 @@ class CRM_Contact_Form_Edit_TagsandGroups { $elements = array(); $groupID = isset($form->_grid) ? $form->_grid : NULL; if ($groupID && $visibility) { - $ids = "= {$groupID}"; + $ids = array($groupID => $groupID); } else { if ($visibility) { @@ -94,8 +94,7 @@ class CRM_Contact_Form_Edit_TagsandGroups { else { $group = CRM_Core_PseudoConstant::group(); } - $ids = implode(',', array_keys($group)); - $ids = 'IN (' . $ids . ')'; + $ids = $group; } if ($groupID || !empty($group)) { diff --git a/CRM/Contact/Form/GroupContact.php b/CRM/Contact/Form/GroupContact.php index ba7ec81bed..ba5f73ccf6 100644 --- a/CRM/Contact/Form/GroupContact.php +++ b/CRM/Contact/Form/GroupContact.php @@ -99,9 +99,7 @@ class CRM_Contact_Form_GroupContact extends CRM_Core_Form { } // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) - $ids = implode(',', array_keys($allGroups)); - $ids = 'IN (' . $ids . ')'; - $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '  ', TRUE); + $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); diff --git a/CRM/Contact/Form/Search/Basic.php b/CRM/Contact/Form/Search/Basic.php index 8326d53643..88d3bae453 100644 --- a/CRM/Contact/Form/Search/Basic.php +++ b/CRM/Contact/Form/Search/Basic.php @@ -79,15 +79,10 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search { if (CRM_Utils_Array::value('groups', $searchOptions)) { // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) - $groupHierarchy = array(); - if (!empty($this->_group)) { - $ids = implode(',', array_keys($this->_group)); - $ids = 'IN (' . $ids . ')'; - $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '  ', TRUE); - } + $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '  ', TRUE); + // add select for groups - $group = array( - '' => ts('- any group -')) + $groupHierarchy; + $group = array('' => ts('- any group -')) + $groupHierarchy; $this->_groupElement = &$this->addElement('select', 'group', ts('in'), $group); } diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 701f0614f3..808490111d 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -53,9 +53,7 @@ class CRM_Contact_Form_Search_Criteria { // multiselect for groups if ($form->_group) { // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) - $ids = implode(',', array_keys($form->_group)); - $ids = 'IN (' . $ids . ')'; - $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '  ', TRUE); + $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '  ', TRUE); $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')) @@ -80,7 +78,7 @@ class CRM_Contact_Form_Search_Criteria { $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE, TRUE); - + $used_for = CRM_Core_OptionGroup::values('tag_used_for'); $tagsTypes = array(); $showAllTagTypes = false; @@ -91,7 +89,7 @@ class CRM_Contact_Form_Search_Criteria { // we will hide searching contact by attachments tags until it will be implemented in core if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') { //if tags exists then add type to display in adv search form help text - $tagsTypes[] = ts($value); + $tagsTypes[] = ts($value); $showAllTagTypes = true; } } diff --git a/CRM/Group/Form/Edit.php b/CRM/Group/Form/Edit.php index 26d6b6d5da..669f0b6faa 100644 --- a/CRM/Group/Form/Edit.php +++ b/CRM/Group/Form/Edit.php @@ -99,9 +99,7 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { $this->_groupValues = array(); $params = array('id' => $this->_id); - $this->_group = &CRM_Contact_BAO_Group::retrieve($params, - $this->_groupValues - ); + $this->_group = CRM_Contact_BAO_Group::retrieve($params, $this->_groupValues); $this->_title = $this->_groupValues['title']; } @@ -134,8 +132,8 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { 'search_custom_id' ); } - if (CRM_Utils_Array::value('created_id', $this->_groupValues)) - $groupValues['created_by'] = + if (CRM_Utils_Array::value('created_id', $this->_groupValues)) + $groupValues['created_by'] = CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $this->_groupValues['created_id'] , 'sort_name', 'id'); $this->assign_by_ref('group', $groupValues);