示例#1
0
 /**
  * Copies the referencing data from the new datasources to the old.
  *
  * Allows newly entered references visibility on the HRT.
  *
  * @param Model_Referencing_Reference $reference
  * The Reference to muntify.
  *
  * @return void
  */
 public function updateReference($reference)
 {
     if (!empty($reference->propertyLease->prospectiveLandlord)) {
         // The Enquiry.newllrefno is the prospective landord details stored in
         // the landlordref table.
         $name = $reference->propertyLease->prospectiveLandlord->name;
         $address = $reference->propertyLease->prospectiveLandlord->address;
         $contactDetails = $reference->propertyLease->prospectiveLandlord->contactDetails;
         $landlordRefDatasource = new Datasource_ReferencingLegacy_LandlordRef();
         $muntingEnquiryFields['newllrefno'] = $landlordRefDatasource->insertLandlordRef($name, $address, $contactDetails);
     }
     // The Enquiry.lrefrefno is the current landlord details.
     $muntingEnquiryFields['lrefrefno'] = '';
     if (!empty($reference->referenceSubject->residences)) {
         foreach ($reference->referenceSubject->residences as $residence) {
             if ($residence->chronology == Model_Referencing_ResidenceChronology::CURRENT) {
                 if ($residence->status == Model_Referencing_ResidenceStatus::TENANT) {
                     //If product is a full reference, then record the landlord reference details
                     if ($reference->productSelection->product->variables[Model_Referencing_ProductVariables::FULL_REFERENCE] == 1) {
                         $name = $residence->refereeDetails->name;
                         $address = $residence->refereeDetails->address;
                         $contactDetails = $residence->refereeDetails->contactDetails;
                         $muntingEnquiryFields['lrefrefno'] = $landlordRefDatasource->insertLandlordRef($name, $address, $contactDetails);
                     }
                 }
                 break;
             }
         }
     }
     //The Enquiry.proprefno holds the property lease details.
     $propertyLeaseDatasource = new Datasource_ReferencingLegacy_PropertyLease();
     $muntingEnquiryFields['proprefno'] = $propertyLeaseDatasource->insertPropertyLease($reference->propertyLease);
     //The Enquiry.TenantID holds the ReferenceSubject details.
     $referenceSubjectDatasource = new Datasource_ReferencingLegacy_ReferenceSubject();
     $muntingEnquiryFields['TenantID'] = $referenceSubjectDatasource->insertReferenceSubject($reference->referenceSubject);
     //The Enquiry.ta[1-3]refno hold indexes to the tenant_address table, which holds up to
     //three of the reference subject addresses.
     $currentResidence = 0;
     $firstPreviousResidence = 0;
     $secondPreviousResidence = 0;
     foreach ($reference->referenceSubject->residences as $residence) {
         switch ($residence->chronology) {
             case Model_Referencing_ResidenceChronology::CURRENT:
                 $currentResidence = $residence;
                 break;
             case Model_Referencing_ResidenceChronology::FIRST_PREVIOUS:
                 $firstPreviousResidence = $residence;
                 break;
             case Model_Referencing_ResidenceChronology::SECOND_PREVIOUS:
                 $secondPreviousResidence = $residence;
                 break;
         }
     }
     //Initial settings for the ta[1-3]refnos
     $muntingEnquiryFields['ta1refno'] = 0;
     $muntingEnquiryFields['ta2refno'] = 0;
     $muntingEnquiryFields['ta3refno'] = 0;
     //Cycle through the residences and save each.
     $residenceDatasource = new Datasource_ReferencingLegacy_Residences();
     for ($i = 0; $i < count($reference->referenceSubject->residences); $i++) {
         if (count($reference->referenceSubject->residences) == $i + 1) {
             $isLast = true;
         } else {
             $isLast = false;
         }
         switch ($i) {
             case 0:
                 $muntingEnquiryFields['ta1refno'] = $residenceDatasource->insertResidence($currentResidence, $isLast);
                 break;
             case 1:
                 $muntingEnquiryFields['ta2refno'] = $residenceDatasource->insertResidence($firstPreviousResidence, $isLast);
                 break;
             case 2:
                 $muntingEnquiryFields['ta3refno'] = $residenceDatasource->insertResidence($secondPreviousResidence, $isLast);
                 break;
         }
     }
     //If the first residence is overseas, then ensure its ID is stored the Enquiry.foreignaddress
     //field.
     $muntingEnquiryFields['foreignaddress'] = 0;
     if ($currentResidence->address->isOverseasAddress) {
         $muntingEnquiryFields['foreignaddress'] = $muntingEnquiryFields['ta1refno'];
         $muntingEnquiryFields['ta1refno'] = 0;
     }
     //Update the Enquiry record.
     $this->_pushToEnquiryMunt($reference, $muntingEnquiryFields);
     //Insert the Occupation records
     $this->_pushToEmploymentMunt($reference);
     //Update the progress record
     $progressDatasource = new Datasource_ReferencingLegacy_Progress();
     $progressDatasource->updateProgress($reference);
 }