Ejemplo n.º 1
0
 public function saveAction()
 {
     $form = new Forum_Form_Forum();
     $table = new Tri_Db_Table('forum');
     $session = new Zend_Session_Namespace('data');
     $data = $this->_getAllParams();
     if ($form->isValid($data)) {
         $data = $form->getValues();
         $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id;
         $data['classroom_id'] = $session->classroom_id;
         if (!$data['end']) {
             unset($data['end']);
         }
         if (isset($data['id']) && $data['id']) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
             Application_Model_Timeline::save('created a new forum', $data['title']);
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $this->_redirect('forum/index/form/id/' . $id);
     }
     $this->_helper->_flashMessenger->addMessage('Error');
     $this->view->form = $form;
     $this->render('form');
 }
Ejemplo n.º 2
0
 /**
  * Edit a forum
  *
  * @throws Zend_Controller_Exception
  * @return void
  */
 public function editAction()
 {
     /**
      * @var $request Zend_Controller_Request_Http
      */
     $request = $this->getRequest();
     $fid = intval($request->getParam('fid'));
     $model = new Forum_Model_DbTable_Forum();
     $forum = $model->find($fid)->current();
     if (!$forum) {
         throw new Zend_Controller_Action_Exception(sprintf("Forum with ID '%d' was not found", $fid), 404);
     }
     $form = new Forum_Form_Forum();
     if ($request->isPost() && $form->isValid($this->_getParam('forumForm'))) {
         $forum->setFromArray($form->getValues())->save();
         $this->_redirect($this->urlHelper->url(array('fid' => $fid), 'forum_show'));
     }
     $this->view->assign('form', $form);
 }