Пример #1
0
        private void Render()
        {
            try
            {
                PageCache currentPage = PageCache.Read(RockPage.PageId);
                PageCache rootPage    = null;

                Guid pageGuid = Guid.Empty;
                if (Guid.TryParse(GetAttributeValue(ROOT_PAGE), out pageGuid))
                {
                    rootPage = PageCache.Read(pageGuid);
                }

                // If a root page was not found, use current page
                if (rootPage == null)
                {
                    rootPage = currentPage;
                }

                int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

                Dictionary <string, string> pageParameters = null;
                if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
                {
                    pageParameters = CurrentPageReference.Parameters;
                }

                NameValueCollection queryString = null;
                if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
                {
                    queryString = CurrentPageReference.QueryString;
                }

                // Get list of pages in current page's heirarchy
                var pageHeirarchy = new List <int>();
                if (currentPage != null)
                {
                    pageHeirarchy = currentPage.GetPageHierarchy().Select(p => p.Id).ToList();
                }

                // add context to merge fields
                var contextEntityTypes = RockPage.GetContextEntityTypes();
                var contextObjects     = new Dictionary <string, object>();
                foreach (var conextEntityType in contextEntityTypes)
                {
                    var contextObject = RockPage.GetCurrentContext(conextEntityType);
                    contextObjects.Add(conextEntityType.FriendlyName, contextObject);
                }

                var pageProperties = new Dictionary <string, object>();
                pageProperties.Add("CurrentPerson", CurrentPerson);
                pageProperties.Add("Context", contextObjects);
                pageProperties.Add("Site", GetSiteProperties(RockPage.Site));
                pageProperties.Add("IncludePageList", GetIncludePageList());

                using (var rockContext = new RockContext())
                {
                    pageProperties.Add("Page", rootPage.GetMenuProperties(levelsDeep, CurrentPerson, rockContext, pageHeirarchy, pageParameters, queryString));
                }
                string content = GetTemplate().Render(Hash.FromDictionary(pageProperties));

                // check for errors
                if (content.Contains("error"))
                {
                    content = "<div class='alert alert-warning'><h4>Warning</h4>" + content + "</div>";
                }

                phContent.Controls.Clear();
                phContent.Controls.Add(new LiteralControl(content));

                // add debug info
                if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
                {
                    StringBuilder tipInfo = new StringBuilder();
                    tipInfo.Append("<p /><div class='alert alert-success' style='clear: both;'><h4>Page Menu Tips</h4>");

                    tipInfo.Append("<p><em>Note:</em> If a page or group of pages is not in the data above check the following: <ul>");
                    tipInfo.Append("<li>The parent page has 'Show Child Pages' enabled in the 'Page Properties' > 'Display Settings'</li>");
                    tipInfo.Append("<li>Check the 'Display Settings' on the child pages</li>");
                    tipInfo.Append("<li>Check the security of the child pages</li>");
                    tipInfo.Append("</ul><br /></p>");
                    tipInfo.Append("</div>");

                    phContent.Controls.Add(new LiteralControl(tipInfo.ToString() + pageProperties.lavaDebugInfo()));
                }
            }
            catch (Exception ex)
            {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.Append("<div class='alert alert-warning'>");
                errorMessage.Append("An error has occurred while generating the page menu. Error details:");
                errorMessage.Append(ex.Message);
                errorMessage.Append("</div>");

                phContent.Controls.Add(new LiteralControl(errorMessage.ToString()));
            }
        }
Пример #2
0
        private void Render()
        {
            try
            {
                PageCache currentPage = PageCache.Read(RockPage.PageId);
                PageCache rootPage    = null;

                Guid pageGuid = Guid.Empty;
                if (Guid.TryParse(GetAttributeValue(ROOT_PAGE), out pageGuid))
                {
                    rootPage = PageCache.Read(pageGuid);
                }

                // If a root page was not found, use current page
                if (rootPage == null)
                {
                    rootPage = currentPage;
                }

                int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

                Dictionary <string, string> pageParameters = null;
                if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
                {
                    pageParameters = CurrentPageReference.Parameters;
                }

                NameValueCollection queryString = null;
                if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
                {
                    queryString = CurrentPageReference.QueryString;
                }

                // Get list of pages in current page's heirarchy
                var pageHeirarchy = new List <int>();
                if (currentPage != null)
                {
                    pageHeirarchy = currentPage.GetPageHierarchy().Select(p => p.Id).ToList();
                }

                // add context to merge fields
                var contextEntityTypes = RockPage.GetContextEntityTypes();
                var contextObjects     = new Dictionary <string, object>();
                foreach (var conextEntityType in contextEntityTypes)
                {
                    var contextObject = RockPage.GetCurrentContext(conextEntityType);
                    contextObjects.Add(conextEntityType.FriendlyName, contextObject);
                }

                var pageProperties = new Dictionary <string, object>();
                pageProperties.Add("CurrentPerson", CurrentPerson);
                pageProperties.Add("Context", contextObjects);
                pageProperties.Add("Site", GetSiteProperties(RockPage.Site));
                pageProperties.Add("IncludePageList", GetIncludePageList());

                using (var rockContext = new RockContext())
                {
                    pageProperties.Add("Page", rootPage.GetMenuProperties(levelsDeep, CurrentPerson, rockContext, pageHeirarchy, pageParameters, queryString));
                }
                string content = GetTemplate().Render(Hash.FromDictionary(pageProperties));

                // check for errors
                if (content.Contains("error"))
                {
                    content = "<div class='alert alert-warning'><h4>Warning</h4>" + content + "</div>";
                }

                phContent.Controls.Clear();
                phContent.Controls.Add(new LiteralControl(content));
            }
            catch (Exception ex)
            {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.Append("<div class='alert alert-warning'>");
                errorMessage.Append("An error has occurred while generating the page menu. Error details:");
                errorMessage.Append(ex.Message);
                errorMessage.Append("</div>");

                phContent.Controls.Add(new LiteralControl(errorMessage.ToString()));
            }
        }
        private void LoadContent()
        {
            var audienceGuid = GetAttributeValue("Audience").AsGuid();

            if (audienceGuid != Guid.Empty)
            {
                lMessages.Text = string.Empty;
                RockContext rockContext = new RockContext();

                // get event occurrences
                var qry = new EventItemOccurrenceService(rockContext).Queryable()
                          .Where(e => e.EventItem.EventItemAudiences.Any(a => a.DefinedValue.Guid == audienceGuid) && e.EventItem.IsActive);

                // filter occurrences for campus (always include the "All Campuses" events)
                if (GetAttributeValue("UseCampusContext").AsBoolean())
                {
                    var campusEntityType = EntityTypeCache.Read("Rock.Model.Campus");
                    var contextCampus    = RockPage.GetCurrentContext(campusEntityType) as Campus;

                    if (contextCampus != null)
                    {
                        // If an EventItemOccurrence's CampusId is null, then the occurrence is an 'All Campuses' event occurrence, so include those
                        qry = qry.Where(e => e.CampusId == contextCampus.Id || !e.CampusId.HasValue);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(GetAttributeValue("Campuses")))
                    {
                        var selectedCampusGuids = GetAttributeValue("Campuses").Split(',').AsGuidList();
                        var selectedCampusIds   = selectedCampusGuids.Select(a => CampusCache.Read(a)).Where(a => a != null).Select(a => a.Id);

                        // If an EventItemOccurrence's CampusId is null, then the occurrence is an 'All Campuses' event occurrence, so include those
                        qry = qry.Where(e => e.CampusId == null || selectedCampusIds.Contains(e.CampusId.Value));
                    }
                }

                // filter by calendar
                var calendarGuid = GetAttributeValue("Calendar").AsGuid();

                if (calendarGuid != Guid.Empty)
                {
                    qry = qry.Where(e => e.EventItem.EventCalendarItems.Any(c => c.EventCalendar.Guid == calendarGuid));
                }

                // retrieve occurrences
                var itemOccurrences = qry.ToList();

                // filter by date range
                var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(GetAttributeValue("DateRange"));
                if (dateRange.Start != null && dateRange.End != null)
                {
                    itemOccurrences.RemoveAll(o => o.GetStartTimes(dateRange.Start.Value, dateRange.End.Value).Count() == 0);
                }
                else
                {
                    // default show all future
                    itemOccurrences.RemoveAll(o => o.GetStartTimes(RockDateTime.Now, DateTime.Now.AddDays(365)).Count() == 0);
                }

                // limit results
                int maxItems = GetAttributeValue("MaxOccurrences").AsInteger();
                itemOccurrences = itemOccurrences.OrderBy(i => i.NextStartDateTime).Take(maxItems).ToList();

                // make lava merge fields
                var mergeFields = new Dictionary <string, object>();

                var contextObjects = new Dictionary <string, object>();
                foreach (var contextEntityType in RockPage.GetContextEntityTypes())
                {
                    var contextEntity = RockPage.GetCurrentContext(contextEntityType);
                    if (contextEntity != null && contextEntity is DotLiquid.ILiquidizable)
                    {
                        var type = Type.GetType(contextEntityType.AssemblyName ?? contextEntityType.Name);
                        if (type != null)
                        {
                            contextObjects.Add(type.Name, contextEntity);
                        }
                    }
                }

                if (contextObjects.Any())
                {
                    mergeFields.Add("Context", contextObjects);
                }

                mergeFields.Add("ListTitle", GetAttributeValue("ListTitle"));
                mergeFields.Add("EventDetailPage", LinkedPageRoute("EventDetailPage"));
                mergeFields.Add("RegistrationPage", LinkedPageRoute("RegistrationPage"));
                mergeFields.Add("EventItemOccurrences", itemOccurrences);

                lContent.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields);
            }
            else
            {
                lMessages.Text = "<div class='alert alert-warning'>No audience is configured for this block.</div>";
            }
        }
Пример #4
0
        private void Render()
        {
            try
            {
                PageCache currentPage = PageCache.Get(RockPage.PageId);
                PageCache rootPage    = null;

                var pageRouteValuePair = GetAttributeValue(ROOT_PAGE).SplitDelimitedValues(false).AsGuidOrNullList();
                if (pageRouteValuePair.Any() && pageRouteValuePair[0].HasValue && !pageRouteValuePair[0].Value.IsEmpty())
                {
                    rootPage = PageCache.Get(pageRouteValuePair[0].Value);
                }

                // If a root page was not found, use current page
                if (rootPage == null)
                {
                    rootPage = currentPage;
                }

                int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

                Dictionary <string, string> pageParameters = null;
                if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
                {
                    pageParameters = CurrentPageReference.Parameters;
                }

                NameValueCollection queryString = null;
                if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
                {
                    queryString = CurrentPageReference.QueryString;
                }

                // Get list of pages in current page's hierarchy
                var pageHeirarchy = new List <int>();
                if (currentPage != null)
                {
                    pageHeirarchy = currentPage.GetPageHierarchy().Select(p => p.Id).ToList();
                }

                // Add context to merge fields
                var contextEntityTypes = RockPage.GetContextEntityTypes();
                var contextObjects     = new Dictionary <string, object>();
                foreach (var conextEntityType in contextEntityTypes)
                {
                    var contextObject = RockPage.GetCurrentContext(conextEntityType);
                    contextObjects.Add(conextEntityType.FriendlyName, contextObject);
                }

                var pageProperties = new Dictionary <string, object>();
                pageProperties.Add("CurrentPerson", CurrentPerson);
                pageProperties.Add("Context", contextObjects);
                pageProperties.Add("Site", GetSiteProperties(RockPage.Site));
                pageProperties.Add("IncludePageList", GetIncludePageList());
                pageProperties.Add("CurrentPage", this.PageCache);

                using (var rockContext = new RockContext())
                {
                    pageProperties.Add("Page", rootPage.GetMenuProperties(levelsDeep, CurrentPerson, rockContext, pageHeirarchy, pageParameters, queryString));
                }

                var lavaTemplate = GetTemplate();

                // Apply Enabled Lava Commands
                var enabledCommands = GetAttributeValue("EnabledLavaCommands");
                lavaTemplate.Registers.AddOrReplace("EnabledCommands", enabledCommands);

                string content = lavaTemplate.Render(Hash.FromDictionary(pageProperties));

                phContent.Controls.Clear();
                phContent.Controls.Add(new LiteralControl(content));
            }
            catch (Exception ex)
            {
                LogException(ex);
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.Append("<div class='alert alert-warning'>");
                errorMessage.Append("An error has occurred while generating the page menu. Error details:");
                errorMessage.Append(ex.Message);
                errorMessage.Append("</div>");

                phContent.Controls.Add(new LiteralControl(errorMessage.ToString()));
            }
        }