/** * Special method to load each type of game notification. New badge, badge grade change, and level up. */ public function actionLoadGameNotificationsSampler() { if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) { throw new NotSupportedException(); } //Level up notification $coinsValue = GameCoinRules::getCoinsByLevel(2); $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setLevelChangeByNextLevelValue(2, $coinsValue); $saved = $gameNotification->save(); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); //New collection Item GameCollection::processRandomReceivingCollectionItemByUser(Yii::app()->user->userModel); echo "Demo data has been loaded. Go back to the application."; }
/** * Special method to load each type of game notification. New badge, badge grade change, and level up. */ public function actionLoadGameNotificationsSampler() { if (Yii::app()->user->userModel->username != 'super') { throw new NotSupportedException(); } //Level up notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setLevelChangeByNextLevelValue(2); $saved = $gameNotification->save(); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); }
public function testGameNotificationsComingUpCorrectly() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals(0, count(GameNotification::getAll())); $this->assertEquals(0, count(GameNotification::getAllByUser($super))); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertTrue(strpos($content, 'ModalGameNotification0') === false); //Level up notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setLevelChangeByNextLevelValue(2); $saved = $gameNotification->save(); $this->assertTrue($saved); $this->assertEquals(1, count(GameNotification::getAll())); $this->assertEquals(1, count(GameNotification::getAllByUser($super))); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertFalse(strpos($content, 'ModalGameNotification0') === false); $this->assertTrue(strpos($content, 'ModalGameNotification1') === false); $this->assertEquals(0, count(GameNotification::getAll())); $this->assertEquals(0, count(GameNotification::getAllByUser($super))); Yii::app()->clientScript->reset(); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertTrue(strpos($content, 'ModalGameNotification0') === false); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); $this->assertTrue($saved); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = $super; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); $this->assertTrue($saved); Yii::app()->clientScript->reset(); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/leaderboard'); $this->assertFalse(strpos($content, 'ModalGameNotification0') === false); $this->assertFalse(strpos($content, 'ModalGameNotification1') === false); }
public function testCreateAndGetGameNotificationById() { $user = UserTestHelper::createBasicUser('Steven'); //Level up notification $gameNotification = new GameNotification(); $gameNotification->user = $user; $gameNotification->setLevelChangeByNextLevelValue(2, 5); $saved = $gameNotification->save(); $this->assertTrue($saved); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = $user; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); $this->assertTrue($saved); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = $user; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); $this->assertTrue($saved); }
/** * Special method to load each type of game notification. New badge, badge grade change, and level up. */ public function actionLoadGameNotificationsSampler() { if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) { throw new NotSupportedException(); } //Level up notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setLevelChangeByNextLevelValue(2); $saved = $gameNotification->save(); //New badge notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setNewBadgeByType('LoginUser'); $saved = $gameNotification->save(); //Badge grade up notification $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setBadgeGradeChangeByTypeAndNewGrade('LoginUser', 5); $saved = $gameNotification->save(); echo "Demo data has been loaded. Go back to the application."; }
protected static function processLevelChangeGameNotification($nextLevelValue) { assert('is_int($nextLevelValue)'); $gameNotification = new GameNotification(); $gameNotification->user = Yii::app()->user->userModel; $gameNotification->setLevelChangeByNextLevelValue($nextLevelValue); $saved = $gameNotification->save(); if (!$saved) { throw new FailedToSaveModelException(); } }
/** * @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(); } }