/**
  * 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();
 }
Example #3
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 #4
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();
                     }
                 }
             }
         }
     }
 }
 protected static function makeModalGameNotificationContainerView()
 {
     return new ModalGameNotificationContainerView(GameNotification::getAllByUser(Yii::app()->user->userModel));
 }
 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);
 }
 /**
  * Tests the global configuration to enable/disable modalNotifications
  */
 public function testGamificationModalNotificationsGlobalConfiguration()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $scot = UserTestHelper::createBasicUser('Scot');
     Yii::app()->user->userModel = $scot;
     $this->assertEquals(0, count(GameNotification::getAllByUser($scot)));
     //test user at general level 0 where they do have enough points to move up   (Game notification created)
     $gamePoint = new GamePoint();
     $gamePoint->type = GamePoint::TYPE_USER_ADOPTION;
     $gamePoint->person = $scot;
     $gamePoint->value = 300;
     $this->assertTrue($gamePoint->save());
     Yii::app()->gameHelper->resolveLevelChange();
     $this->assertEquals(1, count(GameNotification::getAllByUser($scot)));
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, $scot);
     $this->assertEquals(300, $gamePoint->value);
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, $scot);
     $this->assertTrue($gameLevel->id > 0);
     $this->assertEquals(1, $gameLevel->value);
     //test user at general level 1 where they do have enough points to move up   (No game notification created)
     ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'gamificationModalNotificationsEnabled', false);
     $gamePoint = new GamePoint();
     $gamePoint->type = GamePoint::TYPE_USER_ADOPTION;
     $gamePoint->person = $scot;
     $gamePoint->value = 300;
     $this->assertTrue($gamePoint->save());
     Yii::app()->gameHelper->resolveLevelChange();
     $this->assertEquals(1, count(GameNotification::getAllByUser($scot)));
     $this->assertEquals(300, $gamePoint->value);
     $this->assertTrue($gameLevel->id > 0);
     $this->assertEquals(2, $gameLevel->value);
     //test user at general level 2 where they do have enough points to move up   (Game notification created)
     ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'gamificationModalNotificationsEnabled', true);
     $gamePoint = new GamePoint();
     $gamePoint->type = GamePoint::TYPE_USER_ADOPTION;
     $gamePoint->person = $scot;
     $gamePoint->value = 500;
     $this->assertTrue($gamePoint->save());
     Yii::app()->gameHelper->resolveLevelChange();
     $this->assertEquals(2, count(GameNotification::getAllByUser($scot)));
     $this->assertEquals(500, $gamePoint->value);
     $this->assertTrue($gameLevel->id > 0);
     $this->assertEquals(3, $gameLevel->value);
 }
 /**
  * @depends testGetAllByUser
  */
 public function testGameNotificationToModalContentAdapter()
 {
     Yii::app()->user->userModel = User::getByUsername('steven');
     $notifications = GameNotification::getAllByUser(Yii::app()->user->userModel);
     $this->assertEquals(3, count($notifications));
     $adapter1 = new GameNotificationToModalContentAdapter($notifications[0]);
     $adapter2 = new GameNotificationToModalContentAdapter($notifications[1]);
     $adapter3 = new GameNotificationToModalContentAdapter($notifications[2]);
     $this->assertEquals('game-level-change', $adapter1->getIconCssName());
     $this->assertEquals('game-badge-LoginUser', $adapter2->getIconCssName());
     $this->assertEquals('game-badge-LoginUser', $adapter3->getIconCssName());
     $this->assertEquals('<h2>Congratulations!</h2><h3>You have reached level 2</h3><h3> You have received 5 coins</h3>', $adapter1->getMessageContent());
     $this->assertEquals('<h2>New Badge</h2><h3>1 Zurmo login</h3>', $adapter2->getMessageContent());
     $this->assertEquals('<h2>New Badge</h2><h3>75 Zurmo logins</h3>', $adapter3->getMessageContent());
 }