Permalink
Browse files

More granular control of category selection in module settings

  • Loading branch information...
gigocabrera committed Apr 18, 2014
1 parent 3c7ad10 commit 3a8981a92f4e1b847a453a8fdff85c1c2a8893b9
@@ -420,15 +420,23 @@ Public Class Blog
If Not String.IsNullOrEmpty(BlogContext.SearchString) Then
Dim publishValue As Integer = 1
If BlogContext.SearchUnpublished Then publishValue = -1
If BlogContext.Term Is Nothing Then
PostList = PostsController.SearchPosts(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.SearchString, BlogContext.SearchTitle, BlogContext.SearchContents, publishValue, BlogContext.ShowLocale, BlogContext.EndDate, -1, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
If String.IsNullOrEmpty(BlogContext.Categories) Then
If BlogContext.Term Is Nothing Then
PostList = PostsController.SearchPosts(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.SearchString, BlogContext.SearchTitle, BlogContext.SearchContents, publishValue, BlogContext.ShowLocale, BlogContext.EndDate, -1, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
Else
PostList = PostsController.SearchPostsByTerm(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.TermId, BlogContext.SearchString, BlogContext.SearchTitle, BlogContext.SearchContents, publishValue, BlogContext.ShowLocale, BlogContext.EndDate, -1, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
End If
Else
PostList = PostsController.SearchPostsByCategory(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.Categories, BlogContext.SearchString, BlogContext.SearchTitle, BlogContext.SearchContents, publishValue, BlogContext.ShowLocale, BlogContext.EndDate, -1, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
End If
ElseIf String.IsNullOrEmpty(BlogContext.Categories) Then
If BlogContext.Term Is Nothing Then
PostList = PostsController.GetPosts(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, -1, BlogContext.ShowLocale, BlogContext.EndDate, BlogContext.AuthorId, False, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
Else
PostList = PostsController.GetPostsByTerm(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.TermId, -1, BlogContext.ShowLocale, BlogContext.EndDate, BlogContext.AuthorId, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
End If
Else
PostList = PostsController.SearchPostsByTerm(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.TermId, BlogContext.SearchString, BlogContext.SearchTitle, BlogContext.SearchContents, publishValue, BlogContext.ShowLocale, BlogContext.EndDate, -1, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
End If
ElseIf BlogContext.Term Is Nothing Then
PostList = PostsController.GetPosts(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, -1, BlogContext.ShowLocale, BlogContext.EndDate, BlogContext.AuthorId, False, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
Else
PostList = PostsController.GetPostsByTerm(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.TermId, -1, BlogContext.ShowLocale, BlogContext.EndDate, BlogContext.AuthorId, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
PostList = PostsController.GetPostsByCategory(Settings.ModuleId, BlogContext.BlogId, BlogContext.Locale, BlogContext.Categories, -1, BlogContext.ShowLocale, BlogContext.EndDate, BlogContext.AuthorId, _reqPage - 1, pageSize, "PUBLISHEDONDATE DESC", _totalRecords, UserId, BlogContext.Security.UserIsAdmin).Values
End If
_usePaging = True
End If
@@ -46,6 +46,7 @@ Namespace Common
End If
BlogId = blogModule.ViewSettings.BlogId
TermId = blogModule.ViewSettings.TermId
Categories = blogModule.ViewSettings.Categories
AuthorId = blogModule.ViewSettings.AuthorId

Locale = Threading.Thread.CurrentThread.CurrentCulture.Name
@@ -55,6 +56,7 @@ Namespace Common
context.Request.Params.ReadValue("Blog", BlogId)
context.Request.Params.ReadValue("Post", ContentItemId)
context.Request.Params.ReadValue("Term", TermId)
context.Request.Params.ReadValue("Categories", Categories)
context.Request.Params.ReadValue("Author", AuthorId)
context.Request.Params.ReadValue("end", EndDate)
context.Request.Params.ReadValue("search", SearchString)
@@ -133,8 +135,9 @@ Namespace Common
Public Property BlogId As Integer = -1
Public Property ContentItemId As Integer = -1
Public Property TermId As Integer = -1
Public Property Categories As String = ""
Public Property AuthorId As Integer = -1
Public Property EndDate As Date = DateTime.Now.ToUniversalTime
Public Property EndDate As Date = DateTime.Now.ToUniversalTime
Public Property Blog As Entities.Blogs.BlogInfo = Nothing
Public Property Post As Entities.Posts.PostInfo = Nothing
Public Property Term As Entities.Terms.TermInfo = Nothing
@@ -175,6 +178,8 @@ Namespace Common
Return (Me.ContentItemId.ToString(OutputFormat, formatProvider))
Case "termid", "term"
Return (Me.TermId.ToString(OutputFormat, formatProvider))
Case "categories"
Return Me.Categories
Case "authorid", "author"
Return (Me.AuthorId.ToString(OutputFormat, formatProvider))
Case "enddate"
@@ -183,8 +188,8 @@ Namespace Common
Return CBool(BlogId > -1).ToString()
Case "postselected"
Return CBool(ContentItemId > -1).ToString()
Case "termselected"
Return CBool(TermId > -1).ToString()
'Case "termselected"
' Return CBool(TermId > -1).ToString()
Case "authorselected"
Return CBool(AuthorId > -1).ToString()
Case "ismultilingualsite"
@@ -231,6 +236,10 @@ Namespace Common
End Property
#End Region

Shared Function GetBlogContext(httpContext As HttpContext, viewSettings As Controls.ViewSettings) As BlogContextInfo
Throw New NotImplementedException
End Function

End Class

End Namespace
@@ -40,6 +40,7 @@ Namespace Common
Public Property ModifyPageDetails As Boolean = False
Public Property BlogId As Integer = -1
Public Property TermId As Integer = -1
Public Property Categories As String = ""
Public Property AuthorId As Integer = -1
Public Property TemplateSettings As New Dictionary(Of String, String)
Private Property TemplateManager As Templating.TemplateManager
@@ -61,6 +62,7 @@ Namespace Common
_allSettings.ReadValue("ModifyPageDetails", ModifyPageDetails)
_allSettings.ReadValue("BlogId", BlogId)
_allSettings.ReadValue("TermId", TermId)
_allSettings.ReadValue("Categories", Categories)
_allSettings.ReadValue("AuthorId", AuthorId)
If BlogModuleId > -1 Then ' security check
Dim parentModule As DotNetNuke.Entities.Modules.ModuleInfo = (New DotNetNuke.Entities.Modules.ModuleController).GetModule(BlogModuleId)
@@ -102,6 +104,7 @@ Namespace Common
objModules.UpdateTabModuleSetting(tabModuleId, "ModifyPageDetails", ModifyPageDetails.ToString)
objModules.UpdateTabModuleSetting(tabModuleId, "BlogId", BlogId.ToString)
objModules.UpdateTabModuleSetting(tabModuleId, "TermId", TermId.ToString)
objModules.UpdateTabModuleSetting(tabModuleId, "Categories", Categories.ToString)
objModules.UpdateTabModuleSetting(tabModuleId, "AuthorId", AuthorId.ToString)

Dim CacheKey As String = "TabModuleSettings" & tabModuleId.ToString
@@ -44,6 +44,7 @@ Namespace Data
Public MustOverride Function GetPostLocalizations(contentItemId As Int32) As IDataReader
Public MustOverride Function GetPosts(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, onlyActionable As Boolean, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Function GetPostsByTerm(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, termID As Int32, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Function GetPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, categories As String, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Function GetTerm(termId As Int32, moduleId As Int32, locale As String) As IDataReader
Public MustOverride Function GetTermLocalizations(termId As Int32) As IDataReader
Public MustOverride Function GetTermsByModule(moduleId As Int32, locale As String) As IDataReader
@@ -53,6 +54,7 @@ Namespace Data
Public MustOverride Function GetUsersByBlogPermission(portalId As Int32, blogId As Int32, permissionId As Int32) As IDataReader
Public MustOverride Function SearchPosts(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, searchText As String, searchTitle As Boolean, searchContents As Boolean, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Function SearchPostsByTerm(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, termID As Int32, searchText As String, searchTitle As Boolean, searchContents As Boolean, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Function SearchPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, categories As String, searchText As String, searchTitle As Boolean, searchContents As Boolean, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Public MustOverride Sub SetBlogLocalization(blogID As Int32, locale As String, title As String, description As String)
Public MustOverride Sub SetPostLocalization(postID As Int32, locale As String, title As String, summary As String, content As String, updatedByUser As Int32)
Public MustOverride Function SetTerm(termID As Int32, vocabularyID As Int32, parentTermID As Int32, viewOrder As Int32, name As String, description As String, createdByUserID As Int32) As Integer
@@ -103,6 +103,10 @@ Namespace Data
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "GetPostsByTerm", moduleId, blogID, displayLocale, userId, userIsAdmin, termID, published, GetNull(limitToLocale), GetNull(endDate), authorUserId, pageIndex, pageSize, orderBy), IDataReader)
End Function

Public Overrides Function GetPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, categories As String, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "GetPostsByCategory", moduleId, blogID, displayLocale, userId, userIsAdmin, categories, published, GetNull(limitToLocale), GetNull(endDate), authorUserId, pageIndex, pageSize, orderBy), IDataReader)
End Function

Public Overrides Function GetTerm(termId As Int32, moduleId As Int32, locale As String) As IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "GetTerm", termId, moduleId, locale), IDataReader)
End Function
@@ -139,6 +143,11 @@ Namespace Data
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "SearchPostsByTerm", moduleId, blogID, displayLocale, userId, userIsAdmin, termID, searchText, searchTitle, searchContents, published, GetNull(limitToLocale), GetNull(endDate), authorUserId, pageIndex, pageSize, orderBy), IDataReader)
End Function

Public Overrides Function SearchPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, userIsAdmin As Boolean, categories As String, searchText As String, searchTitle As Boolean, searchContents As Boolean, published As Int32, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String) As IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "SearchPostsByTerm", moduleId, blogID, displayLocale, userId, userIsAdmin, categories, searchText, searchTitle, searchContents, published, GetNull(limitToLocale), GetNull(endDate), authorUserId, pageIndex, pageSize, orderBy), IDataReader)
End Function


Public Overrides Sub SetBlogLocalization(blogID As Int32, locale As String, title As String, description As String)
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & ModuleQualifier & "SetBlogLocalization", blogID, locale, title, description)
End Sub
@@ -100,6 +100,23 @@ Namespace Entities.Posts

End Function

Public Shared Function GetPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, categories As String, published As Integer, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String, ByRef totalRecords As Integer, userId As Integer, userIsAdmin As Boolean) As Dictionary(Of Integer, PostInfo)

If pageIndex < 0 Then
pageIndex = 0
pageSize = Integer.MaxValue
End If

Dim res As New Dictionary(Of Integer, PostInfo)
Using ir As IDataReader = DataProvider.Instance().GetPostsByCategory(moduleId, blogID, displayLocale, userId, userIsAdmin, categories, published, limitToLocale, endDate, authorUserId, pageIndex, pageSize, orderBy)
res = DotNetNuke.Common.Utilities.CBO.FillDictionary(Of Integer, PostInfo)("ContentItemID", ir, False)
ir.NextResult()
totalRecords = DotNetNuke.Common.Globals.GetTotalRecords(ir)
End Using
Return GetPostsWithBlog(res, blogID, moduleId, userId, displayLocale)

End Function

Public Shared Function GetPostsByBlog(moduleId As Int32, blogID As Int32, displayLocale As String, userId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String, ByRef totalRecords As Integer) As Dictionary(Of Integer, PostInfo)

If pageIndex < 0 Then
@@ -151,6 +168,23 @@ Namespace Entities.Posts

End Function

Public Shared Function SearchPostsByCategory(moduleId As Int32, blogID As Int32, displayLocale As String, categories As String, searchText As String, searchTitle As Boolean, searchContents As Boolean, published As Integer, limitToLocale As String, endDate As Date, authorUserId As Int32, pageIndex As Int32, pageSize As Int32, orderBy As String, ByRef totalRecords As Integer, userId As Integer, userIsAdmin As Boolean) As Dictionary(Of Integer, PostInfo)

If pageIndex < 0 Then
pageIndex = 0
pageSize = Integer.MaxValue
End If

Dim res As New Dictionary(Of Integer, PostInfo)
Using ir As IDataReader = DataProvider.Instance().SearchPostsByCategory(moduleId, blogID, displayLocale, userId, userIsAdmin, categories, searchText, searchTitle, searchContents, published, limitToLocale, endDate, authorUserId, pageIndex, pageSize, orderBy)
res = DotNetNuke.Common.Utilities.CBO.FillDictionary(Of Integer, PostInfo)("ContentItemID", ir, False)
ir.NextResult()
totalRecords = DotNetNuke.Common.Globals.GetTotalRecords(ir)
End Using
Return GetPostsWithBlog(res, blogID, moduleId, userId, displayLocale)

End Function

Public Shared Function GetAuthors(moduleId As Integer, blogId As Integer) As List(Of PostAuthor)
Return DotNetNuke.Common.Utilities.CBO.FillCollection(Of PostAuthor)(DataProvider.Instance.GetAuthors(moduleId, blogId))
End Function
@@ -159,7 +159,12 @@
<data name="lblTermId.Text" xml:space="preserve">
<value>Category To Show</value>
</data>

<data name="lblCategories.Help" xml:space="preserve">
<value>If you select a category only posts in that category will be shown</value>
</data>
<data name="lblCategories.Text" xml:space="preserve">
<value>Category To Show</value>
</data>
<data name="lblModifyPageDetails.Help" xml:space="preserve">
<value>If checked the module will attempt to adjust teh page title based on the blog's context, such as blog title, post title, etc.</value>
</data>
@@ -31,6 +31,7 @@ Namespace Controls

#Region " Private Properties "
Private Property MainControlId As String = ""
Private Property catList As String = ""
Private Property StorageControlId As String = ""
Protected WithEvents Storage As HiddenField
#End Region
@@ -70,7 +71,6 @@ Namespace Controls
MainControlId = Me.ClientID & "_CategorySelect"
If Me.Page.IsPostBack Then
' read return values
Dim catList As String = ""
Me.Page.Request.Params.ReadValue(Storage.ClientID, catList)
catList = catList.Trim(","c)
SelectedCategories = New List(Of TermInfo)
@@ -114,5 +114,12 @@ Namespace Controls
End Sub
#End Region

#Region " Public Functions"
Public Overrides Function ToString() As String
Return catList
End Function

#End Region

End Class
End Namespace
@@ -1,6 +1,7 @@
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ViewSettings.ascx.vb" Inherits="DotNetNuke.Modules.Blog.Controls.ViewSettings" %>
<%@ Register TagPrefix="dnnweb" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<%@ Register TagPrefix="blog" Namespace="DotNetNuke.Modules.Blog.Controls" Assembly="DotNetNuke.Modules.Blog" %>

<fieldset>
<div class="dnnFormItem">
@@ -10,11 +11,13 @@
<div class="dnnFormItem">
<dnn:label id="lblBlogId" runat="server" controlname="ddBlogId" suffix=":" />
<asp:DropDownList runat="server" ID="ddBlogId" DataTextField="LocalizedTitle" DataValueField="BlogId" />
</div>
<div class="dnnFormItem">
<dnn:label id="lblTermId" runat="server" controlname="ddTermId" suffix=":" />
<asp:DropDownList runat="server" ID="ddTermId" DataTextField="LocalizedName" DataValueField="TermId" />
</div>
</div>
<div class="dnnFormItem">
<asp:Panel ID="pnlCategories" runat="server" class="dnnFormItem">
<dnn:Label ID="lblCategories" ResourceKey="lblCategories" runat="server" controlname="dtCategories" suffix=":" />
<blog:CategorySelect ID="ctlCategories" runat="server" />
</asp:Panel>
</div>
<div class="dnnFormItem">
<dnn:label id="lblAuthorId" runat="server" controlname="ddAuthorId" suffix=":" />
<asp:DropDownList runat="server" ID="ddAuthorId" DataTextField="DisplayName" DataValueField="UserId" />
Oops, something went wrong.

0 comments on commit 3a8981a

Please sign in to comment.