Skip to content

Commit

Permalink
Merge pull request #10 from jonsayer/master
Browse files Browse the repository at this point in the history
changes up to 7/12/2019
  • Loading branch information
Patti501 authored Jul 17, 2019
2 parents 9d6b3ed + 349ee08 commit 0283117
Show file tree
Hide file tree
Showing 11 changed files with 516 additions and 129 deletions.
161 changes: 150 additions & 11 deletions src/classes/C501_CTRL_ClassReg_CreateAcct.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class C501_CTRL_ClassReg_CreateAcct {
public ID loginID {get; set;}
public String schoolName {get; set;}
public Account schoolNameText {get; set;}
public Boolean dontKnowId {get; set;}
public Boolean noAllergies {get; set;}

public String schoolRegion {
get{
if(schoolRegion == null){
Expand All @@ -22,9 +25,12 @@ public class C501_CTRL_ClassReg_CreateAcct {
public School_Term__c term {get; set;}
public String grade {get; set;}
public Boolean noState {get; set;}
public Boolean needPickup {get; set;}
public Boolean noSchool {get; set;}
public Boolean noGrade {get; set;}
public Boolean noWaiver {get; set;}
public Boolean noStuID {get; set;}
public Boolean noAllergyResp {get; set;}
private String RegType {get; set;}

public List<SelectOption> schoolList {
Expand Down Expand Up @@ -103,6 +109,10 @@ public class C501_CTRL_ClassReg_CreateAcct {
noSchool = false;
noGrade = false;
noWaiver = false;
dontKnowId = false;
noStuID = false;
noAllergyResp = false;
needPickup = false;

Map<String, Schema.FieldSet> FsAcctMap = Schema.SObjectType.Account.fieldSets.getMap();
Map<String, Schema.FieldSet> FsContMap = Schema.SObjectType.Contact.fieldSets.getMap();
Expand Down Expand Up @@ -198,10 +208,36 @@ public class C501_CTRL_ClassReg_CreateAcct {
} else {
noGrade = false;
}

if(term.Student_School_ID__c == null && dontKnowId == false){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_RegSite_ProvideStudentId ) );
noStuId = true;
passValidation = false;
} else {
noStuId = false;
}

if(child.Allergies__c == null && noAllergies == false){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_RegSite_NoAllergiesError ) );
noAllergyResp = true;
passValidation = false;
} else {
noAllergyResp = false;
}

if(child.Student_Transportation__c == 'Will receive a ride' && (child.Authorized_Pickup_1_Name__c == null || child.Authorized_Pickup_1_Phone__c == null || child.Authorized_Pickup_1_Relationship__c == null ) ){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_RegSite_PickUpChildError ) );
needPickup = true;
passValidation = false;
} else {
needPickup = false;
}

if( parent.Email == null && parent.HomePhone == null && parent.MobilePhone == null && parent.OtherPhone == null ){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_RegSite_ParentContactRequired) );
passValidation = false;
}

if(term.Waiver__c == false){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_ClassReg_WaiverRequired) );
noWaiver = true;
Expand All @@ -210,6 +246,96 @@ public class C501_CTRL_ClassReg_CreateAcct {
noWaiver = false;
}

Boolean phoneFail = false;

// Phone number validation
if(parent.MobilePhone != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(parent.MobilePhone);
if(NAformat != null){
parent.MobilePhone = NAformat;
} else {
phoneFail = true;
parent.MobilePhone.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(parent.HomePhone != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(parent.HomePhone);
if(NAformat != null){
parent.HomePhone = NAformat;
} else {
phoneFail = true;
parent.HomePhone.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(parent.OtherPhone != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(parent.OtherPhone);
if(NAformat != null){
parent.OtherPhone = NAformat;
} else {
phoneFail = true;
parent.OtherPhone.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.MobilePhone != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.MobilePhone);
if(NAformat != null){
child.MobilePhone = NAformat;
} else {
phoneFail = true;
child.MobilePhone.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.Alternate_Contact_Phone__c != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.Alternate_Contact_Phone__c);
if(NAformat != null){
child.Alternate_Contact_Phone__c = NAformat;
} else {
phoneFail = true;
child.Alternate_Contact_Phone__c.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.Emergency_Contact_2_Phone__c != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.Emergency_Contact_2_Phone__c);
if(NAformat != null){
child.Emergency_Contact_2_Phone__c = NAformat;
} else {
phoneFail = true;
child.Emergency_Contact_2_Phone__c.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.Authorized_Pickup_1_Phone__c != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.Authorized_Pickup_1_Phone__c);
if(NAformat != null){
child.Authorized_Pickup_1_Phone__c = NAformat;
} else {
phoneFail = true;
child.Authorized_Pickup_1_Phone__c.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.Authorized_Pickup_2_Phone__c != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.Authorized_Pickup_2_Phone__c);
if(NAformat != null){
child.Authorized_Pickup_2_Phone__c = NAformat;
} else {
phoneFail = true;
child.Authorized_Pickup_2_Phone__c.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}
if(child.Authorized_Pickup_3_Phone__c != null){
String NAformat = C501_UTIL_ClassRegUtilities.NAformatPhone(child.Authorized_Pickup_3_Phone__c);
if(NAformat != null){
child.Authorized_Pickup_3_Phone__c = NAformat;
} else {
phoneFail = true;
child.Authorized_Pickup_3_Phone__c.addError(Label.C501_ClassReg_PhoneFailSpecific);
}
}

if(phoneFail){
passValidation = false;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,Label.C501_ClassReg_PhoneFail) );
}

if(passValidation == false){
return null;
}
Expand All @@ -229,14 +355,20 @@ public class C501_CTRL_ClassReg_CreateAcct {
term.Student__c = child.Id;
term.Parent__c = parent.Id;
term.School__c = schoolName;
term.C501_Sign_Up_Source__c = 'Online';

schoolNameText = [Select id,
Name,
Teachers_at_Site__c,
Primary_Teacher__r.FirstName ,
Primary_Teacher__r.LastName ,
Secondary_Teacher__r.FirstName ,
Secondary_Teacher__r.LastName
C501_Next_Program_Start_Date__c,
(
SELECT npe5__Status__c,
npe5__Contact__c,
npe5__Contact__r.FirstName,
npe5__Contact__r.LastName
FROM npe5__Affiliations__r
WHERE npe5__Status__c = 'Current'
AND npe5__Role__c = 'Teacher'
)
from Account
where id = :schoolName];

Expand All @@ -250,14 +382,21 @@ public class C501_CTRL_ClassReg_CreateAcct {
C501_UTIL_ClassRegUtilities.sendSMSGenericFuture(parent.MobilePhone,Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name );
}
if(parent.Email != null && parent.Email != '' ){
String teacherName = schoolNameText.Primary_Teacher__r.FirstName + ' ' + schoolNameText.Primary_Teacher__r.LastName;

if(schoolNameText.Secondary_Teacher__r.LastName != null){
teacherName = teacherName + ' ' + Label.C501_ClassReg_AND + ' ' + schoolNameText.Secondary_Teacher__r.FirstName + ' ' + schoolNameText.Secondary_Teacher__r.LastName;
String teacherName = '';
for(Integer i = 0; i < schoolNameText.npe5__Affiliations__r.size(); i++){
if(i != 0 && i + 1 == schoolNameText.npe5__Affiliations__r.size() && schoolNameText.npe5__Affiliations__r.size() > 1){
teacherName = teacherName + ' ' + Label.C501_ClassReg_AND + ' ';
} else if(i != 0 && schoolNameText.npe5__Affiliations__r.size() > 1 ) {
teacherName = teacherName + ', ';
}
teacherName = teacherName + schoolNameText.npe5__Affiliations__r[i].npe5__Contact__r.FirstName + ' ' +schoolNameText.npe5__Affiliations__r[i].npe5__Contact__r.LastName;
}

String emailMessage = Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name +Label.C501_RegSite_EmailConfirmP2+' '+Label.C501_RegSite_EmailConfirmP3+' '+teacherName+Label.C501_RegSite_EmailConfirmP4;
C501_UTIL_ClassRegUtilities.SendEmailGeneric('[email protected]',parent.Email,Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name,emailMessage);

String nextStartDate = Datetime.newInstance(schoolNameText.C501_Next_Program_Start_Date__c, Time.newInstance(0,0,0,0)).format('MMMMM d, yyyy');

String emailMessage = Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name +Label.C501_RegSite_EmailConfirmP2+' '+nextStartDate+' '+Label.C501_RegSite_EmailConfirmP3+' '+teacherName+Label.C501_RegSite_EmailConfirmP4;
C501_UTIL_ClassRegUtilities.SendEmailGeneric('[email protected]',parent.Email,Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name,emailMessage);

C501_UTIL_ClassRegUtilities.logActivityToContact(parent.Id,Label.C501_RegSite_ConfirmSMS+' '+schoolNameText.Name, emailMessage,'Email');
}
Expand Down
5 changes: 5 additions & 0 deletions src/classes/C501_CTRL_ClassReg_CreateAcct.cls-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
<minorNumber>11</minorNumber>
<namespace>npe01</namespace>
</packageVersions>
<packageVersions>
<majorNumber>3</majorNumber>
<minorNumber>7</minorNumber>
<namespace>npe5</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion src/classes/C501_CTRL_ClassReg_Login.cls
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class C501_CTRL_ClassReg_Login {
phoneNumber = '';
confirmation = '';
identityInput = null;
remember = true;
remember = false;
}

public PageReference confirmLoginBySendToAddress(){
Expand Down
21 changes: 18 additions & 3 deletions src/classes/C501_UTIL_ClassRegUtilities.cls
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public class C501_UTIL_ClassRegUtilities {

public static void sendEmailConfirmation(ID AcctID, String emailAddress){
Class_Site_Login_Attempt__c att = generateLoginCode(AcctID, emailAddress);
String message = Label.C501_ClassReg_CodeMessage + ' '+att.Secret_Code__c + ' ' +Label.C501_ClassReg_CodeMessageDisclaim;
SendEmailGeneric('jon-c@501commons.org',emailAddress,Label.C501_ClassReg_ConfirmCodeSubject,message);
String message = Label.C501_ClassReg_CodeMessage + ' '+att.Secret_Code__c + ' ' +Label.C501_ClassReg_CodeMessageDisclaim+' '+Label.C501_ClassReg_CodeMessageExpire;
SendEmailGeneric('salesforce@techbridgegirls.org',emailAddress,Label.C501_ClassReg_ConfirmCodeSubject,message);
insert att;
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public class C501_UTIL_ClassRegUtilities {

public static void sendSMS(ID AcctID,String phoneNumber){
Class_Site_Login_Attempt__c att = generateLoginCode(AcctId, phoneNumber);
sendSMSGeneric(phoneNumber,Label.C501_ClassReg_CodeMessage + ' '+att.Secret_Code__c + ' ' + Label.C501_ClassReg_CodeMessageDisclaim);
sendSMSGeneric(phoneNumber,Label.C501_ClassReg_CodeMessage + ' '+att.Secret_Code__c + ' ' + Label.C501_ClassReg_CodeMessageDisclaim+' '+Label.C501_ClassReg_CodeMessageExpire);
insert att;
}

Expand All @@ -305,9 +305,24 @@ public class C501_UTIL_ClassRegUtilities {
public static string cleanInputPhone(String input){
// to do: clean the string to make sure first number is not '1' and that there are 10 digits.
String output = input.replaceAll('[^0-9]', '');
if(output.left(1) == '1'){
output = output.right( output.length()-1 );
}
if(output.length() != 10){
return null;
}
return output;
}

public static string NAformatPhone(String input){
String output = cleanInputPhone(input);
if(output == null){
return null;
} else {
return '('+output.left(3)+') '+output.left(6).right(3)+'-'+output.right(4);
}
}

public static String generateRandomString(Integer len, Boolean includeNumbers,Boolean includeUppers,Boolean includeLowers) {
String chars = '';
if(includeNumbers){
Expand Down
Loading

0 comments on commit 0283117

Please sign in to comment.