/** * Reference purchase summary * * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { $previouslyPostedData = null; // if we are not posting new data, and a request for $this->formType is stored in the session, prepopulate the form with the stored request $storedRequest = unserialize($request->getSession()->get($this->formType->getName())); if ($request->isMethod('GET') && $storedRequest instanceof Request) { $previouslyPostedData = $this->createForm($this->formType)->handleRequest($storedRequest)->getData(); } $form = $this->createForm($this->formType, $previouslyPostedData); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { // Persist the case to IRIS /** @var ReferencingCase $case */ $case = $form->getData()['case']; $this->irisEntityManager->persist($case); /** @var ReferencingApplication $application */ foreach ($case->getApplications() as $application) { // Always default $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId())); // Persist each guarantor of the application if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId())); } } } $request->getSession()->set('submitted-case', serialize($case)); // Send the user to the success page return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_newreference_tenancyagreement_index'), 301); } } return array('form' => $form->createView()); }
/** * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return array|RedirectResponse * * @throws RequestException */ public function indexAction(Request $request) { $form = $this->createForm($this->directLandlordType, new DirectLandlord(), array('action' => $this->generateUrl('barbon_hostedapi_landlord_authentication_entrypoint_index')))->add('register', 'submit', array('label' => 'Register', 'attr' => array('class' => 'btn-primary pull-right'))); $masterRequest = $this->container->get('request_stack')->getMasterRequest(); // Only process if this is the form that's been POSTed if ($masterRequest->request->has($form->getName())) { $form->handleRequest($masterRequest); if ($form->isValid()) { $directLandlord = $form->getData(); $registrationSuccessful = true; // Attempt to register direct landlord, handling any errors from IRIS try { // Switch to vendor credentials before creating the Landlord // Checking for its existence in the session has already been handled in the EntryPointController $vendorCredentials = $request->getSession()->get('auth-data'); $this->irisEntityManager->getClient()->setSystemCredentials($vendorCredentials->get('systemKey'), $vendorCredentials->get('systemSecret')); // Create the Landlord $this->irisEntityManager->persist($directLandlord); } catch (RequestException $e) { $registrationSuccessful = false; switch ($e->getCode()) { // Catch missing/invalid details case 400: case 422: $form->addError(new FormError('One or more required details are bad or missing, please contact us if this problem persists.')); break; // Catch duplicate registrations // Catch duplicate registrations case 409: $form->addError(new FormError('A landlord with this e-mail address already exists, please try logging in or resetting your password instead.')); $form->get('email')->addError(new FormError('E-mail address already exists')); break; // Catch and re-throw server errors and any other kind // Catch and re-throw server errors and any other kind case 500: default: throw $e; } } if ($registrationSuccessful) { // Commence auto login $username = $form->getData()->getEmail(); $password = $form->getData()->getPassword(); $this->authenticateUser($username, $password); // Return rendered registration successful message return $this->render('BarbonHostedApiLandlordAuthenticationBundle:Register:success.html.twig'); } } } // Send custom registration text to the view $options = $this->systemBrandService->getSystemBrandOptions(); $customHeaderText = null; if (array_key_exists(DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER, $options->getDisplayPreferences()->getCustomText())) { $customHeaderText = $options->getDisplayPreferences()->getCustomText()[DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER]; } $form = $form->createView(); return compact('form', 'customHeaderText'); }
/** * @param NewGuarantorReferenceEvent $event */ public function persistGuarantorReference(NewGuarantorReferenceEvent $event) { $case = $event->getCase(); $application = $event->getApplication(); $guarantor = $event->getGuarantor(); // We don't gather this, but IRIS requires it, so always set to this default. $guarantor->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); $guarantor->setProduct($application->getProduct()); // Persist the Guarantor to IRIS, attaching it to the Application. $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId())); // Put the newly persisted Guarantor into the session $this->requestStack->getCurrentRequest()->getSession()->set('submitted-guarantor', serialize($guarantor)); // Add the Guarantor to the Application. $application->setGuarantors(array($guarantor)); // Add the newly updated Application back into the Case. $case->setApplications(array($application)); // Explicitly set the caseId into the session $case->setCaseId($application->getCaseId()); // Put the newly updated Case back into the session. $this->requestStack->getCurrentRequest()->getSession()->set('submitted-case', serialize($case)); }
/** * Success page after reference purchase * * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return array * @throws CaseNotSubmittedException */ public function indexAction(Request $request) { // Get the submitted case /** @var ReferencingCase $case */ $case = unserialize($request->getSession()->get('submitted-case')); if (false === $case) { // Failed to retrieve case from session throw new CaseNotSubmittedException('submitted-case could not be retrieved from the session.'); } // Flatten application/guarantor hierarchy in depth first search order // todo: only needs doing for applications who are completing now $applications = array(); foreach ($case->getApplications() as $application) { $applications[] = $application; if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { $applications[] = $guarantor; } } } $tenancyAgreement = new TenancyAgreement(); $tenancyAgreement->setApplications($applications); // Create form, with flattened data $form = $this->createForm(new TenancyAgreementType(), $tenancyAgreement); $form->handleRequest($request); if ($form->isValid()) { // Persist each application/guarantor model with the updated marketing preferences /** @var AbstractReferencingApplication $application */ foreach ($applications as $application) { $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId(), 'applicationId' => $application->getApplicationId())); } // Submit the entire case $case->submit($this->irisEntityManager->getClient()); // Flush the case/applications from the session for the next reference $request->getSession()->remove('submitted-case'); return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_cases_view_index', array('caseId' => $case->getCaseId()))); } return array('form' => $form->createView()); }
/** * @param NewMultiReferenceEvent $event */ public function persistMultiReference(NewMultiReferenceEvent $event) { $case = $event->getCase(); // Persist the Case to IRIS. $this->irisEntityManager->persist($case); // Process each Tenant Application. foreach ($case->getApplications() as $application) { // We don't gather this, but IRIS requires it, so always set to this default. $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); // Persist the Applicant to IRIS. $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId())); // If present, process each Guarantor of the Application. if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { // We don't gather this, but IRIS requires it, so always set to this default. $guarantor->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); // Persist the Guarantor to IRIS. $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId())); } } } // Put the newly updated Case back into the session. $this->requestStack->getCurrentRequest()->getSession()->set('submitted-case', serialize($case)); }
/** * @param AbstractReferencingApplication $application * @param $caseId */ protected function persistMarketingPreferences(AbstractReferencingApplication $application, $caseId) { $this->irisEntityManager->persist($application, array('caseId' => $caseId, 'applicationId' => $application->getApplicationId())); }