/// <summary> /// Returns the count of messages in given message board. /// </summary> /// <param name="documentId">ID of the document.</param> /// <param name="boardWebpartName">Messageboard webpart name.</param> /// <param name="type">Type of messageboard: 'document', 'user' or 'group'.</param> public static int GetBoardMessagesCount(int documentId, string boardWebpartName, string type) { // Get board type BoardOwnerTypeEnum boardType = BoardInfoProvider.GetBoardOwnerTypeEnum(type); Guid identifier = Guid.Empty; // Get correct identifier by type switch (boardType) { case BoardOwnerTypeEnum.User: identifier = CMSContext.CurrentUser.UserGUID; break; case BoardOwnerTypeEnum.Group: identifier = GetCurrentGroupGuid(); break; } // Get board name string boardName = BoardInfoProvider.GetMessageBoardName(boardWebpartName, boardType, identifier.ToString()); // Get board info BoardInfo board = BoardInfoProvider.GetBoardInfo(boardName, documentId); if (board != null) { // Get messages count return(BoardMessageInfoProvider.GetMessagesCount(board.BoardID, true, true)); } return(0); }
/// <summary> /// Returns board name according board type. /// </summary> /// <param name="webPartName">Name of the web part</param> /// <param name="boardOwner">Owner of the board</param> private string GetBoardName(string webPartName, string boardOwner) { // Get type BoardOwnerTypeEnum type = BoardInfoProvider.GetBoardOwnerTypeEnum(boardOwner); // Get name switch (boardOwner.ToLowerCSafe()) { case "user": return(BoardInfoProvider.GetMessageBoardName(webPartName, type, CurrentUser.UserGUID.ToString())); default: return(BoardInfoProvider.GetMessageBoardName(webPartName, type, "")); } }
/// <summary> /// Initializes the controls. /// </summary> private void SetupControls() { // If the web part shouldn't proceed further if (StopProcessing) { msgBoard.BoardProperties.StopProcessing = true; Visible = false; } else { // Set the message board transformation msgBoard.MessageTransformation = MessageTransformation; // Set sorting msgBoard.OrderBy = String.IsNullOrEmpty(OrderBy) ? "MessageInserted DESC" : OrderBy; // Set buttons msgBoard.BoardProperties.ShowApproveButton = ShowApprove; msgBoard.BoardProperties.ShowDeleteButton = ShowDelete; msgBoard.BoardProperties.ShowEditButton = ShowEdit; msgBoard.BoardProperties.ShowRejectButton = ShowReject; // Set fields msgBoard.FormResourcePrefix = ResourcePrefix; msgBoard.BoardProperties.ShowNameField = ShowNameField; msgBoard.BoardProperties.ShowEmailField = ShowEmailField; msgBoard.BoardProperties.ShowURLField = ShowURLField; // Set rating msgBoard.BoardProperties.EnableContentRating = EnableContentRating; msgBoard.BoardProperties.RatingType = RatingType; msgBoard.BoardProperties.MaxRatingValue = MaxRatingValue; msgBoard.BoardProperties.AllowEmptyRating = AllowEmptyRating; msgBoard.BoardProperties.CheckIfUserRated = CheckIfUserRated; // Set caching msgBoard.CacheItemName = CacheItemName; msgBoard.CacheMinutes = CacheMinutes; msgBoard.CacheDependencies = CacheDependencies; // Set web part only properties msgBoard.BoardProperties.BoardEnableAnonymousRead = EnableAnonymousRead; msgBoard.BoardProperties.CheckPermissions = CheckPermissions; msgBoard.NoMessagesText = NoMessagesText; // Use board properties if (BoardObj != null) { msgBoard.BoardProperties.BoardAccess = BoardObj.BoardAccess; msgBoard.BoardProperties.BoardName = BoardObj.BoardName; msgBoard.BoardProperties.BoardDisplayName = BoardObj.BoardDisplayName; msgBoard.BoardProperties.BoardUnsubscriptionUrl = BoardInfoProvider.GetUnsubscriptionUrl(BoardObj.BoardUnsubscriptionURL, SiteContext.CurrentSiteName); msgBoard.BoardProperties.BoardBaseUrl = (string.IsNullOrEmpty(BoardObj.BoardBaseURL)) ? ValidationHelper.GetString(SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + ".CMSBoardBaseURL"), "") : BoardObj.BoardBaseURL; msgBoard.BoardProperties.BoardEnableSubscriptions = BoardObj.BoardEnableSubscriptions; msgBoard.BoardProperties.BoardOpened = BoardObj.BoardOpened; msgBoard.BoardProperties.BoardRequireEmails = BoardObj.BoardRequireEmails; msgBoard.BoardProperties.BoardModerated = BoardObj.BoardModerated; msgBoard.BoardProperties.BoardUseCaptcha = BoardObj.BoardUseCaptcha; msgBoard.BoardProperties.BoardOpenedFrom = BoardObj.BoardOpenedFrom; msgBoard.BoardProperties.BoardOpenedTo = BoardObj.BoardOpenedTo; msgBoard.MessageBoardID = BoardObj.BoardID; } // Use default properties else { // If the board is user and information on current user wasn't supplied hide the web part if (((BoardOwner == "user") && (CurrentUser == null))) { if (!String.IsNullOrEmpty(NoMessagesText)) { msgBoard.NoMessagesText = NoMessagesText; } Visible = false; } else { // Default board- document related continue msgBoard.BoardProperties.BoardAccess = BoardAccess; msgBoard.BoardProperties.BoardOwner = BoardOwner; var type = BoardInfoProvider.GetBoardOwnerTypeEnum(BoardOwner); msgBoard.BoardProperties.BoardName = GetBoardName(WebPartName, type); string boardDisplayName; if (!String.IsNullOrEmpty(BoardDisplayName)) { boardDisplayName = BoardDisplayName; } // Use predefined display name format else { boardDisplayName = DocumentContext.CurrentPageInfo.GetDocumentName() + " (" + DocumentContext.CurrentPageInfo.DocumentNamePath + ")"; } // Limit display name length msgBoard.BoardProperties.BoardDisplayName = TextHelper.LimitLength(boardDisplayName, 250, ""); msgBoard.BoardProperties.BoardUnsubscriptionUrl = BoardInfoProvider.GetUnsubscriptionUrl(BoardUnsubscriptionUrl, SiteContext.CurrentSiteName); msgBoard.BoardProperties.BoardBaseUrl = (string.IsNullOrEmpty(BoardBaseUrl)) ? ValidationHelper.GetString(SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + ".CMSBoardBaseURL"), "") : BoardBaseUrl; msgBoard.BoardProperties.BoardEnableSubscriptions = BoardEnableSubscriptions; msgBoard.BoardProperties.BoardOpened = BoardOpened; msgBoard.BoardProperties.BoardRequireEmails = BoardRequireEmails; msgBoard.BoardProperties.BoardModerated = BoardModerated; msgBoard.BoardProperties.BoardRoles = BoardRoles; msgBoard.BoardProperties.BoardModerators = BoardModerators; msgBoard.BoardProperties.BoardUseCaptcha = BoardUseCaptcha; msgBoard.BoardProperties.BoardOpenedFrom = BoardOpenedFrom; msgBoard.BoardProperties.BoardOpenedTo = BoardOpenedTo; msgBoard.BoardProperties.BoardLogActivity = LogActivity; msgBoard.MessageBoardID = 0; } } } }