Esempio n. 1
0
 /**
  * @depends testCreateAndGetGameCoinById
  */
 public function testResolveByPerson()
 {
     Yii::app()->user->userModel = User::getByUsername('steven');
     $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
     $this->assertEquals(20, $gameCoin->value);
     $this->assertEquals(Yii::app()->user->userModel, $gameCoin->person);
     $this->assertTrue($gameCoin->id > 0);
     Yii::app()->user->userModel = User::getByUsername('super');
     $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
     $this->assertEquals(0, $gameCoin->value);
     $this->assertEquals(Yii::app()->user->userModel, $gameCoin->person);
     $this->assertTrue($gameCoin->id < 0);
 }
 protected function getGameCoinForCurrentUser()
 {
     return GameCoin::resolveByPerson(Yii::app()->user->userModel);
 }
 public function actionRefreshGameDashboardCoinContainer($id)
 {
     $user = User::getById((int) $id);
     $gameCoin = GameCoin::resolveByPerson($user);
     echo UserGameDashboardView::renderCoinsContent($gameCoin->value, $user);
 }
 public function testRefreshGameDashboardCoinContainer()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $gameCoin = GameCoin::resolveByPerson($super);
     $gameCoin->addValue(1);
     $saved = $gameCoin->save();
     $this->assertEquals(1, $gameCoin->value);
     $gameCoin = GameCoin::resolveByPerson($super);
     $this->assertEquals(1, $gameCoin->value);
     $this->setGetArray(array('id' => $super->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/refreshGameDashboardCoinContainer');
     $this->assertContains('1 coin', $content);
 }
 protected function resolveFilteredByMetadataBeforeMakingDataProvider($searchForm, &$metadata)
 {
     if ($searchForm->filteredBy == GameRewardsSearchForm::FILTERED_BY_CAN_REDEEM) {
         $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
         $totalCoinsForUser = (int) $gameCoin->value;
         $clauseNumber = count($metadata['clauses']) + 1;
         $metadata['clauses'][$clauseNumber] = array('attributeName' => 'cost', 'operatorType' => 'lessThanOrEqualTo', 'value' => $totalCoinsForUser);
         if ($metadata['structure'] == '') {
             $metadata['structure'] = $clauseNumber;
         } else {
             $metadata['structure'] .= ' AND ' . $clauseNumber;
         }
     }
 }
 protected function getGameCoinForUser()
 {
     return GameCoin::resolveByPerson($this->user);
 }
Esempio n. 7
0
 /**
  * @param int $nextLevelValue
  * @throws FailedToSaveModelException
  */
 protected static function processLevelChangeGameNotification($nextLevelValue)
 {
     assert('is_int($nextLevelValue)');
     $coinsValue = GameCoinRules::getCoinsByLevel((int) $nextLevelValue);
     $gameNotification = new GameNotification();
     $gameNotification->user = Yii::app()->user->userModel;
     $gameNotification->setLevelChangeByNextLevelValue($nextLevelValue, $coinsValue);
     $saved = $gameNotification->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
     $gameCoin->addValue($coinsValue);
     $saved = $gameCoin->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
 }
 public function getAvailableCoinsForCurrentUser()
 {
     $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
     return (int) $gameCoin->value;
 }