/** * Creates a new topic. * * @param Forum $forum The forum in which the new topic is to be created. * @param Post $post The first post of the new topic. * @param string $subject The subject of the new topic * @param array $attachments File attachments for the post. * @param string $question The flag if the new topic is declared as question * @param array $criteria All submitted criteria with option. * @param string $tags All defined tags for this topic * @param string $subscribe The flag if the new topic is subscribed by author * * @validate $post \Mittwald\Typo3Forum\Domain\Validator\Forum\PostValidator * @validate $attachments \Mittwald\Typo3Forum\Domain\Validator\Forum\AttachmentPlainValidator * @validate $subject NotEmpty */ public function createAction(Forum $forum, Post $post, $subject, $attachments = array(), $question = '', $criteria = array(), $tags = '', $subscribe = '') { // Assert authorization $this->authenticationService->assertNewTopicAuthorization($forum); // Create the new post; add the new post to a new topic and add the new // topic to the forum. Then persist the forum object. Not as complicated // as is sounds, honestly! $this->postFactory->assignUserToPost($post); if (!empty($attachments)) { $attachments = $this->attachmentService->initAttachments($attachments); $post->setAttachments($attachments); } if ($tags) { $tags = $this->tagService->initTags($tags); foreach ($tags as $tag) { if ($tag->getUid === NULL) { $this->tagRepository->add($tag); } } } else { $tags = NULL; } $topic = $this->topicFactory->createTopic($forum, $post, $subject, (int) $question, $criteria, $tags, (int) $subscribe); // Notify potential listeners. $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Topic', 'topicCreated', ['topic' => $topic]); $this->clearCacheForCurrentPage(); $uriBuilder = $this->controllerContext->getUriBuilder(); $uri = $uriBuilder->setTargetPageUid($this->settings['pids']['Forum'])->setArguments(array('tx_typo3forum_pi1[forum]' => $forum->getUid(), 'tx_typo3forum_pi1[controller]' => 'Forum', 'tx_typo3forum_pi1[action]' => 'show'))->build(); $this->purgeUrl('http://' . $_SERVER['HTTP_HOST'] . '/' . $uri); // Redirect to single forum display view $this->redirect('show', 'Forum', NULL, array('forum' => $forum)); }
/** * Creates a new post. * * @param Topic $topic The topic in which the new post is to be created. * @param Post $post The new post. * @param array $attachments File attachments for the post. * * @validate $post \Mittwald\Typo3Forum\Domain\Validator\Forum\PostValidator * @validate $attachments \Mittwald\Typo3Forum\Domain\Validator\Forum\AttachmentPlainValidator */ public function createAction(Topic $topic, Post $post, array $attachments = array()) { // Assert authorization $this->authenticationService->assertNewPostAuthorization($topic); // Create new post, add the new post to the topic and persist the topic. $this->postFactory->assignUserToPost($post); if (!empty($attachments)) { $attachments = $this->attachmentService->initAttachments($attachments); $post->setAttachments($attachments); } $topic->addPost($post); $this->topicRepository->update($topic); // All potential listeners (Signal-Slot FTW!) $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Post', 'postCreated', array('post' => $post)); // Display flash message and redirect to topic->show action. $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Post_Create_Success'))); $this->clearCacheForCurrentPage(); $redirectArguments = array('topic' => $topic, 'forum' => $topic->getForum()); $pageNumber = $topic->getPageCount(); if ($pageNumber > 1) { $redirectArguments['@widget_0'] = array('currentPage' => $pageNumber); } $this->redirect('show', 'Topic', NULL, $redirectArguments); }