Portal Engine
Version 3.x > Portal Engine > Adding blog posts under blogyear View modes: 
User avatar
Member
Member
Gabriëlle - 12/4/2008 3:38:48 PM
   
Adding blog posts under blogyear
Hi,

Can anybody advise me about a workaround for adding blogposts automatically under a year instead of month?

Thanks!

Gabriëlle

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 12/8/2008 4:49:05 AM
   
RE:Adding blog posts under blogyear
Hi Gabriëlle,

I am afraid there is not such a known workaround. You would need to develop your own document types and all the functionality of blogs you would need by yourself.

Best regards,
Helena Grulichova

User avatar
Member
Member
Gabriëlle - 12/11/2008 2:45:51 PM
   
RE:Adding blog posts under blogyear
Hi Helena,

Thanks for your reply, eventually I've managed a workarond. For other users who would like to add blogposts automatically under a year instead of a month, below is the changed code in edit.aspx.cs which might have some unnecessary code left behind, but it works.

However, there is another thing:

When changing the already existing date of a blogpost or the startdate of a blogmonth, Kentico doesn't move the underlying documents if the new date isn't valid anymore according to the rules. These rules only apply for adding a new document. Any ideas?

Best regards,

Gabriëlle

// Special treatment for blog post (ensure parent month)
if (newdocument && (ci != null) && (ci.ClassName.ToLower() == "cms.blogpost"))
{
// Get parent node
node = tree.SelectSingleNode(nodeId, TreeProvider.ALL_CULTURES);
if (node != null)
{
// Get parent blog ID when inserting post under blog month
if (node.NodeClassName.ToLower() == "cms.blogmonth")
{
node = tree.SelectSingleNode(node.NodeParentID, TreeProvider.ALL_CULTURES);
if (node != null)
{
parentId = node.NodeID;
}
}
// Get parent blog ID when inserting post under blog
else
{
parentId = nodeId;
}

if (node != null)
{
// Validate the form first
if (formElem.BasicForm.ValidateData())
{
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(CMSContext.CurrentUser.PreferredCultureCode);

// Prepare the data
DateTime startDate = ValidationHelper.GetDateTime(formElem.BasicForm.GetFieldValue("BlogpostDate"), DateTimePicker.NOT_SELECTED);
string monthName = startDate.Year.ToString();
startDate = new DateTime(startDate.Year, 1,1);

// Check existing
DataSet existingDS = tree.SelectNodes(CMSContext.CurrentSite.SiteName, node.NodeAliasPath + "/%", TreeProvider.ALL_CULTURES, true, "cms.blogmonth", "BlogMonthStartingDate = '" + TableManager.GetDateTimeString(startDate)+ "'", null, -1, false);
if (DataHelper.DataSourceIsEmpty(existingDS))
{
// Create the month node
node = new CMS.TreeEngine.TreeNode("CMS.BlogMonth", tree);
node.DocumentCulture = CMSContext.CurrentUser.PreferredCultureCode;

// Insert the month
node.SetValue("BlogMonthName", monthName);
node.SetValue("BlogMonthStartingDate", startDate);
node.DocumentName = monthName;
node.Insert(parentId);

this.formElem.NodeId = node.NodeID;
}
else
{
// Set existing
this.formElem.NodeId = ValidationHelper.GetInteger(existingDS.Tables[0].Rows[0]["NodeID"], 0);
}
}
}
}
}