Beispiel #1
0
 public function editTourAction()
 {
     $form = $this->view->form = new Yntour_Form_Tour_Create();
     $model = new Yntour_Model_DbTable_Tours();
     $id = $this->_getParam('tour_id', 0);
     $item = $model->find($id)->current();
     $request = $this->getRequest();
     if ($request->isGet()) {
         if (is_object($item)) {
             $form->populate($item->toArray());
         } else {
             $uri = parse_url($request->getServer('HTTP_REFERER'));
             $path = trim($uri['path']);
             $baseURL = $request->getBaseUrl();
             $path = str_replace($baseURL, '', $path);
             $bodyid = $this->_getParam('body', 'global_page_user-index-home');
             $form->populate(array('path' => $path, 'bodyid' => $bodyid));
         }
         return;
     }
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $data = $form->getValues();
         if (!is_object($item)) {
             $item = $model->fetchNew();
             $item->creation_date = date('Y-m-d H:i:s');
             $item->setPath($form->getValue('path'));
             $item->hash = md5(mt_rand(0, 999999) . mt_rand(0, 999999) . mt_rand(0, 99999), false);
         }
         $item->setFromArray($data);
         if (!$item->save()) {
             throw Exception("Invalid data");
         }
         $this->_forward('success', 'utility', 'core', array('smoothboxClose' => 10, 'parentRefresh' => 10, 'messages' => array('Successful.')));
     }
 }
 public function deleteAction()
 {
     $form = $this->view->form = new Yntour_Form_Admin_Tour_Delete();
     // In smoothbox
     $this->_helper->layout->setLayout('admin-simple');
     $id = $this->_getParam('id');
     $model = new Yntour_Model_DbTable_Tours();
     // Check post
     if ($this->getRequest()->isPost()) {
         $db = $model->getAdapter();
         $db->beginTransaction();
         try {
             $item = $model->find($id)->current();
             // delete the blog entry into the database
             $item->delete();
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->_forward('success', 'utility', 'core', array('smoothboxClose' => 10, 'parentRefresh' => 10, 'messages' => array('Successful.')));
     }
 }