/** * Saves a fix in the database and gives the user a reward for this action. * * @param array $data The fix data. * * @return string|bool return the JSON-encoded reward for the user of successful, false otherwise */ public function insertFix(array $data) { $rewardHandler = new RewardHandler($this->getDbProxy(), $this); $insertVoteParams = $this->insertParams($data); $this->getDbProxy()->addToTransaction($insertVoteParams); $rewardHandler->applyRewards($data); $result = json_decode($this->getDbProxy()->sendTransaction(), true); $reward = $rewardHandler->extractReward($result); return $reward->toJson(); }
/** * Credit the user with koins for his action. * * @param array $data The data from the user. * * @return void */ protected function updateKoinCount(array $data) { $koinCountQuery = $this->koinCountHandler->getKoinCountQuery($data); $updateKoinCountParams = RewardHandler::updateKoinCountParams($data['user_id'], $koinCountQuery); $this->position["koinCount"] = $this->transProxy->addToTransaction($updateKoinCountParams); }
/** * Insert a new vote and handle the corresponding changes (koin_count, badges, completed etc.). * * @param array $data Vote data. * * @return string JSON-encoded reward for the user. */ public function insertVote(array $data) { $transProxy = new TransactionDbProxy(); $rewardHandler = new RewardHandler($transProxy, $this); $insertVoteParams = $this->insertParams($data); $transProxy->addToTransaction($insertVoteParams); $rewardHandler->applyRewards($data); $completedParams = $this->getCompletedParams($data); $transProxy->addToTransaction($completedParams); $malusParams = $this->getMalusParams($data); $transProxy->addToTransaction($malusParams); $result = json_decode($transProxy->sendTransaction(), true); $reward = $rewardHandler->extractReward($result); return $reward->toJson(); }