public async Task <IEnumerable <NavigationItem> > GetSecondaryNavItemsAsync(string StartingPath, PathSelectionEnum PathType = PathSelectionEnum.ChildrenOnly, string[] PageTypes = null, string OrderBy = null, string WhereCondition = null, int MaxLevel = -1, int TopNumber = -1)
        {
            List <HierarchyTreeNode> HierarchyNodes = new List <HierarchyTreeNode>();

            Dictionary <int, HierarchyTreeNode> NodeIDToHierarchyTreeNode = new Dictionary <int, HierarchyTreeNode>();
            List <TreeNode>        NewNodeList = new List <TreeNode>();
            IEnumerable <TreeNode> Nodes       = _GeneralDocumentRepo.GetDocumentsByPath(
                TreePathUtils.EnsureSingleNodePath(StartingPath),
                PathType,
                OrderBy,
                WhereCondition,
                MaxLevel,
                TopNumber,
                new string[] { nameof(TreeNode.DocumentName), nameof(TreeNode.ClassName), nameof(TreeNode.DocumentCulture), nameof(TreeNode.NodeID), nameof(TreeNode.DocumentID), nameof(TreeNode.DocumentGUID), nameof(TreeNode.NodeParentID), nameof(TreeNode.NodeLevel), nameof(TreeNode.NodeGUID), nameof(TreeNode.NodeAliasPath) },
                PageTypes
                )
                                                 .Select(x => (TreeNode)x);

            // populate ParentNodeIDToTreeNode
            foreach (TreeNode Node in Nodes)
            {
                NodeIDToHierarchyTreeNode.Add(Node.NodeID, new HierarchyTreeNode(Node));
                NewNodeList.Add(Node);
            }

            // Populate the Children of the TypedResults
            foreach (TreeNode Node in NewNodeList)
            {
                // If no parent exists, add to top level
                if (!NodeIDToHierarchyTreeNode.ContainsKey(Node.NodeParentID))
                {
                    HierarchyNodes.Add(NodeIDToHierarchyTreeNode[Node.NodeID]);
                }
                else
                {
                    // Otherwise, add to the parent element.
                    NodeIDToHierarchyTreeNode[Node.NodeParentID].Children.Add(NodeIDToHierarchyTreeNode[Node.NodeID]);
                }
            }

            // Convert to Model
            List <NavigationItem> Items = new List <NavigationItem>();

            foreach (var HierarchyNavTreeNode in HierarchyNodes)
            {
                // Call the check to set the Ancestor is current
                Items.Add(_helper.GetTreeNodeToNavigationItem(HierarchyNavTreeNode));
            }
            return(Items);
        }
Exemplo n.º 2
0
        public IEnumerable <ITreeNode> GetDocuments(string SinglePath, PathSelectionEnum PathType, string[] PageTypes = null, string OrderBy = null, string WhereCondition = null, int MaxLevel = -1, int TopNumber = -1, string[] Columns = null, bool IncludeCoupledColumns = false)
        {
            using (MultiDocumentQuery Query = new MultiDocumentQuery())
            {
                if (PageTypes != null && PageTypes.Length > 0)
                {
                    if (PageTypes.Length == 1)
                    {
                        Query.Type(PageTypes[0]);
                    }
                    else
                    {
                        Query.Types(PageTypes);
                    }
                }
                if (IncludeCoupledColumns)
                {
                    Query.ExpandColumns();
                }

                // Handle culture and versioning and site
                Query.Culture(cultureName)
                .CombineWithDefaultCulture()
                .CombineWithAnyCulture()
                .Published(!latestVersionEnabled)
                .LatestVersion(latestVersionEnabled)
                .OnSite(_SiteRepo.CurrentSiteName());

                PathTypeEnum KenticoPathType = PathTypeEnum.Explicit;
                switch (PathType)
                {
                case PathSelectionEnum.ChildrenOnly:
                    KenticoPathType = PathTypeEnum.Children;
                    break;

                case PathSelectionEnum.ParentAndChildren:
                    KenticoPathType = PathTypeEnum.Section;
                    break;

                case PathSelectionEnum.ParentOnly:
                    KenticoPathType = PathTypeEnum.Single;
                    break;
                }
                Query.Path(SinglePath, KenticoPathType);

                if (!string.IsNullOrWhiteSpace(OrderBy))
                {
                    Query.OrderBy(OrderBy);
                }
                if (!string.IsNullOrWhiteSpace(WhereCondition))
                {
                    Query.Where(WhereCondition);
                }
                if (Columns != null && Columns.Length > 0)
                {
                    Query.Columns(Columns);
                }
                if (MaxLevel >= 0)
                {
                    Query.NestingLevel(MaxLevel);
                }
                if (TopNumber >= 0)
                {
                    Query.TopN(TopNumber);
                }
                return(Query.TypedResult);
            }
        }
 public IEnumerable <NavigationItem> GetSecondaryNavItems(string StartingPath, PathSelectionEnum PathType = PathSelectionEnum.ChildrenOnly, string[] PageTypes = null, string OrderBy = null, string WhereCondition = null, int MaxLevel = -1, int TopNumber = -1)
 {
     return(GetSecondaryNavItemsAsync(StartingPath, PathType, PageTypes, OrderBy, WhereCondition, MaxLevel, TopNumber).Result);
 }
Exemplo n.º 4
0
 public IEnumerable <ITreeNode> GetDocumentsByPath(string SinglePath, string SiteName, PathSelectionEnum PathType, string OrderBy = null, string WhereCondition = null, int MaxLevel = -1, int TopNumber = -1, string[] Columns = null, string[] PageTypes = null, bool IncludeCoupledColumns = false, string Culture = null)
 {
     return(GetDocumentsByPathInternal(SinglePath, (!string.IsNullOrWhiteSpace(SiteName) ? SiteName : siteService.CurrentSite.SiteName), PathType, OrderBy, WhereCondition, MaxLevel, TopNumber, Columns, PageTypes, IncludeCoupledColumns, (!string.IsNullOrWhiteSpace(Culture) ? Culture : _repoContext.CurrentCulture())));
 }