Ejemplo n.º 1
0
    public string[] TagsAutoComplete(string prefixText, int count, string contextKey)
    {
        string where = "(TagName LIKE N'" + SqlHelperClass.GetSafeQueryString(prefixText) + "%')";
        if (contextKey != null)
        {
            where += " AND (TagGroupID = " + ValidationHelper.GetInteger(contextKey, 0) + ")";
        }

        DataSet ds = TagInfoProvider.GetTags(where, "TagName", 20, "TagName");

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            string[] output = new string[ds.Tables[0].Rows.Count];

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i]["TagName"].ToString().Contains(" "))
                {
                    output[i] = "'\"" + HttpUtility.HtmlDecode(ds.Tables[0].Rows[i]["TagName"].ToString()) + "\"'";
                }
                else
                {
                    output[i] = HttpUtility.HtmlDecode(ds.Tables[0].Rows[i]["TagName"].ToString());
                }
            }

            return(output);
        }

        return(null);
    }
Ejemplo n.º 2
0
    public void SaveTags()
    {
        var resultTags = UnsavedTags;

        var items = gridElem.SelectedItems;

        if (items.Count > 0)
        {
            var savedTagNames = TagInfoProvider.GetTags()
                                .WhereIn("TagID", items)
                                .Column("TagName")
                                .OrderBy("TagName")
                                .GetListResult <String>();

            // Combine all selected tags (unsaved + saved)
            resultTags = resultTags.Union(savedTagNames, StringComparer.InvariantCultureIgnoreCase).ToHashSet();
        }

        if (resultTags != null)
        {
            var result = resultTags.Select(t => t.Contains(" ") ? String.Format("\"{0}\"", t.Trim('"')) : t).Join(", ");

            // Update parameters
            UpdateParameters(result);

            ltlScript.Text = ScriptHelper.GetScript("wopener.TS_SetTagsToTextBox(" + ScriptHelper.GetString(textBoxId) + ", " + ScriptHelper.GetString(result) + "); CloseDialog();");
        }
        else
        {
            ltlScript.Text = ScriptHelper.GetScript("CloseDialog();");
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Returns true if document has any/all of the specified tags.
    /// </summary>
    /// <param name="document">Document</param>
    /// <param name="tags">Semicolon separated tags</param>
    /// <param name="allTags">Indicates whether all tags must be present or only one of them</param>
    public static bool HasTags(object document, string tags, bool allTags)
    {
        TreeNode doc = document as TreeNode;

        if (doc != null)
        {
            if (!String.IsNullOrEmpty(tags))
            {
                string[] tagNames = tags.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                string where = SqlHelperClass.GetWhereCondition("TagName", tagNames);
                var tagInfos = TagInfoProvider.GetTags(doc.DocumentID, where, null, 0, null).Items;

                // Return true if all/any tags were found
                return(allTags ? (tagInfos.Count == tagNames.Length) : (tagInfos.Count > 0));
            }

            // No tags were selected
            if (allTags)
            {
                return(true);
            }
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get current tag ID
        mTagId = QueryHelper.GetInteger("tagid", 0);
        TagInfo ti = TagInfoProvider.GetTagInfo(mTagId);

        EditedObject = ti;

        if (ti != null)
        {
            int groupId = QueryHelper.GetInteger("groupid", 0);
            int siteId  = QueryHelper.GetInteger("siteid", 0);

            string[,] pageTitleTabs = new string[2, 3];
            pageTitleTabs[0, 0]     = GetString("taggroup_edit.itemlistlink");
            pageTitleTabs[0, 1]     = "~/CMSModules/TagGroups/Pages/Development/TagGroup_Edit_Tags.aspx?groupid=" + groupId + "&siteid=" + siteId;
            pageTitleTabs[0, 2]     = "groupContent";
            pageTitleTabs[1, 0]     = ti.TagName;
            pageTitleTabs[1, 1]     = string.Empty;
            pageTitleTabs[1, 2]     = string.Empty;

            CurrentMaster.Title.Breadcrumbs = pageTitleTabs;

            docElem.SiteName = filterDocuments.SelectedSite;
            docElem.UniGrid.OnBeforeDataReload += new OnBeforeDataReload(UniGrid_OnBeforeDataReload);
            docElem.UniGrid.OnAfterDataReload  += new OnAfterDataReload(UniGrid_OnAfterDataReload);
        }
    }
Ejemplo n.º 5
0
    private void gridTagGroups_OnAction(string actionName, object actionArgument)
    {
        int    groupId = -1;
        string siteId  = null;

        switch (actionName)
        {
        // Editing of the category fired
        case "edit":
            // Get category ID
            groupId = ValidationHelper.GetInteger(actionArgument, -1);
            siteId  = Convert.ToString(this.siteSelector.Value);

            // Create a target site URL and pass the category ID as a parameter
            string editUrl = "TagGroup_Edit.aspx?groupid=" + groupId.ToString() + "&siteid=" + siteId;
            URLHelper.Redirect(editUrl);
            break;

        // Deleteing of the category was fired
        case "delete":
            groupId = ValidationHelper.GetInteger(actionArgument, -1);

            if (groupId > -1)
            {
                // If no item depends on the current group
                DataSet ds = TagInfoProvider.GetTags("TagGroupID = " + groupId, null);
                if (DataHelper.DataSourceIsEmpty(ds))
                {
                    // Delete the class
                    TagGroupInfoProvider.DeleteTagGroupInfo(groupId);
                }
                else
                {
                    // Display error on deleting
                    this.lblError.Visible = true;
                    this.lblError.Text    = GetString("tags.taggroup_list.hasdependencies");
                }
            }
            break;
        }
    }
Ejemplo n.º 6
0
    protected void gridElem_OnAfterDataReload()
    {
        if (DataHelper.DataSourceIsEmpty(gridElem.GridView.DataSource))
        {
            return;
        }

        if (RequestHelper.IsPostBack())
        {
            return;
        }

        // Get tag IDs for given tag names
        var tags = TagInfoProvider.GetTags()
                   .WhereIn("TagName", selectedTags)
                   .WhereEquals("TagGroupID", groupId)
                   .Columns("TagID", "TagName")
                   .Select(row => new Tuple <string, string>(row["TagID"].ToString(), row["TagName"].ToString())).ToList();

        UnsavedTags = selectedTags.Except(tags.Select(t => t.Item2)).ToHashSet();

        gridElem.SelectedItems = tags.Select(t => t.Item1).ToList();
    }
Ejemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get current tag ID
        mTagId = QueryHelper.GetInteger("tagid", 0);
        TagInfo ti = TagInfoProvider.GetTagInfo(mTagId);

        EditedObject = ti;

        if (ti != null)
        {
            int groupId = QueryHelper.GetInteger("groupid", 0);
            int siteId  = QueryHelper.GetInteger("siteid", 0);

            UIElementInfo ui  = UIElementInfoProvider.GetUIElementInfo("CMS.Taxonomy", "tags");
            String        url = String.Empty;
            if (ui != null)
            {
                url  = UIContextHelper.GetElementUrl(ui, UIContext);
                url += String.Format("&parentobjectid={0}&tagid={1}&siteid={2}&displaytitle={3}", groupId, mTagId, siteId, QueryHelper.GetBoolean("displaytitle", false));
            }

            PageBreadcrumbs.Items.Add(new BreadcrumbItem()
            {
                Text        = GetString("taggroup_edit.itemlistlink"),
                RedirectUrl = url
            });

            PageBreadcrumbs.Items.Add(new BreadcrumbItem()
            {
                Text = ti.TagName
            });

            docElem.SiteName = filterDocuments.SelectedSite;
            docElem.UniGrid.OnBeforeDataReload += new OnBeforeDataReload(UniGrid_OnBeforeDataReload);
            docElem.UniGrid.OnAfterDataReload  += new OnAfterDataReload(UniGrid_OnAfterDataReload);
        }
    }
    /// <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>";
            }
        }
    }