/** * Get list of all the groups and groups for a contact. * * @param int $contactId * Contact id. * * @param bool $visibility * * * @return array * this array has key-> group id and value group title */ public static function getGroupList($contactId = 0, $visibility = FALSE) { $group = new CRM_Contact_DAO_Group(); $select = $from = $where = ''; $select = 'SELECT DISTINCT civicrm_group.id, civicrm_group.title '; $from = ' FROM civicrm_group '; $where = " WHERE civicrm_group.is_active = 1 "; if ($contactId) { $from .= ' , civicrm_group_contact '; $where .= " AND civicrm_group.id = civicrm_group_contact.group_id\n AND civicrm_group_contact.contact_id = " . CRM_Utils_Type::escape($contactId, 'Integer'); } if ($visibility) { $where .= " AND civicrm_group.visibility != 'User and User Admin Only'"; } $orderby = " ORDER BY civicrm_group.name"; $sql = $select . $from . $where . $orderby; $group->query($sql); $values = array(); while ($group->fetch()) { $values[$group->id] = $group->title; } return $values; }