/** * Actually convert from $source to $targetType * * @param string $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @throws \Exception * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException * @return Vote * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL) { /** @var Vote $vote */ $vote = $this->objectManager->get(Vote::class); $vote->setUser($this->getUserService()->getUserIdentifier()); $vote->setIp(GeneralUtility::getIndpEnv('REMOTE_ADDR')); $vote->setTime(time()); $vote->setValue((int) GeneralUtility::_GP('value')); $vote->setPid($this->getContentElementPid()); /** @var VotedObject $votedObject */ $votedObject = $this->objectManager->get(VotedObject::class); $votedObject->setIdentifier((int) $source); $votedObject->setContentType($this->getContentType()); $vote->setVotedObject($votedObject); // Retrieve uid $voteData = $this->voteRepository->getVoteData($vote); if (array_key_exists('uid', $voteData)) { $vote->_setProperty('uid', (int) $voteData['uid']); } return $vote; }
/** * @param Vote $vote * @return string * @validate $vote \Visol\Votable\Domain\Validator\VoteExistsValidator */ public function removeAction(Vote $vote) { // Send signal $signalResult = $this->getSignalSlotDispatcher()->dispatch(self::class, 'beforeVoteChange', [$vote, 'remove']); $vote = $signalResult[0]; $this->voteRepository->remove($vote); $this->view->assign('vote', $vote); // Send signal $this->getSignalSlotDispatcher()->dispatch(self::class, 'afterVoteChange', [$vote, 'remove']); $this->response->setHeader('Content-Type', 'application/json'); return json_encode(['action' => 'remove', 'success' => !$this->voteRepository->exists($vote), 'identifier' => 0]); }