/**
  * Search in HRT.
  *
  * @param int $currentAgentSchemeNumber
  * @param SearchIndividualApplicationsCriteria $criteria
  * @param int $offset
  * @param int $limit
  * @return array Simple array of 'records' containing an array of ReferencingApplicationFindResult and
  *               'totalRecords' containing an integer of all possible records findable with the current criteria
  */
 private function searchInHrt($currentAgentSchemeNumber, SearchIndividualApplicationsCriteria $criteria, $offset, $limit)
 {
     if ($this->debugMode) {
         error_log('--- Search in HRT method invoked ---');
     }
     $records = array();
     $hrtReferenceManager = new \Manager_ReferencingLegacy_Munt();
     $hrtCriteria = array('refno' => $criteria->getReferenceNumber(), 'firstname' => $criteria->getApplicantFirstName(), 'lastname' => $criteria->getApplicantLastName(), 'address' => $criteria->getPropertyAddress(), 'town' => $criteria->getPropertyTown(), 'postcode' => $criteria->getPropertyPostcode(), 'state' => $criteria->getApplicationStatus(), 'type' => $criteria->getProductType());
     $hrtRows = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, \Model_Referencing_SearchResult::STARTDATE_DESC, 0, $limit, $offset);
     foreach ($hrtRows->results as $hrtRow) {
         $status = self::APPLICATION_STATUS_INCOMPLETE;
         if ('Complete' == ucfirst(strtolower(trim($hrtRow['resulttx'])))) {
             $status = self::APPLICATION_STATUS_COMPLETE;
         }
         $model = new ReferencingApplicationFindResult();
         $model->setReferenceNumber($hrtRow['RefNo'])->setReferencingApplicationUuId($hrtRow['RefNo'])->setApplicantFirstName($hrtRow['firstname'])->setApplicantLastName($hrtRow['lastname'])->setStreet($hrtRow['address1'])->setCreatedAt($hrtRow['start_time'])->setStatusId($status)->setDataSource(self::DATA_SOURCE_HRT);
         $records[] = $model;
     }
     // Get total records by passing in a zero for both offset and limit
     $hrtRecordCount = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, null, 0, 0, 0);
     $totalRecords = (int) $hrtRecordCount->totalNumberOfResults;
     return array('records' => $records, 'totalRecords' => $totalRecords);
 }
 /**
  * Get a ReferencingApplication object from IRIS.
  *
  * @param ReferencingApplicationFindResult $result
  * @return ReferencingApplication
  */
 private function getReferencingApplication(ReferencingApplicationFindResult $result)
 {
     return $this->clientRegistry->getAgentContext()->getReferencingApplicationClient()->getReferencingApplication(array('referencingApplicationUuId' => $result->getReferencingApplicationUuId()));
 }
 /**
  * @test
  */
 public function reference_is_put_into_session_when_found()
 {
     // Assert that putReferenceInSession is called on a MockSessionHolder
     $firstReferenceFound = new ReferencingApplicationFindResult();
     $firstReferenceFound->setReferenceNumber('HLT999');
     $searchCriteria = new SearchIndividualApplicationsCriteria();
     $searchCriteria->setReferenceNumber('HLT999');
     $this->mockSearchClient->expects($this->once())->method('search')->with('1234567', $searchCriteria)->willReturn($this->mockSearchResults);
     $this->mockSearchResults->expects($this->once())->method('getTotalRecords')->willReturn(1);
     $this->mockSearchResults->expects($this->once())->method('getRecords')->willReturn(array($firstReferenceFound, new ReferencingApplicationFindResult()));
     $this->mockReferencingApplicationClient->expects($this->once())->method('getReferencingApplication')->willReturn(new ReferencingApplication());
     $mockSessionHolder = $this->getMockBuilder('RRP\\Utility\\SessionReferenceHolder')->disableOriginalConstructor()->setMethods(array('putReferenceInSession'))->getMock();
     $mockSessionHolder->expects($this->once())->method('putReferenceInSession')->with(new ReferencingApplication());
     $constraint = new ReferenceBelongsToAgentConstraint($this->mockClientRegistry, $this->mockSearchClient, $searchCriteria, $mockSessionHolder);
     $constraint->verify('HLT999', array('current_asn' => '1234567'));
 }