public function remove(Post $post) { $topic = $post->getTopic(); if (1 === $post->getNumber()) { 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 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()); }