/** 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); } }
/** Add a new rally * @access public * @return void * @todo move functionality to model */ public function addAction() { $form = new RallyForm(); $form->submit->setLabel('Add a new rally'); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $insert = $this->getRallies()->addAndProcess($formData); $this->getCache()->remove('rallydds'); $this->redirect(self::URL . 'rally/id/' . $insert); $this->getFlash()->addMessage('Details for ' . $form->getValue('rally_name') . ' have been created!'); } else { $data = $this->_request->getPost(); $form->populate($data); if (array_key_exists('countyID', $data)) { $district_list = $this->_districts->getDistrictsToCountyList($data['countyID']); $form->districtID->addMultiOptions(array(null => 'Choose a district', 'Available districts' => $district_list)); } if (array_key_exists('districtID', $data)) { $parish_list = $this->_parishes->getParishesToDistrictList($data['districtID']); $form->parishID->addMultiOptions(array(null => 'Choose a parish', 'Available parishes' => $parish_list)); } } } }