Skip to content

Commit

Permalink
+ Fixed an issue with check-in when using the people/group/location a…
Browse files Browse the repository at this point in the history
…uto check-in option that would allow people to check-in again to same service even though option was selected to prevent this. (Fixes #2478)
  • Loading branch information
azturner committed Dec 14, 2017
1 parent 7574dc9 commit d5c19a7
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 104 deletions.
13 changes: 8 additions & 5 deletions Rock/CheckIn/CheckInPerson.cs
Expand Up @@ -216,15 +216,18 @@ public List<CheckInPersonSummary> GetOptions( bool onlyPreSelected, bool onlyOne

foreach ( var possibleSchedule in PossibleSchedules )
{
foreach ( var groupType in GroupTypes.Where( t => t.PreSelected || !onlyPreSelected ) )
var scheduleId = possibleSchedule.Schedule.Id;

foreach ( var groupType in GroupTypes.Where( t => t.AvailableForSchedule.Contains( scheduleId ) && ( t.PreSelected || !onlyPreSelected ) ) )
{
foreach ( var group in groupType.Groups.Where( t => t.PreSelected || !onlyPreSelected ) )
foreach ( var group in groupType.Groups.Where( t => t.AvailableForSchedule.Contains( scheduleId ) && ( t.PreSelected || !onlyPreSelected ) ) )
{
foreach ( var location in group.Locations.Where( t => t.PreSelected || !onlyPreSelected ) )
foreach ( var location in group.Locations.Where( t => t.AvailableForSchedule.Contains( scheduleId ) && ( t.PreSelected || !onlyPreSelected ) ) )
{
foreach ( var schedule in location.Schedules.Where( s => s.Schedule.Id == possibleSchedule.Schedule.Id && ( s.PreSelected || !onlyPreSelected ) ) )
foreach ( var schedule in location.Schedules.Where( s => s.Schedule.Id == scheduleId && ( s.PreSelected || !onlyPreSelected ) ) )
{
if ( !onlyOneOptionPerSchedule || !options.Any( o => o.Schedule.Schedule.Id == schedule.Schedule.Id ) )
if ( location.AvailableForSchedule.Contains( schedule.Schedule.Id ) &&
( !onlyOneOptionPerSchedule || !options.Any( o => o.Schedule.Schedule.Id == schedule.Schedule.Id ) ) )
{
options.Add( new CheckInPersonSummary( schedule, groupType, group, location ) );
}
Expand Down
146 changes: 84 additions & 62 deletions Rock/Workflow/Action/CheckIn/FilterByPreviousCheckin.cs
Expand Up @@ -53,97 +53,119 @@ public override bool Execute( RockContext rockContext, Model.WorkflowAction acti
if ( checkInState != null && checkInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Family )
{
bool configPrevents = checkInState.CheckInType.PreventDuplicateCheckin;

var family = checkInState.CheckIn.CurrentFamily;
return FilterByPreviousCheckin.ProcessForFamily( rockContext, family, configPrevents );
}

if ( family != null )
{
var remove = GetAttributeValue( action, "Remove" ).AsBoolean();
return false;
}

var personIds = family.People.Select( p => p.Person.Id ).ToList();
var today = RockDateTime.Today;
var tomorrow = RockDateTime.Today.AddDays( 1 );
/// <summary>
/// Processes this action for a check-in family.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="family">The family.</param>
/// <param name="preventDuplicateCheckin">if set to <c>true</c> [prevent duplicate checkin].</param>
/// <returns></returns>
public static bool ProcessForFamily( RockContext rockContext, CheckInFamily family, bool preventDuplicateCheckin )
{
if ( family != null )
{
var personIds = family.People.Select( p => p.Person.Id ).ToList();
var today = RockDateTime.Today;
var tomorrow = RockDateTime.Today.AddDays( 1 );

var existingAttendance = new AttendanceService( rockContext )
.Queryable().AsNoTracking()
.Where( a =>
a.StartDateTime.CompareTo( today ) >= 0 &&
a.StartDateTime.CompareTo( tomorrow ) < 0 &&
a.DidAttend.HasValue &&
a.DidAttend.Value &&
a.PersonAlias != null &&
personIds.Contains( a.PersonAlias.PersonId ) &&
a.ScheduleId.HasValue )
.Select( a => new
{
PersonId = a.PersonAlias.PersonId,
ScheduleId = a.ScheduleId.Value
} )
.ToList();
var existingAttendance = new AttendanceService( rockContext )
.Queryable().AsNoTracking()
.Where( a =>
a.StartDateTime.CompareTo( today ) >= 0 &&
a.StartDateTime.CompareTo( tomorrow ) < 0 &&
a.DidAttend.HasValue &&
a.DidAttend.Value &&
!a.EndDateTime.HasValue &&
a.PersonAlias != null &&
personIds.Contains( a.PersonAlias.PersonId ) &&
a.ScheduleId.HasValue )
.Select( a => new
{
PersonId = a.PersonAlias.PersonId,
ScheduleId = a.ScheduleId.Value
} )
.ToList();

if ( existingAttendance.Any() )
if ( existingAttendance.Any() )
{
foreach ( var person in family.People.ToList() )
{
foreach ( var person in family.People.ToList() )
var attendedScheduleIds = existingAttendance.Where( a => a.PersonId == person.Person.Id ).Select( a => a.ScheduleId ).ToList();
if ( attendedScheduleIds.Any() )
{
var attendedScheduleIds = existingAttendance.Where( a => a.PersonId == person.Person.Id ).Select( a => a.ScheduleId ).ToList();
if ( attendedScheduleIds.Any() )
foreach ( var groupType in person.GroupTypes.ToList() )
{
foreach ( var groupType in person.GroupTypes.ToList() )
if ( preventDuplicateCheckin || groupType.GroupType.GetAttributeValue( "PreventDuplicateCheckin" ).AsBoolean() )
{
if ( configPrevents || groupType.GroupType.GetAttributeValue( "PreventDuplicateCheckin" ).AsBoolean() )
{
attendedScheduleIds.ForEach( s => groupType.AvailableForSchedule.Remove( s ) );
attendedScheduleIds.ForEach( s => groupType.AvailableForSchedule.Remove( s ) );

if ( !groupType.AvailableForSchedule.Any() )
{
person.GroupTypes.Remove( groupType );
}
else
if ( !groupType.AvailableForSchedule.Any() )
{
person.GroupTypes.Remove( groupType );
}
else
{
foreach ( var group in groupType.Groups.ToList() )
{
foreach ( var group in groupType.Groups.ToList() )
attendedScheduleIds.ForEach( s => group.AvailableForSchedule.Remove( s ) );
if ( !group.AvailableForSchedule.Any() )
{
attendedScheduleIds.ForEach( s => group.AvailableForSchedule.Remove( s ) );
if ( !group.AvailableForSchedule.Any() )
{
groupType.Groups.Remove( group );
}
else
groupType.Groups.Remove( group );
}
else
{
foreach ( var location in group.Locations.ToList() )
{
foreach ( var location in group.Locations.ToList() )
attendedScheduleIds.ForEach( s => location.AvailableForSchedule.Remove( s ) );
if ( !location.AvailableForSchedule.Any() )
{
attendedScheduleIds.ForEach( s => location.AvailableForSchedule.Remove( s ) );
if ( !location.AvailableForSchedule.Any() )
{
group.Locations.Remove( location );
}
group.Locations.Remove( location );
}
if ( group.Locations.Count == 0 )
else
{
groupType.Groups.Remove( group );
foreach ( var schedule in location.Schedules )
{
if ( schedule.PreSelected && !location.AvailableForSchedule.Contains( schedule.Schedule.Id ) )
{
schedule.PreSelected = false;
location.PreSelected = false;
group.PreSelected = false;
groupType.PreSelected = false;
}
}
}
}
if ( group.Locations.Count == 0 )
{
groupType.Groups.Remove( group );
}
}
if ( groupType.Groups.Count == 0 )
{
person.GroupTypes.Remove( groupType );
}
}
if ( groupType.Groups.Count == 0 )
{
person.GroupTypes.Remove( groupType );
}
}
}
}

if ( person.GroupTypes.Count == 0 )
{
family.People.Remove( person );
}
if ( person.GroupTypes.Count == 0 )
{
family.People.Remove( person );
}
}
}
}

return true;
}

return false;
return true;
}
}
}
59 changes: 33 additions & 26 deletions Rock/Workflow/Action/CheckIn/SetAvailableSchedules.cs
Expand Up @@ -50,48 +50,55 @@ public override bool Execute( RockContext rockContext, Model.WorkflowAction acti
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null )
{
var family = checkInState.CheckIn.CurrentFamily;
if ( family != null )
{
var remove = GetAttributeValue( action, "Remove" ).AsBoolean();
ProcessForFamily( rockContext, checkInState.CheckIn.CurrentFamily );
return true;
}

foreach ( var person in family.People )
return false;
}

/// <summary>
/// Processes this action for a check-in family.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="family">The family.</param>
public static void ProcessForFamily( RockContext rockContext, CheckInFamily family )
{
if ( family != null )
{
foreach ( var person in family.People )
{
foreach ( var groupType in person.GroupTypes )
{
foreach ( var groupType in person.GroupTypes )
foreach ( var group in groupType.Groups )
{
foreach ( var group in groupType.Groups )
foreach ( var location in group.Locations )
{
foreach ( var location in group.Locations )
{
location.AvailableForSchedule =
location.Schedules
.Where( s => !s.ExcludedByFilter )
.Select( s => s.Schedule.Id )
.ToList();
}

group.AvailableForSchedule =
group.Locations
.Where( l => !l.ExcludedByFilter )
.SelectMany( l => l.AvailableForSchedule )
.Distinct()
location.AvailableForSchedule =
location.Schedules
.Where( s => !s.ExcludedByFilter )
.Select( s => s.Schedule.Id )
.ToList();
}

groupType.AvailableForSchedule =
groupType.Groups
group.AvailableForSchedule =
group.Locations
.Where( l => !l.ExcludedByFilter )
.SelectMany( l => l.AvailableForSchedule )
.Distinct()
.ToList();
}

groupType.AvailableForSchedule =
groupType.Groups
.Where( l => !l.ExcludedByFilter )
.SelectMany( l => l.AvailableForSchedule )
.Distinct()
.ToList();
}
}

return true;
}

return false;
}

}
Expand Down

0 comments on commit d5c19a7

Please sign in to comment.