/// <summary>
        /// Allows for Related Pages lookup using Ordering on non-MultpleDocumentQuery queries.  The given Node must be on the "left" hand side in this case for ordering.
        /// </summary>
        /// <param name="baseQuery">The Base Document Query</param>
        /// <param name="nodeGuid">The NodeGuid</param>
        /// <param name="relationshipName">Name of the relationship. If not provided documents from all relationships will be retrieved.</param>
        public static MultiDocumentQuery InRelationWithOrder(this MultiDocumentQuery baseQuery, Guid nodeGuid, string relationshipName = null)
        {
            // Get the RelationshipID and NodeID
            int?RelationshipNameID = GetRelationshipNameID(relationshipName);
            int?NodeID             = GetNodeID(nodeGuid);

            if (!NodeID.HasValue)
            {
                return(baseQuery);
            }

            // Add the Inner Join with proper alias formatting
            if (RelationshipNameID.HasValue)
            {
                baseQuery.Source((QuerySource s) => s.InnerJoin(new QuerySourceTable("CMS_Relationship"), new WhereCondition("NodeID = RightNodeID").WhereEquals("RelationshipNameID", RelationshipNameID.Value).WhereEquals("LeftNodeID", NodeID.Value)));
            }
            else
            {
                baseQuery.Source((QuerySource s) => s.InnerJoin(new QuerySourceTable("CMS_Relationship"), new WhereCondition("NodeID = RightNodeID").WhereEquals("LeftNodeID", NodeID.Value)));
            }

            // add the by the Relationship Order
            baseQuery.OrderBy("RelationshipOrder");

            return(baseQuery);
        }
 /// <summary>
 /// Returns the <see cref="MultiDocumentQuery"/> ordered by <see cref="TreeNode.NodeOrder"/>
 /// </summary>
 /// <param name="query">The current MultiDocumentQuery</param>
 /// <returns></returns>
 public static MultiDocumentQuery OrderByNodeOrder(this MultiDocumentQuery query) =>
 query.OrderBy(nameof(TreeNode.NodeOrder));
示例#3
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);
            }
        }