using System; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Controls; using CMS.UIControls; /// /// Site selector for selecting site specific, all sites or global objects. /// public partial class CMSModules_Polls_Controls_Filters_SiteSelector : CMSAbstractBaseFilterControl { #region "Properties" /// /// Where condition. /// public override string WhereCondition { get { base.WhereCondition = GetWhereCondition(); return base.WhereCondition; } set { base.WhereCondition = value; } } /// /// Gets or sets site ID. /// public int SiteID { get { return siteSelector.SiteID; } set { siteSelector.SiteID = value; } } /// /// Filter value. /// public override object Value { get { return siteSelector.Value; } set { siteSelector.Value = value; } } /// /// Gets inner uniselector. /// public DropDownList Selector { get { return siteSelector.Selector; } } /// /// Indicates if all global polls should be displayed. If FALSE then only objects /// assigned to given site are displayed. Default is FALSE. /// public bool DisplayAllGlobals { get; set; } #endregion #region "Methods and events" /// /// OnLoad override - check whether filter is set. /// protected override void OnLoad(EventArgs e) { base.OnLoad(e); siteSelector.Selector.SelectedIndexChanged += new EventHandler(Selector_SelectedIndexChanged); } /// /// Generates where condition. /// public string GetWhereCondition() { string where = null; int currentSiteID = CMSContext.CurrentSiteID; switch (siteSelector.SiteID) { case UniSelector.US_GLOBAL_RECORD: // Global objects only where = "(PollGroupID IS NULL) AND (PollSiteID IS NULL)"; if (!DisplayAllGlobals) { where += "AND (PollID IN (SELECT PollID FROM Polls_PollSite WHERE SiteID=" + currentSiteID + "))"; } return where; case UniSelector.US_GLOBAL_OR_SITE_RECORD: // Global and site objects if (DisplayAllGlobals) { return "(PollGroupID IS NULL) AND ((PollSiteID IS NULL) OR (PollSiteID=" + currentSiteID + "))"; } else { return "(PollGroupID IS NULL) AND ((PollSiteID=" + currentSiteID + ") OR ((PollSiteID IS NULL) AND (PollID IN (SELECT PollID FROM Polls_PollSite WHERE SiteID=" + currentSiteID + "))))"; } default: // Site objects only return "(PollGroupID IS NULL) AND PollSiteID=" + siteSelector.SiteID; } } /// /// Handles Site selector OnSelectionChanged event. /// protected void Selector_SelectedIndexChanged(object sender, EventArgs e) { // Raise OnFilterChange event RaiseOnFilterChanged(); } #endregion }