/**
  * Renders the setting as a radio list.
  * @return A string containing the element's content.
  */
 protected function renderThemeContent()
 {
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, Yii::app()->user->userModel);
     $content = ZurmoHtml::tag('h3', array(), Zurmo::t('Core', 'Theme'));
     $content .= ZurmoHtml::radioButtonList($this->getEditableInputName(KanbanBoard::SELECTED_THEME), $this->model->getKanbanBoard()->getSelectedTheme(), $this->resolveThemeColorNamesAndLabelsForLocking($gameLevel), $this->getEditableThemeHtmlOptions(), array(), $this->resolveDataHtmlOptions($gameLevel));
     return $content;
 }
 /**
  * Renders the setting as a radio list.
  * @return A string containing the element's content.
  */
 protected function renderControlEditable()
 {
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, Yii::app()->user->userModel);
     $content = null;
     $content .= $this->form->radioButtonList($this->model, $this->attribute, $this->makeData($gameLevel), $this->getEditableHtmlOptions(), array(), $this->resolveDataHtmlOptions($gameLevel));
     $this->registerScript();
     return $content;
 }
 /**
  * Renders the setting as a radio list.
  * @return A string containing the element's content.
  */
 protected function renderControlEditable()
 {
     if (!$this->shouldRenderControlEditable()) {
         return null;
     }
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, Yii::app()->user->userModel);
     $content = null;
     $content .= $this->form->radioButtonList($this->model, $this->getAttributeForRadioButtonList(), $this->resolveThemeColorNamesAndLabelsForLocking($gameLevel), $this->getEditableHtmlOptions(), array(), $this->resolveDataHtmlOptions($gameLevel));
     $this->registerScript();
     return $content;
 }
 public function makeAll(&$demoDataHelper)
 {
     assert('$demoDataHelper instanceof DemoDataHelper');
     assert('$demoDataHelper->isSetRange("User")');
     foreach (User::getAll() as $user) {
         $gameScore = GameScore::resolveToGetByTypeAndPerson('LoginUser', $user);
         $gameScore->value = 10;
         $saved = $gameScore->save();
         assert('$saved');
         $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, $user);
         $gamePoint->value = mt_rand(100, 300);
         $saved = $gamePoint->save();
         assert('$saved');
         $gameScore = GameScore::resolveToGetByTypeAndPerson('CreateAccount', $user);
         $gameScore->value = 10;
         $saved = $gameScore->save();
         assert('$saved');
         $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_NEW_BUSINESS, $user);
         $gamePoint->value = 100;
         $saved = $gamePoint->save();
         assert('$saved');
         //Badges
         $gameBadge = new GameBadge();
         $gameBadge->type = 'LoginUser';
         $gameBadge->grade = 2;
         $gameBadge->person = $user;
         $saved = $gameBadge->save();
         assert('$saved');
         $gameBadge = new GameBadge();
         $gameBadge->type = 'CreateAccount';
         $gameBadge->grade = 3;
         $gameBadge->person = $user;
         $saved = $gameBadge->save();
         assert('$saved');
         //Levels
         $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, $user);
         $gameLevel->value = 1;
         $saved = $gameLevel->save();
         assert('$saved');
         $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_NEW_BUSINESS, $user);
         $gameLevel->value = 1;
         $saved = $gameLevel->save();
         assert('$saved');
     }
 }
 /**
  * @param User $user
  * @param $levelType
  * @return array
  */
 public static function getStatisticsDataForAGivenLevelType(User $user, $levelType)
 {
     assert('is_string($levelType) && $levelType != null');
     $rulesClassName = $levelType . 'GameLevelRules';
     $currentGameLevel = GameLevel::resolveByTypeAndPerson($levelType, $user);
     $currentPointsData = GamePoint::getSummationPointsDataByLevelTypeAndUser($user, $levelType);
     if ($currentPointsData != null) {
         $currentPoints = $currentPointsData['sum'];
     } else {
         $currentPoints = 0;
     }
     //If the user has not reached level one, the model has not been saved yet
     if ($currentGameLevel->id < 0) {
         $nextLevel = 1;
         $trueCurrentGameLevel = 0;
         $className = $levelType . 'GameLevelRules';
         $nextLevelPointValue = $className::getMinimumPointsForLevel(1);
         $currentLevelMinimumPointValue = 0;
     } else {
         $nextLevelPointValue = GameLevelUtil::getNextLevelPointValueByTypeAndCurrentLevel($levelType, $currentGameLevel);
         $nextLevel = GameLevelUtil::getNextLevelByTypeAndCurrentLevel($levelType, $currentGameLevel);
         $currentLevelMinimumPointValue = $rulesClassName::getMinimumPointsForLevel(intval($currentGameLevel->value));
         $trueCurrentGameLevel = $currentGameLevel->value;
     }
     if ($nextLevel !== false) {
         $pointsCollectedTowardsNextLevel = $currentPoints - $currentLevelMinimumPointValue;
         if ($pointsCollectedTowardsNextLevel == 0) {
             $nextLevelPercentageComplete = 0;
         } else {
             $nextLevelPercentageComplete = $pointsCollectedTowardsNextLevel / ($nextLevelPointValue - $currentLevelMinimumPointValue) * 100;
         }
     } else {
         $nextLevelPercentageComplete = null;
     }
     $rankingData = array('level' => (int) $trueCurrentGameLevel, 'points' => (int) $currentPoints, 'nextLevelPercentageComplete' => round($nextLevelPercentageComplete), 'levelTypeLabel' => $rulesClassName::getDisplayLabel());
     return $rankingData;
 }
 /**
  * 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 testResolveByTypeAndPerson
  */
 public function testProcessBonusPointsOnLevelChange()
 {
     Yii::app()->user->userModel = User::getByUsername('steven');
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(0, $gamePoint->value);
     //Testing a level that does not give bonus points.
     $gameLevel = new GameLevel();
     $gameLevel->person = Yii::app()->user->userModel;
     $gameLevel->type = GameLevel::TYPE_SALES;
     $gameLevel->value = 1;
     $this->assertTrue($gameLevel->save());
     GameLevel::processBonusPointsOnLevelChange($gameLevel, Yii::app()->user->userModel);
     //Test that bonus points were actually received.
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(100, $gamePoint->value);
     //Now get the GameLevel again, and make sure it works for level 2
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_SALES, Yii::app()->user->userModel);
     $gameLevel->person = Yii::app()->user->userModel;
     $gameLevel->type = GameLevel::TYPE_SALES;
     $gameLevel->value = 2;
     $this->assertTrue($gameLevel->save());
     GameLevel::processBonusPointsOnLevelChange($gameLevel, Yii::app()->user->userModel);
     //Test that bonus points were actually received.
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(210, $gamePoint->value);
 }