/** Populate the form with the array of data * @access public * @param array $data */ public function populate(array $data) { $this->_view->form->populate($data); if (array_key_exists('countyID', $data)) { $districts = new OsDistricts(); $district = $districts->getDistrictsToCountyList($data['countyID']); if ($district) { $this->_view->form->districtID->addMultiOptions(array(null => 'Choose a district', 'Available districts' => $district)); } if (array_key_exists('districtID', $data)) { $parishModel = new OsParishes(); $parishes = $parishModel->getParishesToDistrictList($data['districtID']); $this->_view->form->parishID->addMultiOptions(array(null => 'Choose a parish', 'Available parishes' => $parishes)); } if (array_key_exists('countyID', $data)) { $countyModel = new OsCounties(); $regions = $countyModel->getCountyToRegionList($data['countyID']); $this->_view->form->regionID->addMultiOptions(array(null => 'Choose a region', 'Available regions' => $regions)); } } if (array_key_exists('landusevalue', $data)) { $landcodes = new Landuses(); $landusecode_options = $landcodes->getLandusesChildList($data['landusevalue']); $this->_view->form->landusecode->addMultiOptions(array(null => 'Choose code', 'Available landuses' => $landusecode_options)); } if (array_key_exists('landowner', $data)) { $finders = new People(); $finders = $finders->getName($data['landowner']); foreach ($finders as $finder) { $this->_view->form->landownername->setValue($finder['term']); } } }
/** Edit individual rally details * @access public * @return void * @todo DRY this * @throws Pas_Exception_Param */ public function editAction() { if ($this->getParam('id', false)) { $form = new RallyForm(); $form->submit->setLabel('Update details'); $this->view->form = $form; if ($this->_request->isPost()) { if ($form->isValid($this->_request->getPost())) { $updateData = $this->getRallies()->updateAndProcess($form->getValues()); $where = array(); $where[] = $this->getRallies()->getAdapter()->quoteInto('id = ?', $this->getParam('id')); unset($updateData['created']); $this->getRallies()->update($updateData, $where); $this->getCache()->remove('rallydds'); $this->getFlash()->addMessage('Rally information updated!'); $this->redirect(self::URL . 'rally/id/' . $this->getParam('id')); } else { if (!is_null($formData['districtID'])) { $district_list = $this->_districts->getDistrictsToCountyList($formData['countyID']); $form->districtID->addMultiOptions(array(null => 'Choose a district', 'Available districts' => $district_list)); $parish_list = $this->_parishes->getParishesToDistrictList($formData['districtID']); $form->parishID->addMultiOptions(array(null => 'Choose a parish', 'Available parishes' => $parish_list)); } $form->populate($this->_request->getPost()); } } else { // find id is expected in $params['id'] $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $rally = $this->getRallies()->fetchRow('id=' . $id); if ($rally) { $form->populate($rally->toArray()); } else { throw new Pas_Exception_Param($this->_nothingFound, 404); } $district_list = $this->getDistricts()->getDistrictsToCountyList($rally['countyID']); $form->districtID->addMultiOptions(array(null => 'Choose a district', 'Available districts' => $district_list)); $parish_list = $this->getParishes()->getParishesToDistrictList($rally['districtID']); $form->parishID->addMultiOptions(array(null => 'Choose a parish', 'Available parishes' => $parish_list)); if (!is_null($rally['organiser'])) { $organisers = $this->getPeople()->getName($rally['organiser']); foreach ($organisers as $organiser) { $form->organisername->setValue($organiser['term']); } } } } } else { throw new Pas_Exception_Param($this->_missingParameter, 404); } }