Пример #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
 /** 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);
     }
 }
Пример #3
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;
 }
Пример #4
0
 /** Check the parish exists from the model
  * @access protected
  * @param integer $value
  * @return array
  */
 protected function _getParish($value)
 {
     $parishes = new OsParishes();
     $where[] = $parishes->getAdapter()->quoteInto('osID = ?', $value);
     return $parishes->fetchRow($where);
 }
Пример #5
0
 /** Get os parishes by district
  * @access public
  */
 public function osparishesbydistrictAction()
 {
     if ($this->getParam('term', false)) {
         $parishes = new OsParishes();
         $json = $parishes->getParishesToDistrict($this->getParam('term'));
     } else {
         $json = array(null => 'You must choose a district first');
     }
     echo Zend_Json::encode($json);
 }