/**
* 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 = '<span class="child-indent"></span>',
$titleOnly = FALSE
) {
+ if (empty($groupIDs)) {
+ return array();
+ }
+
+ $groupIdString = '(' . implode(',', array_keys($groupIDs)) . ')';
// <span class="child-icon"></span>
// need to return id, title (w/ spacer), description, visibility
// 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);
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'],
+ );
}
}
$elements = array();
$groupID = isset($form->_grid) ? $form->_grid : NULL;
if ($groupID && $visibility) {
- $ids = "= {$groupID}";
+ $ids = array($groupID => $groupID);
}
else {
if ($visibility) {
else {
$group = CRM_Core_PseudoConstant::group();
}
- $ids = implode(',', array_keys($group));
- $ids = 'IN (' . $ids . ')';
+ $ids = $group;
}
if ($groupID || !empty($group)) {
}
// 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);
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);
}
// 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 -'))
$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;
// 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;
}
}
$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'];
}
'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);