Пример #1
0
        /// <summary>
        /// Handles the RowDataBound event of the gDonations control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gDonations_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var item        = e.Row.DataItem;
                var isExporting = ( bool )item.GetPropertyValue("IsExporting");

                //
                // Get the merge fields to be available.
                //
                var options = new CommonMergeFieldsOptions();
                options.GetLegacyGlobalMergeFields = false;
                var mergeFields = LavaHelper.GetCommonMergeFields(RockPage, CurrentPerson, options);
                mergeFields.AddOrReplace("Group", item.GetPropertyValue("Group"));
                mergeFields.AddOrReplace("Donor", item.GetPropertyValue("Donor"));
                mergeFields.AddOrReplace("Participant", item.GetPropertyValue("Participant"));

                //
                // Set the Donor column value.
                //
                var column = gDonations.ColumnsOfType <RockLiteralField>().First(c => c.HeaderText == "Donor");
                if (column.Visible)
                {
                    var literal   = ( Literal )e.Row.Cells[gDonations.Columns.IndexOf(column)].Controls[0];
                    var donorText = GetAttributeValue("DonorColumn").ResolveMergeFields(mergeFields);
                    if (isExporting)
                    {
                        donorText = donorText.ScrubHtmlAndConvertCrLfToBr();
                    }
                    literal.Text = donorText;
                }

                //
                // Set the Participant column value.
                //
                column = gDonations.ColumnsOfType <RockLiteralField>().First(c => c.HeaderText == "Participant");
                if (column.Visible)
                {
                    var literal   = ( Literal )e.Row.Cells[gDonations.Columns.IndexOf(column)].Controls[0];
                    var donorText = GetAttributeValue("ParticipantColumn").ResolveMergeFields(mergeFields);
                    if (isExporting)
                    {
                        donorText = donorText.SanitizeHtml().Trim();
                    }
                    literal.Text = donorText;
                }
            }
        }
Пример #2
0
        public object GetItems(int pageNumber = 0)
        {
            var contentChannelId = GetAttributeValue(AttributeKeys.ContentChannel).AsInteger();
            var pageSize         = GetAttributeValue(AttributeKeys.PageSize).AsInteger();
            var checkSecurity    = GetAttributeValue(AttributeKeys.CheckItemSecurity).AsBoolean();
            var skipNumber       = pageNumber * pageSize;

            var rockContext = new RockContext();
            var contentChannelItemService            = new ContentChannelItemService(rockContext);
            var contentChannelItemAssociationService = new ContentChannelItemAssociationService(rockContext);

            var qry = contentChannelItemService.Queryable().AsNoTracking().Where(i => i.ContentChannelId == contentChannelId);

            //
            // Determine if we should be loading child items from a parent
            //
            var showChildrenOfParent = GetAttributeValue(AttributeKeys.ShowChildrenOfParent).AsBoolean();
            var parentKeyPassed      = RequestContext.GetPageParameters().ContainsKey("ParentItemId");

            if (parentKeyPassed && showChildrenOfParent)
            {
                var parentItemId = RequestContext.GetPageParameters()["ParentItemId"].AsIntegerOrNull();

                if (parentItemId.HasValue)
                {
                    var assoctaionsQry = contentChannelItemAssociationService.Queryable().Where(a => a.ContentChannelItemId == parentItemId);

                    qry = qry.Where(i => assoctaionsQry.Any(a => a.ChildContentChannelItemId == i.Id));
                }
            }

            //
            // Apply custom filtering.
            //
            qry = FilterResults(rockContext, contentChannelItemService, qry);

            //
            // Apply custom sorting to the results.
            //
            qry = SortResults(qry);

            var results = new List <ContentChannelItem>();

            //
            // Determine if we need to check the security of the items. Is can be slow, especially for channels with LOTS of items.
            //
            if (checkSecurity)
            {
                // We have to take all items to check security to ensure we have enough to return the desired item count
                results = qry.ToList();
                foreach (var item in results)
                {
                    if (item.IsAuthorized(Authorization.VIEW, RequestContext.CurrentPerson))
                    {
                        results.Add(item);
                    }
                }

                // Take the final number of items requested.
                results = results.Skip(skipNumber)
                          .Take(pageSize)
                          .ToList();
            }
            else
            {
                // Just take the number requested
                results = qry.Skip(skipNumber)
                          .Take(pageSize)
                          .ToList();
            }

            // Load attributes
            foreach (var item in results)
            {
                item.LoadAttributes(rockContext);
            }

            var followedItemIds = GetFollowedItemIds(rockContext, results);

            var lavaTemplate = CreateLavaTemplate(followedItemIds);

            var commonMergeFields = new CommonMergeFieldsOptions
            {
                GetLegacyGlobalMergeFields = false
            };

            var mergeFields = RequestContext.GetCommonMergeFields(null, commonMergeFields);

            mergeFields.Add("Items", results);
            mergeFields.Add("FollowedItemIds", followedItemIds);

            var output = lavaTemplate.ResolveMergeFields(mergeFields);

            return(ActionOk(new StringContent(output, Encoding.UTF8, "application/json")));
        }
Пример #3
0
        public object GetEvents(DateTime beginDate, DateTime endDate)
        {
            using (var rockContext = new RockContext())
            {
                var eventCalendar = new EventCalendarService(rockContext).Get(Calendar ?? Guid.Empty);
                var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);

                if (eventCalendar == null)
                {
                    return(new List <object>());
                }

                // Grab events
                var qry = eventItemOccurrenceService
                          .Queryable("EventItem, EventItem.EventItemAudiences, Schedule")
                          .Where(m =>
                                 m.EventItem.EventCalendarItems.Any(i => i.EventCalendarId == eventCalendar.Id) &&
                                 m.EventItem.IsActive &&
                                 m.EventItem.IsApproved);

                // Check for Campus Parameter or Campus Context.
                if (EnableCampusFiltering)
                {
                    var campusGuid = RequestContext.GetPageParameter("CampusGuid").AsGuidOrNull();
                    if (campusGuid.HasValue)
                    {
                        // Check if there's a campus with this guid.
                        var campus = CampusCache.Get(campusGuid.Value);
                        if (campus != null)
                        {
                            qry = qry.Where(a => !a.CampusId.HasValue || a.CampusId == campus.Id);
                        }
                    }
                    else
                    {
                        var contextCampus = RequestContext.GetContextEntity <Campus>();
                        if (contextCampus != null)
                        {
                            qry = qry.Where(a => !a.CampusId.HasValue || a.Campus.Id == contextCampus.Id);
                        }
                        else if (RequestContext.CurrentPerson != null && RequestContext.CurrentPerson.PrimaryCampusId.HasValue)
                        {
                            var campusId = RequestContext.CurrentPerson.PrimaryCampusId.Value;

                            qry = qry.Where(a => !a.CampusId.HasValue || a.CampusId == campusId);
                        }
                    }
                }

                // Get the occurrences
                var occurrences = qry.ToList()
                                  .SelectMany(a =>
                {
                    var duration = a.Schedule?.DurationInMinutes ?? 0;

                    return(a.GetStartTimes(beginDate, endDate)
                           .Where(b => b >= beginDate && b < endDate)
                           .Select(b => new
                    {
                        Date = b.ToRockDateTimeOffset(),
                        Duration = duration,
                        AudienceGuids = a.EventItem.EventItemAudiences.Select(c => DefinedValueCache.Get(c.DefinedValueId)?.Guid).Where(c => c.HasValue).Select(c => c.Value).ToList(),
                        EventItemOccurrence = a
                    }));
                })
                                  .Select(a => new
                {
                    a.EventItemOccurrence,
                    a.EventItemOccurrence.Guid,
                    a.EventItemOccurrence.Id,
                    a.EventItemOccurrence.EventItem.Name,
                    DateTime            = a.Date,
                    EndDateTime         = a.Duration > 0 ? ( DateTimeOffset? )a.Date.AddMinutes(a.Duration) : null,
                    Date                = a.Date.ToString("d"), // Short date
                    Time                = a.Date.ToString("t"), // Short time
                    Campus              = a.EventItemOccurrence.Campus != null ? a.EventItemOccurrence.Campus.Name : "All Campuses",
                    Location            = a.EventItemOccurrence.Campus != null ? a.EventItemOccurrence.Campus.Name : "All Campuses",
                    LocationDescription = a.EventItemOccurrence.Location,
                    Audiences           = a.AudienceGuids,
                    a.EventItemOccurrence.EventItem.Description,
                    a.EventItemOccurrence.EventItem.Summary,
                    OccurrenceNote = a.EventItemOccurrence.Note.SanitizeHtml()
                });

                var lavaTemplate = CreateLavaTemplate();

                var commonMergeFields = new CommonMergeFieldsOptions
                {
                    GetLegacyGlobalMergeFields = false
                };

                var mergeFields = RequestContext.GetCommonMergeFields(null, commonMergeFields);
                mergeFields.Add("Items", occurrences.ToList());

                var output = lavaTemplate.ResolveMergeFields(mergeFields);

                return(ActionOk(new StringContent(output, Encoding.UTF8, "application/json")));
            }
        }
Пример #4
0
        public object GetEvents(DateTime beginDate, DateTime endDate)
        {
            using (var rockContext = new RockContext())
            {
                var eventCalendar = new EventCalendarService(rockContext).Get(Calendar ?? Guid.Empty);
                var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);

                if (eventCalendar == null)
                {
                    return(new List <object>());
                }

                // Grab events
                var qry = eventItemOccurrenceService
                          .Queryable("EventItem, EventItem.EventItemAudiences, Schedule")
                          .Where(m =>
                                 m.EventItem.EventCalendarItems.Any(i => i.EventCalendarId == eventCalendar.Id) &&
                                 m.EventItem.IsActive &&
                                 m.EventItem.IsApproved);

                // Get the occurrences
                var occurrences = qry.ToList()
                                  .SelectMany(a =>
                {
                    var duration = a.Schedule?.DurationInMinutes ?? 0;

                    return(a.GetStartTimes(beginDate, endDate)
                           .Where(b => b >= beginDate && b < endDate)
                           .Select(b => new
                    {
                        Date = b,
                        Duration = duration,
                        AudienceGuids = a.EventItem.EventItemAudiences.Select(c => DefinedValueCache.Get(c.DefinedValueId)?.Guid).Where(c => c.HasValue).Select(c => c.Value).ToList(),
                        EventItemOccurrence = a
                    }));
                })
                                  .Select(a => new
                {
                    a.EventItemOccurrence,
                    a.EventItemOccurrence.Guid,
                    a.EventItemOccurrence.Id,
                    a.EventItemOccurrence.EventItem.Name,
                    DateTime            = a.Date,
                    EndDateTime         = a.Duration > 0 ? ( DateTime? )a.Date.AddMinutes(a.Duration) : null,
                    Date                = a.Date.ToShortDateString(),
                    Time                = a.Date.ToShortTimeString(),
                    Campus              = a.EventItemOccurrence.Campus != null ? a.EventItemOccurrence.Campus.Name : "All Campuses",
                    Location            = a.EventItemOccurrence.Campus != null ? a.EventItemOccurrence.Campus.Name : "All Campuses",
                    LocationDescription = a.EventItemOccurrence.Location,
                    Audiences           = a.AudienceGuids,
                    a.EventItemOccurrence.EventItem.Description,
                    a.EventItemOccurrence.EventItem.Summary,
                    OccurrenceNote = a.EventItemOccurrence.Note.SanitizeHtml()
                });

                var lavaTemplate = CreateLavaTemplate();

                var commonMergeFields = new CommonMergeFieldsOptions
                {
                    GetLegacyGlobalMergeFields = false
                };

                var mergeFields = RequestContext.GetCommonMergeFields(null, commonMergeFields);
                mergeFields.Add("Items", occurrences.ToList());

                var output = lavaTemplate.ResolveMergeFields(mergeFields);

                return(ActionOk(new StringContent(output, Encoding.UTF8, "application/json")));
            }
        }