$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 )
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;
}
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
";