using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using CMS.CMSHelper;
using CMS.Controls;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.SettingsProvider;
public partial class CMSWebParts_Forums_ForumMostActiveThreads : CMSAbstractWebPart
{
#region "Public properties"
///
/// Gest or sest the cache item name.
///
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
forumDataSource.CacheItemName = value;
}
}
///
/// Cache dependencies, each cache dependency on a new line.
///
public override string CacheDependencies
{
get
{
return ValidationHelper.GetString(base.CacheDependencies, forumDataSource.CacheDependencies);
}
set
{
base.CacheDependencies = value;
forumDataSource.CacheDependencies = value;
}
}
///
/// Gets or sets the cache minutes.
///
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
forumDataSource.CacheMinutes = value;
}
}
///
/// Gets or sets transformation name.
///
public string TransformationName
{
get
{
return ValidationHelper.GetString(GetValue("TransformationName"), "");
}
set
{
SetValue("TransformationName", value);
}
}
///
/// Gets or sets forum groups names, use semicolon like separator.
///
public string ForumGroups
{
get
{
return ValidationHelper.GetString(GetValue("ForumGroups"), "");
}
set
{
SetValue("ForumGroups", value);
}
}
///
/// Gets or sets WHERE condition.
///
public string WhereCondition
{
get
{
return ValidationHelper.GetString(GetValue("WhereCondition"), "");
}
set
{
SetValue("WhereCondition", value);
forumDataSource.WhereCondition = value;
}
}
///
/// Gets or sets the columns to get.
///
public string Columns
{
get
{
return DataHelper.GetNotEmpty(GetValue("Columns"), String.Empty);
}
set
{
SetValue("Columns", value);
forumDataSource.SelectedColumns = value;
}
}
///
/// Gets or sets HideControlForZeroRows property.
///
public bool HideControlForZeroRows
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), true);
}
set
{
SetValue("HideControlForZeroRows", value);
repMostActiveThread.HideControlForZeroRows = value;
}
}
///
/// Gets or sets ZeroRowsText property.
///
public string ZeroRowsText
{
get
{
return ValidationHelper.GetString(GetValue("ZeroRowsText"), "");
}
set
{
SetValue("ZeroRowsText", value);
repMostActiveThread.ZeroRowsText = value;
}
}
///
/// Gets or sets TopN.
///
public int SelectTopN
{
get
{
return ValidationHelper.GetInteger(GetValue("SelectTopN"), -1);
}
set
{
SetValue("SelectTopN", value);
forumDataSource.TopN = value;
}
}
///
/// Gets or sets the site name.
///
public string SiteName
{
get
{
return DataHelper.GetNotEmpty(GetValue("SiteName"), CMSContext.CurrentSiteName);
}
set
{
SetValue("SiteName", value);
forumDataSource.SiteName = value;
}
}
///
/// Indicates if group posts should be included.
///
public bool ShowGroupPosts
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowGroupPosts"), false);
}
set
{
SetValue("ShowGroupPosts", value);
forumDataSource.ShowGroupPosts = value;
}
}
///
/// Gets or sets community group name.
///
public string GroupName
{
get
{
return ValidationHelper.GetString(GetValue("GroupName"), "");
}
set
{
SetValue("GroupName", value);
}
}
#endregion
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Reloads the control data.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (StopProcessing)
{
// Do nothing
}
else
{
if (!String.IsNullOrEmpty(TransformationName))
{
repMostActiveThread.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName, false);
repMostActiveThread.HideControlForZeroRows = HideControlForZeroRows;
repMostActiveThread.ZeroRowsText = ZeroRowsText;
// Set data source groupid according to group name
if (!String.IsNullOrEmpty(GroupName))
{
if (GroupName == CMSConstants.COMMUNITY_CURRENT_GROUP)
{
forumDataSource.GroupID = ModuleCommands.CommunityGetCurrentGroupID();
}
else
{
GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName);
if (gi != null)
{
forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0);
}
else
{
forumDataSource.StopProcessing = true;
}
}
}
if (!forumDataSource.StopProcessing)
{
forumDataSource.TopN = SelectTopN;
forumDataSource.OrderBy = "PostThreadPosts DESC";
forumDataSource.CacheItemName = CacheItemName;
forumDataSource.CacheDependencies = CacheDependencies;
forumDataSource.CacheMinutes = CacheMinutes;
forumDataSource.FilterName = ValidationHelper.GetString(GetValue("WebPartControlID"), ClientID);
forumDataSource.SelectOnlyApproved = false;
forumDataSource.SiteName = SiteName;
forumDataSource.ShowGroupPosts = ShowGroupPosts && String.IsNullOrEmpty(ForumGroups);
forumDataSource.SelectedColumns = Columns;
#region "Complete where condition"
string where = "";
// Get groups part of where condition
string[] groups = ForumGroups.Split(';');
foreach (string group in groups)
{
if (group != "")
{
if (where != "")
{
where += " OR ";
}
where += "(GroupName = N'" + SqlHelperClass.GetSafeQueryString(group, false) + "')";
}
}
where = "(" + (where == "" ? "(GroupName NOT LIKE 'AdHoc%')" : "(" + where + ")") + " AND (PostLevel = 0))";
// Append where condition and set PostLevel to 0 (only threads are needed)
// and filter out AdHoc forums
if (!String.IsNullOrEmpty(WhereCondition))
{
where += " AND (" + WhereCondition + ")";
}
#endregion
forumDataSource.WhereCondition = where;
forumDataSource.CheckPermissions = true;
repMostActiveThread.DataSource = forumDataSource.DataSource;
if (!DataHelper.DataSourceIsEmpty(repMostActiveThread.DataSource))
{
repMostActiveThread.DataBind();
}
}
}
}
}
///
/// OnPreRender override.
///
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// Hide control for zero rows
if (((repMostActiveThread.DataSource == null) || (DataHelper.DataSourceIsEmpty(repMostActiveThread.DataSource))) && (HideControlForZeroRows))
{
Visible = false;
}
}
///
/// Clears cache.
///
public override void ClearCache()
{
forumDataSource.ClearCache();
}
}