コード例 #1
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)
        {
            DocumentQuery Query = null;

            if (PageTypes != null && PageTypes.Length > 0)
            {
                if (PageTypes.Length == 1)
                {
                    Query = new DocumentQuery(PageTypes[0]);
                }
                else
                {
                    Query = new DocumentQuery()
                            .WhereIn("ClassName", PageTypes);
                    if (IncludeCoupledColumns)
                    {
                        Query.ExpandColumns();
                    }
                }
            }
            else
            {
                Query = new DocumentQuery();
            }

            // 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);
        }