Skip to content

Commit

Permalink
+ GroupFinder and GroupRegistration now honor a group's GroupCapacity…
Browse files Browse the repository at this point in the history
… and GroupTypeRole.MaxCount (Fixes #1275).
  • Loading branch information
tcavaletto committed Aug 3, 2016
1 parent 85b6463 commit 66b7b80
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
18 changes: 17 additions & 1 deletion RockWeb/Blocks/Groups/GroupFinder.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace RockWeb.Blocks.Groups
[GroupTypeField( "Geofenced Group Type", "", false, "", "CustomSetting" )]
[TextField( "ScheduleFilters", "", false, "", "CustomSetting" )]
[BooleanField( "Display Campus Filter", "", false, "CustomSetting" )]
[BooleanField( "Enable Campus Context", "", false , "CustomSetting" )]
[BooleanField( "Enable Campus Context", "", false, "CustomSetting" )]
[BooleanField( "Hide Overcapacity Groups", "When set to true, groups that are at capacity or whose default GroupTypeRole are at capacity are hidden.", true )]
[AttributeField( Rock.SystemGuid.EntityType.GROUP, "Attribute Filters", "", false, true, "", "CustomSetting" )]

// Map Settings
Expand Down Expand Up @@ -844,6 +845,21 @@ private void ShowResults()
}
}

// This hides the groups that are at or over capacity by doing two things:
// 1) If the group has a GroupCapacity, check that we haven't met or exceeded that.
// 2) When someone registers for a group on the front-end website, they automatically get added with the group's default
// GroupTypeRole. If that role exists and has a MaxCount, check that we haven't met or exceeded it yet.
if ( GetAttributeValue( "HideOvercapacityGroups" ).AsBoolean() )
{
groupQry = groupQry.Where( g => g.GroupCapacity == null || g.Members.Count() < g.GroupCapacity );

groupQry = groupQry.Where( g =>
g.GroupType == null ||
g.GroupType.DefaultGroupRole == null ||
g.GroupType.DefaultGroupRole.MaxCount == null ||
g.Members.Where( m => m.GroupRoleId == g.GroupType.DefaultGroupRole.Id ).Count() < g.GroupType.DefaultGroupRole.MaxCount );
}

// Filter query by any configured attribute filters
if ( AttributeFilters != null && AttributeFilters.Any() )
{
Expand Down
1 change: 1 addition & 0 deletions RockWeb/Blocks/Groups/GroupRegistration.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<ContentTemplate>

<Rock:NotificationBox ID="nbNotice" runat="server" Visible="false" NotificationBoxType="Danger"/>
<Rock:NotificationBox ID="nbWarning" runat="server" Visible="false" NotificationBoxType="Warning" />

<asp:Panel ID="pnlView" runat="server">

Expand Down
44 changes: 44 additions & 0 deletions RockWeb/Blocks/Groups/GroupRegistration.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace RockWeb.Blocks.Groups
", "", 8 )]
[CustomRadioListField( "Auto Fill Form", "If set to FALSE then the form will not load the context of the logged in user (default: 'True'.)", "true^True,false^False", true, "true", "", 9 )]
[TextField( "Register Button Alt Text", "Alternate text to use for the Register button (default is 'Register').", false, "", "", 10 )]
[BooleanField( "Prevent Overcapacity Registrations", "When set to true, user cannot register for groups that are at capacity or whose default GroupTypeRole are at capacity. If only one spot is available, no spouses can be registered.", true, "", 11 )]
public partial class GroupRegistration : RockBlock
{
#region Fields
Expand Down Expand Up @@ -494,6 +495,49 @@ private void ShowDetails()
}
}
}

if ( GetAttributeValue( "PreventOvercapacityRegistrations" ).AsBoolean() )
{
int openGroupSpots = 2;
int openRoleSpots = 2;

// If the group has a GroupCapacity, check how far we are from hitting that.
if ( _group.GroupCapacity.HasValue )
{
openGroupSpots = _group.GroupCapacity.Value - _group.Members.Count();
}

// When someone registers for a group on the front-end website, they automatically get added with the group's default
// GroupTypeRole. If that role exists and has a MaxCount, check how far we are from hitting that.
if ( _defaultGroupRole != null && _defaultGroupRole.MaxCount.HasValue )
{
openRoleSpots = _defaultGroupRole.MaxCount.Value - _group.Members.Where( m => m.GroupRoleId == _defaultGroupRole.Id ).Count();
}

// Between the group's GroupCapacity and DefaultGroupRole.MaxCount, grab the one we're closest to hitting, and how close we are to
// hitting it.
int openSpots = Math.Min( openGroupSpots, openRoleSpots );

// If there's only one spot open, disable the spouse fields and display a warning message.
if ( openSpots == 1 )
{
tbSpouseFirstName.Enabled = false;
tbSpouseLastName.Enabled = false;
pnSpouseCell.Enabled = false;
cbSpouseSms.Enabled = false;
tbSpouseEmail.Enabled = false;
nbWarning.Text = "This group is near its capacity. Only one individual can register.";
nbWarning.Visible = true;
}

// If no spots are open, display a message that says so.
if ( openSpots <= 0 )
{
nbNotice.Text = "This group is at or exceeds capacity.";
nbNotice.Visible = true;
pnlView.Visible = false;
}
}
}
}

Expand Down

0 comments on commit 66b7b80

Please sign in to comment.