/// <summary> /// Returns true if document is in one/all of selected categories. /// </summary> /// <param name="document">Document to check</param> /// <param name="categories">Category names separated with a semicolon</param> /// <param name="all">If true, document must be in all of the selected categories.</param> public static bool IsInCategories(object document, string categories, bool allCategories) { TreeNode doc = document as TreeNode; if (doc != null) { if (!String.IsNullOrEmpty(categories)) { string[] categoryNames = categories.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Get categories selected by user string where = SqlHelperClass.GetWhereCondition("CategoryName", categoryNames); var categoryInfos = CategoryInfoProvider.GetDocumentCategories(doc.DocumentID, where, null, 0, null).Items; // Return true if all/any categories were found return(allCategories ? (categoryInfos.Count == categoryNames.Length) : (categoryInfos.Count > 0)); } // No categories were selected if (allCategories) { return(true); } } return(false); }
/// <summary> /// Initializes the current values /// </summary> public void InitCurrentValues() { if (string.IsNullOrEmpty(mCurrentValues) && (Node != null)) { // Prepare selected values DataSet ds = CategoryInfoProvider.GetDocumentCategories(Node.DocumentID, GetWhereCondition(), null, 0, "CMS_Category.CategoryID"); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "CategoryID")); } } }
/// <summary> /// Reloads control data /// </summary> public override void ReloadData(bool forceReload) { // Prepare selected values DataSet ds = CategoryInfoProvider.GetDocumentCategories(Node.DocumentID, GetWhereCondition(), null, 0, "CMS_Category.CategoryID"); if (!DataHelper.DataSourceIsEmpty(ds)) { selectCategory.Value = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "CategoryID")); } if (forceReload) { selectCategory.Reload(true); } }
/// <summary> /// Returns dataset with categories. /// </summary> protected DataSet GetDataSet() { DataSet ds = null; // Prepare user id int userId = 0; if ((MembershipContext.AuthenticatedUser != null) && (MembershipContext.AuthenticatedUser.UserID > 0)) { userId = MembershipContext.AuthenticatedUser.UserID; } // Try to get data from cache using (var cs = new CachedSection <DataSet>(ref ds, CacheMinutes, true, CacheItemName, "categorylist", SiteContext.CurrentSiteName, DisplayGlobalCategories, AllowGlobalCategories, DisplaySiteCategories, DisplayCustomCategories, userId, UseDocumentFilter, AliasPath, CultureCode, MaxRelativeLevel, CombineWithDefaultCulture, SelectOnlyPublished, WhereCondition, StartingCategory)) { if (cs.LoadData) { string where = GetCompleteWhereCondition(); if (mUseCompleteWhere) { ds = CategoryInfoProvider.GetDocumentCategories(where, OrderBy, SelectTopN); } else { ds = CategoryInfoProvider.GetCategories(where, OrderBy, SelectTopN); } // Save the result to the cache if (cs.Cached) { cs.CacheDependency = GetCacheDependency(); } cs.Data = ds; } } return(ds); }
protected void Page_Load(object sender, EventArgs e) { if (!this.StopProcessing) { // Propagate options selectCategory.IsLiveSite = this.IsLiveSite; selectCategory.Enabled = Enabled; selectCategory.GridName = "~/CMSModules/Categories/Controls/Categories.xml"; selectCategory.OnAdditionalDataBound += new CMSAdminControls_UI_UniSelector_UniSelector.AdditionalDataBoundEventHandler(selectCategory_OnAdditionalDataBound); selectCategory.UniGrid.OnAfterRetrieveData += new OnAfterRetrieveData(UniGrid_OnAfterRetrieveData); selectCategory.ItemsPerPage = 25; // Select appropriate dialog window if (this.IsLiveSite) { selectCategory.SelectItemPageUrl = "~/CMSModules/Categories/CMSPages/LiveCategorySelection.aspx"; } else { selectCategory.SelectItemPageUrl = "~/CMSModules/Categories/Dialogs/CategorySelection.aspx"; } // Prepare selected values DataSet ds = CategoryInfoProvider.GetDocumentCategories(DocumentID, null, null); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "CategoryID")); } if (!RequestHelper.IsPostBack()) { selectCategory.Value = mCurrentValues; } isSaved = QueryHelper.GetBoolean("saved", false); } }
protected void Page_Load(object sender, EventArgs e) { if (!StopProcessing) { // Propagate options selectCategory.IsLiveSite = IsLiveSite; selectCategory.GridName = "~/CMSModules/Categories/Controls/Categories.xml"; selectCategory.OnAdditionalDataBound += selectCategory_OnAdditionalDataBound; selectCategory.UniGrid.OnAfterRetrieveData += UniGrid_OnAfterRetrieveData; selectCategory.ItemsPerPage = 25; // Select appropriate dialog window if (IsLiveSite) { selectCategory.SelectItemPageUrl = "~/CMSModules/Categories/CMSPages/LiveCategorySelection.aspx"; } else { selectCategory.SelectItemPageUrl = "~/CMSModules/Categories/Dialogs/CategorySelection.aspx"; } // Prepare selected values DataSet ds = CategoryInfoProvider.GetDocumentCategories(DocumentID, GetWhereCondition(), null, 0, "CMS_Category.CategoryID"); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "CategoryID")); } if (!RequestHelper.IsPostBack()) { selectCategory.Value = mCurrentValues; } isSaved = QueryHelper.GetBoolean("saved", false); } }
/// <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; }