Example #1
0
 /**
  * Removes a Post
  * @param    Courtyard\Forum\Entity\PostInterface
  */
 public function delete($post)
 {
     if ($post->getNumber() == 1) {
         throw new \BadMethodCallException('Cannot delete the first post of a topic');
     }
     $postEvent = new PostEvent($post);
     $postEvent->addEntityToRemove($post);
     $this->dispatcher->dispatch($this->dispatcher->newTransaction()->addFirstPass(ForumEvents::POST_DELETE_PRE, $postEvent)->addSecondPass(ForumEvents::POST_DELETE_POST, clone $postEvent));
 }
Example #2
0
 /**
  * Creates a new Topic
  *
  * @param    Courtyard\Forum\Entity\TopicInterface
  */
 public function persist($topic)
 {
     if (!$topic->getPostFirst()) {
         throw new \InvalidArgumentException('Cannot persist a Topic without a first Post');
     }
     $topic->setStatus(TopicStatuses::STATUS_PUBLISHED);
     $post = $topic->getPostFirst();
     $post->setNumber(1);
     $post->setStatus(postStatuses::STATUS_PUBLISHED);
     $topic->getPostFirst()->setNumber(1);
     $topic->GetPostFirst()->setStatus(PostStatuses::STATUS_PUBLISHED);
     $topicEvent = new TopicEvent($topic);
     $topicEvent->addEntityToPersist($topic);
     $postEvent = new PostEvent($post);
     $postEvent->addEntityToPersist($post);
     $this->dispatcher->dispatch($this->dispatcher->newTransaction()->addFirstPass(ForumEvents::TOPIC_CREATE_PRE, $topicEvent)->addFirstPass(ForumEvents::POST_CREATE_PRE, $postEvent)->addSecondPass(ForumEvents::TOPIC_CREATE_POST, clone $topicEvent)->addSecondPass(ForumEvents::POST_CREATE_POST, clone $postEvent));
 }