예제 #1
0
 /** Edit an event
  */
 public function editAction()
 {
     $form = new EventForm();
     $form->details->setLegend('Edit event');
     $form->submit->setLabel('Save event');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $address = $form->getValue('eventLocation');
             $coords = $this->_geocoder->getCoordinates($address);
             if ($coords) {
                 $lat = $coords['lat'];
                 $long = $coords['lon'];
                 $pm = new Pas_Service_Geoplanet();
                 $place = $pm->reverseGeoCode($lat, $lon);
                 $woeid = $place['woeid'];
             } else {
                 $lat = NULL;
                 $lon = NULL;
                 $woeid = NULL;
             }
             $insertdata = array('eventTitle' => $form->getValue('eventTitle'), 'eventDescription' => $form->getValue('eventDescription'), 'eventLocation' => $form->getValue('eventLocation'), 'organisation' => $form->getValue('organisation'), 'eventStartTime' => $form->getValue('eventStartTime'), 'eventEndTime' => $form->getValue('eventEndTime'), 'eventStartDate' => $form->getValue('eventStartDate'), 'eventEndDate' => $form->getValue('eventEndDate'), 'eventRegion' => $form->getValue('eventRegion'), 'eventType' => $form->getValue('eventType'), 'latitude' => $lat, 'longitude' => $long, 'adultsAttend' => $form->getValue('adultsAttend'), 'childrenAttend' => $form->getValue('childrenAttend'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms());
             foreach ($insertdata as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($insertdata[$key]);
                 }
             }
             $events = new Events();
             $where = array();
             $where[] = $events->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
             $events->update($insertdata, $where);
             $this->_flashMessenger->addMessage('You updated: <em>' . $form->getValue('eventTitle') . '</em> successfully.');
             $this->_redirect('/admin/events/');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = (int) $this->_getParam('id', 0);
         if ($id > 0) {
             $events = new Events();
             $event = $events->fetchRow('id=' . (int) $id);
             $form->populate($event->toArray());
         }
     }
 }