/** * @param \Mittwald\Typo3Forum\Domain\Model\Forum\Post $post * @param string $countTarget * @param string $countUserTarget * @param string $title * @return string */ public function render(\Mittwald\Typo3Forum\Domain\Model\Forum\Post $post, $countTarget = NULL, $countUserTarget = NULL, $title = '') { $class = $this->settings['forum']['post']['helpfulBtn']['iconClass']; if ($this->hasArgument('class')) { $class .= ' ' . $this->arguments['class']; } if ($post->getAuthor()->getUid() != $this->authenticationService->getUser()->getUid() and !$this->authenticationService->getUser()->isAnonymous()) { $class .= ' tx-typo3forum-helpfull-btn'; } if ($post->hasBeenSupportedByUser($this->authenticationService->getUser())) { $class .= ' supported'; } $btn = '<div data-toogle="tooltip" title="' . $title . '" data- class="' . $class . '" data-countusertarget="' . $countUserTarget . '" data-counttarget="' . $countTarget . '" data-post="' . $post->getUid() . '" data-pageuid="' . $this->settings['pids']['Forum'] . '" data-eid="' . $this->settings['forum']['post']['helpfulBtn']['eID'] . '"></div>'; return $btn; }
/** * @param Post $post * @return string */ public function removeSupporterAction(Post $post) { /** @var FrontendUser $currentUser */ $currentUser = $this->authenticationService->getUser(); if (!$post->hasBeenSupportedByUser($currentUser)) { return json_encode(array("error" => true, "error_msg" => "not_allowed")); } // Set helpfulCount for Author $post->removeSupporter($currentUser); $this->postRepository->update($post); $post->getAuthor()->setHelpfulCount($post->getAuthor()->getHelpfulCount() - 1); $post->getAuthor()->decreasePoints((int) $this->settings['rankScore']['gotHelpful']); $this->frontendUserRepository->update($post->getAuthor()); $currentUser->decreasePoints((int) $this->settings['rankScore']['markHelpful']); $this->frontendUserRepository->update($currentUser); // output new Data return json_encode(array("error" => false, "add" => 1, "postHelpfulCount" => $post->getHelpfulCount(), "userHelpfulCount" => $post->getAuthor()->getHelpfulCount())); }