private void SetSelectedCategory()
    {
        string value = hidItem.Value;

        if (string.IsNullOrEmpty(value))
        {
            return;
        }

        string[] values = value.Split(new[] { ValuesSeparator }, StringSplitOptions.RemoveEmptyEntries);
        if (values.Length != 1)
        {
            return;
        }

        int catId;

        if (returnColumnName == "CategoryID")
        {
            catId = ValidationHelper.GetInteger(values[0], 0);
        }
        else
        {
            CategoryInfo cat = CategoryInfoProvider.GetCategoryInfo(values[0], SiteContext.CurrentSiteName);
            catId = (cat != null) ? cat.CategoryID : 0;
        }

        if (catId > 0)
        {
            // Select category
            SelectedCategoryID = catId;
        }
    }
        // GET: Polygomy
        public ActionResult Index()
        {
            Polygomy Page = DynamicRouteHelper.GetPage <Polygomy>();

            HttpContext.Kentico().PageBuilder().Initialize(Page.DocumentID);
            // Get Categories
            List <int> PageCategories = TreeCategoryInfoProvider.GetTreeCategories()
                                        .WhereEquals("NodeID", Page.NodeID)
                                        .Select(x => x.CategoryID).ToList();

            PolygomyViewModel model = new PolygomyViewModel()
            {
                MemeCategories = CategoryInfoProvider.GetCategories()
                                 .WhereIn("CategoryID", PageCategories)
                                 .Select(x => x.CategoryDisplayName).ToArray(),
            };

            if (PageCategories.Count > 0)
            {
                model.Memes = MemeProvider.GetMemes()
                              .Where(RelHelper.GetNodeCategoryWhere(PageCategories.Select(x => (object)x)))
                              .ToList();
            }
            return(View("NEWCC/Polygomy", model));
        }
Esempio n. 3
0
    /// <summary>
    /// Creates subcategory. Called when the "Create subcategory" button is pressed.
    /// </summary>
    private bool CreateSubcategory()
    {
        // Get the parent category
        CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", SiteContext.CurrentSiteName);

        if (parentCategory != null)
        {
            // Create new category object
            CategoryInfo newSubcategory = new CategoryInfo();

            // Set the properties
            newSubcategory.CategoryDisplayName = "My new subcategory";
            newSubcategory.CategoryName        = "MyNewSubcategory";
            newSubcategory.CategoryDescription = "My new subcategory description";
            newSubcategory.CategorySiteID      = SiteContext.CurrentSiteID;
            newSubcategory.CategoryCount       = 0;
            newSubcategory.CategoryEnabled     = true;
            newSubcategory.CategoryParentID    = parentCategory.CategoryID;

            // Save the category
            CategoryInfoProvider.SetCategoryInfo(newSubcategory);

            return(true);
        }

        return(false);
    }
Esempio n. 4
0
    /// <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>
    /// Handles request for deleting category.
    /// </summary>
    public void Delete()
    {
        CategoryInfo categoryObj = SelectedCategory;

        if ((categoryObj != null) && CanModifySelectedCategory)
        {
            // Remove deleted category from selection
            if (!string.IsNullOrEmpty(hidItem.Value))
            {
                hidItem.Value = hidItem.Value.Replace(ValuesSeparator + categoryObj.CategoryID + ValuesSeparator, ValuesSeparator);
                hidHash.Value = ValidationHelper.GetHashString(hidItem.Value, new HashSettings(mSecurityPurpose));
                pnlHidden.Update();
            }

            // Preselect parent category
            CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;
                PreselectCategory(parentCategory, true);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = categoryObj.CategoryIsPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
            }

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            pnlUpdateTrees.Update();
        }
    }
    /// <summary>
    /// Handles request for deleting category.
    /// </summary>
    /// <param name="sender">Sender object.</param>
    /// <param name="e">Arguments.</param>
    public void lnkDelete_Click(object sender, EventArgs e)
    {
        CategoryInfo categoryObj = SelectedCategory;

        if ((categoryObj != null) && CanModifySelectedCategory)
        {
            // Remove deleted category from selection
            if (!string.IsNullOrEmpty(hidItem.Value))
            {
                hidItem.Value = hidItem.Value.Replace(valuesSeparator + categoryObj.CategoryID + valuesSeparator, valuesSeparator);
                pnlHidden.Update();
            }

            // Preselect parent category
            CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;
                PreselectCategory(parentCategory, true);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = categoryObj.CategoryIsPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
            }

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            pnlUpdateTrees.Update();
        }
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // Init trees handlers
        treeElemG.OnGetImage    += treeElem_OnGetImage;
        treeElemP.OnGetImage    += treeElem_OnGetImage;
        treeElemG.OnNodeCreated += treeElem_OnNodeCreated;
        treeElemP.OnNodeCreated += treeElem_OnNodeCreated;

        // Load parameters
        LoadParameters();

        // Stop personal category tree when disabled
        if (!string.IsNullOrEmpty(disabledItems))
        {
            if (disabledItems.ToLower().Contains("personal"))
            {
                treeElemP.StopProcessing = true;
            }
            if (disabledItems.ToLower().Contains("globalandsite"))
            {
                treeElemG.StopProcessing = true;
            }
        }

        // Get and store permissions
        canModifyGlobal = AllowGlobalCategories && CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", "GlobalModify");
        canModifySite   = CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", "Modify");

        // Expand and preselect selected category when in single select mode
        if (!RequestHelper.IsPostBack() && !allowMultiple)
        {
            string value = hidItem.Value;
            if (!string.IsNullOrEmpty(value))
            {
                string[] values = value.Split(new string[] { valuesSeparator }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 1)
                {
                    int catId = 0;

                    if (returnColumnName == "CategoryID")
                    {
                        catId = ValidationHelper.GetInteger(values[0], 0);
                    }
                    else
                    {
                        CategoryInfo cat = CategoryInfoProvider.GetCategoryInfo(values[0], CMSContext.CurrentSiteName);
                        catId = (cat != null) ? cat.CategoryID : 0;
                    }

                    if (catId > 0)
                    {
                        // Select category
                        SelectedCategoryID = catId;
                    }
                }
            }
        }
    }
Esempio n. 8
0
    /// <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);
    }
Esempio n. 9
0
    private void DeleteCategory(CategoryInfo categoryObj, bool reload = false)
    {
        // Check if category
        if ((categoryObj != null) && CanModifyCategory(categoryObj.CategoryIsPersonal, categoryObj.CategoryIsGlobal))
        {
            var parentCategory = CategoryInfoProvider.GetCategoryInfo(categoryObj.CategoryParentID);
            var isPersonal     = categoryObj.CategoryIsPersonal;

            // Delete category
            CategoryInfoProvider.DeleteCategoryInfo(categoryObj);

            // Check if deleted category has parent
            if (parentCategory != null)
            {
                SelectedCategoryID = parentCategory.CategoryID;

                // Switch to editing of parent category
                catEdit.UserID   = parentCategory.CategoryUserID;
                catEdit.Category = parentCategory;

                SwitchToEdit(reload);
                PreselectCategory(parentCategory, false);
            }
            else
            {
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = isPersonal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
                SwitchToInfo();
            }

            pnlUpdateTree.Update();
            pnlUpdateContent.Update();
        }
    }
        public ActionResult IndexReversed()
        {
            // Get "Banner1"
            var Banner1 = PageRetriever.Retrieve <Banner>(applyQueryParametersAction: query =>
                                                          query.Path("/Banners/Banner-1")
                                                          ).FirstOrDefault();

            // Get Items to look up on
            int        MobileCategoryID = CategoryInfoProvider.Get("Mobile", 0).CategoryID;
            List <int> WesternUSOrEasternUSCategoryIDs = CategoryInfoProvider.Get()
                                                         .WhereIn(nameof(CategoryInfo.CategoryName), new string[] { "RegionWestUSA", "RegionEasternUSA" })
                                                         .Select(x => x.CategoryID).ToList();
            int FooAID         = FooInfoProvider.Get("FooA").FooID;
            int BazAID         = BazInfoProvider.Get("BazA").BazID;
            int BarAID         = BarInfoProvider.Get("BarA").BarID;
            int BlahCategoryID = CategoryInfoProvider.Get("BlahCategory", 0).CategoryID;

            TestReverseViewModel model = new TestReverseViewModel();

            // Get Test pages related to banner 1
            model.Banner1Pages = PageRetriever.Retrieve <Testing>(query =>
                                                                  query.InRelationWithOrder(Banner1.NodeID, "Banners", ReverseRelationship: true)
                                                                  ).ToList();

            model.MobilePages = PageRetriever.Retrieve <Testing>(query =>
                                                                 query.TreeCategoryCondition(new object[] { MobileCategoryID })
                                                                 )
                                .ToList();

            model.WesternUSOrEasternUSPages = PageRetriever.Retrieve <Testing>(query =>
                                                                               query.BindingCategoryCondition <Testing, NodeRegionInfo>(BindingConditionType.FilterParentsByChildren, WesternUSOrEasternUSCategoryIDs.Cast <object>())
                                                                               )
                                              .ToList();

            model.FooAPages = PageRetriever.Retrieve <Testing>(query =>
                                                               query.BindingCondition <Testing, NodeFooInfo>(BindingConditionType.FilterParentsByChildren, new object[] { FooAID })
                                                               )
                              .ToList();

            model.BazAPages = PageRetriever.Retrieve <Testing>(query =>
                                                               query.BindingCondition <Testing, NodeBazInfo>(BindingConditionType.FilterParentsByChildren, new object[] { BazAID })
                                                               )
                              .ToList();

            model.BarAFoos = FooInfoProvider.Get()
                             .BindingCondition <FooInfo, FooBarInfo>(BindingConditionType.FilterParentsByChildren, new object[] { BarAID })
                             .ToList();


            model.BazAFoos = FooInfoProvider.Get()
                             .BindingCondition <FooInfo, FooBazInfo>(BindingConditionType.FilterParentsByChildren, new object[] { BarAID })
                             .ToList();

            model.BlahCategoryFoos = FooInfoProvider.Get()
                                     .BindingCategoryCondition <FooInfo, FooCategoryInfo>(BindingConditionType.FilterParentsByChildren, new object[] { BlahCategoryID })
                                     .ToList();


            return(View("IndexReversed", model));
        }
        private async Task CreateCategoriesTaxonomy()
        {
            try
            {
                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "CREATECATEGORIESTAXONOMY");

                var categories = CategoryInfoProvider.GetCategories()
                                 .OnSite(Settings.Sitename, true)
                                 .WhereNull("CategoryUserID")
                                 // Global first
                                 .OrderBy("CategorySiteID", "CategoryOrder")
                                 .TypedResult;

                var externalId = GetTaxonomyExternalId(CATEGORIES_GUID);
                var endpoint   = $"/taxonomies";

                var payload = new
                {
                    name        = "Categories",
                    codename    = CATEGORIES.ToLower(),
                    external_id = externalId,
                    terms       = GetCategoryTerms(categories),
                };

                await ExecuteWithoutResponse(endpoint, HttpMethod.Post, payload);
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "CREATECATEGORIESTAXONOMY", ex);
                throw;
            }
        }
Esempio n. 12
0
    /// <summary>
    /// Gets and bulk updates categories. Called when the "Get and bulk update categories" button is pressed.
    /// Expects the CreateCategory method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCategories()
    {
        // Prepare the parameters
        string where = "CategoryName LIKE N'MyNewCategory%'";

        // Get the data
        DataSet categories = CategoryInfoProvider.GetCategories(where, null);

        if (!DataHelper.DataSourceIsEmpty(categories))
        {
            // Loop through the individual items
            foreach (DataRow categoryDr in categories.Tables[0].Rows)
            {
                // Create object from DataRow
                CategoryInfo modifyCategory = new CategoryInfo(categoryDr);

                // Update the properties
                modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();

                // Save the changes
                CategoryInfoProvider.SetCategoryInfo(modifyCategory);
            }

            return(true);
        }

        return(false);
    }
Esempio n. 13
0
    /// <summary>
    /// Returns true if given codename is unique, otherwise false.
    /// </summary>
    /// <param name="newCodeName">Code name of the category.</param>
    /// <param name="isPersonal">Indicates if category is personal.</param>
    /// <param name="isGlobal">Indicates if category is global.</param>
    private bool CodeNameIsUnique(string newCodeName, bool isPersonal, bool isGlobal)
    {
        string where = "CategoryName = N'" + SqlHelperClass.GetSafeQueryString(newCodeName, false) + "'";

        // Check if site category
        if (!isPersonal && !isGlobal)
        {
            // Look for category in global, personal and selected site categories
            where = SqlHelperClass.AddWhereCondition(where, "CategorySiteID = " + SiteID + " OR CategorySiteID IS NULL");
        }

        // Get existing category
        DataSet ds = CategoryInfoProvider.GetCategories(where, "CategoryID", 1, "CategoryID");

        if (SqlHelperClass.DataSourceIsEmpty(ds))
        {
            return(true);
        }
        else
        {
            int id = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["CategoryID"], 0);

            // If the existing category is updated the code name already exists
            return((id > 0) && (this.CategoryID == id));
        }
    }
        protected IEnumerable <String> GetCategories(String parentName)
        {
            CategoryInfo info     = CategoryInfoProvider.GetCategoryInfo(parentName, CMSContext.CurrentSite.SiteName);
            var          children = CategoryInfoProvider.GetChildCategories(info.CategoryID, null, null, -1, null, CMSContext.CurrentSite.SiteID);

            children.AsEnumerable().ToArray();
        }
        public ActionResult IndexSimplified()
        {
            // Get current page
            var CurrentTestPage = DataRetriever.Retrieve <Testing>().Page;

            TestViewModel model = new TestViewModel();

            model.Banners = PageRetriever.Retrieve <Banner>(query =>
                                                            query.InRelationWithOrder(CurrentTestPage.NodeID, "Banners")
                                                            ).ToList();

            model.Categories = CategoryInfoProvider.Get()
                               .BindingCondition <CategoryInfo, TreeCategoryInfo>(BindingConditionType.FilterChildrenByParents, new object[] { CurrentTestPage.NodeID })
                               .ToList();

            model.Regions = CategoryInfoProvider.Get()
                            .InCustomRelationshipWithOrder <CategoryInfo, NodeRegionInfo>(BindingQueryType.GetChildrenByParent, CurrentTestPage.NodeID)
                            .ToList();

            model.Foos = FooInfoProvider.Get()
                         .InCustomRelationshipWithOrder <FooInfo, NodeFooInfo>(BindingQueryType.GetChildrenByParentOrdered, CurrentTestPage.NodeID)
                         .ToList();

            model.Bazs = BazInfoProvider.Get()
                         .InCustomRelationshipWithOrder <BazInfo, NodeBazInfo>(BindingQueryType.GetChildrenByParent, CurrentTestPage.NodeID)
                         .ToList();

            // Get Foo Bars
            foreach (var Foo in model.Foos)
            {
                model.FooBars.Add(Foo.FooID,
                                  BarInfoProvider.Get()
                                  .InCustomRelationshipWithOrder <BarInfo, FooBarInfo>(BindingQueryType.GetChildrenByParentOrdered, Foo.FooID)
                                  .ToList()
                                  );
            }

            // Get Foo Baz
            foreach (var Foo in model.Foos)
            {
                model.FooBazs.Add(Foo.FooID,
                                  BazInfoProvider.Get()
                                  .InCustomRelationshipWithOrder <BazInfo, FooBazInfo>(BindingQueryType.GetChildrenByParent, Foo.FooID)
                                  .ToList()
                                  );
            }

            // Get Foo Categories
            foreach (var Foo in model.Foos)
            {
                model.FooCategories.Add(Foo.FooID,
                                        CategoryInfoProvider.Get()
                                        .InCustomRelationshipWithOrder <CategoryInfo, FooCategoryInfo>(BindingQueryType.GetChildrenByParentOrdered, Foo.FooID)
                                        .ToList()
                                        );
            }

            return(View("Index", model));
        }
    /// <summary>
    /// Handles actions risen from javascript.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void hdnButton_Click(object sender, EventArgs e)
    {
        string param = hidParam.Value;

        // Check if action was saving of existing category
        if (param.StartsWith("edit"))
        {
            // Check if category was disabled during editing
            if ((SelectedCategory != null) && !SelectedCategory.CategoryEnabled)
            {
                // Select coresponding root element
                bool personal = SelectedCategory.CategoryIsPersonal;
                SelectedCategoryID       = 0;
                SelectedCategoryParentID = personal ? PERSONAL_CATEGORIES_ROOT_PARENT_ID : CATEGORIES_ROOT_PARENT_ID;
            }

            pnlUpdateTrees.Update();
        }
        // Check if action was creation of new category
        else if (param.StartsWith("new"))
        {
            string[] splits = param.Split('|');
            if (splits.Length == 2)
            {
                int id = ValidationHelper.GetInteger(splits[1], 0);
                if (id > 0)
                {
                    // Select created category
                    CategoryInfo category = CategoryInfoProvider.GetCategoryInfo(id);
                    if (category != null)
                    {
                        SelectedCategoryID = category.CategoryID;
                        PreselectCategory(category, false);

                        if (!allowMultiple)
                        {
                            if (returnColumnName == "CategoryID")
                            {
                                hidItem.Value = valuesSeparator + id + valuesSeparator;
                            }
                            else
                            {
                                hidItem.Value = valuesSeparator + ScriptHelper.GetString(category.CategoryName, false) + valuesSeparator;
                            }
                            pnlHidden.Update();
                        }
                    }
                }
            }

            pnlUpdateTrees.Update();
        }

        // Remove parameter
        hidParam.Value = "";
    }
Esempio n. 17
0
    /// <summary>
    /// Deletes category. Called when the "Delete category" button is pressed.
    /// Expects the CreateCategory method to be run first.
    /// </summary>
    private bool DeleteCategory()
    {
        // Get the category
        CategoryInfo deleteCategory = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", CMSContext.CurrentSiteName);

        // Delete the category
        CategoryInfoProvider.DeleteCategoryInfo(deleteCategory);

        return(deleteCategory != null);
    }
Esempio n. 18
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        // Init trees handlers
        treeElemG.OnGetImage    += treeElem_OnGetImage;
        treeElemP.OnGetImage    += treeElem_OnGetImage;
        treeElemG.OnNodeCreated += treeElem_OnNodeCreated;
        treeElemP.OnNodeCreated += treeElem_OnNodeCreated;

        // Set enabled state of actions before rendering actions
        Page.PreRender += (sender, args) =>
        {
            HandleEnabledActions();
        };

        // Load parameters
        LoadParameters();

        StopDisabledTrees();

        // Get and store permissions
        canModifyGlobal = AllowGlobalCategories && CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", "GlobalModify");
        canModifySite   = CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", "Modify");

        // Expand and preselect selected category when in single select mode
        if (!RequestHelper.IsPostBack() && !AllowMultipleSelection)
        {
            string value = hidItem.Value;
            if (!string.IsNullOrEmpty(value))
            {
                string[] values = value.Split(new string[] { ValuesSeparator }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 1)
                {
                    int catId = 0;

                    if (returnColumnName == "CategoryID")
                    {
                        catId = ValidationHelper.GetInteger(values[0], 0);
                    }
                    else
                    {
                        CategoryInfo cat = CategoryInfoProvider.GetCategoryInfo(values[0], CMSContext.CurrentSiteName);
                        catId = (cat != null) ? cat.CategoryID : 0;
                    }

                    if (catId > 0)
                    {
                        // Select category
                        SelectedCategoryID = catId;
                    }
                }
            }
        }
    }
Esempio n. 19
0
    /// <summary>
    /// Creates HTML code for category link.
    /// </summary>
    /// <param name="categoryId">ID of the category to create link for.</param>
    protected string CreateCategoryPartLink(int categoryId)
    {
        CategoryInfo cat = CategoryInfoProvider.GetCategoryInfo(categoryId);

        if (cat != null)
        {
            return(CreateCategoryPartLink(cat));
        }

        return("");
    }
    /// <summary>
    /// Handles Move category down button click.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Arguments</param>
    protected void btnDownElem_Click(object sender, EventArgs e)
    {
        var category = SelectedCategory;

        if (category != null && CanModifyOrder(category))
        {
            CategoryInfoProvider.MoveCategoryDown(category.CategoryID);
        }

        pnlUpdateTree.Update();
    }
Esempio n. 21
0
    /// <summary>
    /// Handles Move category down button click.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Arguments</param>
    protected void btnDownElem_Click(object sender, EventArgs e)
    {
        int catId = SelectedCategoryID;

        if (catId > 0)
        {
            CategoryInfoProvider.MoveCategoryDown(catId);
        }

        pnlUpdateTree.Update();
    }
    /// <summary>
    /// Handles request for moving category down.
    /// </summary>
    /// <param name="sender">Sender object.</param>
    /// <param name="e">Arguments.</param>
    public void lnkDown_Click(object sender, EventArgs e)
    {
        // Move selected category down
        int catId = SelectedCategoryID;

        if ((catId > 0) && CanModifySelectedCategory)
        {
            CategoryInfoProvider.MoveCategoryDown(catId);
        }

        pnlUpdateTrees.Update();
    }
 /// <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"));
         }
     }
 }
Esempio n. 24
0
    /// <summary>
    /// Handles request for moving category down.
    /// </summary>
    public void Down()
    {
        // Move selected category down
        int catId = SelectedCategoryID;

        if ((catId > 0) && CanModifySelectedCategory)
        {
            CategoryInfoProvider.MoveCategoryDown(catId);
        }

        pnlUpdateTrees.Update();
    }
    /// <summary>
    /// Handles Move category up button click.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Arguments</param>
    protected void btnUpElem_Click(object sender, EventArgs e)
    {
        int catId = SelectedCategoryID;

        if (catId > 0)
        {
            CategoryInfoProvider.MoveCategoryUp(catId);
        }

        gridSubCategories.ReloadData();

        pnlUpdateTree.Update();
    }
Esempio n. 26
0
    /// <summary>
    /// Builds category tree from given dataset and returns root node object.
    /// </summary>
    /// <param name="data">Dataset containing categories to be organized as tree.</param>
    private void CreateCategoryTrees(DataSet data)
    {
        generalRoot  = new CategoryNode(CategoriesRoot);
        personalRoot = new CategoryNode(PersonalCategoriesRoot);

        if (!DataHelper.DataSourceIsEmpty(data))
        {
            // Handle custom starting category
            string prefixToRemove = "";
            if (!string.IsNullOrEmpty(StartingCategory) && (StartingCategoryObj != null))
            {
                prefixToRemove = StartingCategoryObj.CategoryIDPath;
            }

            foreach (DataRow dr in data.Tables[0].Rows)
            {
                // Get processed category path
                string idPath = dr["CategoryIDPath"].ToString();

                // Shorten ID path when starting category entered
                if (!string.IsNullOrEmpty(prefixToRemove))
                {
                    idPath = idPath.Replace(prefixToRemove, "");
                }

                // Split path
                string[] idSplits = idPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                int[]    ids      = ValidationHelper.GetIntegers(idSplits, -1);

                // Add categories from path to tree
                foreach (int id in ids)
                {
                    CategoryInfo category = CategoryInfoProvider.GetCategoryInfo(id);

                    if (category != null)
                    {
                        if (category.CategoryIsPersonal)
                        {
                            personalRoot.AddCategory(category);
                        }
                        else
                        {
                            generalRoot.AddCategory(category);
                        }
                    }
                }
            }
        }
    }
 private void SetPossibleAndSelectedCategories()
 {
     PossibleCategories  = new List <CategoryInfo>();
     PossibleCategoryIDs = new List <int>();
     SelectedCategories  = new List <CategoryInfo>();
     SelectedCategoryIDs = new List <int>();
     // navigate through the tree structure
     foreach (TreeNode node in tvwCategoryTree.Nodes)
     {
         SetPossibleAndSelectedCategoriesTreeRecursive(node);
     }
     // Get allowed category IDs and those found
     PossibleCategories = CategoryInfoProvider.GetCategories().WhereIn("CategoryID", PossibleCategoryIDs).TypedResult.ToList();
     SelectedCategories = CategoryInfoProvider.GetCategories().WhereIn("CategoryID", SelectedCategoryIDs).TypedResult.ToList();
 }
Esempio n. 28
0
    /// <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);
        }
    }
Esempio n. 29
0
    /// <summary>
    /// Handles sub categories grid actions.
    /// </summary>
    /// <param name="actionName">Action name</param>
    /// <param name="actionArgument">Parameter</param>
    protected void gridSubCategories_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        case "delete":
            int categoryId = ValidationHelper.GetInteger(actionArgument, 0);

            // Get category
            CategoryInfo categoryObj = CategoryInfoProvider.GetCategoryInfo(categoryId);
            if (categoryObj != null)
            {
                // Delete the category
                DeleteCategory(categoryObj);
            }
            break;
        }
    }
Esempio n. 30
0
        public static CMS.DataEngine.ObjectQuery <CategoryInfo> GenerateCategoryQuery(List <string> IncludeSites, bool IncludeGlobalCategories, bool IncludeDisabledCategories)
        {
            try
            {
                List <int> siteFilterIDs = new List <int>();
                if (IncludeSites != null && IncludeSites.Count() > 0)
                {
                    foreach (var siteCodeName in IncludeSites)
                    {
                        var site = SiteInfoProvider.GetSiteInfo(siteCodeName);
                        if (site != null)
                        {
                            siteFilterIDs.Add(site.SiteID);
                        }
                    }
                }

                CMS.DataEngine.ObjectQuery <CategoryInfo> categoriesQuery = CategoryInfoProvider
                                                                            .GetCategories();

                if (!IncludeDisabledCategories)
                {
                    categoriesQuery = categoriesQuery.WhereEquals("CategoryEnabled", true);
                }

                categoriesQuery = categoriesQuery.WhereEquals("CategorySiteID", SiteContext.CurrentSiteID);
                foreach (var siteC in siteFilterIDs)
                {
                    categoriesQuery = categoriesQuery.Or().WhereEquals("CategorySiteID", siteC);
                }

                if (IncludeGlobalCategories)
                {
                    categoriesQuery = categoriesQuery.Or().WhereEquals("CategorySiteID", null); // Also get global categories
                }

                categoriesQuery = categoriesQuery.OrderBy("CategorySiteId", "CategoryLevel", "CategoryOrder");

                return(categoriesQuery);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }