/** * 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)); }
/** * Deletes a post. * * @param Post $post The post that is to be deleted. * @return void */ public function deleteAction(Post $post) { // Assert authorization $this->authenticationService->assertDeletePostAuthorization($post); // Delete the post. $postCount = $post->getTopic()->getPostCount(); $this->postFactory->deletePost($post); $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Post_Delete_Success'))); // Notify observers and clear cache. $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Post', 'postDeleted', array('post' => $post)); $this->clearCacheForCurrentPage(); // If there is still on post left in the topic, redirect to the topic // view. If we have deleted the last post of a topic (i.e. the topic // itself), redirect to the forum view instead. if ($postCount > 1) { $this->redirect('show', 'Topic', NULL, array('topic' => $post->getTopic())); } else { $this->redirect('show', 'Forum', NULL, array('forum' => $post->getForum())); } }