objectManager = $objectManager; } /** * @var \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService */ protected $extensionHelperService; /** * @param \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService $extensionHelperService */ public function injectExtensionHelperService(ExtensionHelperService $extensionHelperService): void { $this->extensionHelperService = $extensionHelperService; } /** * Constructs a new rating object * * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating|null $rating * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter|null $voter * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf|null $vote * @throws InvalidConfigurationTypeException */ /** @noinspection PhpUnused */ public function __construct( Rating $rating = null, Voter $voter = null, Stepconf $vote = null ) { if ($rating) { $this->setRating($rating); } if ($voter) { $this->setVoter($voter); } if ($vote) { $this->setVote($vote); } $this->initializeObject(); } /** * Initializes the new vote object * @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException */ public function initializeObject() { if (empty($this->objectManager)) { $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); } if (empty($this->extensionHelperService)) { $this->extensionHelperService = GeneralUtility::makeInstance(ExtensionHelperService::class); } $this->logger = $this->extensionHelperService->getLogger(__CLASS__); $this->settings = $this->objectManager->get(ConfigurationManager::class)->getConfiguration( 'Settings', 'thRating', 'pi1' ); //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this,get_class($this).' initializeObject'); } /** * Sets the rating this vote is part of * * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating $rating The Rating */ public function setRating(Rating $rating) { $this->rating = $rating; $this->setPid($rating->getPid()); } /** * Returns the rating this vote is part of * * @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating The rating this vote is part of */ public function getRating(): Rating { return $this->rating; } /** * Sets the frontenduser of this vote * * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter $voter The frontenduser */ public function setVoter(Voter $voter) { $this->voter = $voter; } /** * Returns the frontenduser of this vote * * @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter|null */ public function getVoter(): ?Voter { return $this->voter; } /** * Sets the choosen stepconfig * * @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $vote */ public function setVote($vote) { $this->vote = $vote; } /** * Gets the rating object uid * * @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf|null Reference to selected stepconfig */ public function getVote() { return $this->vote; } /** * Sets the rating this vote is part of * * @return bool */ /** @noinspection PhpUnused */ public function hasRated() { return $this->getVote() !== null && ($this->getVote() instanceof Stepconf); } /** * Checks if vote is done by anonymous user * * @return bool */ public function isAnonymous(): bool { return !empty($this->settings['mapAnonymous']) && !empty($this->getVoter()) && $this->getVoter()->getUid() === (int)$this->settings['mapAnonymous']; } /** * Checks cookie if anonymous vote is already done * always false if cookie checks is deactivated * * @param string $prefixId Extension prefix to identify cookie * @return bool */ public function hasAnonymousVote($prefixId = 'DummyPrefix'): bool { $anonymousRating = GeneralUtility::makeInstance(\WapplerSystems\BookmarksLikesRatings\Service\JsonService::class) ->decodeJsonToArray($_COOKIE[$prefixId . '_AnonymousRating_' . $this->getRating()->getUid()]); return !empty($anonymousRating['voteUid']); } /** * Method to use Object as plain string * * @return string */ public function __toString(): string { return (string)$this->getVote(); } }