示例#1
0
        private static void PopulateSub(Category cat, IEnumerable <Category> cats, BusiBlocksTreeNode docoCat, int maxLevel, int level)
        {
            if (level > maxLevel)
            {
                return;
            }

            var subCats =
                from x in cats
                where (x.ParentCategory == null) ? 1 == 0 : x.ParentCategory.Equals(cat)
                select x;

            foreach (Category subCat in subCats)
            {
                var node = new BusiBlocksTreeNode {
                    Id = subCat.Id, Name = subCat.DisplayName, IsFolder = true
                };

                IList <Article> items = GetArticles(subCat, ArticleStatus.All, false);
                foreach (Article item in items)
                {
                    node.ChildNodes.Add(new BusiBlocksTreeNode {
                        Id = item.Id, Name = item.Name, IsFolder = false
                    });
                }
                docoCat.ChildNodes.Add(node);
                level = level + 1;
                PopulateSub(subCat, cats, node, maxLevel, level);
            }
        }
示例#2
0
        private static void CreateCategoryStructure(BusiBlocksTreeNode rootNode, IList <Category> categories, Category category, int maxLevel, int level, bool includeItems, string username)
        {
            if (level > maxLevel)
            {
                return;
            }

            var subCategories = from x in categories where (x.ParentCategory == null) ? 1 == 0 : x.ParentCategory.Equals(category) select x;

            foreach (Category subCategory in subCategories)
            {
                IList <Item> items = NewsManager.GetItems(subCategory, false);

                BusiBlocksTreeNode categoryNode = new BusiBlocksTreeNode {
                    Name = subCategory.Name, Id = subCategory.Id, IsFolder = true, ChildNodes = new List <BusiBlocksTreeNode>()
                };

                if (items.Count > 0 && includeItems)
                {
                    foreach (Item item in items)
                    {
                        if (BusiBlocks.SecurityHelper.CanUserView(username, subCategory.Id))
                        {
                            categoryNode.ChildNodes.Add(new BusiBlocksTreeNode {
                                Id = item.Id, Name = item.Title, IsFolder = false
                            });
                        }
                    }
                }

                if (BusiBlocks.SecurityHelper.CanUserView(username, categoryNode.Id))
                {
                    rootNode.ChildNodes.Add(categoryNode);
                    CreateCategoryStructure(categoryNode, categories, subCategory, maxLevel, level++, includeItems, username);
                }
            }
        }
示例#3
0
        public static BusiBlocksTreeView GetCategoriesItemsTree(bool includeItems, string username)
        {
            BusiBlocksTreeView tree = new BusiBlocksTreeView {
                Nodes = new List <BusiBlocksTreeNode>()
            };
            IList <Category> categories = NewsManager.GetAllCategories();

            var rootCategories = from x in categories where x.ParentCategory == null select x;

            int maxLevel = 100;

            foreach (Category category in rootCategories)
            {
                BusiBlocksTreeNode node = new BusiBlocksTreeNode {
                    Name = category.Name, Id = category.Id, IsFolder = true, ChildNodes = new List <BusiBlocksTreeNode>()
                };
                if (BusiBlocks.SecurityHelper.CanUserView(username, node.Id))
                {
                    tree.Nodes.Add(node);
                    IList <Item> items = NewsManager.GetItems(category, false);
                    if (items.Count > 0 && includeItems)
                    {
                        foreach (Item item in items)
                        {
                            if (BusiBlocks.SecurityHelper.CanUserView(username, category.Id))
                            {
                                node.ChildNodes.Add(new BusiBlocksTreeNode {
                                    Id = item.Id, Name = item.Title, IsFolder = false
                                });
                            }
                        }
                    }
                    CreateCategoryStructure(node, categories, category, maxLevel, 0, includeItems, username);
                }
            }
            return(tree);
        }
示例#4
0
        private static BusiBlocksTreeView PopulateTreeView(string username)
        {
            var catTreeView = new BusiBlocksTreeView();

            IList <Category> cats = GetAllCategories();

            IList <Category> toRemove = new List <Category>();

            foreach (Category cat in cats)
            {
                // Remove this category from the list if it is not viewable by this user.
                if (!SecurityHelper.CanUserView(username, cat.Id))
                {
                    toRemove.Add(cat);
                }
            }
            foreach (Category cat in toRemove)
            {
                cats.Remove(cat);
            }

            // Need to form the hierarchical structure by selecting the categories with no parent
            // and then adding sub collections of categories with the chosen parent.

            var noParent =
                from x in cats
                where x.ParentCategory == null
                select x;

            int maxLevel = 20;

            if (!noParent.Any())
            {
                // Try to pick the "all docs" category.
                noParent =
                    from x in cats
                    where x.DisplayName.Equals("All Documents")
                    select x;
            }
            foreach (Category cat in noParent)
            {
                var node = new BusiBlocksTreeNode {
                    Id = cat.Id, Name = cat.DisplayName, IsFolder = true
                };
                IList <Article> items = GetArticles(cat, ArticleStatus.All, false);
                foreach (Article item in items)
                {
                    node.ChildNodes.Add(new BusiBlocksTreeNode {
                        Id = item.Id, Name = item.Name, IsFolder = false
                    });
                }
                catTreeView.Nodes.Add(node);
                PopulateSub(cat, cats, node, maxLevel, 0);
            }
            // todo Remove this commented out block when we're sure it isn't doing anything.
            //// Set the selected category.
            //if (noParent.Any())
            //{
            //    Category cat = noParent.First();
            //}
            return(catTreeView);
        }