コード例 #1
0
ファイル: PostRemover.php プロジェクト: jewome62/ForumBundle
 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());
 }
コード例 #2
0
ファイル: PostCreator.php プロジェクト: jewome62/ForumBundle
 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());
 }
コード例 #3
0
 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());
 }