I wanna reduce the number of queries and showing only the days in which I have published posts, so I'll change the query to return if the entry has been published or not and the blog data I need for that, the changed stored proc looks like this:
The data for this query is stored in objects of the ArchiveDays class, so I will modify the class with the new attibutes, the final code is this (The file is blogInfo.vb):
#Region "Class ArchiveDays"
Public Class ArchiveDays
#Region "local property declarations"
Dim _BlogID As Integer
Dim _EntryID As Integer
Dim _AddedDate As DateTime
Dim _Title As String
Dim _userName As String
Dim _userID As Integer
Dim _published As Boolean
Dim _culture As String
Dim _dateFormat As String
Dim _timeZone As Integer
#End Region
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal BlogID As Integer, ByVal EntryID As Integer, ByVal AddedDate As DateTime, _
ByVal Title As String, ByVal UserName As String, ByVal UserID As Integer, ByVal Published As Boolean, ByVal Culture As String, _
ByVal DateFormat As String, ByVal TimeZone As Integer)
Me.BlogID = BlogID
Me.EntryID = EntryID
Me.AddedDate = AddedDate
Me.Title = Title
Me.UserName = UserName
Me.UserID = UserID
Me.Published = Published
Me.Culture = Culture
Me.DateFormat = DateFormat
Me.TimeZone = TimeZone
End Sub
#End Region
#Region "Public Properties"
Public Property BlogID() As Integer
Get
Return _BlogID
End Get
Set(ByVal Value As Integer)
_BlogID = Value
End Set
End Property
Public Property EntryID() As Integer
Get
Return _EntryID
End Get
Set(ByVal Value As Integer)
_EntryID = Value
End Set
End Property
Public Property AddedDate() As DateTime
Get
Return _AddedDate
End Get
Set(ByVal Value As DateTime)
_AddedDate = Value
End Set
End Property
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal Value As String)
_Title = Value
End Set
End Property
Public Property UserName() As String
Get
Return _userName
End Get
Set(ByVal Value As String)
_userName = Value
End Set
End Property
Public Property UserID() As Integer
Get
Return _userID
End Get
Set(ByVal value As Integer)
_userID = value
End Set
End Property
Public ReadOnly Property AddedDay() As Integer
Get
Return _AddedDate.Day
End Get
End Property
Public ReadOnly Property AddedMonth() As Integer
Get
Return _AddedDate.Month
End Get
End Property
Public ReadOnly Property AddedYear() As Integer
Get
Return _AddedDate.Year
End Get
End Property
Public Property Published() As Boolean
Get
Return _published
End Get
Set(ByVal value As Boolean)
_published = value
End Set
End Property
Public Property Culture() As String
Get
Return _culture
End Get
Set(ByVal value As String)
_culture = value
End Set
End Property
Public Property DateFormat() As String
Get
Return _dateFormat
End Get
Set(ByVal value As String)
_dateFormat = value
End Set
End Property
Public Property TimeZone() As Integer
Get
Return _timeZone
End Get
Set(ByVal value As Integer)
_timeZone = value
End Set
End Property
#End Region
End Class
#End Region
#Region "Class ArchiveDays"
Public Class ArchiveDays
#Region "local property declarations"
Dim _BlogID As Integer
Dim _EntryID As Integer
Dim _AddedDate As DateTime
Dim _Title As String
Dim _userName As String
Dim _userID As Integer
Dim _published As Boolean
Dim _culture As String
Dim _dateFormat As String
Dim _timeZone As Integer
#End Region
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal BlogID As Integer, ByVal EntryID As Integer, ByVal AddedDate As DateTime, _
ByVal Title As String, ByVal UserName As String, ByVal UserID As String, _
ByVal Published As Boolean, ByVal Culture As String, _
ByVal DateFormat As String, ByVal TimeZone As Integer)
Me.BlogID = BlogID
Me.EntryID = EntryID
Me.AddedDate = AddedDate
Me.Title = Title
Me.UserName = UserName
Me.Published = Published
Me.Culture = Culture
Me.DateFormat = DateFormat
Me.TimeZone = TimeZone
End Sub
#End Region
#Region "Public Properties"
Public Property BlogID() As Integer
Get
Return _BlogID
End Get
Set(ByVal Value As Integer)
_BlogID = Value
End Set
End Property
Public Property EntryID() As Integer
Get
Return _EntryID
End Get
Set(ByVal Value As Integer)
_EntryID = Value
End Set
End Property
Public Property AddedDate() As DateTime
Get
Return _AddedDate
End Get
Set(ByVal Value As DateTime)
_AddedDate = Value
End Set
End Property
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal Value As String)
_Title = Value
End Set
End Property
Public Property UserName() As String
Get
Return _userName
End Get
Set(ByVal Value As String)
_userName = Value
End Set
End Property
Public Property UserID() As Integer
Get
Return _userID
End Get
Set(ByVal value As Integer)
_userID = value
End Set
End Property
Public ReadOnly Property AddedDay() As Integer
Get
Return _AddedDate.Day
End Get
End Property
Public ReadOnly Property AddedMonth() As Integer
Get
Return _AddedDate.Month
End Get
End Property
Public ReadOnly Property AddedYear() As Integer
Get
Return _AddedDate.Year
End Get
End Property
Public Property Published() As Boolean
Get
Return _published
End Get
Set(ByVal value As Boolean)
_published = value
End Set
End Property
Public Property Culture() As String
Get
Return _culture
End Get
Set(ByVal value As String)
_culture = value
End Set
End Property
Public Property DateFormat() As String
Get
Return _dateFormat
End Get
Set(ByVal value As String)
_dateFormat = value
End Set
End Property
Public Property TimeZone() As Integer
Get
Return _timeZone
End Get
Set(ByVal value As Integer)
_timeZone = value
End Set
End Property
#End Region
End Class
#End Region
Then I have to change the loop to check if the entry is published or not, and in case the user is admin (or whatever, I know little about dnn security model), mark the day or not. I copied the check from viewEntry.ascx.vb. Note that I will only check the permissions when the entry is not published, So the loop in Archive.ascx.vb Line 73 would be:
The result should be that the calendar shows only the proper posts and that only the necessary database calls are made, there is no point on enhancing DNN core when a module makes n database calls to sending all the optimizations to hell.
The calendar also has the problem of the dates which are not calculated properly, I have just came across an entry located on February 1st but due to the extrange issues with timezones it is stored as being from January 31th, so it appears on the January calendar as being February the 1st and does not appear in february calendar. And there is still the problem that when the only post in a month has not been published, the month appears in the month list... I think I'll try to fix this soon.