using System;
using CMS.ExtendedControls;
using CMS.GlobalHelper;
using CMS.Polls;
using CMS.SettingsProvider;
using CMS.SiteProvider;
public partial class CMSModules_Polls_InlineControls_PollControl : InlineUserControl
{
///
/// Poll code name.
///
public string PollName
{
get
{
return ValidationHelper.GetString(GetValue("PollName"), null);
}
set
{
SetValue("PollName", value);
PollView1.PollCodeName = value;
}
}
///
/// Poll site name.
///
public string SiteName
{
get
{
return ValidationHelper.GetString(GetValue("SiteName"), null);
}
set
{
SetValue("SiteName", value);
PollView1.PollSiteID = GetSiteID();
}
}
///
/// Poll group name.
///
public string GroupName
{
get
{
return ValidationHelper.GetString(GetValue("GroupName"), null);
}
set
{
SetValue("GroupName", value);
PollView1.PollGroupID = GetGroupID();
}
}
///
/// Type of the representation of the answers count in the graph.
///
public CountTypeEnum CountType
{
get
{
string value = ValidationHelper.GetString(GetValue("CountType"), "absolute");
switch (value.ToLowerCSafe())
{
case "none":
case "0":
return CountTypeEnum.None;
case "percentage":
case "2":
return CountTypeEnum.Percentage;
default:
return CountTypeEnum.Absolute;
}
}
set
{
SetValue("CountType", value.ToString().ToLowerCSafe());
PollView1.CountType = value;
}
}
///
/// Control parameter.
///
public override string Parameter
{
get
{
return PollName;
}
set
{
PollName = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
PollView1.PollCodeName = PollName;
PollView1.PollSiteID = GetSiteID();
PollView1.PollGroupID = GetGroupID();
PollView1.CountType = CountType;
}
///
/// Returns site ID according to site name.
///
protected int GetSiteID()
{
if (!string.IsNullOrEmpty(SiteName))
{
// Get site object
SiteInfo site = SiteInfoProvider.GetSiteInfo(SiteName);
if (site != null)
{
return site.SiteID;
}
}
return 0;
}
///
/// Returns group ID according to group name.
///
protected int GetGroupID()
{
if (!string.IsNullOrEmpty(GroupName))
{
// Get group object
GeneralizedInfo group = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName);
if (group != null)
{
// Get ID column value
return ValidationHelper.GetInteger(group.GetValue(group.IDColumn), 0);
}
}
return 0;
}
}