Example #1
0
 public function showAction()
 {
     $slug = $this->params('slug', null);
     if (!$slug) {
         return $this->redirect()->toRoute('home');
     }
     $post = $this->postService->getPostBySlug($slug);
     if (!$post) {
         $this->flashMessenger()->addErrorMessage($this->getTranslation('POST_NOT_FOUND_SLUG', array($slug)));
         return $this->redirect()->toRoute('posts');
     }
     $request = $this->getRequest();
     $comment = new Comment();
     $this->commentForm->bind($comment);
     if ($request->isPost()) {
         $data = $request->getPost();
         $this->commentForm->setData($data);
         if ($this->commentForm->isValid()) {
             /** @var Comment $comment */
             $comment = $this->commentForm->getData();
             $this->commentService->addComment($comment, $post);
             $this->flashMessenger()->addSuccessMessage($this->getTranslation('FORM_SUCCESS_COMMENT'));
             return $this->redirect()->toRoute('posts/show', array('slug' => $post->getSlug()));
         }
     }
     return new ViewModel(array('post' => $post, 'form' => $this->commentForm));
 }
 /**
  * Removes a comment given it's ID
  *
  * @param void
  * @return JsonModel
  * @throws AccessProhibitedException
  **/
 public function deleteAction()
 {
     $this->_checkAcl('delete');
     $comment = $this->_service->getOne($this->getRequest()->getQuery('id'));
     $this->_service->delete($comment);
     return new JsonModel(array('success' => true, 'message' => 'Successfully removed comment'));
 }
Example #3
0
 public function indexAction()
 {
     $criteria = array();
     $page = $this->params('page', 1);
     $post = $this->params('post', null);
     $author = $this->params('author', null);
     if ($post) {
         $criteria['post'] = $post;
     }
     if ($author) {
         $criteria['author'] = $author;
     }
     $comments = $this->commentService->getActiveComment($criteria);
     $comments->setItemCountPerPage(5)->setCurrentPageNumber($page);
     return new ViewModel(array('comments' => $comments, 'post' => isset($criteria['post']) ? $criteria['post'] : null, 'author' => isset($criteria['author']) ? $criteria['author'] : null));
 }
Example #4
0
 /**
  * To view a specific blog post
  *
  * @param void
  * @return ViewModel
  * @throws AccessProhibitedException
  **/
 public function viewAction()
 {
     $this->_checkAcl('view');
     $request = $this->getRequest();
     $post = $this->_postService->getFromTitle($request->getQuery('title'));
     $form = new CommentForm();
     $form->setReplyToList($post->getComments());
     $viewVars = array();
     if ($request->isPost()) {
         $service = new CommentService($this->_em);
         $service->setForm($form);
         $service->setPost($post);
         $service->save($request->getPost());
         $viewVars['messages'] = $service->getMessages(CommentService::MSG_NOTICE);
         $viewVars['errors'] = $service->getMessages(CommentService::MSG_ERROR);
     }
     $viewVars['post'] = $post;
     $viewVars['form'] = $form;
     $viewVars['query'] = $request->getQuery();
     return new ViewModel($viewVars);
 }