Skip to content

Commit

Permalink
+ (Check-in) Fixed reprint labels with check-in by phone number so th…
Browse files Browse the repository at this point in the history
…at people with the “can check-in" relationship appear. (Fixes #5096)
  • Loading branch information
melzs0627 committed Apr 11, 2023
1 parent e6ff1b9 commit 59dae11
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions RockWeb/Blocks/CheckIn/Welcome.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,82 @@ private IQueryable<int> PhoneSearch( string numericPhone )
.Select( p => p.PersonId )
.Distinct();

var peopleCheckInIds = RetrievePeopleCanCheckIn( personIds.ToList(), rockContext );

personIds = personIds.AsQueryable().Concat( peopleCheckInIds );

return personIds;
}

private IQueryable<int> RetrievePeopleCanCheckIn(List<int> familyMemberIds, RockContext rockContext)
{
IQueryable<int> personIds = null;

var roles = GetRoles( rockContext );
var groupMemberService = new GroupMemberService( rockContext );

var knownRelationshipGroupType = GroupTypeCache.Get( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid() );
if ( knownRelationshipGroupType != null )
{
var ownerRole = knownRelationshipGroupType.Roles.FirstOrDefault( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() );
if ( ownerRole != null )
{
// Get the Known Relationship group id's for each person in the family
var relationshipGroupIds = groupMemberService
.Queryable().AsNoTracking()
.Where( g =>
g.GroupRoleId == ownerRole.Id &&
familyMemberIds.Contains( g.PersonId ) )
.Select( g => g.GroupId );

personIds = groupMemberService
.Queryable().AsNoTracking()
.Where( g =>
relationshipGroupIds.Contains( g.GroupId ) &&
roles.Contains( g.GroupRoleId ) )
.Select( g => g.PersonId );
}
}

return personIds;
}

/// <summary>
/// Gets the roles.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
private static List<int> GetRoles( RockContext rockContext )
{
string cacheKey = "Rock.FindRelationships.Roles";

List<int> roles = RockCache.Get( cacheKey ) as List<int>;

if ( roles == null )
{
roles = new List<int>();

foreach ( var role in new GroupTypeRoleService( rockContext )
.Queryable().AsNoTracking()
.Where( r => r.GroupType.Guid.Equals( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS ) ) ) )
{
role.LoadAttributes( rockContext );
if ( role.Attributes.ContainsKey( "CanCheckin" ) )
{
bool canCheckIn = false;
if ( bool.TryParse( role.GetAttributeValue( "CanCheckin" ), out canCheckIn ) && canCheckIn )
{
roles.Add( role.Id );
}
}
}

RockCache.AddOrUpdate( cacheKey, null, roles, RockDateTime.Now.AddSeconds( 300 ) );
}

return roles;
}

#endregion

/// <summary>
Expand Down

0 comments on commit 59dae11

Please sign in to comment.