/** * 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())); } }
/** * Delete a topic from repository! * * @param Topic $topic The topic that is be deleted. * * @return void */ public function topicConformDeleteAction(Topic $topic) { $this->authenticationService->assertModerationAuthorization($topic->getForum()); foreach ($topic->getPosts() as $post) { $this->postRepository->remove($post); } $this->topicRepository->remove($topic); $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Moderation_DeleteTopic_Success', 'Typo3Forum'))); $this->clearCacheForCurrentPage(); $this->redirect('show', 'Forum', NULL, array('forum' => $topic->getForum())); }
/** * * Adds a localized message to the flash message container. This method is * just a shorthand for * * this->flashMessageContainer->add(Tx_Extbase_Utility_Localization(...)); * * @param string $key The language key that is to be used for the * flash messages. * @param array $arguments Arguments for the flash message. * @param string $titleKey Optional language key for the message's title. * @param int $severity Message severity (see \TYPO3\CMS\Core\Messaging\FlashMessage::*) * * @return void */ protected function addLocalizedFlashmessage($key, array $arguments = array(), $titleKey = NULL, $severity = FlashMessage::OK) { $message = new FlashMessage(Localization::translate($key, 'Typo3Forum', $arguments), Localization::translate($titleKey, 'Typo3Forum'), $severity); $this->controllerContext->getFlashMessageQueue()->enqueue($message); }