/**
  * @param string $postSummarys
  * @return array
  */
 private function _getPostSummarys($postSummarys)
 {
     $postSummarys = json_decode($postSummarys);
     $data = array();
     $counter = 0;
     $this->request->setFormat('html');
     foreach ($postSummarys as $summary) {
         $post = false;
         switch ($summary->type) {
             case 'lastForumPost':
                 $forum = $this->forumRepository->findByUid($summary->uid);
                 /* @var Post */
                 $post = $forum->getLastPost();
                 break;
             case 'lastTopicPost':
                 $topic = $this->topicRepository->findByUid($summary->uid);
                 /* @var Post */
                 $post = $topic->getLastPost();
                 break;
         }
         if ($post) {
             $data[$counter] = $summary;
             $this->view->assign('post', $post)->assign('hiddenImage', $summary->hiddenimage);
             $data[$counter]->html = $this->view->render('postSummary');
             $counter++;
         }
     }
     $this->request->setFormat('json');
     return $data;
 }
 /**
  * Displays a dashboard for the current user
  *
  * @return void
  * @throws \Mittwald\Typo3Forum\Domain\Exception\Authentication\NotLoggedInException
  */
 public function dashboardAction()
 {
     $user = $this->frontendUserRepository->findCurrent();
     if (!$user || $user->isAnonymous()) {
         throw new NotLoggedInException('You need to be logged in to view your dashboard!', 1335120249);
     }
     $this->view->assignMultiple(['user', $user, 'myNotifications', $this->notificationRepository->findNotificationsForUser($user, 6), 'myMessages', $this->privateMessageRepository->findReceivedMessagesForUser($user, 6), 'myFavorites', $this->topicRepository->findTopicsFavSubscribedByUser($user, 6), 'myTopics', $this->topicRepository->findTopicsCreatedByAuthor($user, 6)]);
 }
 /**
  * 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()));
 }
Example #4
0
 /**
  *
  * Deletes a post and decreases the user's post count by 1.
  *
  * @param Post $post
  */
 public function deletePost(Post $post)
 {
     $topic = $post->getTopic();
     // If the post is the only one in the topic, delete the whole topic instead of
     // this single post. Empty topics are not allowed.
     if ($topic->getPostCount() === 1) {
         $this->topicFactory->deleteTopic($topic);
     } else {
         $post->getAuthor()->decreasePostCount();
         $post->getAuthor()->decreasePoints((int) $this->settings['rankScore']['newPost']);
         $this->frontendUserRepository->update($post->getAuthor());
         $topic->removePost($post);
         $this->topicRepository->update($topic);
     }
 }
 /**
  * Show all unread topics of the current user
  * @param Forum $forum
  *
  * @throws NotLoggedInException
  * @return void
  */
 public function showUnreadAction(Forum $forum)
 {
     $user = $this->getCurrentUser();
     if ($user->isAnonymous()) {
         throw new NotLoggedInException('You need to be logged in.', 1288084981);
     }
     $topics = array();
     $unreadTopics = array();
     $tmpTopics = $this->topicRepository->getUnreadTopics($forum, $user);
     foreach ($tmpTopics as $tmpTopic) {
         $unreadTopics[] = $tmpTopic['uid'];
     }
     if (!empty($unreadTopics)) {
         $topics = $this->topicRepository->findByUids($unreadTopics);
     }
     $this->view->assign('forum', $forum)->assign('topics', $topics);
 }
 /**
  * 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);
 }
 /**
  *  Listing Action.
  */
 public function listLatestAction()
 {
     if (!empty($this->settings['countLatestPost'])) {
         $limit = (int) $this->settings['countLatestPost'];
     } else {
         $limit = 3;
     }
     $topics = $this->topicRepository->findLatest(0, $limit);
     $this->view->assign('topics', $topics);
 }
 /**
  * Sets a post as solution
  *
  * @param Topic $topic
  * @param Post  $post
  */
 public function setPostAsSolution(Topic $topic, Post $post)
 {
     $topic->setSolution($post);
     $this->topicRepository->update($topic);
     $this->forumRepository->update($topic->getForum());
 }
 /**
  * Show all topics of a given tag
  * @param Tag $tag
  */
 public function showAction(Tag $tag)
 {
     $this->view->assign('tag', $tag);
     $this->view->assign('topics', $this->topicRepository->findAllTopicsWithGivenTag($tag));
 }