/** * * Add a new contact... */ public function addContactAction() { $return = array(); $pageSession = new Zend_Session_Namespace('letting_agents_application'); $agent = new LettingAgents_Manager_AgentApplication(); $agentData = new LettingAgents_Object_AgentApplication(); $agentData = $agent->fetchByUid($pageSession->agentUniqueId); $agencyid = $agentData->get_id(); $postData = $this->getRequest()->getParams(); $contactManager = new LettingAgents_Manager_Contacts(); $agent = new LettingAgents_Manager_AgentApplication(); $agentData = new LettingAgents_Object_AgentApplication(); $agentData = $agent->fetchByUid($pageSession->agentUniqueId); $organisation_type = $agentData->get_organisation_type(); switch ($organisation_type) { case LettingAgents_Object_CompanyTypes::LimitedCompany: $data = new LettingAgents_Object_Contact(); $partialFile = "limited-company-list.phtml"; break; case LettingAgents_Object_CompanyTypes::LimitedLiabilityPartnership: case LettingAgents_Object_CompanyTypes::Partnership: $data = new LettingAgents_Object_PartnershipContact(); $partialFile = "partnership-list.phtml"; break; } $data->set_agency_id($agencyid); if (isset($postData['contact_name'])) { $data->set_contact_name($postData['contact_name']); } if (isset($postData['address1'])) { $data->set_address1($postData['address1']); } if (isset($postData['address2'])) { $data->set_address2($postData['address2']); } if (isset($postData['address3'])) { $data->set_address3($postData['address3']); } if (isset($postData['birth_date'])) { $data->set_birth_date($postData['birth_date']); } if (isset($postData['ni_number'])) { $data->set_ni_number($postData['ni_number']); } if (isset($postData['passport_number'])) { $data->set_passport_number($postData['passport_number']); } if (isset($postData['postcode'])) { $data->set_postcode($postData['postcode']); } $lastid = $contactManager->save($data); # $contactManager->fetchByAgencyUid($pageSession->agentUniqueId); $return['contactHtml'] = $this->view->partialLoop("partials/{$partialFile}", $contactManager->fetchByAgencyUid($pageSession->agentUniqueId)); echo Zend_Json::encode($return); }
/** * Initialise the step 2 form * * @return void */ public function step2Action() { $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 2;'); // Append the address lookup javascript $this->view->headScript()->appendFile('/assets/common/js/addressLookup.js', 'text/javascript')->appendFile('/assets/cms/js/letting-agents/letting-agents_form.js', 'text/javascript'); $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(); $pageForm = new LettingAgents_Form_Step2(array('organisationId' => $organisation_type)); if ($this->getRequest()->isPost()) { // We need to validate and save the data // TODO: Need to re-factor this to make it quicker $valid = $this->_formStepCommonValidate($pageForm, 2); if ($valid) { $postData = $pageForm->getValues(); switch ($organisation_type) { case LettingAgents_Object_CompanyTypes::LimitedCompany: $agentData->set_uid($pageSession->agentUniqueId); // Assign subform_limited company if (isset($postData['subform_limitedcompanyregistration']['registration_number'])) { $agentData->set_company_registration_number($postData['subform_limitedcompanyregistration']['registration_number']); } $agent->save($agentData); break; case LettingAgents_Object_CompanyTypes::LimitedLiabilityPartnership: case LettingAgents_Object_CompanyTypes::Partnership: break; case LettingAgents_Object_CompanyTypes::SoleTrader: $data = new LettingAgents_Object_SoleTraderContact(); // Assign agenty_id, this is the index NOT the agent scheme number $data->set_agency_id($agentData->get_id()); // Set unique ID if (isset($postData['subform_common']['uid'])) { $data->set_uid($postData['subform_common']['uid']); } // Assign subform_soletrader if (isset($postData['subform_soletrader']['contact_name'])) { $data->set_contact_name($postData['subform_soletrader']['contact_name']); } if (isset($postData['subform_soletrader']['ni_number'])) { $data->set_ni_number($postData['subform_soletrader']['ni_number']); } if (isset($postData['subform_soletrader']['passport_number'])) { $data->set_passport_number($postData['subform_soletrader']['passport_number']); } if (isset($postData['subform_soletrader']['birth_date'])) { $data->set_birth_date($postData['subform_soletrader']['birth_date']); } // Assign subform_address if (isset($postData['subform_address']['address_line1'])) { $data->set_address1($postData['subform_address']['address_line1']); } if (isset($postData['subform_address']['address_line2'])) { $data->set_address2($postData['subform_address']['address_line2']); } if (isset($postData['subform_address']['address_line3'])) { $data->set_address3($postData['subform_address']['address_line3']); } if (isset($postData['subform_address']['postcode'])) { $data->set_postcode($postData['subform_address']['postcode']); } // Zend_Debug::dump($data);die(); $contactManager = new LettingAgents_Manager_Contacts(); $contactManager->save($data); break; } $this->_formStepCommonNavigate(2); return; } elseif (isset($_POST['back'])) { $this->_formStepCommonNavigate(2); return; } } // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 2)) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->render('step'); } }