public function remove(Post $post) { $topic = $post->getTopic(); if (1 === $topic->getNumPosts()) { throw new LogicException('You shall not remove the first topic post. Remove the topic instead'); } $this->objectManager->remove($post); // Must flush because the topic updater will fetch posts from DB $this->objectManager->flush(); $this->topicUpdater->update($topic); // Must flush because the category updater will fetch topics from DB $this->objectManager->flush(); $this->categoryUpdater->update($topic->getCategory()); }
public function create(Post $post) { if (!($topic = $post->getTopic())) { throw new LogicException('Each post must have a topic'); } if (!($category = $topic->getCategory())) { throw new LogicException('Each topic must have a category'); } if (!$topic->getFirstPost()) { $topic->setFirstPost($post); } $topic->incrementNumPosts(); $topic->setLastPost($post); $topic->setPulledAt(new DateTime()); $category->setLastPost($post); $category->incrementNumPosts(); $post->setNumber($topic->getNumPosts()); }
public function createAction(Topic $topic) { $form = $this->get('forum.form.post'); $post = new Post(); $post->setTopic($topic); $form->bind($this->get('request'), $post); if (!$form->isValid()) { return $this->render('ForumBundle:Post:new.html.' . $this->getRenderer(), array('form' => $form, 'topic' => $topic)); } $post->setTopic($topic); $this->get('forum.creator.post')->create($post); $this->get('forum.blamer.post')->blame($post); $objectManager = $this->get('forum.object_manager'); $objectManager->persist($post); $objectManager->flush(); $this->get('session')->setFlash('forum_post_create/success', true); $url = $this->get('forum.router.url_generator')->urlForPost($post); return $this->redirect($url); }
public function urlForPost(Post $post, $absolute = false) { $topicUrl = $this->urlForTopic($post->getTopic(), $absolute); $topicPage = ceil($post->getNumber() / $this->nbPostsPerPage); return sprintf('%s?page=%d#%d', $topicUrl, $topicPage, $post->getNumber()); }
public function isPosteriorTo(Post $post = null) { if (!$post) { return true; } return $this->getCreatedAt()->getTimestamp() > $post->getCreatedAt()->getTimestamp(); }