Esempio n. 1
0
 /** Edit an event
  * @access public
  * @return void
  * @todo Add geocoding in model
  */
 public function editAction()
 {
     $form = new EventForm();
     $form->details->setLegend('Edit event');
     $form->submit->setLabel('Save event');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $where = array();
             $where[] = $this->_events->getAdapter()->quoteInto('id = ?', $this->getParam('id'));
             $this->_events->update($form->getValues(), $where);
             $this->getFlash()->addMessage('You updated this events successfully.');
             $this->redirect('/admin/events/');
         } else {
             $form->populate($this->_request->getPost());
         }
     } else {
         $form->populate($this->_events->fetchRow('id=' . $this->getParam('id'))->toArray());
     }
 }
Esempio n. 2
0
 /** Edit event details
  */
 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'];
             } else {
                 $lat = null;
                 $lon = 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->getFlash()->addMessage('You updated: <em>' . $form->getValue('eventTitle') . '</em> successfully.');
             $this->redirect('/users/events/');
         } else {
             $form->populate($formData);
         }
     } else {
         // find id is expected in $params['id']
         $id = (int) $this->_request->getParam('id', 0);
         if ($id > 0) {
             $events = new Events();
             $event = $events->fetchRow('id=' . (int) $id);
             $form->populate($event->toArray());
         }
     }
 }