/** * Get ALL references from IRIS that have been paid for. * * @Route() * @Template() * @Method({"GET"}) * @param Request $request * @return array */ public function indexAction(Request $request) { // Firstly, get all references for this user, regardless of application status and payment status. $resultSet = $this->referenceRetriever->getReferencesByStatus(null, true); if (!$resultSet instanceof ReferencingApplicationSummaryCollection) { return array('landlord' => $this->irisEntityManager->find(new DirectLandlord()), 'results' => array(), 'viewMore' => false); } // Now filter out all references that haven't had a successful payment $filteredResults = $this->referenceRetriever->filterByPaymentStatus($resultSet, array(PaymentStatusCodes::SUCCESS)); // Update the result with the filtered out results. $resultSet->setRecords((array) $filteredResults); // Only show the 5 most recent results on the dashboard. // Break results into 5 per page... if (0 < count($resultSet->getRecords())) { $resultPages = array_chunk($resultSet->getRecords(), 5); // ...then only return the 1st page $resultSet->setRecords(reset($resultPages)); // Do we have more than 1 page? $viewMore = 1 < count($resultPages); } else { // We filtered down to an empty result set. $viewMore = false; $resultSet = array(); } return array('landlord' => $this->irisEntityManager->find(new DirectLandlord()), 'results' => $resultSet, 'viewMore' => $viewMore); }
/** * Case overview * * @Route("/{caseId}") * @Method({"GET", "POST"}) * @Template() * * @param $caseId * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction($caseId) { try { $case = $this->irisEntityManager->find(new ReferencingCase(), array('caseId' => $caseId)); $applications = $this->irisEntityManager->find(new ReferencingApplicationCollection(), array('caseId' => $caseId)); } catch (NotFoundException $ex) { // Case could not be found throw $this->createNotFoundException(sprintf('Case with caseId "%s" could not be found', $caseId)); } return array('caseId' => $caseId, 'case' => $case, 'applications' => $applications); }
/** * Latest application report * * @Route("/{applicationId}/report") * @Method({"GET", "POST"}) * @Template() * * @param $applicationId * @return Response */ public function viewApplicationReportAction($applicationId) { try { /** @var Report $report */ $report = $this->irisEntityManager->find(new Report(), array('applicationId' => $applicationId)); } catch (NotFoundException $ex) { // Case could not be found throw $this->createNotFoundException(sprintf('Application with applicationId "%s" could not be found', $applicationId)); } return new Response($report, 200, array('Content-Type' => $report->getContentType())); }
/** * Get lookup collection model * * @return LookupCollection */ public function getCollection() { if (null === $this->lookupCollection) { $this->lookupCollection = $this->cache->fetch('LookupCollection'); if (!$this->lookupCollection) { $this->lookupCollection = $this->entityManager->find(new LookupCollection(), array()); $this->cache->save('LookupCollection', $this->lookupCollection); } } return $this->lookupCollection; }
/** * @param $id * @param $rentGuaranteeOfferingType * @param $propertyLettingType * @return mixed * @throws \Exception */ public function lookupLabel($id, $rentGuaranteeOfferingType, $propertyLettingType) { $products = $this->irisEntityManager->find(new ProductCollection(), array('rentGuaranteeOfferingType' => $rentGuaranteeOfferingType, 'propertyLettingType' => $propertyLettingType)); // Search the given product ID within the collection of Products retrieved from IRIS. foreach ($products as $product) { if ($product->getProductId() == $id) { return $product->getName(); } } // Error if our loop couldn't find a match. throw new \Exception(sprintf('Unable to find a valid product name for product ID: %d', $id)); }
/** * Application overview * * @Route("/{applicationId}") * @Method({"GET", "POST"}) * @Template() * * @param $applicationId * @return Response */ public function indexAction($applicationId) { try { /** @var Progress $progress */ $progress = $this->irisEntityManager->find(new Progress(), array('applicationId' => $applicationId)); } catch (NotFoundException $ex) { // Case could not be found throw $this->createNotFoundException(sprintf('Progress for applicationId "%s" could not be found', $applicationId)); } $application = $this->getApplication($this->irisEntityManager, $applicationId); $case = $this->getCase($this->irisEntityManager, $application->getCaseId()); $allowAddGuarantor = $this->isAllowedToAddGuarantor($application) ?: false; return array('caseId' => $application->getCaseId(), 'case' => $case, 'application' => $application, 'progress' => $progress, 'allowAddGuarantor' => $allowAddGuarantor); }
/** * Initialise the product collection from the products service * * @return ProductCollection|null */ private function initialiseChoices() { // Fetch a vendor key if possible, to cache against try { $vendorKey = $this->systemBrandService->getVendorCredentials()['vendorKey']; } catch (\Exception $e) { $vendorKey = 'defaultVendor'; } if (null !== $this->rentGuaranteeOfferingType && null !== $this->propertyLettingType && !$this->isInitialised) { $cacheKey = sprintf('Lookup-Product-Collection-%s-%s-%s', $this->rentGuaranteeOfferingType, $this->propertyLettingType, $vendorKey); $productCollection = $this->cache->fetch($cacheKey); $this->values = array(); $this->choices = array(); if (!$productCollection) { $productCollection = $this->entityManager->find(new ProductCollection(), array('rentGuaranteeOfferingType' => $this->rentGuaranteeOfferingType, 'propertyLettingType' => $this->propertyLettingType)); $this->cache->save($cacheKey, $productCollection); } /** @var \Barbon\HostedApi\AppBundle\Form\Common\Model\Product $product */ foreach ($productCollection as $product) { $this->values[] = (string) $product->getProductId(); $this->choices[] = (string) $product->getProductId(); //$product->getName(); $this->labels[] = (string) $product->getName(); } $this->isInitialised = true; return $productCollection; } return null; }
/** * Application overview * * @Route("/{applicationId}") * @Method({"GET", "POST"}) * @Template() * * @param $applicationId * @return Response */ public function indexAction($applicationId) { try { /** @var ReferencingApplication $application */ $application = $this->irisEntityManager->find(new ReferencingApplication(), array('applicationId' => $applicationId)); /** @var Progress $progress */ $progress = $this->irisEntityManager->find(new Progress(), array('applicationId' => $applicationId)); } catch (NotFoundException $ex) { // Case could not be found throw $this->createNotFoundException(sprintf('Application with applicationId "%s" could not be found', $applicationId)); } try { /** @var ReferencingCase $case */ $case = $this->irisEntityManager->find(new ReferencingCase(), array('caseId' => $application->getCaseId())); } catch (NotFoundException $ex) { // Case could not be found throw $this->createNotFoundException(sprintf('Case with caseId "%s" could not be found', $application->getCaseId())); } return array('caseId' => $application->getCaseId(), 'case' => $case, 'application' => $application, 'progress' => $progress); }
/** * Postcode lookup from address * * @Route("/postcode/{postcode}", defaults={"postcode" = null}) * @Method({"GET"}) * @Template() * * @param Request $request * @return Response */ public function postcodeAction(Request $request) { // Get postcode from request $postcode = $request->get('postcode'); // todo: Check postcode is in valid format // Set cache key $cacheKey = 'postcodeLookup-' . $postcode; // Check if cache contains address lookup details for this postcode if ($addressDataJson = $this->cache->fetch($cacheKey)) { // Cache hit, do nothing } else { // Cache miss or stale, do the work of fetching new details $addressDataAsPaf = $this->irisEntityManager->find(new AddressLookupCollection(), array('postcode' => $postcode)); $addressData = $this->addressLookupCollectionToAddressCollection($addressDataAsPaf); $addressDataJson = json_encode($addressData); // Cache the results $this->cache->save($cacheKey, $addressDataJson); } // Formulate JSON response $this->response->headers->set('Content-Type', 'application/json'); $this->response->setContent($addressDataJson); return $this->response; }
/** * @param IrisEntityManager $irisEntityManager * @param string $caseId * @return ReferencingApplication * @throws NotFoundException */ public function getApplications(IrisEntityManager $irisEntityManager, $caseId) { try { $collection = $irisEntityManager->find(new ReferencingApplicationCollection(), array('caseId' => $caseId)); if (null !== $collection) { $applications = array(); foreach ($collection as $application) { $applications[] = $application; } } return $applications; } catch (NotFoundException $ex) { throw new NotFoundException(sprintf('Applications with caseId "%s" could not be found', $caseId)); } }
/** * Create a ReferencingCase with pre populated ProspectiveLandlord object. * * @return ReferencingCase */ private function getPrePopulatedCase() { // First, get the DirectLandlord object from IRIS and instantiate an empty ProspectiveLandlord. $directLandlord = $this->irisEntityManager->find(new DirectLandlord()); $prospectiveLandlord = new ProspectiveLandlord(); // Now map the DirectLandlord into a new ProspectiveLandlord: // foreach property in the DirectLandlord, if the ProspectiveLandlord contains a setter method, set it using the corresponding get method. // TODO getter and setter discovery can be handled more effectively $directLandlordReflect = new \ReflectionClass($directLandlord); $properties = $directLandlordReflect->getProperties(); foreach ($properties as $property) { $setMethod = sprintf('set%s', ucfirst($property->getName())); $getMethod = sprintf('get%s', ucfirst($property->getName())); if (method_exists($prospectiveLandlord, $setMethod) && method_exists($directLandlord, $getMethod)) { $prospectiveLandlord->{$setMethod}($directLandlord->{$getMethod}()); } } // Add the newly formed ProspectiveLandlord to the case. $case = new ReferencingCase(); $case->setProspectiveLandlord($prospectiveLandlord); return $case; }
/** * Fetch a system brand object from cache or via REST, using the vendor key and secret * * @param mixed $model * @param string $cacheKeyRoot * @return mixed * @throws \Exception */ private function getCachableSystemBrandObject($model, $cacheKeyRoot) { $vendorCredentials = $this->getVendorCredentials(); $cacheKey = $cacheKeyRoot . '-' . $vendorCredentials['vendorKey']; // Check if cache contains system brand object details for this key if ($systemBrandObjectSerialized = $this->cache->fetch($cacheKey)) { // Cache hit $systemBrandObject = unserialize($systemBrandObjectSerialized); } else { // Cache miss or stale, do the work of fetching new details // Temporarily "resume" the vendor's key and secret for the brand details lookup $irisClient = $this->irisEntityManager->getClient(); // Take note of the original auth details to set back to $originalAuth = $irisClient->getSubscriber(); // Switch to using the vendor credentials and look up the system brand object $client = $irisClient->resume(array('consumerKey' => $vendorCredentials['vendorKey'], 'consumerSecret' => $vendorCredentials['vendorSecret'])); $systemBrandObject = $this->irisEntityManager->find($model); // Now resume the original auth $irisClient->setSubscriber($originalAuth); // Cache the results $this->cache->save($cacheKey, serialize($systemBrandObject)); } return $systemBrandObject; }
/** * @param $productId * @param ReferencingCase $case * @param AbstractReferencingApplication $application * @param int $guarantorSequenceNumber * @return int */ public function getPrice($productId, ReferencingCase $case, AbstractReferencingApplication $application, $guarantorSequenceNumber = 0) { $criteria = array('productId' => $productId, 'propertyLetType' => $case->getPropertyLetType(), 'rentGuaranteeOfferingType' => $case->getRentGuaranteeOfferingType(), 'shareOfRent' => $application->getRentShare(), 'policyLengthInMonths' => $case->getTenancyTerm(), 'guarantorSequenceNumber' => $guarantorSequenceNumber, 'isRenewal' => 0); $productPrice = $this->irisEntityManager->find(new ProductPrice(), $criteria); return $productPrice->getGrossPrice(); }
/** * Fetch all products available to this vendor. * todo: Hardcoded criteria should come from user input data instead. * * @return ProductCollection */ protected function getProducts() { $criteria = array('rentGuaranteeOfferingType' => 1, 'propertyLettingType' => 1); $products = $this->irisEntityManager->find(new ProductCollection(), $criteria); return $products; }