Example #1
0
    /// <summary>
    /// Deletes tag group. Called when the "Delete group" button is pressed.
    /// Expects the CreateTagGroup method to be run first.
    /// </summary>
    private bool DeleteTagGroup()
    {
        // Get the tag group
        string where = "TagGroupName LIKE 'MyNew%'";

        // Get the data
        DataSet groups = TagGroupInfoProvider.GetTagGroups(where, null);

        if (!DataHelper.DataSourceIsEmpty(groups))
        {
            // Loop through the individual items
            foreach (DataRow groupDr in groups.Tables[0].Rows)
            {
                // Create object from DataRow
                TagGroupInfo deleteGroup = new TagGroupInfo(groupDr);

                // Delete the tag group
                TagGroupInfoProvider.DeleteTagGroupInfo(deleteGroup);
            }

            return(true);
        }

        return(false);
    }
Example #2
0
    /// <summary>
    /// Creates tag. Called when the "Create tag" button is pressed.
    /// </summary>
    private bool AddTagToDocument()
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the root document
        TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);

        // Get tag group ID
        TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", CMSContext.CurrentSiteID);

        if ((root != null) && (updateGroup != null))
        {
            // Add tag to document
            root.DocumentTags = "\"My New Tag\"";

            // Add tag to document
            root.DocumentTagGroupID = updateGroup.TagGroupID;

            // Update document
            root.Update();

            return(true);
        }

        return(false);
    }
Example #3
0
    /// <summary>
    /// Gets and bulk updates tag groups. Called when the "Get and bulk update groups" button is pressed.
    /// Expects the CreateTagGroup method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateTagGroups()
    {
        // Prepare the parameters
        string where = "TagGroupName LIKE 'MyNew%'";

        // Get the data
        DataSet groups = TagGroupInfoProvider.GetTagGroups(where, null);

        if (!DataHelper.DataSourceIsEmpty(groups))
        {
            // Loop through the individual items
            foreach (DataRow groupDr in groups.Tables[0].Rows)
            {
                // Create object from DataRow
                TagGroupInfo modifyGroup = new TagGroupInfo(groupDr);

                // Update the property
                modifyGroup.TagGroupDisplayName = modifyGroup.TagGroupDisplayName.ToUpper();

                // Update the tag group
                TagGroupInfoProvider.SetTagGroupInfo(modifyGroup);
            }

            return(true);
        }

        return(false);
    }
Example #4
0
    /// <summary>
    /// Initializes the breadcrumb master page element.
    /// </summary>
    private void InitializeBreadcrumb()
    {
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("Development.TagGroups");

        string backUrl = "~/CMSModules/TagGroups/Pages/Development/TagGroup_List.aspx";

        // If the ID of the selected site on tag group list page was supplied use it
        if (this.mSiteId != 0)
        {
            breadcrumbs[0, 1] = backUrl + "?siteid=" + this.mSiteId;
        }
        else
        {
            breadcrumbs[0, 1] = backUrl;
        }

        breadcrumbs[0, 2] = "_parent";

        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(this.mGroupID);

        breadcrumbs[1, 0] = tgi.TagGroupDisplayName;

        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;
    }
    /// <summary>
    /// Handles pre-actions required when editing existing tag group.
    /// </summary>
    private void HandleExisting()
    {
        // Get info on existing tag group
        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(GroupID);

        // Prefill the fields with obtained data
        txtDisplayName.Text = tgi.TagGroupDisplayName;
        txtCodeName.Text    = tgi.TagGroupName;
        txtDescription.Text = tgi.TagGroupDescription;
    }
Example #6
0
    /// <summary>
    /// Creates tag group. Called when the "Create group" button is pressed.
    /// </summary>
    private bool CreateTagGroup()
    {
        // Create new tag group object
        TagGroupInfo newGroup = new TagGroupInfo();

        // Set the properties
        newGroup.TagGroupDisplayName = "My new group";
        newGroup.TagGroupName        = "MyNewGroup";
        newGroup.TagGroupDescription = "";
        newGroup.TagGroupSiteID      = CMSContext.CurrentSiteID;
        newGroup.TagGroupIsAdHoc     = false;

        // Create the tag group
        TagGroupInfoProvider.SetTagGroupInfo(newGroup);

        return(true);
    }
Example #7
0
    /// <summary>
    /// Gets and updates tag group. Called when the "Get and update group" button is pressed.
    /// Expects the CreateTagGroup method to be run first.
    /// </summary>
    private bool GetAndUpdateTagGroup()
    {
        // Get the tag group
        TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", CMSContext.CurrentSiteID);

        if (updateGroup != null)
        {
            // Update the property
            updateGroup.TagGroupDisplayName = updateGroup.TagGroupDisplayName.ToLower();

            // Update the tag group
            TagGroupInfoProvider.SetTagGroupInfo(updateGroup);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Validates required entries.
    /// </summary>
    /// <param name="newGroupName">Group name to check for unique</param>
    /// <param name="siteId">ID of the site tag group should be inserted</param>
    /// <returns>True if all the necessary data were entered, otherwise false is returned</returns>
    private bool CodeNameIsUnique(string newGroupName, int siteId)
    {
        // Gheck if the tag group already exist
        TagGroupInfo tagGroup = TagGroupInfoProvider.GetTagGroupInfo(newGroupName, siteId);

        if (tagGroup == null)
        {
            return(true);
        }
        else
        {
            // If the existing tag group is updated the code name already exist
            if ((GroupID > 0) && (GroupID == tagGroup.TagGroupID))
            {
                return(true);
            }

            return(false);
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate form entries
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            TagGroupInfo tgi = null;

            try
            {
                // Edit existing tag group
                if (this.GroupID > 0)
                {
                    tgi = TagGroupInfoProvider.GetTagGroupInfo(this.GroupID);
                }
                else
                {
                    tgi = new TagGroupInfo();
                }

                // Update tag group info fields
                tgi.TagGroupDisplayName = this.txtDisplayName.Text;
                tgi.TagGroupName = this.txtCodeName.Text;
                tgi.TagGroupDescription = this.txtDescription.Text;
                tgi.TagGroupSiteID = this.SiteID;

                // If the new tag group is created set the default value for TagGroupIsAdHoc property
                if (!this.IsEdit)
                {
                    tgi.TagGroupIsAdHoc = false;
                }

                // Update tag group info
                TagGroupInfoProvider.SetTagGroupInfo(tgi);

                // Redirect to edit page once the new tag group is created
                if (!this.IsEdit)
                {
                    string editUrl = "~/CMSModules/TagGroups/Pages/Development/TagGroup_Edit.aspx?groupid=" + tgi.TagGroupID.ToString() + "&siteid=" + this.SiteID.ToString() + "&saved=1";
                    URLHelper.Redirect(editUrl);
                }

                // Inform about success while editing
                this.lblError.Visible = false;
                this.lblInfo.Text = GetString("general.changessaved");
                this.lblInfo.Visible = true;

                // Refresh header
                ScriptHelper.RefreshTabHeader(this.Page, "general");
            }
            catch (Exception ex)
            {
                // Display error message
                this.lblInfo.Visible = false;
                this.lblError.Text = GetString("general.erroroccurred") + " " + ex.Message;
                this.lblError.Visible = true;
            }
        }
        else
        {
            // Display error message
            this.lblInfo.Visible = false;
            this.lblError.Text = errorMessage;
            this.lblError.Visible = true;
        }
    }
    /// <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>";
            }
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate form entries
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            TagGroupInfo tgi = null;

            try
            {
                // Edit existing tag group
                if (GroupID > 0)
                {
                    tgi = TagGroupInfoProvider.GetTagGroupInfo(GroupID);
                }
                else
                {
                    tgi = new TagGroupInfo();
                }

                // Update tag group info fields
                tgi.TagGroupDisplayName = txtDisplayName.Text;
                tgi.TagGroupName        = txtCodeName.Text;
                tgi.TagGroupDescription = txtDescription.Text;
                tgi.TagGroupSiteID      = SiteID;

                // If the new tag group is created set the default value for TagGroupIsAdHoc property
                if (!IsEdit)
                {
                    tgi.TagGroupIsAdHoc = false;
                }

                // Update tag group info
                TagGroupInfoProvider.SetTagGroupInfo(tgi);

                // Redirect to edit page once the new tag group is created
                if (!IsEdit)
                {
                    string editUrl = "~/CMSModules/TagGroups/Pages/Development/TagGroup_Edit.aspx?groupid=" + tgi.TagGroupID.ToString() + "&siteid=" + SiteID.ToString() + "&saved=1";
                    URLHelper.Redirect(editUrl);
                }

                // Show message
                ShowChangesSaved();

                // Refresh header
                ScriptHelper.RefreshTabHeader(Page, "general");
            }
            catch (Exception ex)
            {
                // Show error message
                ShowError(GetString("general.erroroccurred") + " " + ex.Message);
            }
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Process additional department tasks.
    /// </summary>
    public void ProcessDepartment(object sender, EventArgs e)
    {
        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Get department template source document
        TreeNode sourceNode = DocumentHelper.GetDocument(CMSContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, 0, false, null, TreeProvider);

        // Copy relevant template data to department document
        if (sourceNode != null)
        {
            DocumentHelper.CopyNodeData(sourceNode, editedNode, true, true, false, true, true, false, false, "DocumentName;NodeAlias;DocumentTagGroupID;DocumentStylesheetID;DocumentPublishFrom;DocumentPublishTo");
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #region "Create department tag group"

        // Get tag group info
        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID);

        // If not exist, create new tag group and set it to document
        if (tgi == null)
        {
            // Populate tag group info fields
            tgi = new TagGroupInfo();
            tgi.TagGroupDisplayName = editedNode.DocumentName;
            tgi.TagGroupName = editedNode.NodeGUID.ToString();
            tgi.TagGroupDescription = "";
            tgi.TagGroupSiteID = CMSContext.CurrentSiteID;
            tgi.TagGroupIsAdHoc = false;

            // Store tag group info to DB
            TagGroupInfoProvider.SetTagGroupInfo(tgi);

            // Update document Tag group ID
            editedNode.DocumentTagGroupID = tgi.TagGroupID;
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #endregion

        if (!DataHelper.DataSourceIsEmpty(TemplateDocuments))
        {
            // List of selected documents
            string selectedDocs = ";" + Value + ";";

            // Get already created documents under edited document
            DataSet dsExistingDocs = DocumentHelper.GetDocuments(CMSContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + TreeProvider.SELECTNODES_REQUIRED_COLUMNS, null);
            StringBuilder sbExistDocs = new StringBuilder();

            // Process existing documents to obtain list of aliases
            foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows)
            {
                sbExistDocs.Append(";");
                sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLower());
            }
            sbExistDocs.Append(";");
            string existingDocs = sbExistDocs.ToString();

            // Set same ordering as for original template documents
            bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering;
            TreeProvider.UseAutomaticOrdering = false;

            // Process template documents
            foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows)
            {
                string nodeAlias = drDoc["NodeAlias"].ToString().ToLower();
                string contNodeAlias = ";" + nodeAlias + ";";

                // Set marks
                bool existing = existingDocs.Contains(contNodeAlias);
                bool selected = selectedDocs.Contains(contNodeAlias);

                int nodeId = ValidationHelper.GetInteger(drDoc["NodeID"], 0);
                string docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], "");
                TreeNode srcNode = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider);

                // Check if section exists
                if (srcNode != null)
                {
                    // Copy or remove marked document sections
                    if (selected)
                    {
                        if (!existing)
                        {
                            CopyDocumentSection(srcNode, editedNode.NodeID, TreeProvider);
                        }
                    }
                    else
                    {
                        if (existing)
                        {
                            // Select node to delete
                            TreeNode delNode = TreeHelper.SelectSingleNode(editedNode.NodeAliasPath + "/" + nodeAlias);
                            if (delNode != null)
                            {
                                DeleteDocumentSection(delNode, TreeProvider);
                            }
                        }
                    }

                    // Process additional operations
                    if (selected && !existing)
                    {
                        switch (nodeAlias)
                        {
                            // Create department forum
                            case FORUM_DOCUMENT_ALIAS:
                                CreateDepartmentForumGroup(editedNode);
                                CreateDepartmentForumSearchIndex(editedNode);
                                break;

                            // Create media library
                            case MEDIA_DOCUMENT_ALIAS:
                                CreateDepartmentMediaLibrary(editedNode);
                                break;
                        }
                    }
                }
            }

            // Set previous ordering
            TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering;
        }
        mDocumentSaved = true;
    }
Example #13
0
    /// <summary>
    /// Gets and bulk updates tag groups. Called when the "Get and bulk update groups" button is pressed.
    /// Expects the CreateTagGroup method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateTagGroups()
    {
        // Prepare the parameters
        string where = "TagGroupName LIKE 'MyNew%'";

        // Get the data
        DataSet groups = TagGroupInfoProvider.GetTagGroups(where, null);
        if (!DataHelper.DataSourceIsEmpty(groups))
        {
            // Loop through the individual items
            foreach (DataRow groupDr in groups.Tables[0].Rows)
            {
                // Create object from DataRow
                TagGroupInfo modifyGroup = new TagGroupInfo(groupDr);

                // Update the property
                modifyGroup.TagGroupDisplayName = modifyGroup.TagGroupDisplayName.ToUpper();

                // Update the tag group
                TagGroupInfoProvider.SetTagGroupInfo(modifyGroup);
            }

            return true;
        }

        return false;
    }
    /// <summary>
    /// Process additional department tasks.
    /// </summary>
    public void ProcessDepartment(object sender, EventArgs e)
    {
        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Get department template source document
        TreeNode sourceNode = DocumentHelper.GetDocument(CMSContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, 0, false, null, TreeProvider);

        // Copy relevant template data to department document
        if (sourceNode != null)
        {
            DocumentHelper.CopyNodeData(sourceNode, editedNode, true, true, false, true, true, false, false, "DocumentName;NodeAlias;DocumentTagGroupID;DocumentStylesheetID;DocumentPublishFrom;DocumentPublishTo");
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #region "Create department tag group"

        // Get tag group info
        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID);

        // If not exist, create new tag group and set it to document
        if (tgi == null)
        {
            // Populate tag group info fields
            tgi = new TagGroupInfo();
            tgi.TagGroupDisplayName = editedNode.DocumentName;
            tgi.TagGroupName        = editedNode.NodeGUID.ToString();
            tgi.TagGroupDescription = "";
            tgi.TagGroupSiteID      = CMSContext.CurrentSiteID;
            tgi.TagGroupIsAdHoc     = false;

            // Store tag group info to DB
            TagGroupInfoProvider.SetTagGroupInfo(tgi);

            // Update document Tag group ID
            editedNode.DocumentTagGroupID = tgi.TagGroupID;
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #endregion

        if (!DataHelper.DataSourceIsEmpty(TemplateDocuments))
        {
            // List of selected documents
            string selectedDocs = ";" + Value + ";";

            // Get already created documents under edited document
            DataSet       dsExistingDocs = DocumentHelper.GetDocuments(CMSContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + TreeProvider.SELECTNODES_REQUIRED_COLUMNS, null);
            StringBuilder sbExistDocs    = new StringBuilder();

            // Process existing documents to obtain list of aliases
            foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows)
            {
                sbExistDocs.Append(";");
                sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLower());
            }
            sbExistDocs.Append(";");
            string existingDocs = sbExistDocs.ToString();

            // Set same ordering as for original template documents
            bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering;
            TreeProvider.UseAutomaticOrdering = false;

            // Process template documents
            foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows)
            {
                string nodeAlias     = drDoc["NodeAlias"].ToString().ToLower();
                string contNodeAlias = ";" + nodeAlias + ";";

                // Set marks
                bool existing = existingDocs.Contains(contNodeAlias);
                bool selected = selectedDocs.Contains(contNodeAlias);

                int      nodeId     = ValidationHelper.GetInteger(drDoc["NodeID"], 0);
                string   docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], "");
                TreeNode srcNode    = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider);

                // Check if section exists
                if (srcNode != null)
                {
                    // Copy or remove marked document sections
                    if (selected)
                    {
                        if (!existing)
                        {
                            CopyDocumentSection(srcNode, editedNode.NodeID, TreeProvider);
                        }
                    }
                    else
                    {
                        if (existing)
                        {
                            // Select node to delete
                            TreeNode delNode = TreeHelper.SelectSingleNode(editedNode.NodeAliasPath + "/" + nodeAlias);
                            if (delNode != null)
                            {
                                DeleteDocumentSection(delNode, TreeProvider);
                            }
                        }
                    }

                    // Process additional operations
                    if (selected && !existing)
                    {
                        switch (nodeAlias)
                        {
                        // Create department forum
                        case FORUM_DOCUMENT_ALIAS:
                            CreateDepartmentForumGroup(editedNode);
                            CreateDepartmentForumSearchIndex(editedNode);
                            break;

                        // Create media library
                        case MEDIA_DOCUMENT_ALIAS:
                            CreateDepartmentMediaLibrary(editedNode);
                            break;
                        }
                    }
                }
            }

            // Set previous ordering
            TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering;
        }
        mDocumentSaved = true;
    }
Example #15
0
    /// <summary>
    /// Creates tag group. Called when the "Create group" button is pressed.
    /// </summary>
    private bool CreateTagGroup()
    {
        // Create new tag group object
        TagGroupInfo newGroup = new TagGroupInfo();

        // Set the properties
        newGroup.TagGroupDisplayName = "My new group";
        newGroup.TagGroupName = "MyNewGroup";
        newGroup.TagGroupDescription = "";
        newGroup.TagGroupSiteID = CMSContext.CurrentSiteID;
        newGroup.TagGroupIsAdHoc = false;

        // Create the tag group
        TagGroupInfoProvider.SetTagGroupInfo(newGroup);

        return true;
    }
Example #16
0
    /// <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 = CMSContext.ResolveCurrentPath(aliasPath);

                // Prepare site name
                siteName = SiteName;
                if (String.IsNullOrEmpty(siteName))
                {
                    siteName = CMSContext.CurrentSiteName;
                }

                // Prepare culture code
                cultureCode = CultureCode;
                if (String.IsNullOrEmpty(cultureCode))
                {
                    cultureCode = CMSContext.PreferredCultureCode;
                }

                string renderedTags = null;

                // Try to get data from cache
                using (CachedSection<string> cs = new CachedSection<string>(ref renderedTags, this.CacheMinutes, true, this.CacheItemName, "tagcloud", TagGroupName, OrderBy, SelectTopN, DocumentListPath, 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 (!this.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);
                            }

                            // Base URL of the links
                            string url;
                            if (String.IsNullOrEmpty(DocumentListPath))
                            {
                                url = URLHelper.CurrentURL;
                            }
                            else
                            {
                                url = CMSContext.GetUrl(CMSContext.ResolveCurrentPath(DocumentListPath));
                            }
                            url = URLHelper.ResolveUrl(url);

                            // 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 behaviour
                    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>";
            }
        }
    }
    /// <summary>
    /// Process additional department tasks.
    /// </summary>
    public void ProcessDepartment(object sender, EventArgs e)
    {
        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Get department template source document
        TreeNode sourceNode = DocumentHelper.GetDocument(SiteContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, TreeProvider.ALL_LEVELS, false, null, TreeProvider);

        // Copy relevant template data to department document. Proceed only when creating a department, updating a department must not rewrite its data with template's data.
        if (Form.IsInsertMode && (sourceNode != null))
        {
            var excludeColumns = new []
            {
                "DocumentName",
                "NodeAlias",
                "DocumentTagGroupID",
                "DocumentStylesheetID",
                "DocumentPublishFrom",
                "DocumentPublishTo"
            };
            DocumentHelper.CopyNodeData(sourceNode, editedNode, new CopyNodeDataSettings(true, true, false, true, true, false, false, false, excludeColumns));
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }


        #region "Create department tag group"

        // Get tag group info
        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID);

        // If not exist, create new tag group and set it to document
        if (tgi == null)
        {
            // Populate tag group info fields
            tgi = new TagGroupInfo();
            tgi.TagGroupDisplayName = editedNode.GetDocumentName();
            tgi.TagGroupName        = editedNode.NodeGUID.ToString();
            tgi.TagGroupDescription = "";
            tgi.TagGroupSiteID      = SiteContext.CurrentSiteID;
            tgi.TagGroupIsAdHoc     = false;

            // Store tag group info to DB
            TagGroupInfoProvider.SetTagGroupInfo(tgi);

            // Update document Tag group ID
            editedNode.DocumentTagGroupID = tgi.TagGroupID;
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #endregion


        if (!DataHelper.DataSourceIsEmpty(TemplateDocuments))
        {
            // List of selected documents
            string selectedDocs = ";" + Value + ";";

            // Get already created documents under edited document
            DataSet       dsExistingDocs = DocumentHelper.GetDocuments(SiteContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS, null);
            StringBuilder sbExistDocs    = new StringBuilder();

            // Process existing documents to obtain list of aliases
            foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows)
            {
                sbExistDocs.Append(";");
                sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLowerCSafe());
            }
            sbExistDocs.Append(";");
            string existingDocs = sbExistDocs.ToString();

            // Set same ordering as for original template documents
            bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering;
            TreeProvider.UseAutomaticOrdering = false;

            // Process template documents
            foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows)
            {
                if (DocumentHelper.IsDocumentTypeAllowed(editedNode, ValidationHelper.GetInteger(drDoc["NodeClassID"], 0)))
                {
                    string nodeAlias     = drDoc["NodeAlias"].ToString().ToLowerCSafe();
                    string contNodeAlias = ";" + nodeAlias + ";";

                    // Set marks
                    bool existing = existingDocs.Contains(contNodeAlias);
                    bool selected = selectedDocs.Contains(contNodeAlias);

                    int      nodeId     = ValidationHelper.GetInteger(drDoc["NodeID"], 0);
                    string   docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], "");
                    TreeNode srcNode    = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider);

                    // Check if section exists
                    if (srcNode != null)
                    {
                        // Copy or remove marked document sections
                        if (selected)
                        {
                            if (!existing)
                            {
                                CopyDocumentSection(srcNode, editedNode, TreeProvider);
                            }
                        }
                        else
                        {
                            if (existing)
                            {
                                // Select node to delete
                                var aliasPath = editedNode.NodeAliasPath + "/" + nodeAlias;
                                var combineWithDefaultCulture = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCombineWithDefaultCulture");

                                TreeProvider tree    = new TreeProvider(MembershipContext.AuthenticatedUser);
                                TreeNode     delNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliasPath, LocalizationContext.PreferredCultureCode, combineWithDefaultCulture);

                                if (delNode != null)
                                {
                                    DeleteDocumentSection(delNode, TreeProvider);
                                }
                            }
                        }

                        // Process additional operations
                        if (selected && !existing)
                        {
                            switch (nodeAlias)
                            {
                            // Create department forum
                            case FORUM_DOCUMENT_ALIAS:
                                CreateDepartmentForumGroup(editedNode);
                                CreateDepartmentForumSearchIndex(editedNode);
                                break;

                            // Create media library
                            case MEDIA_DOCUMENT_ALIAS:
                                CreateDepartmentMediaLibrary(editedNode);
                                break;
                            }
                        }
                    }
                }
            }

            // Set previous ordering
            TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering;
        }
        mDocumentSaved = true;
    }
Example #18
0
    /// <summary>
    /// Deletes tag group. Called when the "Delete group" button is pressed.
    /// Expects the CreateTagGroup method to be run first.
    /// </summary>
    private bool DeleteTagGroup()
    {
        // Get the tag group
        string where = "TagGroupName LIKE 'MyNew%'";

        // Get the data
        DataSet groups = TagGroupInfoProvider.GetTagGroups(where, null);
        if (!DataHelper.DataSourceIsEmpty(groups))
        {
            // Loop through the individual items
            foreach (DataRow groupDr in groups.Tables[0].Rows)
            {
                // Create object from DataRow
                TagGroupInfo deleteGroup = new TagGroupInfo(groupDr);

                // Delete the tag group
                TagGroupInfoProvider.DeleteTagGroupInfo(deleteGroup);
            }

            return true;
        }

        return false;
    }