예제 #1
0
 /**
  * Delete a specific Post
  * 
  * @param    Courtyard\Forum\Entity\PostInterface
  * @return   TemplateResponse or RedirectResponse on completion
  */
 public function deleteAction(PostInterface $post)
 {
     if ($post->getNumber() == 1) {
         throw new AccessDeniedHttpException('Cannot delete the first post.');
     }
     $form = $this->formFactory->create('forum_post_delete', $post);
     if ($this->request->getMethod() == 'POST') {
         $form->bindRequest($this->request);
         if ($form->isValid()) {
             $this->manager->delete($post);
             $this->session->getFlashBag()->add('success', 'Message deleted successfully.');
             return new RedirectResponse($this->router->generateTopicUrl($post->getTopic()));
         }
     }
     return new TemplateResponse(new TemplateReference('Posts', 'delete'), array('post' => $post, 'topic' => $post->getTopic(), 'board' => $post->getTopic()->getBoard(), 'form' => $form->createView()), ForumEvents::VIEW_POST_DELETE);
 }
예제 #2
0
 public function generatePostDeleteUrl(PostInterface $post, $absolute = false)
 {
     return $this->generator->generate('forum_post_delete', array('postId' => $post->getId()), $absolute);
 }