Esempio n. 1
0
 /**
  * 
  * 
  */
 public function fetchByAgencyUid($agencyUid)
 {
     #Zend_Debug::dump($agencyUid);die();
     $agent = new LettingAgents_Manager_AgentApplication();
     $agentData = $agent->fetchByUid($agencyUid);
     $contacts = new LettingAgents_Datasource_Contacts();
     #Zend_Debug::dump($agentData);die();
     return $contacts->fetchByAgentId($agentData->get_id());
 }
 public function validatePageAction()
 {
     $return = array();
     $pageSession = new Zend_Session_Namespace('letting_agents_application');
     $postData = $this->getRequest()->getParams();
     $page = $postData['page'];
     switch ($page) {
         case '1':
             $ajaxForm = new LettingAgents_Form_Step1();
             break;
         case '2':
             $pageSession = new Zend_Session_Namespace('letting_agents_application');
             $agent = new LettingAgents_Manager_AgentApplication();
             $agentData = new LettingAgents_Object_AgentApplication();
             $agentData = $agent->fetchByUid($pageSession->agentUniqueId);
             /*
              *  What we need to present as stage 2 is dependant on the selection of organisation type
              *  step 2 will need to load different subforms
              * so pass organisation_type to the form   
              */
             $organisation_type = $agentData->get_organisation_type();
             $ajaxForm = new LettingAgents_Form_Step2(array('organisationId' => $organisation_type));
             switch ($organisation_type) {
                 case LettingAgents_Object_CompanyTypes::LimitedCompany:
                     break;
                 case LettingAgents_Object_CompanyTypes::LimitedLiabilityPartnership:
                     break;
                 case LettingAgents_Object_CompanyTypes::Partnership:
                     break;
                 case LettingAgents_Object_CompanyTypes::SoleTrader:
                     break;
             }
             break;
         case '3':
             $ajaxForm = new LettingAgents_Form_Step3();
             break;
         case '4':
             $ajaxForm = new LettingAgents_Form_Step4();
             break;
     }
     $valid = $ajaxForm->isValid($postData);
     if (!$valid) {
         $errorMessages = $ajaxForm->getMessagesFlattened();
         // We need to strip out some complex messages that the end user won't care about
         if (isset($errorMessages['email_address'])) {
             if (isset($errorMessages['email_address']['hostnameUnknownTld'])) {
                 unset($errorMessages['email_address']['hostnameUnknownTld']);
             }
             if (isset($errorMessages['email_address']['hostnameLocalNameNotAllowed'])) {
                 unset($errorMessages['email_address']['hostnameLocalNameNotAllowed']);
             }
         }
         $return['errorJs'] = $errorMessages;
         $return['errorCount'] = count($errorMessages);
         // don't push errors into the parent page
         $return['errorHtml'] = $this->view->partial('partials/error-list.phtml', array('errors' => $errorMessages));
     } else {
         $return['errorJs'] = '';
         $return['errorCount'] = '';
         $return['errorHtml'] = '';
     }
     echo Zend_Json::encode($return);
 }
 /**
  * Private function to handle form population
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $pageSession = new Zend_Session_Namespace('letting_agents_application');
     // First of all check that this form should be viewable and the user isn't trying to skip ahead
     //	$agentData = new LettingAgents_Object_AgentApplication();
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $response = $this->getResponse();
         $response->setRedirect('/letting-agents/sign-up/step' . $lastCompleted);
         $response->sendResponse();
         return false;
     }
     // Only populate from DB if we are in session and have a reference number
     if (isset($pageSession->agentUniqueId)) {
         $formData = array();
         // Populate $formData with data from model, if available
         switch ($stepNum) {
             case 1:
                 $agent = new LettingAgents_Manager_AgentApplication();
                 if ($agentData = $agent->fetchByUid($pageSession->agentUniqueId)) {
                     #Zend_Debug::dump($agentData);die();
                     $formData['is_previous_client'] = $agentData->get_is_previous_client();
                     $formData['campaign_code'] = $agentData->get_campaign_code();
                     $formData['legal_name'] = $agentData->get_legal_name();
                     $formData['trading_name'] = $agentData->get_trading_name();
                     $formData['organisation_type'] = $agentData->get_organisation_type();
                     list($year, $month, $day) = explode("-", $agentData->get_date_established());
                     $formData['date_established'] = "{$day}/{$month}/{$year}";
                     $formData['is_associated'] = $agentData->get_is_associated();
                     $formData['associated_text'] = $agentData->get_associated_text();
                     $formData['contact_name'] = $agentData->get_contact_name();
                     $formData['contact_number'] = $agentData->get_contact_number();
                     $formData['general_email'] = $agentData->get_contact_email();
                 }
                 $pageForm->populate($formData);
                 break;
             case 2:
                 $agent = new LettingAgents_Manager_AgentApplication();
                 $agentData = $agent->fetchByUid($pageSession->agentUniqueId);
                 //	Zend_Debug::dump($agentData);die();
                 // There could be multiple contacts here depending on the organisation type
                 $contactManager = new LettingAgents_Manager_Contacts();
                 $contactData = $contactManager->fetchByAgencyUid($pageSession->agentUniqueId);
                 switch ($agentData->get_organisation_type()) {
                     // Fetch Agency contacts when agency type is LimitedCompany
                     case LettingAgents_Object_CompanyTypes::LimitedCompany:
                         $formData['registration_number'] = $agentData->get_company_registration_number();
                         $contactsHtml = $this->view->partialLoop('partials/limited-company-list.phtml', $contactData);
                         $this->view->contacts = $contactsHtml;
                         break;
                         // Fetch Agency contacts when agency type is LimitedLiabilityPartnership
                     // Fetch Agency contacts when agency type is LimitedLiabilityPartnership
                     case LettingAgents_Object_CompanyTypes::LimitedLiabilityPartnership:
                         $contactsHtml = $this->view->partialLoop('partials/partnership-list.phtml', $contactData);
                         $this->view->contacts = $contactsHtml;
                         break;
                         // Fetch Agency contacts when agency type is Partnership
                     // Fetch Agency contacts when agency type is Partnership
                     case LettingAgents_Object_CompanyTypes::Partnership:
                         $contactsHtml = $this->view->partialLoop('partials/partnership-list.phtml', $contactData);
                         $this->view->contacts = $contactsHtml;
                         break;
                         // Fetch Agency contacts when agency type is SoleTrader
                     // Fetch Agency contacts when agency type is SoleTrader
                     case LettingAgents_Object_CompanyTypes::SoleTrader:
                         $formData['uid'] = $contactData[0]['uid'];
                         $formData['contact_name'] = $agentData->get_contact_name();
                         list($year, $month, $day) = explode("-", $contactData[0]['birth_date']);
                         $formData['birth_date'] = "{$day}/{$month}/{$year}";
                         $formData['ni_number'] = $contactData[0]['ni_number'];
                         $formData['passport_number'] = $contactData[0]['passport_number'];
                         $formData['address_line1'] = $contactData[0]['address1'];
                         $formData['address_line2'] = $contactData[0]['address2'];
                         $formData['address_line3'] = $contactData[0]['address3'];
                         $formData['address_postcode'] = $contactData[0]['postcode'];
                         $formData['postcode'] = $contactData[0]['postcode'];
                         break;
                 }
                 $pageForm->populate($formData);
                 break;
             case 3:
                 // Fetch Agent data
                 $agent = new LettingAgents_Manager_AgentApplication();
                 $agentData = $agent->fetchByUid($pageSession->agentUniqueId);
                 //Zend_Debug::dump($agentData);die();
                 $formData['current_referencing_supplier'] = $agentData->get_current_referencing_supplier();
                 $formData['general_email_address'] = $agentData->get_contact_email();
                 $agentData->get_number_of_branches() == 0 ? $formData['no_of_branches'] = "" : ($formData['no_of_branches'] = $agentData->get_number_of_branches());
                 $agentData->get_number_of_employees() == 0 ? $formData['no_of_staff'] = "" : ($formData['no_of_staff'] = $agentData->get_number_of_employees());
                 $agentData->get_number_of_lets() == 0 ? $formData['no_of_properties_managed'] = "" : ($formData['no_of_properties_managed'] = $agentData->get_number_of_lets());
                 $agentData->get_number_of_landlords() == 0 ? $formData['no_of_landlords'] = "" : ($formData['no_of_landlords'] = $agentData->get_number_of_landlords());
                 // Fetch agency office data
                 $officeManager = new LettingAgents_Manager_Office();
                 // This only returns two items
                 $offices = $officeManager->fetchAllByAgencyUid($pageSession->agentUniqueId);
                 $officeManager = new LettingAgents_Manager_Office();
                 foreach ($offices as $office) {
                     //Zend_Debug::dump($office);die();
                     switch ($office->office_type) {
                         case LettingAgents_Object_OfficeTypes::BranchOffice:
                             $formData['trading_uid'] = $office->uid;
                             $formData['trading_address_line1'] = $office->address_1;
                             $formData['trading_address_line2'] = $office->address_2;
                             $formData['trading_address_line3'] = $office->address_3;
                             $formData['trading_address_postcode'] = $office->postcode;
                             $formData['trading_postcode'] = $office->postcode;
                             break;
                         case LettingAgents_Object_OfficeTypes::HeadOffice:
                             $formData['accounts_uid'] = $office->uid;
                             $formData['accounts_address_line1'] = $office->address_1;
                             $formData['accounts_address_line2'] = $office->address_2;
                             $formData['accounts_address_line3'] = $office->address_3;
                             $formData['accounts_address_postcode'] = $office->postcode;
                             $formData['accounts_postcode'] = $office->postcode;
                             break;
                     }
                 }
                 // Fetch the multiple emails
                 $multiEmail = new LettingAgents_Datasource_Email();
                 $emails = array();
                 $emails = $multiEmail->fetchById($agentData->get_id());
                 foreach ($emails as $email) {
                     switch ($email['address_type']) {
                         case LettingAgents_Object_EmailTypes::General:
                             $formData['general_email_address'] = $email['email_address'];
                             break;
                         case LettingAgents_Object_EmailTypes::Referencing:
                             $formData['email_for_referencing'] = $email['email_address'];
                             break;
                         case LettingAgents_Object_EmailTypes::Insurance:
                             $formData['email_for_insurance'] = $email['email_address'];
                             break;
                         case LettingAgents_Object_EmailTypes::RentGuaranteeRenewals:
                             $formData['email_for_rg_renewals'] = $email['email_address'];
                             break;
                         case LettingAgents_Object_EmailTypes::Invoicing:
                             $formData['email_for_invoicing'] = $email['email_address'];
                             break;
                         case LettingAgents_Object_EmailTypes::HomeLetUpdates:
                             $formData['email_for_marketing'] = $email['email_address'];
                             break;
                     }
                 }
                 $pageForm->populate($formData);
                 break;
             case 4:
                 // Fetch Agent data
                 $agent = new LettingAgents_Manager_AgentApplication();
                 $agentData = $agent->fetchByUid($pageSession->agentUniqueId);
                 // ensure that agent_type has a value
                 $agent_type = $agentData->get_application_type();
                 $agent_type == "" ? $formData['agent_type'] = "standard" : ($formData['agent_type'] = $agent_type);
                 $pageForm->populate($formData);
                 break;
         }
     }
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     return true;
 }