From 9be31c7a88cdfda61ba980d3988a829a690759fc Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Sun, 5 May 2013 09:16:46 -0700 Subject: [PATCH] CRM-12525 ---------------------------------------- * CRM-12525: Hidden smart groups show in Groups view http://issues.civicrm.org/jira/browse/CRM-12525 --- CRM/Contact/BAO/GroupContactCache.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index e9a7345607..562f9614fd 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -96,8 +96,8 @@ class CRM_Contact_BAO_GroupContactCache extends CRM_Contact_DAO_GroupContactCach $query = " SELECT g.id FROM civicrm_group g -WHERE ( g.saved_search_id IS NOT NULL OR - g.children IS NOT NULL ) +WHERE ( g.saved_search_id IS NOT NULL OR g.children IS NOT NULL ) +AND ( g.is_hidden = 0 OR g.is_hidden IS NULL ) AND ( g.cache_date IS NULL OR ( TIMESTAMPDIFF(MINUTE, g.cache_date, $now) >= $smartGroupCacheTimeout ) OR ( $now >= g.refresh_date ) @@ -447,7 +447,17 @@ AND civicrm_group_contact.group_id = $groupID "; return 5; } - static function contactGroup($contactID) { + /** + * Get all the smart groups that this contact belongs to + * Note that this could potentially be a super slow function since + * it ensure that all contact groups are loaded in the cache + * + * @param int $contactID + * @param boolean $showHidden - hidden groups are shown only if this flag is set + * + * @return array an array of groups that this contact belongs to + */ + static function contactGroup($contactID, $showHidden = FALSE) { if (empty($contactID)) { return; } @@ -461,12 +471,18 @@ AND civicrm_group_contact.group_id = $groupID "; self::loadAll(); + $hiddenClause = ''; + if (!$showHidden) { + $hiddenClause = ' AND (g.is_hidden = 0 OR g.is_hidden IS NULL) '; + } + $contactIDString = CRM_Core_DAO::escapeString(implode(', ', $contactIDs)); $sql = " SELECT gc.group_id, gc.contact_id, g.title, g.children, g.description FROM civicrm_group_contact_cache gc INNER JOIN civicrm_group g ON g.id = gc.group_id WHERE gc.contact_id IN ($contactIDString) + $hiddenClause ORDER BY gc.contact_id, g.children "; -- 2.25.1