示例#1
0
 /** 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']);
         }
     }
 }
示例#2
0
 /** Get whether the district exists in the OS system
  * @access protected
  * @param string $value
  * @return string
  */
 protected function _getDistrict($value)
 {
     $districts = new OsDistricts();
     $where[] = $districts->getAdapter()->quoteInto('osID = ?', $value);
     $district = $districts->fetchRow($where);
     return $district;
 }
 /** Clone the options and add to form
  * @access public
  * @return \Pas_Controller_Action_Helper_FindspotFormOptions
  */
 public function optionsAddClone($data)
 {
     $this->_view->form->populate($data);
     Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage('Your last record data has been cloned');
     if (array_key_exists('countyID', $data) && !is_null($data['countyID'])) {
         $districts = new OsDistricts();
         $district = $districts->getDistrictsToCountyList($data['countyID']);
         if ($district) {
             $this->_view->form->districtID->addMultiOptions(array(null => 'Choose district', 'Available districts' => $district));
         }
         if (array_key_exists('districtID', $data) && !is_null($data['districtID'])) {
             $parishes = new OsParishes();
             $parishes = $parishes->getParishesToDistrictList($data['districtID']);
             $this->_view->form->parishID->addMultiOptions(array(null => 'Choose parish', 'Available parishes' => $parishes));
         }
         if (array_key_exists('countyID', $data) && !is_null($data['countyID'])) {
             $cnts = new OsCounties();
             $region_list = $cnts->getCountyToRegionList($data['countyID']);
             $this->_view->form->regionID->addMultiOptions(array(null => 'Choose region', 'Available regions' => $region_list));
         }
     }
     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));
     }
     return $this;
 }
 /** 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);
     }
 }
示例#5
0
 /** Function for updating findspots with processing of geodata
  * @access public
  * @param array $data
  * @return array
  */
 public function updateAndProcess(array $data)
 {
     if (is_array($data)) {
         foreach ($data as $k => $v) {
             if ($v == "") {
                 $data[$k] = null;
             }
         }
         if (!is_null($data['gridref'])) {
             $data = $this->_processFindspot($data);
         }
     }
     if (array_key_exists('csrf', $data)) {
         unset($data['csrf']);
     }
     if (array_key_exists('submit', $data)) {
         unset($data['submit']);
     }
     if (array_key_exists('organisername', $data)) {
         unset($data['organisername']);
     }
     if (array_key_exists('parishID', $data) && !is_null($data['parishID'])) {
         $parishes = new OsParishes();
         $data['parish'] = $parishes->fetchRow($parishes->select()->where('osID = ?', $data['parishID']))->label;
     }
     if (array_key_exists('countyID', $data) && !is_null($data['countyID'])) {
         $counties = new OsCounties();
         $data['county'] = $counties->fetchRow($counties->select()->where('osID = ?', $data['countyID']))->label;
     }
     if (array_key_exists('districtID', $data) && !is_null($data['districtID'])) {
         $district = new OsDistricts();
         $data['district'] = $district->fetchRow($district->select()->where('osID = ?', $data['districtID']))->label;
     }
     return $data;
 }
示例#6
0
 /** Get the os districts by county json
  * @access public
  */
 public function osdistrictsbycountyAction()
 {
     if ($this->getParam('term', false)) {
         $districts = new OsDistricts();
         $json = $districts->getDistrictsToCounty($this->getParam('term'));
     } else {
         $json = array(null => 'You must choose a county first');
     }
     echo Zend_Json::encode($json);
 }