Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * 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();
 }