/// <summary> /// Get the document categories and applies the separator /// </summary> /// <param name="documentID"></param> /// <param name="separator"></param> /// <param name="contentBefore"></param> /// <param name="contentAfter"></param> /// <returns></returns> public string GetCategories(int documentID, string separator, string contentBefore, string contentAfter) { string categorieNames = ""; var documentCategories = DocumentCategoryInfoProvider.GetDocumentCategories(documentID) .Columns("CMS_Category.CategoryID, CategoryDisplayName"); if (documentCategories != null && documentCategories.Count > 0) { categorieNames = contentBefore; int i = 0; foreach (var cat in documentCategories) { if (i > 0) { categorieNames += separator; } categorieNames += cat.CategoryDisplayName; i++; } categorieNames += contentAfter; } return(categorieNames); }
/// <summary> /// Removes document from category. Called when the button "Remove document from category" is pressed. /// Expects the method AddDocumentToCategory to be run first. /// </summary> private bool RemoveDocumentFromCategory() { // Get the category CategoryInfo category = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", CMSContext.CurrentSiteName); if (category != null) { // Get the tree structure TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get the root document TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true); // Get the document category relationship DocumentCategoryInfo documentCategory = DocumentCategoryInfoProvider.GetDocumentCategoryInfo(root.DocumentID, category.CategoryID); if (documentCategory != null) { // Remove document from category DocumentCategoryInfoProvider.DeleteDocumentCategoryInfo(documentCategory); return(true); } } return(false); }
private IList <Guid> GetCategoryGuids(TreeNode node) { var siteId = SiteInfoProvider.GetSiteID(Settings.Sitename); var guids = DocumentCategoryInfoProvider.GetDocumentCategories(node.DocumentID) .OnSite(Settings.Sitename, true) .WhereNull("CategoryUserID") .TypedResult .Select(category => category.CategoryGUID) .ToList(); return(guids); }
/// <summary> /// Initializes the current values /// </summary> public void InitCurrentValues() { if (string.IsNullOrEmpty(mCurrentValues) && (Node != null)) { DataSet ds = DocumentCategoryInfoProvider.GetDocumentCategories(Node.DocumentID) .Column("CategoryID") .Where(GetWhereCondition()) .TypedResult; if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "CategoryID")); } } }
/// <summary> /// Adds document to category. Called when the button "Add document from category" is pressed. /// </summary> private bool AddDocumentToCategory() { // Get the category CategoryInfo category = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", CMSContext.CurrentSiteName); if (category != null) { // Get the tree structure TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get the root document TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true); // Add document to category DocumentCategoryInfoProvider.AddDocumentToCategory(root.DocumentID, category.CategoryID); return(true); } return(false); }
/// <summary> /// Reloads control data /// </summary> public override void ReloadData(bool forceReload) { if (Node == null) { return; } DataSet ds = DocumentCategoryInfoProvider.GetDocumentCategories(Node.DocumentID) .Column("CategoryID") .Where(GetWhereCondition()) .TypedResult; if (!DataHelper.DataSourceIsEmpty(ds)) { selectCategory.Value = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "CategoryID")); } if (forceReload) { selectCategory.Reload(true); } }
/// <summary> /// Saves the values. /// </summary> public void Save() { if (!RaiseOnCheckPermissions(CMSAdminControl.PERMISSION_MODIFY, this)) { CurrentUserInfo cui = CMSContext.CurrentUser; if ((cui == null) || ((this.UserID != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", CMSAdminControl.PERMISSION_MODIFY))) { RedirectToAccessDenied("CMS.Users", CMSAdminControl.PERMISSION_MODIFY); } } // Remove old items string newValues = ValidationHelper.GetString(selectCategory.Value, null); string items = DataHelper.GetNewItemsInList(newValues, mCurrentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); DocumentCategoryInfoProvider.RemoveDocumentFromCategory(this.mDocumentID, categoryId); } } } // Add new items items = DataHelper.GetNewItemsInList(mCurrentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); // Make sure, that category still exists if (CategoryInfoProvider.GetCategoryInfo(categoryId) != null) { DocumentCategoryInfoProvider.AddDocumentToCategory(this.mDocumentID, categoryId); } } } } // Raise on after save if (OnAfterSave != null) { OnAfterSave(); } if (!this.FormControlMode) { // Refresh page URLHelper.Redirect(URLHelper.AddParameterToUrl(URLHelper.CurrentURL, "saved", "1")); } isSaved = true; }
/// <summary> /// Takes the existing value and sets the Category Tree /// </summary> protected void setCategoryTree() { tvwCategoryTree.Nodes.Clear(); // Grab Current Categories CurrentCategories = new List <CategoryInfo>(); if (SaveModeVal == SaveType.ToJoinTable) { // Get initial categories from Join Table. if (!IsPostBack) { // Get the CategoryNames currently in the join table. int totalRecords = 0; var currentCategoriesDS = ConnectionHelper.ExecuteQuery(JoinTableName + ".selectall", null, string.Format("{0} = '{1}'", JoinTableLeftFieldName, CurrentItemIdentification), null, -1, null, -1, -1, ref totalRecords); string CategoryFieldName = ""; switch (FieldSaveModeVal) { case FieldSaveType.ID: CategoryFieldName = "CategoryID"; break; case FieldSaveType.GUID: CategoryFieldName = "CategoryGUID"; break; case FieldSaveType.CategoryName: CategoryFieldName = "CategoryName"; break; } List <string> currentCategories = new List <string>(); foreach (DataRow dr in currentCategoriesDS.Tables[0].Rows) { currentCategories.Add(ValidationHelper.GetString(dr[JoinTableRightFieldName], "")); } var CurrentCategoryObjects = CategoryInfoProvider.GetCategories(null, null, -1, null, SiteContext.CurrentSiteID).WhereIn(CategoryFieldName, currentCategories).Select(x => CategoryInfo.New(x)); if (CurrentCategoryObjects != null) { CurrentCategories.AddRange(CurrentCategoryObjects); } } } else { // Get initial categories from Document listing. if (!IsPostBack) { // Will set the txtValue to the current proper categories after the first setup. var CurrentCategoriesOfDoc = DocumentCategoryInfoProvider.GetDocumentCategories(ValidationHelper.GetInteger(PageDocument.GetValue("DocumentID"), -1)); if (CurrentCategoriesOfDoc != null) { CurrentCategories.AddRange(CurrentCategoriesOfDoc); } /* * // Handle default if new form and no categories * if (Form.Mode != FormModeEnum.Update && CurrentCategories.Count == 0 && !string.IsNullOrWhiteSpace(txtValue.Text)) * { * // Don't know if default is CodeName, Guid, or ID, so cover all * string[] DelimitedValues = SplitAndSecure(txtValue.Text); * string DefaultValueWhereCondition = ""; * int[] intArray = StringArrayToIntArray(DelimitedValues); * Guid[] guidArray = StringArrayToGuidArray(DelimitedValues); * DefaultValueWhereCondition = SqlHelper.AddWhereCondition(DefaultValueWhereCondition, string.Format("CategoryName in ('{0}')", string.Join("','", DelimitedValues)), "OR"); * if (intArray.Length > 0) * { * DefaultValueWhereCondition = SqlHelper.AddWhereCondition(DefaultValueWhereCondition, string.Format("CategoryID in ('{0}')", string.Join("','", intArray)), "OR"); * } * if (guidArray.Length > 0) * { * DefaultValueWhereCondition = SqlHelper.AddWhereCondition(DefaultValueWhereCondition, string.Format("CategoryGUID in ('{0}')", string.Join("','", guidArray)), "OR"); * } * foreach (CategoryInfo catInfo in CategoryInfo.Provider.Get().Where(DefaultValueWhereCondition)) * { * CurrentCategories.Add(catInfo); * } * }*/ } else { /* * var CurrentCategoriesOfDoc = CategoryInfoProvider.GetCategories("CategoryID in ('" + string.Join("','", SplitAndSecure(initialCategories)) + "')", null, -1, null, SiteContext.CurrentSiteID); * if (CurrentCategoriesOfDoc != null) * { * CurrentCategories.AddRange(CurrentCategoriesOfDoc); * } */ } } if (OnlyLeafSelectable) { if (ParentSelectsChildren) { tvwCategoryTree.ShowCheckBoxes = TreeNodeTypes.All; } else { tvwCategoryTree.ShowCheckBoxes = TreeNodeTypes.Leaf; } } else { tvwCategoryTree.ShowCheckBoxes = TreeNodeTypes.All; } // Root Category given, all items must be under that root // If Tree Structure, must go through all children of root and then compare to the "Where" List of items, if where is set // If List, display all valid categories under the root. int RootCategoryID = 0; var rootCategory = CategoryInfo.Provider.Get(RootCategory, SiteContext.CurrentSiteID); if (rootCategory == null && int.TryParse(RootCategory, out RootCategoryID)) { rootCategory = CategoryInfo.Provider.Get(RootCategoryID); } // Grab allowable Categories if user sets a WHERE string TempWhere = "CategoryNamePath like " + (rootCategory == null ? "'/%'" : "'" + rootCategory.CategoryNamePath + "/%'") + (string.IsNullOrWhiteSpace(WhereFilter) ? "" : " and " + WhereFilter); DefaultSortOrder = (string.IsNullOrWhiteSpace(OrderBy) ? (DisplayMode == DisplayType.List ? "CategoryDisplayName" : "CategoryLevel, CategoryOrder") : OrderBy); var AllowableCategoryList = CategoryInfoProvider.GetCategories(TempWhere, DefaultSortOrder, -1, null, SiteContext.CurrentSiteID); if (AllowableCategoryList.Count > 0) { AllowableCategoryIDWhere = "CategoryID in (" + string.Join(",", AllowableCategoryList.Select(x => new CategoryInfo(x).CategoryID)) + ")"; } else { AllowableCategoryIDWhere = ""; } if (DisplayMode == DisplayType.Tree) { pnlSearchFilter.Visible = false; tvwCategoryTree.ShowLines = true; TreeNode rootNode = null; if (rootCategory == null) { rootNode = new TreeNode("Root", GetNodeValue(rootCategory)); rootNode.ShowCheckBox = (OnlyLeafSelectable && ParentSelectsChildren); rootNode.SelectAction = TreeNodeSelectAction.None; // Expand to the nth level from the Category Level. ExpandCategoryLevel = 0 + ExpandToLevel; rootNode.Expanded = (0 < ExpandCategoryLevel); SetNodeChecked(rootNode, rootCategory); } else { rootNode = new TreeNode(GetInputDataPrepend(rootCategory), GetNodeValue(rootCategory)); rootNode.SelectAction = TreeNodeSelectAction.None; // Expand to the nth level from the Category Level. ExpandCategoryLevel = rootCategory.CategoryLevel + ExpandToLevel; rootNode.Expanded = (rootCategory.CategoryLevel < ExpandCategoryLevel); SetNodeChecked(rootNode, rootCategory); // If either all items selectable, or if only leaf selectable and this is a leaf node, save to the possible categories list. if (rootCategory.Children.Count == 0 || !OnlyLeafSelectable) { PossibleCategories.Add(rootCategory); } } CreateChildTreeNodes(rootCategory, ref rootNode, ref CurrentCategories); tvwCategoryTree.Nodes.Add(rootNode); } else if (DisplayMode == DisplayType.List) { pnlTreeButtons.Visible = false; // Just loop through allowable Categories and add to list. foreach (CategoryInfo CategoryItem in AllowableCategoryList) { TreeNode childNode = new TreeNode(GetInputDataPrepend(CategoryItem), GetNodeValue(CategoryItem)); childNode.SelectAction = TreeNodeSelectAction.None; childNode.Expanded = (CategoryItem.CategoryLevel < ExpandCategoryLevel); SetNodeChecked(childNode, CategoryItem); PossibleCategories.Add(CategoryItem); tvwCategoryTree.Nodes.Add(childNode); } } }
/// <summary> /// Handles the logic of assigning categories to the document. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveToDocumentCategories() { SetPossibleAndSelectedCategories(); // Do check of min/max here // Do check of min/max here if (MinimumCategories > 0 && SelectedCategories.Count() < MinimumCategories) { AddError("Must select at least " + MinimumCategories + " " + (MinimumCategories == 1 ? "category" : "categories")); return; } if (MaximumCategories > 0 && SelectedCategories.Count() > MaximumCategories) { AddError("Can select no more than " + MaximumCategories + " " + (MaximumCategories == 1 ? "category" : "categories")); return; } int DocumentID = ValidationHelper.GetInteger(PageDocument.GetValue("DocumentID"), -1); // Can only do Document/Category if there is a DocumentID on the current object. if (DocumentID > 0) { // Get selected categories, except only those in the possible categories List <int> DocumentCategoryIds = new List <int>(); foreach (var DocCategory in DocumentCategoryInfoProvider.GetDocumentCategories(DocumentID)) { DocumentCategoryIds.Add(DocCategory.CategoryID); } // Find IDs we need to add and remove. List <int> NotSelectedIds = PossibleCategoryIDs.Except(SelectedCategoryIDs).ToList(); List <int> DeselectIds = DocumentCategoryIds.Intersect(NotSelectedIds).ToList(); List <int> SelectIds = SelectedCategoryIDs.Except(DocumentCategoryIds).ToList(); bool CategoriesChanged = false; foreach (int DeselectId in DeselectIds) { DocumentCategoryInfo.Provider.Remove(DocumentID, DeselectId); CategoriesChanged = true; } foreach (int SelectId in SelectIds) { DocumentCategoryInfo.Provider.Add(DocumentID, SelectId); CategoriesChanged = true; } // Page changes require custom logic for staging if (CategoriesChanged && LicenseHelper.CheckFeature(Request.Url.AbsoluteUri, FeatureEnum.Staging)) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); List <ServerInfo> targetServers = ServerInfo.Provider.Get().Where(x => x.ServerSiteID == SiteContext.CurrentSiteID && x.ServerEnabled).ToList(); foreach (ServerInfo targetServer in targetServers) { var docObj = DocumentHelper.GetDocument(DocumentID, tree); var settings = new LogMultipleDocumentChangeSettings() { EnsurePublishTask = true, NodeAliasPath = docObj.NodeAliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = targetServer.ServerID, KeepTaskData = false, RunAsynchronously = false, SiteName = docObj.Site.SiteName }; // Logs parent task, which will run through the task on insert event and do the same check. var currentNodeUpdateTask = DocumentSynchronizationHelper.LogDocumentChange(settings); } } AddConfirmation(string.Format("{0} Categories Added, {1} Categories Removed.", SelectIds.Count, DeselectIds.Count)); } }
/// <summary> /// Saves the values. /// </summary> public void Save() { if (Node == null) { return; } if (!RaiseOnCheckPermissions(PERMISSION_MODIFY, this)) { var cui = MembershipContext.AuthenticatedUser; if ((cui == null) || ((UserID != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", PERMISSION_MODIFY))) { RedirectToAccessDenied("CMS.Users", PERMISSION_MODIFY); } } // Prepare selected values InitCurrentValues(); bool logUpdateTask = false; // Remove old items string newValues = ValidationHelper.GetString(selectCategory.Value, null); string items = DataHelper.GetNewItemsInList(newValues, mCurrentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); DocumentCategoryInfoProvider.RemoveDocumentFromCategory(Node.DocumentID, categoryId); } logUpdateTask = true; } // Add new items items = DataHelper.GetNewItemsInList(mCurrentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); // Make sure, that category still exists if (CategoryInfoProvider.GetCategoryInfo(categoryId) != null) { DocumentCategoryInfoProvider.AddDocumentToCategory(Node.DocumentID, categoryId); } } // Find all categories which child categories are bound to edited document DataSet catsToRemove = CategoryInfoProvider.GetDocumentCategories(Node.DocumentID, "EXISTS (SELECT CategoryID FROM CMS_Category AS CC WHERE CC.CategoryIDPath LIKE CMS_Category.CategoryIDPath + '/%' AND CC.CategoryID IN (SELECT CategoryID FROM CMS_DocumentCategory WHERE DocumentID = " + Node.DocumentID + "))", null, 0, "CMS_Category.CategoryID AS ID"); if (!DataHelper.DataSourceIsEmpty(catsToRemove)) { foreach (DataRow dr in catsToRemove.Tables[0].Rows) { // Remove categories covered by their children from document DocumentCategoryInfoProvider.RemoveDocumentFromCategory(Node.DocumentID, ValidationHelper.GetInteger(dr["ID"], 0)); } } logUpdateTask = true; } // Raise on after save if (OnAfterSave != null) { OnAfterSave(); } if (logUpdateTask) { // Log the synchronization if category bindings were changed DocumentSynchronizationHelper.LogDocumentChange(Node.NodeSiteName, Node.NodeAliasPath, TaskTypeEnum.UpdateDocument, DocumentManager.Tree); } isSaved = true; // Clear content changed flag, changes are saved directly DocumentManager.ClearContentChanged(); }
/// <summary> /// Saves the values. /// </summary> public void Save() { if (!RaiseOnCheckPermissions(PERMISSION_MODIFY, this)) { CurrentUserInfo cui = CMSContext.CurrentUser; if ((cui == null) || ((UserID != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", PERMISSION_MODIFY))) { RedirectToAccessDenied("CMS.Users", PERMISSION_MODIFY); } } // Remove old items string newValues = ValidationHelper.GetString(selectCategory.Value, null); string items = DataHelper.GetNewItemsInList(newValues, mCurrentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); DocumentCategoryInfoProvider.RemoveDocumentFromCategory(mDocumentID, categoryId); } } } // Add new items items = DataHelper.GetNewItemsInList(mCurrentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to user foreach (string item in newItems) { int categoryId = ValidationHelper.GetInteger(item, 0); // Make sure, that category still exists if (CategoryInfoProvider.GetCategoryInfo(categoryId) != null) { DocumentCategoryInfoProvider.AddDocumentToCategory(mDocumentID, categoryId); } } // Find all categories which child categories are bound to edited document DataSet catsToRemove = CategoryInfoProvider.GetDocumentCategories(mDocumentID, "EXISTS (SELECT CategoryID FROM CMS_Category AS CC WHERE CC.CategoryIDPath LIKE CMS_Category.CategoryIDPath + '/%' AND CC.CategoryID IN (SELECT CategoryID FROM CMS_DocumentCategory WHERE DocumentID = " + mDocumentID + "))", null, 0, "CMS_Category.CategoryID AS ID"); if (!DataHelper.DataSourceIsEmpty(catsToRemove)) { foreach (DataRow dr in catsToRemove.Tables[0].Rows) { // Remove categories covered by their children from document DocumentCategoryInfoProvider.RemoveDocumentFromCategory(mDocumentID, ValidationHelper.GetInteger(dr["ID"], 0)); } // Prepare selected values selectCategory.Value = ""; DataSet ds = CategoryInfoProvider.GetDocumentCategories(DocumentID, GetWhereCondition(), null, 0, "CMS_Category.CategoryID"); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "CategoryID")); selectCategory.Value = mCurrentValues; selectCategory.Reload(true); } } } } // Raise on after save if (OnAfterSave != null) { OnAfterSave(); } isSaved = true; }