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.SiteProvider;
using CMS.SettingsProvider;
public partial class CMSWebParts_Forums_ForumTopContributors : CMSAbstractWebPart
{
#region "Public properties"
///
/// Gest or sest the cache item name.
///
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
}
}
///
/// Cache dependencies, each cache dependency on a new line.
///
public override string CacheDependencies
{
get
{
return CacheHelper.GetCacheDependencies(base.CacheDependencies, "cms.user|all");
}
set
{
base.CacheDependencies = CacheHelper.GetCacheDependencies(value, "cms.user|all");
}
}
///
/// Gets or sets the cache minutes.
///
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
}
}
///
/// Gets or sets transformation name.
///
public string TransformationName
{
get
{
return ValidationHelper.GetString(GetValue("TransformationName"), "");
}
set
{
SetValue("TransformationName", value);
}
}
///
/// Gets or sets WHERE condition.
///
public string WhereCondition
{
get
{
return ValidationHelper.GetString(GetValue("WhereCondition"), "");
}
set
{
SetValue("WhereCondition", value);
}
}
///
/// Gets or sets HideControlForZeroRows property.
///
public bool HideControlForZeroRows
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), true);
}
set
{
SetValue("HideControlForZeroRows", value);
}
}
///
/// Gets or sets ZeroRowsText property.
///
public string ZeroRowsText
{
get
{
return ValidationHelper.GetString(GetValue("ZeroRowsText"), "");
}
set
{
SetValue("ZeroRowsText", value);
}
}
///
/// Gets or sets TopN.
///
public int SelectTopN
{
get
{
return ValidationHelper.GetInteger(GetValue("SelectTopN"), -1);
}
set
{
SetValue("SelectTopN", value);
}
}
#endregion
#region "Methods"
///
/// 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))
{
repTopContributors.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName, false);
repTopContributors.HideControlForZeroRows = HideControlForZeroRows;
repTopContributors.ZeroRowsText = ZeroRowsText;
DataSet ds = null;
// Try to get data from cache
using (CachedSection cs = new CachedSection(ref ds, CacheMinutes, true, CacheItemName, "forumtopcontributors", CMSContext.CurrentSiteName, WhereCondition, SelectTopN))
{
if (cs.LoadData)
{
// Get the data
ds = GetData();
// Save to the cache
if (cs.Cached)
{
// Save to the cache
cs.CacheDependency = GetCacheDependency();
}
cs.Data = ds;
}
}
repTopContributors.DataSource = ds;
if (!DataHelper.DataSourceIsEmpty(repTopContributors.DataSource))
{
repTopContributors.DataBind();
}
}
}
}
///
/// OnPreRender override.
///
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// Hide control for zero rows
if (((repTopContributors.DataSource == null) || (DataHelper.DataSourceIsEmpty(repTopContributors.DataSource))) && (HideControlForZeroRows))
{
Visible = false;
}
}
///
/// Returns the Users data.
///
private DataSet GetData()
{
string where = "(UserID IN (SELECT UserID FROM CMS_UserSite WHERE SiteID IN (SELECT SiteID FROM CMS_Site WHERE SiteName = '" + SqlHelperClass.GetSafeQueryString(CMSContext.CurrentSiteName) + "')))";
if (!String.IsNullOrEmpty(WhereCondition))
{
where += " AND (" + WhereCondition + ")";
}
return UserInfoProvider.GetFullUsers(where, "UserForumPosts DESC", SelectTopN, null);
}
#endregion
}