/// <summary> /// Returns complete WHERE condition. /// </summary> protected string GetCompleteWhereCondition() { string where = ""; string comleteWhere = ""; // Global where condition if (DisplayGlobalCategories && AllowGlobalCategories) { where = " ((CategoryUserID IS NULL) AND (CategorySiteID IS NULL)) "; } // Site where condition if (DisplaySiteCategories) { where = SqlHelperClass.AddWhereCondition(where, "CategorySiteID = " + CMSContext.CurrentSiteID, "OR"); } // User where condition if (DisplayCustomCategories) { if ((CMSContext.CurrentUser != null) && (CMSContext.CurrentUser.UserID > 0)) { where = SqlHelperClass.AddWhereCondition(where, "CategoryUserID = " + CMSContext.CurrentUser.UserID, "OR"); } } // Nothing to display if (string.IsNullOrEmpty(where)) { where = "(1=0)"; } // Get complete where condition if (UseDocumentFilter && (!String.IsNullOrEmpty(AliasPath) || !String.IsNullOrEmpty(CultureCode) || (MaxRelativeLevel > -1))) { comleteWhere = TreeProvider.GetCompleteWhereCondition(CMSContext.CurrentSiteName, AliasPath, CultureCode, CombineWithDefaultCulture, null, SelectOnlyPublished, MaxRelativeLevel); comleteWhere += "))"; mUseCompleteWhere = true; // Add complete where condition where = SqlHelperClass.AddWhereCondition(where, comleteWhere); } // Add custom where condition if specified where = SqlHelperClass.AddWhereCondition(where, WhereCondition); // Display only enabled categories under enabled predecesors where = SqlHelperClass.AddWhereCondition(where, "CategoryEnabled = 1 AND (NOT EXISTS(SELECT CategoryID FROM CMS_Category AS pc WHERE (pc.CategoryEnabled = 0) AND (CMS_Category.CategoryIDPath like pc.CategoryIDPath+'/%')))"); // Filter non-personal categories by starting category if (!string.IsNullOrEmpty(StartingCategory)) { string startingIdPath = (StartingCategoryObj != null) ? StartingCategoryObj.CategoryIDPath : ""; where = SqlHelperClass.AddWhereCondition(where, "(CategoryUserID IS NOT NULL) OR (CategoryIDPath LIKE N'" + SqlHelperClass.GetSafeQueryString(startingIdPath) + "/%')"); } return(where); }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { try { // Prepare alias path aliasPath = AliasPath; if (String.IsNullOrEmpty(aliasPath)) { aliasPath = "/%"; } aliasPath = MacroResolver.ResolveCurrentPath(aliasPath); // Prepare site name siteName = SiteName; if (String.IsNullOrEmpty(siteName)) { siteName = SiteContext.CurrentSiteName; } // Prepare culture code cultureCode = CultureCode; if (String.IsNullOrEmpty(cultureCode)) { cultureCode = LocalizationContext.PreferredCultureCode; } // Base URL of the links string url; if (String.IsNullOrEmpty(DocumentListPath)) { url = RequestContext.CurrentURL; } else { url = DocumentURLProvider.GetUrl(MacroResolver.ResolveCurrentPath(DocumentListPath)); } url = UrlResolver.ResolveUrl(url); string renderedTags = null; // Try to get data from cache using (var cs = new CachedSection <string>(ref renderedTags, CacheMinutes, true, CacheItemName, "tagcloud", TagGroupName, OrderBy, SelectTopN, url, TagSeparator, QueryStringName, MaxTagSize, MinTagSize, "documents", siteName, aliasPath, CacheHelper.GetCultureCacheKey(cultureCode), CombineWithDefaultCulture, WhereCondition, SelectOnlyPublished, MaxRelativeLevel)) { if (cs.LoadData) { // Get the correct range int maxSize = Math.Max(MaxTagSize, MinTagSize); int minSize = Math.Min(MaxTagSize, MinTagSize); // Get the tags SiteInfo si = SiteInfoProvider.GetSiteInfo(siteName); int siteId = 0; if (si != null) { siteId = si.SiteID; } // Get tag group info tgi = TagGroupInfoProvider.GetTagGroupInfo(TagGroupName, siteId); // Get the data DataSet ds = null; if (!UseDocumentFilter) { // Get the tag group if (tgi != null) { // Get the tags for group ds = TagInfoProvider.GetTags("TagGroupID = " + tgi.TagGroupID, OrderBy, SelectTopN); } } else { // Get the tags for documents string comleteWhere = TreeProvider.GetCompleteWhereCondition(siteName, aliasPath, cultureCode, CombineWithDefaultCulture, WhereCondition, SelectOnlyPublished, MaxRelativeLevel); ds = TagInfoProvider.GetTags(TagGroupName, siteId, comleteWhere, OrderBy, SelectTopN); } // DS must have at least three columns (fist for IDs, second for names, third for counts) if (!DataHelper.DataSourceIsEmpty(ds)) { // First we need to find the maximum and minimum int max = Int32.MinValue; int min = Int32.MaxValue; foreach (DataRow dr in ds.Tables[0].Rows) { int tagCount = ValidationHelper.GetInteger(dr["TagCount"], 0); max = Math.Max(tagCount, max); min = Math.Min(tagCount, min); } // Now generate the tags int count = ds.Tables[0].Rows.Count; StringBuilder sb = new StringBuilder(count * 100); int index = 0; // Process the tags foreach (DataRow dr in ds.Tables[0].Rows) { if (index > 0) { sb.Append(TagSeparator + "\n"); } // Count the percentage and get the final size of the tag int tagCount = ValidationHelper.GetInteger(dr["TagCount"], 0); int val = (min == max ? 100 : (((tagCount - min) * 100) / (max - min))); int pixelSize = minSize + ((val * (maxSize - minSize)) / 100); // Create the link with query string parameter string paramUrl = URLHelper.AddParameterToUrl(url, QueryStringName, ValidationHelper.GetString(dr["TagID"], "")); sb.Append("<span><a href=\"" + HTMLHelper.HTMLEncode(paramUrl) + "\" style=\"font-size:" + pixelSize.ToString() + "px;\" >" + HTMLHelper.HTMLEncode(dr["TagName"].ToString()) + "</a></span>"); index++; } renderedTags = sb.ToString(); } // Save to cache if (cs.Cached) { cs.CacheDependency = GetCacheDependency(); } cs.Data = renderedTags; } } if (String.IsNullOrEmpty(renderedTags)) { // Ensure no data behavior if (HideControlForZeroRows) { Visible = false; } else { renderedTags = ZeroRowsText; } } // Display the tags ltlTags.Text = renderedTags; } catch (Exception ex) { // Display the error ltlTags.Text = "<div style=\"color: red\">" + ex.Message + "</div>"; } } }