예제 #1
0
 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
 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
 /**
  * Sets the first post
  *
  * @param Post
  * @return null
  */
 public function setFirstPost(Post $post)
 {
     $post->setTopic($this);
     $this->firstPost = $post;
 }
예제 #4
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());
 }
예제 #5
0
 public function isPosteriorTo(Post $post = null)
 {
     if (!$post) {
         return true;
     }
     return $this->getCreatedAt()->getTimestamp() > $post->getCreatedAt()->getTimestamp();
 }