/**
  *
  * @access protected
  * @param  \Map2u\ForumBundle\Entity\Post                        $post
  * @return \Map2u\ForumBundle\Form\Handler\PostUpdateFormHandler
  */
 protected function getFormHandlerToEditPost(Post $post)
 {
     // If post is the very first post of the topic then use a topic handler so user can change topic title.
     if ($post->getTopic()->getFirstPost()->getId() == $post->getId()) {
         $formHandler = $this->container->get('map2u_forum.form.handler.topic_update');
     } else {
         $formHandler = $this->container->get('map2u_forum.form.handler.post_update');
     }
     $formHandler->setPost($post);
     $formHandler->setUser($this->getUser());
     $formHandler->setRequest($this->getRequest());
     return $formHandler;
 }
 /**
  *
  * @access public
  * @return \Symfony\Component\Form\Form
  */
 public function getForm()
 {
     if (null == $this->form) {
         if (!is_object($this->post) || !$this->post instanceof Post) {
             throw new \Exception('Post must be specified to be update a Topic in TopicUpdateFormHandler');
         }
         $topic = $this->post->getTopic();
         if (!is_object($topic) || !$topic instanceof Topic) {
             throw new \Exception('Post must have a valid Topic in TopicUpdateFormHandler');
         }
         $topicOptions = array('auto_initialize' => false);
         $this->dispatcher->dispatch(ForumEvents::USER_POST_EDIT_INITIALISE, new UserPostEvent($this->request, $this->post));
         $this->form = $this->factory->create($this->formPostType, $this->post);
         $this->form->add($this->factory->create($this->formTopicType, $topic, $topicOptions));
     }
     return $this->form;
 }
 /**
  *
  * @access protected
  * @param \Map2u\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     $post->setCreatedDate(new \DateTime());
     $post->setCreatedBy($this->user);
     $post->setTopic($this->topic);
     $post->setDeleted(false);
     $this->dispatcher->dispatch(ForumEvents::USER_TOPIC_REPLY_SUCCESS, new UserTopicEvent($this->request, $post->getTopic()));
     $this->postModel->savePost($post);
     $this->dispatcher->dispatch(ForumEvents::USER_TOPIC_REPLY_COMPLETE, new UserTopicEvent($this->request, $this->topic, $this->didAuthorSubscribe()));
 }
 /**
  *
  * @access public
  * @param  \Map2u\ForumBundle\Entity\Forum                        $forum
  * @param  \Map2u\ForumBundle\Entity\Post                         $post
  * @return \Map2u\ForumBundle\Component\Crumbs\Factory\CrumbTrail
  */
 public function addUserPostShow(Forum $forum, Post $post)
 {
     return $this->addUserTopicShow($forum, $post->getTopic())->add('# ' . $post->getId(), array('route' => 'ccdn_forum_user_post_show', 'params' => array('forumName' => $forum->getName(), 'postId' => $post->getId())));
 }
 /**
  *
  * @access protected
  * @param \Map2u\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     $post->setCreatedDate(new \DateTime());
     $post->setCreatedBy($this->user);
     $post->setDeleted(false);
     $topic = $post->getTopic();
     $topic->setCachedViewCount(0);
     $topic->setCachedReplyCount(0);
     $topic->setClosed(false);
     $topic->setDeleted(false);
     $topic->setSticky(false);
     $this->dispatcher->dispatch(ForumEvents::USER_TOPIC_CREATE_SUCCESS, new UserTopicEvent($this->request, $topic));
     $this->postModel->savePost($post);
     $topic->setFirstPost($post);
     $topic->setLastPost($post);
     $this->topicModel->saveTopic($topic);
     $this->dispatcher->dispatch(ForumEvents::USER_TOPIC_CREATE_COMPLETE, new UserTopicEvent($this->request, $topic, $this->didAuthorSubscribe()));
 }
Exemple #6
0
 public function canShowPost(Post $post, Forum $forum = null)
 {
     if ($post->getTopic()) {
         if (!$this->canShowTopic($post->getTopic(), $forum)) {
             return false;
         }
     }
     if ($post->isDeleted() && !$this->securityContext->isGranted('ROLE_MODERATOR')) {
         return false;
     }
     return true;
 }