Example #1
0
 public function joinBorrower($data)
 {
     $volunteerMentor = VolunteerMentorQuery::create()->findOneByBorrowerId($data['volunteerMentorId']);
     $referrer = BorrowerQuery::create()->findOneById($data['referrerId']);
     $user = new User();
     $user->setUsername($data['username']);
     $user->setEmail($data['email']);
     $user->setFacebookId($data['facebookId']);
     $user->setRole('borrower');
     $borrower = new Borrower();
     $borrower->setFirstName($data['firstName']);
     $borrower->setLastName($data['lastName']);
     $borrower->setCountryId($data['countryId']);
     $borrower->setVolunteerMentor($volunteerMentor);
     $borrower->setReferrer($referrer);
     $borrower->setUser($user);
     $profile = new Profile();
     $profile->setAddress($data['address']);
     $profile->setAddressInstructions($data['addressInstructions']);
     $profile->setCity($data['city']);
     $profile->setNationalIdNumber($data['nationalIdNumber']);
     $profile->setPhoneNumber($data['phoneNumber']);
     $profile->setAlternatePhoneNumber($data['alternatePhoneNumber']);
     $borrower->setProfile($profile);
     $communityLeader = new Contact();
     $communityLeader->setType('communityLeader')->setFirstName($data['communityLeader']['firstName'])->setLastName($data['communityLeader']['lastName'])->setPhoneNumber($data['communityLeader']['phoneNumber'])->setDescription($data['communityLeader']['description']);
     $borrower->addContact($communityLeader);
     for ($i = 1; $i <= 3; $i++) {
         $familyMember = new Contact();
         $familyMember->setType('familyMember')->setFirstName($data['familyMember'][$i]['firstName'])->setLastName($data['familyMember'][$i]['lastName'])->setPhoneNumber($data['familyMember'][$i]['phoneNumber'])->setDescription($data['familyMember'][$i]['description']);
         $borrower->addContact($familyMember);
     }
     for ($i = 1; $i <= 3; $i++) {
         $neighbor = new Contact();
         $neighbor->setType('neighbor')->setFirstName($data['neighbor'][$i]['firstName'])->setLastName($data['neighbor'][$i]['lastName'])->setPhoneNumber($data['neighbor'][$i]['phoneNumber'])->setDescription($data['neighbor'][$i]['description']);
         $borrower->addContact($neighbor);
     }
     $borrower->save();
     $joinLog = new JoinLog();
     $joinLog->setIpAddress($data['ipAddress'])->setBorrower($borrower);
     $joinLog->save();
     $this->sendVerificationCode($borrower);
     $this->borrowerMailer->sendBorrowerJoinedConfirmationMail($borrower);
     if ($borrower->getVolunteerMentor()) {
         $this->borrowerMailer->sendBorrowerJoinedVolunteerMentorConfirmationMail($borrower);
     }
     foreach ($borrower->getContacts() as $contact) {
         $this->borrowerSmsService->sendBorrowerJoinedContactConfirmationSms($contact);
     }
     return $borrower;
 }