public static function group($type, $contactID = NULL, $tableName = 'civicrm_saved_search', $allGroups = NULL, $includedGroups = NULL) { $acls = CRM_ACL_BAO_Cache::build($contactID); if (!empty($includedGroups) && is_array($includedGroups)) { $ids = $includedGroups; } else { $ids = array(); } if (!empty($acls)) { $aclKeys = array_keys($acls); $aclKeys = implode(',', $aclKeys); $query = "\nSELECT a.operation, a.object_id\n FROM civicrm_acl_cache c, civicrm_acl a\n WHERE c.acl_id = a.id\n AND a.is_active = 1\n AND a.object_table = %1\n AND a.id IN ( {$aclKeys} )\nORDER BY a.object_id\n"; $params = array(1 => array($tableName, 'String')); $dao = CRM_Core_DAO::executeQuery($query, $params); while ($dao->fetch()) { if ($dao->object_id) { if (self::matchType($type, $dao->operation)) { $ids[] = $dao->object_id; } } else { // this user has got the permission for all objects of this type // check if the type matches if (self::matchType($type, $dao->operation)) { foreach ($allGroups as $id => $dontCare) { $ids[] = $id; } } break; } } } CRM_Utils_Hook::aclGroup($type, $contactID, $tableName, $allGroups, $ids); return $ids; }