/** Edit individual rally details */ public function editAction() { if ($this->_getParam('id', false)) { $form = new RallyForm(); $form->submit->setLabel('Update details'); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $results = $this->GridCalc($form->getValue('gridref')); $fourFigure = $this->FourFigure($form->getValue('gridref')); $updateData = array('rally_name' => $form->getValue('rally_name'), 'organiser' => $form->getValue('organiser'), 'county' => $form->getValue('county'), 'district' => $form->getValue('district'), 'parish' => $form->getValue('parish'), 'gridref' => $form->getValue('gridref'), 'easting' => $results['Easting'], 'northing' => $results['Northing'], 'latitude' => $results['Latitude'], 'longitude' => $results['Longitude'], 'map10k' => $results['Tenk'], 'map25k' => $results['2pt5K'], 'fourFigure' => $fourFigure, 'comments' => $form->getValue('comments'), 'record_method' => $form->getValue('record_method'), 'date_from' => $form->getValue('date_from'), 'date_to' => $form->getValue('date_to'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms()); $where = array(); $where[] = $this->_rallies->getAdapter()->quoteInto('id = ?', $this->_getParam('id')); $update = $this->_rallies->update($updateData, $where); $this->_cache->remove('rallydd'); $this->_flashMessenger->addMessage('Rally information updated!'); $this->_redirect(self::URL . 'rally/id/' . $this->_getParam('id')); } else { if (!is_null($formData['district'])) { $districts = new Places(); $district_list = $districts->getDistrictList($formData['county']); $form->district->addMultiOptions(array(NULL => NULL, 'Choose district' => $district_list)); $parish_list = $districts->getParishList($formData['district']); $form->parish->addMultiOptions(array(NULL => NULL, 'Choose parish' => $parish_list)); } $form->populate($formData); } } else { // find id is expected in $params['id'] $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $rallies = new Rallies(); $rally = $rallies->fetchRow('id=' . $id); if (count($rally)) { $form->populate($rally->toArray()); } else { throw new Exception($this->_nothingFound); } if (!is_null($rally['district'])) { $districts = new Places(); $district_list = $districts->getDistrictList($rally['county']); $form->district->addMultiOptions(array(NULL => NULL, 'Choose district' => $district_list)); $parish_list = $districts->getParishList($rally['district']); $form->parish->addMultiOptions(array(NULL => NULL, 'Choose parish' => $parish_list)); } if (!is_null($rally['organiser'])) { $organisers = new Peoples(); $organisers = $organisers->getName($rally['organiser']); foreach ($organisers as $organiser) { $form->organisername->setValue($organiser['term']); } } } } } else { throw new Exception($this->_missingParameter); } }
/** 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); } }