Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion force-app/main/default/classes/SummitEventsReadShared.cls
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public without sharing class SummitEventsReadShared {
return new Map<Id, Summit_Events_Appointment_Type__c>([
SELECT Id, Name, Title__c, Description__c, Appointment_Type__c, Appointment_Category__c, Appointment_Limits__c, Chosen_State__c,
Registrant_Input__c, Custom_Picklist__c, Sort_Order__c, Auto_Confirm_Appointment__c, Auto_add_building__c, Auto_Add_Time__c, Do_Not_Show_Time__c,
Date_Available_Start__c, Date_Available_End__c, Day_of_Week_Availability__c, Required_Appointment__c, Appointment_Type_Status__c
Date_Available_Start__c, Date_Available_End__c, Day_of_Week_Availability__c, Required_Appointment__c, Appointment_Type_Status__c,
Enforce_Registrations_Limit__c, Appointment_Registrations_Limit__c
FROM Summit_Events_Appointment_Type__c
WHERE Summit_Events__c = :eventId
AND (Restrict_To_Instance_Title__r.Instance_Title__c = :instanceTitle OR Restrict_To_Instance_Title__r.Instance_Title__c = NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public with sharing class SummitEventsRegisterAppointmentCtlr {
//Build available appointments
appointments = SummitEventsREadShared.getAppointmentTypesByEventId(eventInformation.eventId, evtInstance.Instance_Title__c, evtInstance.Instance_Start_Date__c, evtInstance.Instance_End_Date__c, dayOfWeek);

removeAppointmentsWithExceedingRegistrationLimit(appointments, evtInstance);

formattedNavDate = SummitEventsShared.navBreadcrumbBuilder(evtInstance);

//Check if the user gets to select any appointments or they are all auto added
Expand Down Expand Up @@ -224,6 +226,33 @@ public with sharing class SummitEventsRegisterAppointmentCtlr {
return pageFlow.get('Previous');
}

private static void removeAppointmentsWithExceedingRegistrationLimit(Map<Id, Summit_Events_Appointment_Type__c> appointments, Summit_Events_Instance__c evtInstance){
AggregateResult[] eventAppointmentCounts = [
SELECT Count(Id) aCount, Event_Appointment_Type__c
FROM Summit_Events_Appointments__c
WHERE Event_Appointment_Type__r.Enforce_Registrations_Limit__c = TRUE
AND Event_Registration__r.Event_Instance__c =: evtInstance.Id
GROUP BY Event_Appointment_Type__c
];

Map<Id, Integer> appointmentTypeIdMapToCount = new Map<Id, Integer>();
for (AggregateResult ar : eventAppointmentCounts) {
appointmentTypeIdMapToCount.put((Id) ar.get('Event_Appointment_Type__c'), (Integer) ar.get('aCount'));
}

List<Id> unavailableAppointments = new List<Id>();
for(Summit_Events_Appointment_Type__c apt : appointments.values()){
if(apt.Enforce_Registrations_Limit__c && appointmentTypeIdMapToCount.containsKey(apt.Id)){
if(appointmentTypeIdMapToCount.get(apt.Id) >= apt.Appointment_Registrations_Limit__c){
unavailableAppointments.add(apt.Id);
}
}
}
for(Id unavailableAppointmentId : unavailableAppointments){
appointments.remove(unavailableAppointmentId);
}
}

/**
* Summit Events is a multi-step, guest user, registration solution so CRUD work needs to be done on records where guest record ownership is lost between steps.
* The security aspects of guest record updating is achieved by:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
<behavior>Required</behavior>
<field>Title__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Appointment_Registrations_Limit__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Enforce_Registrations_Limit__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Appointment_Registrations_Limit__c</fullName>
<defaultValue>9999</defaultValue>
<externalId>false</externalId>
<label>Appointment Registrations Limit</label>
<precision>18</precision>
<required>false</required>
<scale>0</scale>
<trackTrending>false</trackTrending>
<type>Number</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Enforce_Registrations_Limit__c</fullName>
<defaultValue>false</defaultValue>
<label>Enforce Registrations Limit</label>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
<field>Summit_Events_Appointment_Type__c.Appointment_Limits__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Summit_Events_Appointment_Type__c.Appointment_Registrations_Limit__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Summit_Events_Appointment_Type__c.Appointment_Type__c</field>
Expand Down Expand Up @@ -142,6 +147,11 @@
<field>Summit_Events_Appointment_Type__c.Do_Not_Show_Time__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Summit_Events_Appointment_Type__c.Enforce_Registrations_Limit__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Summit_Events_Appointment_Type__c.Registrant_Input__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
<field>Summit_Events_Appointment_Type__c.Required_Appointment__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Summit_Events_Appointment_Type__c.Enforce_Registrations_Limit__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Summit_Events_Appointment_Type__c.Appointment_Registrations_Limit__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Summit_Events_Appointment_Type__c.Restrict_To_Instance_Title__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ private class SummitEventsRegisterAppointment_TEST {
List<Summit_Events_Instance__c> seaTestInstances = SummitEventsTestSharedDataFactory.createTestEvent();
Summit_Events_Registration__c seaTestRegistration = SummitEventsTestSharedDataFactory.createEventRegistration(seaTestInstances[1], 'TestFirst', 'TestLast', 'test@valleyhill.net', '55418', '1971-03-22', '2012', null);
List<Summit_Events_Appointment_Type__c> testAppointmentTypes = SummitEventsTestSharedDataFactory.createAppointmentTypes(seaTestInstances[1].Event__c);
Summit_Events_Appointment_Type__c limitedAppointType = testAppointmentTypes[0];
limitedAppointType.Appointment_Registrations_Limit__c = 1;
limitedAppointType.Enforce_Registrations_Limit__c = true;
update limitedAppointType;

User testUser = SummitEventsTestSharedDataFactory.userToRunWith('Standard User', 'Summit_Events_Registrant');

Expand Down Expand Up @@ -70,6 +74,7 @@ private class SummitEventsRegisterAppointment_TEST {
//run constructor again to simulate page load after save
seaTestRegistration.UG_Event_Appointments__r.add(new Summit_Events_Appointments__c(Client_Created_Appointment__c = true));
optionsCtrl = new SummitEventsRegisterAppointmentCtlr();
System.assertEquals(optionsCtrl.appointments.size(), 4);
Test.stopTest();
}
}
Expand Down