/** * 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)); }
/** * @param string $name * @param string $subscribe * * @validate $name \Mittwald\Typo3Forum\Domain\Validator\Forum\TagValidator * @throws NotLoggedInException */ public function createAction($name = '', $subscribe = '') { $user = $this->getCurrentUser(); if ($user->isAnonymous()) { throw new NotLoggedInException("You need to be logged in.", 1288084981); } /** @var Tag $tag */ $tag = $this->objectManager->get('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Tag'); $tag->setName($name); $tag->setCrdate(new \DateTime()); if ((int) $subscribe === 1) { $tag->addFeuser($user); } $this->tagRepository->add($tag); if ((int) $subscribe === 0) { $this->redirect('list'); } else { $this->redirect('listUserTags'); } }