/// <summary>
        /// Menus the XML element.
        /// </summary>
        /// <param name="levelsDeep">The levels deep.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns></returns>
        private XElement MenuXmlElement(int levelsDeep, Person person, RockContext rockContext, PageCache currentPage = null, Dictionary <string, string> parameters = null, NameValueCollection queryString = null)
        {
            if (levelsDeep < 0 || !DisplayInNav(person))
            {
                return(null);
            }

            var iconUrl = string.Empty;

            if (IconFileId.HasValue)
            {
                iconUrl = $"{HttpContext.Current.Request.ApplicationPath}/GetImage.ashx?{IconFileId.Value}";
            }

            var isCurrentPage = currentPage != null && currentPage.Id == Id;

            var pageElement = new XElement(
                "page",
                new XAttribute("id", Id),
                new XAttribute("title", string.IsNullOrWhiteSpace(PageTitle) ? InternalName : PageTitle),
                new XAttribute("current", isCurrentPage.ToString()),
                new XAttribute("url", new PageReference(Id, 0, parameters, queryString).BuildUrl()),
                new XAttribute("display-description", MenuDisplayDescription.ToString().ToLower()),
                new XAttribute("display-icon", MenuDisplayIcon.ToString().ToLower()),
                new XAttribute("display-child-pages", MenuDisplayChildPages.ToString().ToLower()),
                new XAttribute("icon-css-class", IconCssClass ?? string.Empty),
                new XElement("description", Description ?? string.Empty),
                new XElement("icon-url", iconUrl));

            var childPagesElement = new XElement("pages");

            pageElement.Add(childPagesElement);

            if (levelsDeep <= 0 || !MenuDisplayChildPages)
            {
                return(pageElement);
            }

            foreach (var page in GetPages(rockContext))
            {
                var childPageElement = page?.MenuXmlElement(levelsDeep - 1, person, rockContext, currentPage, parameters, queryString);
                if (childPageElement != null)
                {
                    childPagesElement.Add(childPageElement);
                }
            }

            return(pageElement);
        }
示例#2
0
        /// <summary>
        /// Gets the menu properties.
        /// </summary>
        /// <param name="levelsDeep">The levels deep.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="currentPageHeirarchy">The current page hierarchy.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns></returns>
        public Dictionary <string, object> GetMenuProperties(int levelsDeep, Person person, RockContext rockContext, List <int> currentPageHeirarchy = null, Dictionary <string, string> parameters = null, NameValueCollection queryString = null)
        {
            if (levelsDeep < 0)
            {
                return(null);
            }

            var iconUrl = string.Empty;

            if (IconFileId.HasValue)
            {
                iconUrl = $"{HttpContext.Current.Request.ApplicationPath}/GetImage.ashx?{IconFileId.Value}";
            }

            var isCurrentPage     = false;
            var isParentOfCurrent = false;

            if (currentPageHeirarchy != null && currentPageHeirarchy.Any())
            {
                isCurrentPage     = currentPageHeirarchy.First() == Id;
                isParentOfCurrent = currentPageHeirarchy.Skip(1).Any(p => p == Id);
            }

            var properties = new Dictionary <string, object>
            {
                { "Id", Id },
                { "Title", string.IsNullOrWhiteSpace(PageTitle) ? InternalName : PageTitle },
                { "Current", isCurrentPage.ToString().ToLower() },
                { "IsParentOfCurrent", isParentOfCurrent.ToString().ToLower() },
                { "Url", new PageReference(Id, 0, parameters, queryString).BuildUrl() },
                { "DisplayDescription", MenuDisplayDescription.ToString().ToLower() },
                { "DisplayIcon", MenuDisplayIcon.ToString().ToLower() },
                { "DisplayChildPages", MenuDisplayChildPages.ToString().ToLower() },
                { "IconCssClass", IconCssClass ?? string.Empty },
                { "Description", Description ?? string.Empty },
                { "IconUrl", iconUrl }
            };

            if (levelsDeep <= 0 || !MenuDisplayChildPages)
            {
                return(properties);
            }

            var childPages = new List <Dictionary <string, object> >();

            foreach (var page in GetPages(rockContext))
            {
                if (page == null || !page.DisplayInNav(person))
                {
                    continue;
                }

                var childPageElement = page.GetMenuProperties(levelsDeep - 1, person, rockContext, currentPageHeirarchy, parameters, queryString);
                if (childPageElement != null)
                {
                    childPages.Add(childPageElement);
                }
            }

            // Add the Pages property so that Lava users can check it via the "empty" check or size.
            properties.Add("Pages", childPages);

            return(properties);
        }