/**
  *
  * @access public
  * @param  \CCDNForum\ForumBundle\Entity\Post $post
  * @return bool
  */
 public function isLocked(Post $post)
 {
     if ($this->enabled) {
         return $post->isLocked();
     }
     return false;
 }
 protected function createPost($topic, $body, $author)
 {
     $post = new Post();
     $post->setTopic($topic);
     $post->setCreatedBy($author);
     $post->setCreatedDate(new \DateTime());
     $post->setDeleted(false);
     $post->setBody($body);
     return $post;
 }
 /**
  *
  * @access protected
  * @param  \CCDNForum\ForumBundle\Entity\Post                        $post
  * @return \CCDNForum\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('ccdn_forum_forum.form.handler.topic_update');
     } else {
         $formHandler = $this->container->get('ccdn_forum_forum.form.handler.post_update');
     }
     $formHandler->setPost($post);
     $formHandler->setUser($this->getUser());
     $formHandler->setRequest($this->getRequest());
     return $formHandler;
 }
 /**
  *
  * @access public
  * @param  \CCDNForum\ForumBundle\Entity\Forum                        $forum
  * @param  \CCDNForum\ForumBundle\Entity\Post                         $post
  * @return \CCDNForum\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 \CCDNForum\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     // get the current time, and compare to when the post was made.
     $now = new \DateTime();
     $interval = $now->diff($post->getCreatedDate());
     // if post is less than 15 minutes old, don't add that it was edited.
     if ($interval->format('%i') > 15) {
         $post->setEditedDate(new \DateTime());
         $post->setEditedBy($this->user);
     }
     $this->dispatcher->dispatch(ForumEvents::USER_POST_EDIT_SUCCESS, new UserPostEvent($this->request, $this->post));
     $this->postModel->updatePost($post);
     $this->dispatcher->dispatch(ForumEvents::USER_POST_EDIT_COMPLETE, new UserPostEvent($this->request, $this->post));
 }
 /**
  *
  * @access public
  * @param  \CCDNForum\ForumBundle\Entity\Post                  $post
  * @param  \Symfony\Component\Security\Core\User\UserInterface $user
  * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
  */
 public function softDelete(Post $post, UserInterface $user)
 {
     // Don't overwite previous users accountability.
     if (!$post->getDeletedBy() && !$post->getDeletedDate()) {
         $post->setDeleted(true);
         $post->setDeletedBy($user);
         $post->setDeletedDate(new \DateTime());
         // update the record
         $this->persist($post)->flush();
     }
     return $this;
 }
 /**
  *
  * @access protected
  * @param \CCDNForum\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     $post->setCreatedDate(new \DateTime());
     if ($this->anon) {
         $post->setAnonName($post->GetAnonName());
     } else {
         $post->setCreatedBy($this->user);
     }
     $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()));
 }
 /**
  *
  * @access protected
  * @param \CCDNForum\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     $post->setCreatedDate(new \DateTime());
     if ($this->anon) {
         $post->setAnonName($post->GetAnonName());
     } else {
         $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()));
 }
 public function canRestorePost(Post $post, Forum $forum = null)
 {
     if (!$this->securityContext->isGranted('ROLE_MODERATOR')) {
         return false;
     }
     if (!$post->isDeleted()) {
         return false;
     }
     if (!$this->canShowPost($post, $forum) && !$this->securityContext->isGranted('ROLE_MODERATOR')) {
         return false;
     }
     return true;
 }
 /**
  *
  * @access protected
  * @param \CCDNForum\ForumBundle\Entity\Post $post
  */
 protected function onSuccess(Post $post)
 {
     $post->setUnlockedDate(new \Datetime('now'));
     $post->setUnlockedBy($this->user);
     $this->dispatcher->dispatch(ForumEvents::MODERATOR_POST_UNLOCK_SUCCESS, new ModeratorPostEvent($this->request, $this->post));
     $this->postModel->updatePost($post);
     $this->dispatcher->dispatch(ForumEvents::MODERATOR_POST_UNLOCK_COMPLETE, new ModeratorPostEvent($this->request, $post));
 }
 /**
  *
  * @access protected
  * @param \CCDNForum\ForumBundle\Entity\Post $post
  */
 protected function updateRegistryStats(Post $post)
 {
     $user = $post->getCreatedBy();
     if ($user) {
         $registry = $this->registryModel->findOrCreateOneRegistryForUser($user);
         $postCount = $this->postModel->countPostsForUserById($user->getId());
         $registry->setCachedPostCount($postCount ? $postCount : 0);
         $this->registryModel->saveRegistry($registry);
     }
 }