Esempio n. 1
0
 /**
  * Removes a Post.
  *
  * @param Post $post The Post to be removed
  *
  * @return void
  * @throws \Mittwald\Typo3Forum\Domain\Exception\InvalidOperationException
  */
 public function removePost(\Mittwald\Typo3Forum\Domain\Model\Forum\Post $post)
 {
     if ($this->postCount === 1) {
         throw new \Mittwald\Typo3Forum\Domain\Exception\InvalidOperationException('You cannot delete the last post of a topic without deleting the topic itself (use \\Mittwald\\Typo3Forum\\Domain\\Factory\\Forum\\TopicFactory::deleteTopic for that).', 1334603895);
     }
     $this->posts->detach($post);
     $this->postCount--;
     if ($this->lastPost == $post) {
         $postsArray = $this->posts->toArray();
         $this->setLastPost(array_pop($postsArray));
     }
     if ($this->forum !== NULL) {
         $this->forum->_increasePostCount(-1);
         if ($this->forum->getLastPost() === $post) {
             $this->forum->_resetLastPost();
         }
     }
 }