/** * Save a record to the database and return the id on success * @param $data array * @return * @author John Burrin * @since */ public function save($agencyData) { //Zend_Debug::dump($agencyData);die(); $agent = new LettingAgents_Datasource_AgentApplication(); $this->_index = $agent->save($agencyData); // Save the general email address $objEmail = new LettingAgents_Object_AgencyEmail(); $dsEmail = new LettingAgents_Datasource_Email(); $objEmail->setAddress_type(LettingAgents_Object_EmailTypes::General); $objEmail->setAgency_id($this->_index); $objEmail->setEmail_address($agencyData->get_contact_email()); $dsEmail->deleteById($this->_index, LettingAgents_Object_EmailTypes::General); $dsEmail->save($objEmail); return $this->_index; }
/** * Deletes an agent application and accociated Contact/Email records * return id of record of record deleted */ public function cascadeDeleteByUid($uid) { $select = $this->select()->from($this->_name, array('id'))->where('uid = ?', $uid); $row = $this->fetchRow($select); if ($row) { // Delete associated Contacts $contacts = new LettingAgents_Datasource_Contacts(); $contacts->deleteById($row['id']); $this->deleteById($row['id']); // Delete associated Emails $emails = new LettingAgents_Datasource_Email(); $emails->deleteById($row['id']); } return false; }
/** * 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; }