Пример #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));
 }
Пример #2
0
 /**
  * Edits the content of a comment
  *
  * @param void
  * @return ViewModel
  * @throws AccessProhibitedException
  **/
 public function editAction()
 {
     $this->_checkAcl('edit');
     $comment = $this->_service->getOne($this->getRequest()->getQuery('id'));
     $form = new CommentForm();
     $form->bind($comment);
     $form->remove('parentId');
     $form->remove('captcha');
     $form->get('comment')->setAttribute('id', 'commentEditor');
     $form->get('comment')->setAttribute('class', 'ckeditor');
     $form->get('submit')->setValue('Save');
     $this->_service->setForm($form);
     if ($this->getRequest()->isPost()) {
         $this->_service->edit($this->getRequest()->getPost());
     }
     return new ViewModel(array('form' => $form, 'messages' => $this->_service->getMessages(CommentService::MSG_NOTICE), 'errors' => $this->_service->getMessages(CommentService::MSG_ERROR)));
 }