/**
  * Post comment (via ajax)
  */
 public function postcommentAction()
 {
     $add_comment_form = new Application_Form_AddComment();
     $json = array();
     $request = $this->getRequest();
     if ($request->isPost() && $add_comment_form->isValid($_POST)) {
         $comment_content = $add_comment_form->getValue('comment');
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             $this->getHelper('json')->sendJson(false);
         }
         $resource_type = $add_comment_form->getValue('resource_type');
         $resource_id = (int) $add_comment_form->getValue('resource_id');
         $Comments = new Application_Model_Comments();
         $Comments->addComment($comment_content, $resource_id, $resource_type);
         $new_comments_data = $Comments->getCommentsForResources(array($resource_id), $resource_type);
         if (isset($new_comments_data[$resource_id])) {
             $add_comment_form->reset();
             $this->view->comments = $new_comments_data[$resource_id];
             $this->view->resource_type = $resource_type;
             $this->view->resource_id = $resource_id;
             $this->view->add_comment_form = $add_comment_form;
             $comments_html = $this->view->render('/partial/comments.phtml');
             $json['html'] = $comments_html;
         }
     }
     $json['errors'] = $add_comment_form->getMessages();
     $this->getHelper('json')->sendJson($json);
 }
Beispiel #2
0
 public function listAction()
 {
     $authorization = Zend_Auth::getInstance();
     $identity = $authorization->getIdentity();
     if ($identity->user_type == "admin") {
         $model = new Application_Model_Comments();
         $comments = $model->listComments();
         $this->view->comments = $comments;
         $form = new Application_Form_Comments();
         $mid = $this->getRequest()->getParam('mid');
         $cid = $this->getRequest()->getParam('cid');
         if ($cid) {
             $model = new Application_Model_Comments();
             $comment_data = $model->getCommentById($cid);
             var_dump($comment_data);
             $form->populate($comment_data[0]);
             if ($this->getRequest()->isPost()) {
                 if ($form->isValid($_POST)) {
                     $model = new Application_Model_Comments();
                     $model->editComment($form->getValues(), $cid);
                     //$this->view->identity->id
                     $this->redirect("/comments/list");
                 }
             }
         }
         if ($mid) {
             //$this->view->page_title = "Add Course";
             //$page=$this->_getParam('page',1);
             //$paginator = Zend_Paginator::factory($courses);
             // $paginator->setItemCountPerPage(10);
             //$paginator->setCurrentPageNumber($page);
             if ($this->getRequest()->isPost()) {
                 if ($form->isValid($_POST)) {
                     $model = new Application_Model_Comments();
                     //var_dump($identity);
                     $form->getElement("uid")->setValue($identity->id);
                     //session
                     $form->getElement("mid")->setValue($mid);
                     $form->getElement("cdate")->setValue(date('Y-m-d'));
                     $model->addComment($form->getValues());
                     $form->reset();
                     $this->redirect('comments/list/mid/' . $mid);
                 }
             }
         }
         $this->view->form = $form;
         $this->view->identity = $identity;
     } else {
         echo "hjjjj";
         $mid = $this->getRequest()->getParam('mid');
         if ($mid) {
             $model = new Application_Model_Comments();
             $comments = $model->listComments();
             $this->view->comments = $comments;
             $form = new Application_Form_Comments();
             if ($this->getRequest()->isPost()) {
                 if ($form->isValid($_POST)) {
                     $model = new Application_Model_Comments();
                     //var_dump($identity);
                     $form->getElement("uid")->setValue($identity->id);
                     //session
                     $form->getElement("mid")->setValue($mid);
                     $form->getElement("cdate")->setValue(date('Y-m-d'));
                     $model->addComment($form->getValues());
                     $form->reset();
                     $this->redirect('comments/list/mid/' . $mid);
                 }
             }
             $this->view->form = $form;
             $this->view->identity = $identity;
         } else {
             $this->redirect('users/login');
         }
     }
 }