Пример #1
0
        /// <summary>
        /// Handles the RowDataBound event of the gAttendees control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gAttendees_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            RosterAttendee attendee = e.Row.DataItem as RosterAttendee;

            var lPhoto = e.Row.FindControl("lPhoto") as Literal;

            lPhoto.Text = attendee.GetPersonPhotoImageHtmlTag();
            var lName = e.Row.FindControl("lName") as Literal;

            lName.Text = attendee.GetAttendeeNameHtml();

            var lGroupNameAndPath = e.Row.FindControl("lGroupNameAndPath") as Literal;

            if (lGroupNameAndPath != null && lGroupNameAndPath.Visible)
            {
                if (_showOnlyParentGroup)
                {
                    lGroupNameAndPath.Text = lGroupNameAndPath.Text = attendee.GetParentGroupNameAndPathHtml();
                }
                else
                {
                    lGroupNameAndPath.Text = lGroupNameAndPath.Text = attendee.GetGroupNameAndPathHtml();
                }
            }

            var lLocation = e.Row.FindControl("lLocation") as Literal;

            lLocation.Text = attendee.RoomName;
        }
Пример #2
0
        /// <summary>
        /// Handles the RowDataBound event of the gAttendees control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gAttendees_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            RosterAttendee attendee = e.Row.DataItem as RosterAttendee;

            // Desktop only.
            var lPhoto = e.Row.FindControl("lPhoto") as Literal;

            lPhoto.Text = attendee.GetPersonPhotoImageHtmlTag();

            // Mobile only.
            var lMobileIcon = e.Row.FindControl("lMobileIcon") as Literal;

            lMobileIcon.Text = attendee.GetStatusIconHtmlTag(true);

            // Shared between desktop and mobile.
            var lName = e.Row.FindControl("lName") as Literal;

            lName.Text = attendee.GetAttendeeNameHtml();

            // Desktop only.
            var lBadges = e.Row.FindControl("lBadges") as Literal;

            lBadges.Text = string.Format("<div>{0}</div>", attendee.GetBadgesHtml(_attributesForAlertIcons));

            // Mobile only.
            var lMobileTagAndSchedules = e.Row.FindControl("lMobileTagAndSchedules") as Literal;

            lMobileTagAndSchedules.Text = attendee.GetMobileTagAndSchedulesHtml();

            // Desktop only.
            var lStatusTag = e.Row.FindControl("lStatusTag") as Literal;

            lStatusTag.Text = attendee.GetStatusIconHtmlTag(false);
        }
Пример #3
0
        /// <summary>
        /// Gets the attendees.
        /// </summary>
        private IList <RosterAttendee> GetAttendees(RockContext rockContext)
        {
            var startDateTime = RockDateTime.Today;

            CampusCache campusCache = GetCampusFromContext();
            DateTime    currentDateTime;

            if (campusCache != null)
            {
                currentDateTime = campusCache.CurrentDateTime;
            }
            else
            {
                currentDateTime = RockDateTime.Now;
            }

            // Get all Attendance records for the current day and location
            var attendanceQuery = new AttendanceService(rockContext).Queryable().Where(a =>
                                                                                       a.StartDateTime >= startDateTime &&
                                                                                       a.DidAttend == true &&
                                                                                       a.StartDateTime <= currentDateTime &&
                                                                                       a.PersonAliasId.HasValue &&
                                                                                       a.Occurrence.GroupId.HasValue &&
                                                                                       a.Occurrence.ScheduleId.HasValue &&
                                                                                       a.Occurrence.LocationId.HasValue &&
                                                                                       a.Occurrence.ScheduleId.HasValue);

            if (campusCache != null)
            {
                // limit locations (rooms) to locations within the selected campus
                var campusLocationIds = new LocationService(rockContext).GetAllDescendentIds(campusCache.LocationId.Value).ToList();
                attendanceQuery = attendanceQuery.Where(a => campusLocationIds.Contains(a.Occurrence.LocationId.Value));
            }

            var selectedScheduleIds = lbSchedules.SelectedValues.AsIntegerList().Where(a => a > 0).ToList();
            var selectedGroupIds    = GetSelectedGroupIds();

            if (selectedScheduleIds.Any())
            {
                attendanceQuery = attendanceQuery.Where(a => selectedScheduleIds.Contains(a.Occurrence.ScheduleId.Value));
            }

            if (selectedGroupIds.Any())
            {
                if (cbIncludeChildGroups.Checked)
                {
                    var groupService = new GroupService(rockContext);
                    foreach (var groupId in selectedGroupIds.ToList())
                    {
                        var childGroupIds = groupService.GetAllDescendentGroupIds(groupId, false);
                        selectedGroupIds.AddRange(childGroupIds);
                    }
                }

                attendanceQuery = attendanceQuery.Where(a => selectedGroupIds.Contains(a.Occurrence.GroupId.Value));
            }
            else
            {
                var checkinAreaFilter = CheckinManagerHelper.GetCheckinAreaFilter(this);

                if (checkinAreaFilter != null)
                {
                    // if there is a checkin area filter, limit to groups within the selected check-in area
                    var checkinAreaGroupTypeIds = new GroupTypeService(rockContext).GetCheckinAreaDescendants(checkinAreaFilter.Id).Select(a => a.Id).ToList();
                    selectedGroupIds = new GroupService(rockContext).Queryable().Where(a => checkinAreaGroupTypeIds.Contains(a.GroupTypeId)).Select(a => a.Id).ToList();
                    attendanceQuery  = attendanceQuery.Where(a => selectedGroupIds.Contains(a.Occurrence.GroupId.Value));
                }
            }

            RosterStatusFilter rosterStatusFilter = this.GetAttributeValue(AttributeKey.FilterBy).ConvertToEnumOrNull <RosterStatusFilter>() ?? RosterStatusFilter.CheckedIn;

            attendanceQuery = CheckinManagerHelper.FilterByRosterStatusFilter(attendanceQuery, rosterStatusFilter);

            var attendanceList = RosterAttendeeAttendance.Select(attendanceQuery).ToList();

            attendanceList = CheckinManagerHelper.FilterByActiveCheckins(currentDateTime, attendanceList);

            attendanceList = attendanceList.Where(a => a.Person != null).ToList();

            if (tbSearch.Text.IsNotNullOrWhiteSpace())
            {
                // search by name
                var searchValue = tbSearch.Text;

                // ignore the result of reversed (LastName, FirstName vs FirstName LastName
                bool reversed;

                var personIds = new PersonService(rockContext)
                                .GetByFullName(searchValue, false, false, false, out reversed)
                                .AsNoTracking()
                                .Select(a => a.Id)
                                .ToList();

                attendanceList = attendanceList.Where(a => personIds.Contains(a.PersonId)).ToList();
            }

            var attendees = RosterAttendee.GetFromAttendanceList(attendanceList);

            return(attendees);
        }
Пример #4
0
        /// <summary>
        /// Adds to room list.
        /// </summary>
        /// <param name="roomList">The room list.</param>
        /// <param name="groupLocation">The group location.</param>
        private void AddToRoomList(List <RoomInfo> roomList, GroupLocationInfo groupLocation)
        {
            Dictionary <int, List <RosterAttendee> > rosterAttendeesForLocationByGroupId = _attendancesByLocationIdAndGroupId
                                                                                           .GetValueOrNull(groupLocation.LocationId)
                                                                                           ?.ToDictionary(k => k.Key, v => RosterAttendee.GetFromAttendanceList(v.Value.ToList()).ToList());

            List <RosterAttendee> rosterAttendeesForLocationAndGroup;

            if (rosterAttendeesForLocationByGroupId != null)
            {
                rosterAttendeesForLocationAndGroup = rosterAttendeesForLocationByGroupId.GetValueOrNull(groupLocation.GroupId);

                if (rosterAttendeesForLocationAndGroup == null)
                {
                    // no attendances for this Location (Room) and Group
                    rosterAttendeesForLocationAndGroup = new List <RosterAttendee>();
                }
            }
            else
            {
                // no attendances for this Location (Room)
                rosterAttendeesForLocationByGroupId = new Dictionary <int, List <RosterAttendee> >();
                rosterAttendeesForLocationAndGroup  = new List <RosterAttendee>();
            }

            var roomCounts = new RoomCounts
            {
                CheckedInList  = rosterAttendeesForLocationAndGroup.Where(a => a.Status == RosterAttendeeStatus.CheckedIn).ToList(),
                PresentList    = rosterAttendeesForLocationAndGroup.Where(a => a.Status == RosterAttendeeStatus.Present).ToList(),
                CheckedOutList = rosterAttendeesForLocationAndGroup.Where(a => a.Status == RosterAttendeeStatus.Present).ToList(),
            };

            if (_showOnlyParentGroup)
            {
                // roll group/location counts into the parent group
                // for example, if the Group Structure is
                // - Babies
                // --- 101 Blue
                // --- 101 Green
                // --- 101 Orange
                // --- 101 Red
                // --- 102 Blue
                // combine each ChildGroup+Location into Babies.
                // also, the grid would be single location per row, instead of location+group per row
                RoomInfoByParentGroups groupInfoByParentGroups = roomList.OfType <RoomInfoByParentGroups>().Where(a => a.LocationId == groupLocation.LocationId).FirstOrDefault();
                if (groupInfoByParentGroups == null)
                {
                    // since we are rolling into ParentGroup, use the ParentGroup/ParentGroupId as the group
                    groupInfoByParentGroups = new RoomInfoByParentGroups
                    {
                        LocationId       = groupLocation.LocationId,
                        LocationName     = groupLocation.LocationName,
                        RoomCounts       = roomCounts,
                        ParentGroupNames = new Dictionary <int, string>(),
                    };

                    roomList.Add(groupInfoByParentGroups);
                }
                else
                {
                    groupInfoByParentGroups.RoomCounts.CheckedInList.AddRange(roomCounts.CheckedInList);
                    groupInfoByParentGroups.RoomCounts.PresentList.AddRange(roomCounts.PresentList);
                    groupInfoByParentGroups.RoomCounts.CheckedOutList.AddRange(roomCounts.CheckedOutList);
                }

                if (groupLocation.ParentGroupId.HasValue)
                {
                    groupInfoByParentGroups.ParentGroupNames.AddOrIgnore(groupLocation.ParentGroupId.Value, groupLocation.ParentGroupName);
                }
            }
            else
            {
                var roomInfoByGroup = new RoomInfoByGroup
                {
                    LocationId   = groupLocation.LocationId,
                    GroupId      = groupLocation.GroupId,
                    GroupName    = groupLocation.GroupName,
                    LocationName = groupLocation.LocationName,
                    RoomCounts   = roomCounts,
                    GroupPath    = new RoomGroupPathInfo
                    {
                        GroupId       = groupLocation.GroupId,
                        GroupName     = groupLocation.GroupName,
                        GroupTypePath = _checkinAreaPathsLookupByGroupTypeId.GetValueOrNull(groupLocation.GroupTypeId)
                    }
                };

                roomList.Add(roomInfoByGroup);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the attendees.
        /// </summary>
        private IList <RosterAttendee> GetAttendees(RockContext rockContext)
        {
            var         startDateTime = RockDateTime.Today;
            CampusCache campusCache   = CampusCache.Get(CurrentCampusId);
            DateTime    currentDateTime;

            if (campusCache != null)
            {
                currentDateTime = campusCache.CurrentDateTime;
            }
            else
            {
                currentDateTime = RockDateTime.Now;
            }

            // Get all Attendance records for the current day
            var attendanceQuery = new AttendanceService(rockContext)
                                  .Queryable()
                                  .Include(a => a.AttendanceCode)
                                  .Include(a => a.PersonAlias.Person)
                                  .Include(a => a.Occurrence.Schedule)
                                  .Include(a => a.Occurrence.Group)
                                  .Include(a => a.Occurrence.Location)
                                  .Where(a =>
                                         a.StartDateTime >= startDateTime &&
                                         a.DidAttend == true &&
                                         a.StartDateTime <= currentDateTime &&
                                         a.PersonAliasId.HasValue &&
                                         a.Occurrence.GroupId.HasValue &&
                                         a.Occurrence.ScheduleId.HasValue &&
                                         a.Occurrence.LocationId.HasValue);

            attendanceQuery = attendanceQuery.Where(a => a.DidAttend == true);

            // Do the person search
            var        personService = new PersonService(rockContext);
            List <int> personIds     = null;

            // ignore the result of reversed (LastName, FirstName vs FirstName LastName
            bool reversed = false;

            string searchValue = tbSearch.Text.Trim();

            if (searchValue.IsNullOrWhiteSpace())
            {
                personIds = new List <int>();
            }
            else
            {
                // If searching by code is enabled, first search by the code
                if (GetAttributeValue(AttributeKey.SearchByCode).AsBoolean())
                {
                    var dayStart = RockDateTime.Today;
                    personIds = new AttendanceService(rockContext)
                                .Queryable().Where(a =>
                                                   a.StartDateTime >= dayStart &&
                                                   a.StartDateTime <= currentDateTime &&
                                                   a.AttendanceCode.Code == searchValue)
                                .Select(a => a.PersonAlias.PersonId)
                                .Distinct().ToList();
                }

                if (personIds == null || !personIds.Any())
                {
                    // If searching by code was disabled or nobody was found with code, search by name
                    personIds = personService
                                .GetByFullName(searchValue, false, false, false, out reversed)
                                .AsNoTracking()
                                .Select(a => a.Id)
                                .ToList();
                }
            }

            IList <RosterAttendee> attendees;

            if (personIds.Any())
            {
                // Get *all* of today's transactions.
                // Not sure why we aren't filtering by PersonIds yet, but
                // it could be to make performance more consistent in case the PersonQuery is complex.
                var attendanceQueryList = RosterAttendeeAttendance.Select(attendanceQuery).ToList();

                // join (in memory) matching person ids and attendances
                var peopleAttendances = personIds
                                        .GroupJoin(
                    attendanceQueryList,
                    pId => pId,
                    a => a.PersonId,
                    (p, a) => a)
                                        .SelectMany(a => a)
                                        .Distinct()
                                        .ToList();

                attendees = RosterAttendee.GetFromAttendanceList(peopleAttendances);
            }
            else
            {
                // no matching persons, so return empty list
                attendees = new List <RosterAttendee>();
            }

            return(attendees);
        }