/** * 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'); } }
protected function resolveLevelChangeByType($levelType, GameLevel $currentGameLevel, $pointSumsIndexedByType) { assert('is_string($levelType) && $levelType != null'); assert('is_array($pointSumsIndexedByType)'); //If the user has not reached level one, the model has not been saved yet if ($currentGameLevel->id < 0) { $className = $levelType . 'GameLevelRules'; $nextLevelPointValue = $className::getMinimumPointsForLevel(1); $nextLevelValue = 1; } else { $nextLevelPointValue = GameLevelUtil::getNextLevelPointValueByTypeAndCurrentLevel($levelType, $currentGameLevel); $nextLevelValue = GameLevelUtil::getNextLevelByTypeAndCurrentLevel($levelType, $currentGameLevel); } if ($nextLevelValue !== false && static::resolveSummationValueByLevelTypeAndPointSums($levelType, $pointSumsIndexedByType) > $nextLevelPointValue) { $currentGameLevel->value = $nextLevelValue; $saved = $currentGameLevel->save(); if (!$saved) { throw new FailedToSaveModelException(); } GameLevel::processBonusPointsOnLevelChange($currentGameLevel, Yii::app()->user->userModel); if ($levelType == GameLevel::TYPE_GENERAL && $this->modalNotificationsEnabled) { static::processLevelChangeGameNotification($nextLevelValue); } } }
/** * @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); }
public static function createSampleLevel(HungerGamesPlugIn $plugin) { $portal = new GameLevel("sample_portal"); $portal->levelName = "portal"; $portal->displayName = "map portal"; $portal->type = self::TYPE_LEVEL_ONE; $portal->enterpos = new Position("128", "12", "123"); $portal->enterLevelName = "HG_Island"; $portal->exitpos = new Position("128", "12", "123"); $portal->exitLevelName = "MinigamesHub"; $portal->location = new Position("128", "12", "123"); $portal->maps = array("catching_fire", "hg_tornament"); $portal->save($plugin->getDataFolder()); }
/** * @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); }
/** * @see GamificationUtil::logAndNotifyOnDuplicateGameModel($logContent for an explanation of why you would * use this method. */ public function actionRepairGamification() { $duplicateModelsData = array(); //Check GameCoin for duplication person models $gameCoinDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByPersonKey(GameCoin::getTableName()); $duplicateModelsData['GameCoin'] = $gameCoinDuplicateData; //Check GameCollection, GameLevel, GamePoint, and GameScore for duplicate type/person models $gameCollectionDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameCollection::getTableName()); $duplicateModelsData['GameCollection'] = $gameCollectionDuplicateData; $gameLevelDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameLevel::getTableName()); $duplicateModelsData['GameLevel'] = $gameLevelDuplicateData; $gamePointDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GamePoint::getTableName()); $duplicateModelsData['GamePoint'] = $gamePointDuplicateData; $gameScoreDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameScore::getTableName()); $duplicateModelsData['GameScore'] = $gameScoreDuplicateData; foreach ($duplicateModelsData as $modelClassName => $duplicatesData) { if (empty($duplicatesData)) { echo 'No duplicates found for ' . $modelClassName . "<BR>"; } else { echo 'Duplicates discovered for ' . $modelClassName . "<BR>"; foreach ($duplicatesData as $typePersonKeyDuplicateData) { $searchAttributeData = array(); if ($modelClassName == 'GameCoin') { $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['person_item_id'])); $searchAttributeData['structure'] = '1'; } else { $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['type']), 2 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['person_item_id'])); $searchAttributeData['structure'] = '1 and 2'; } $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName); $where = RedBeanModelDataProvider::makeWhere($modelClassName, $searchAttributeData, $joinTablesAdapter); $models = $modelClassName::getSubset($joinTablesAdapter, null, null, $where, null); if ($modelClassName == 'GameCoin') { echo $modelClassName . ' --- Quantity of duplicates: ' . count($models) . ' --- for person_item_id: ' . $typePersonKeyDuplicateData['person_item_id'] . "<BR>"; } else { echo $modelClassName . ' --- Quantity of duplicates: ' . count($models) . ' --- for person_item_id: ' . $typePersonKeyDuplicateData['person_item_id'] . ' with type: ' . $typePersonKeyDuplicateData['type'] . "<BR>"; } $messageContent = null; GamificationUtil::removeDuplicatesByModels($models, $messageContent); echo $messageContent; } } } echo "<BR>" . 'Repair complete.' . "<BR>"; }