/**
  * 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.";
 }
Example #2
0
 /**
  * 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 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);
 }
Example #4
0
 /**
  * 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.";
 }
Example #5
0
 /**
  * Called at the end of the page request.  Processes any new badges or badge grade changes for the current user.
  */
 public function resolveNewBadges()
 {
     if (!$this->enabled) {
         return;
     }
     $userBadgesByType = GameBadge::getAllByPersonIndexedByType(Yii::app()->user->userModel);
     $userPointsByType = GamePoint::getAllByPersonIndexedByType(Yii::app()->user->userModel);
     $userScoresByType = GameScore::getAllByPersonIndexedByType(Yii::app()->user->userModel);
     $badgeRulesClassNames = GameBadgeRules::getBadgeRulesData();
     foreach ($badgeRulesClassNames as $badgeRulesClassName) {
         $newBadge = false;
         $gradeChange = false;
         $badgeGrade = $badgeRulesClassName::badgeGradeUserShouldHaveByPointsAndScores($userPointsByType, $userScoresByType);
         if ($badgeGrade > 0) {
             if (isset($userBadgesByType[$badgeRulesClassName::getType()])) {
                 $gameBadge = $userBadgesByType[$badgeRulesClassName::getType()];
                 if ($badgeGrade > $gameBadge->grade) {
                     $gameBadge->grade = $badgeGrade;
                     $saved = $gameBadge->save();
                     if (!$saved) {
                         throw new NotSupportedException();
                     }
                     $gradeChange = true;
                 }
             } else {
                 $gameBadge = new GameBadge();
                 $gameBadge->type = $badgeRulesClassName::getType();
                 $gameBadge->person = Yii::app()->user->userModel;
                 $gameBadge->grade = 1;
                 $saved = $gameBadge->save();
                 if (!$saved) {
                     throw new NotSupportedException();
                 }
                 $newBadge = true;
             }
             if ($gradeChange || $newBadge) {
                 if ($gradeChange) {
                     $gradeChangeOrNewBadge = 'GradeChange';
                 } else {
                     $gradeChangeOrNewBadge = 'NewBadge';
                 }
                 GameBadge::processBonusPoints($gameBadge, Yii::app()->user->userModel, $gradeChangeOrNewBadge);
                 if ($this->modalNotificationsEnabled) {
                     $gameNotification = new GameNotification();
                     $gameNotification->user = Yii::app()->user->userModel;
                     if ($newBadge) {
                         $gameNotification->setNewBadgeByType($gameBadge->type);
                     } elseif ($gradeChange) {
                         $gameNotification->setBadgeGradeChangeByTypeAndNewGrade($gameBadge->type, $gameBadge->grade);
                     }
                     $saved = $gameNotification->save();
                     if (!$saved) {
                         throw new FailedToSaveModelException();
                     }
                 }
             }
         }
     }
 }
 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);
 }