Esempio n. 1
0
 public function editAction()
 {
     $post = Engine_Api::_()->core()->getSubject('event_post');
     $event = $post->getParent('event');
     $viewer = Engine_Api::_()->user()->getViewer();
     if (!$event->isOwner($viewer) || !$post->isOwner($viewer)) {
         if (!$this->_helper->requireAuth()->setAuthParams($event, null, 'edit')->isValid()) {
             return;
         }
     }
     $this->view->form = $form = new Event_Form_Post_Edit();
     if (!$this->getRequest()->isPost()) {
         $form->populate($post->toArray());
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $table = $post->getTable();
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $post->setFromArray($form->getValues());
         $post->modified_date = date('Y-m-d H:i:s');
         $post->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     // Try to get topic
     return $this->_forward('success', 'utility', 'core', array('closeSmoothbox' => true, 'parentRefresh' => true));
 }
Esempio n. 2
0
 public function editAction()
 {
     $post = Engine_Api::_()->core()->getSubject('event_post');
     $event = $post->getParent('event');
     $viewer = Engine_Api::_()->user()->getViewer();
     if (!$event->isOwner($viewer) && !$post->isOwner($viewer)) {
         if (!$this->_helper->requireAuth()->setAuthParams($event, null, 'edit')->isValid()) {
             return;
         }
     }
     $this->view->form = $form = new Event_Form_Post_Edit();
     if (!$this->getRequest()->isPost()) {
         $form->populate($post->toArray());
         $form->body->setValue(html_entity_decode($post->body));
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $table = $post->getTable();
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $post->setFromArray($form->getValues());
         $post->modified_date = date('Y-m-d H:i:s');
         $post->body = htmlspecialchars($post->body, ENT_NOQUOTES, 'UTF-8');
         $post->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     // Try to get topic
     return $this->_forward('success', 'utility', 'core', array('closeSmoothbox' => true, 'parentRefresh' => true, 'messages' => array(Zend_Registry::get('Zend_Translate')->_('Your changes have been saved.'))));
 }