/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { return(false); } var family = checkInState.CheckIn.Families.FirstOrDefault(f => f.Selected); if (family != null) { foreach (var person in family.People.Where(f => f.Selected && !f.FirstTime).ToList()) { if (person.LastCheckIn != null) { var groupType = person.GroupTypes.FirstOrDefault(gt => gt.Selected || gt.LastCheckIn == person.LastCheckIn); if (groupType != null) { groupType.PreSelected = true; groupType.Selected = true; var group = groupType.Groups.FirstOrDefault(g => g.Selected || g.LastCheckIn == person.LastCheckIn); if (group != null) { group.PreSelected = true; group.Selected = true; var location = group.Locations.FirstOrDefault(l => l.Selected || l.LastCheckIn == person.LastCheckIn); if (location != null) { location.PreSelected = true; location.Selected = true; var schedule = location.Schedules.FirstOrDefault(s => s.Selected || s.LastCheckIn == person.LastCheckIn); if (schedule != null) { schedule.PreSelected = true; schedule.Selected = true; } } } } } } } return(true); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState == null) { return(false); } var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var remove = GetAttributeValue(action, "Remove").AsBoolean(); foreach (var person in family.People) { FilterGroups(person, rockContext, remove); } } return(true); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { //This is an optimization over standard Rock //Core Rock has this inside the loop. Reading all the iCals is slow. var activeKioskGroupTypes = new List <KioskGroupType>(); foreach (var kioskGroupType in checkInState.Kiosk.ActiveGroupTypes(checkInState.ConfiguredGroupTypes)) { if (kioskGroupType.KioskGroups.SelectMany(g => g.KioskLocations).Any(l => l.IsCheckInActive && l.Location.IsActive)) { activeKioskGroupTypes.Add(kioskGroupType); } } foreach (var family in checkInState.CheckIn.GetFamilies(true)) { foreach (var person in family.People) { foreach (var kioskGroupType in activeKioskGroupTypes) { if (!person.GroupTypes.Any(g => g.GroupType.Id == kioskGroupType.GroupType.Id)) { var checkinGroupType = new CheckInGroupType(); checkinGroupType.GroupType = kioskGroupType.GroupType; person.GroupTypes.Add(checkinGroupType); } } } } return(true); } errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState == null) { errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); } var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var remove = GetAttributeValue(action, "Remove").AsBoolean(); foreach (var person in family.People) { FilterGroups(person, rockContext, remove); } } return(true); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState == null) { throw new Exception("Check-In state lost: Filter Groups By Birthday"); } var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var remove = GetAttributeValue(action, "Remove").AsBoolean(); bool ageRequired = checkInState.CheckInType == null || checkInState.CheckInType.AgeRequired; // get the admin-selected attribute key instead of using a hardcoded key var birthdayRangeAttributeKey = string.Empty; var birthdayRangeAttributeGuid = GetAttributeValue(action, "GroupBirthdayRangeAttribute").AsGuid(); if (birthdayRangeAttributeGuid != Guid.Empty) { birthdayRangeAttributeKey = AttributeCache.Read(birthdayRangeAttributeGuid, rockContext).Key; } // log a warning if the attribute is missing or invalid if (string.IsNullOrWhiteSpace(birthdayRangeAttributeKey)) { throw new Exception("Workflow attribute not set: Filter Groups By Birthday | Birthday Range Attribute"); } var filterGradeSchoolGuid = GetAttributeValue(action, "GroupFilterGradeSchoolAttribute").AsGuid(); if (filterGradeSchoolGuid == Guid.Empty) { throw new Exception("Workflow attribute not set: Filter Groups By Birthday | Filter GradeSchool Students"); } string filterGradeSchoolKey = AttributeCache.Read(filterGradeSchoolGuid, rockContext).Key; if (string.IsNullOrWhiteSpace(filterGradeSchoolKey)) { throw new Exception("Workflow attribute not set: Filter Groups By Birthday | Filter GradeSchool Students"); } foreach (var person in family.People) { if (person.Person.BirthDate == null && !ageRequired) { continue; } foreach (var groupType in person.GroupTypes.ToList()) { foreach (var group in groupType.Groups.ToList()) { if (person.Person.BirthDate == null) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } var birthdayRange = group.Group.GetAttributeValue(birthdayRangeAttributeKey); if (string.IsNullOrWhiteSpace(birthdayRange)) { continue; } var dateRangePair = birthdayRange.Split(new char[] { ',' }, StringSplitOptions.None); DateTime?minDate = null; DateTime?maxDate = null; if (dateRangePair.Length == 2) { minDate = dateRangePair[0].AsDateTime(); maxDate = dateRangePair[1].AsDateTime(); } if (minDate != null) { if (person.Person.BirthDate < minDate) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } } if (maxDate != null) { if (person.Person.BirthDate > maxDate) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } } //Filter kids out who are in school if (group.Group.GetAttributeValue(filterGradeSchoolKey).AsBoolean()) { if (person.Person.GradeOffset != null && person.Person.GradeOffset < 13 && person.Person.GradeOffset >= 0) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } } } } } } return(true); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState == null) { errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); } var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var remove = GetAttributeValue(action, "Remove").AsBoolean(); bool gradeRequired = checkInState.CheckInType == null || checkInState.CheckInType.GradeRequired; foreach (var person in family.People) { if (person.Person.GraduationYear == null && !gradeRequired) { continue; } foreach (var groupType in person.GroupTypes.ToList()) { int?personsGradeOffset = person.Person.GraduationYear - CurrentGraduationYear(groupType.GroupType); foreach (var group in groupType.Groups.ToList()) { string gradeOffsetRange = group.Group.GetAttributeValue("GradeRange") ?? string.Empty; var gradeOffsetRangePair = gradeOffsetRange.Split(new char[] { ',' }, StringSplitOptions.None).AsGuidOrNullList().ToArray(); DefinedValueCache minGradeDefinedValue = null; DefinedValueCache maxGradeDefinedValue = null; if (gradeOffsetRangePair.Length == 2) { minGradeDefinedValue = gradeOffsetRangePair[0].HasValue ? DefinedValueCache.Get(gradeOffsetRangePair[0].Value) : null; maxGradeDefinedValue = gradeOffsetRangePair[1].HasValue ? DefinedValueCache.Get(gradeOffsetRangePair[1].Value) : null; } /* * example (assuming defined values are the stock values): * minGrade,maxGrade of between 4th and 6th grade * 4th grade is 8 years until graduation * 6th grade is 6 years until graduation * GradeOffsetRange would be 8 and 6 * if person is in: * 7th grade or older (gradeOffset 5 or smaller), they would be NOT included * 6th grade (gradeOffset 6), they would be included * 5th grade (gradeOffset 7), they would be included * 4th grade (gradeOffset 8), they would be included * 3th grade or younger (gradeOffset 9 or bigger), they would be NOT included * NULL grade, not included */ // if the group type specifies a min grade (max gradeOffset)... if (maxGradeDefinedValue != null) { // NOTE: minGradeOffset is actually based on the MAX Grade since GradeOffset's are Years Until Graduation int?minGradeOffset = maxGradeDefinedValue.Value.AsIntegerOrNull(); if (minGradeOffset.HasValue) { // remove if the person does not have a grade or if their grade offset is more than the max offset (too young) // example person is in 3rd grade (offset 9) and range is 4th to 6th (offset 6 to 8) if (!personsGradeOffset.HasValue || personsGradeOffset < minGradeOffset.Value) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } } } // if the group type specifies a max grade (min gradeOffset)... if (minGradeDefinedValue != null) { // NOTE: maxGradeOffset is actually based on the MIN Grade since GradeOffset's are Years Until Graduation int?maxGradeOffset = minGradeDefinedValue.Value.AsIntegerOrNull(); if (maxGradeOffset.HasValue) { // remove if the person does not have a grade or if their grade offset is less than the min offset (too old) // example person is in 7rd grade (offset 5) and range is 4th to 6th (offset 6 to 8) if (!personsGradeOffset.HasValue || personsGradeOffset > maxGradeOffset) { if (remove) { groupType.Groups.Remove(group); } else { group.ExcludedByFilter = true; } continue; } } } } } } } return(true); }