public function actionLoadCollectionItems() { if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) { throw new NotSupportedException(); } $collectionData = GameCollection::resolvePersonAndAvailableTypes(Yii::app()->user->userModel, GameCollection::getAvailableTypes()); foreach ($collectionData as $collection) { $itemsData = $collection->getItemsData(); foreach ($itemsData as $type => $quantity) { $itemsData[$type] = $quantity + 1; } $collection->setItemsData($itemsData); $saved = $collection->save(); if (!$saved) { throw new FailedToSaveModelException(); } } }
/** * @depends testRedeem * @return boolean */ public function testShouldReceiveCollectionItem() { Yii::app()->user->userModel = User::getByUsername('steven'); $bool = GameCollection::shouldReceiveCollectionItem(); $this->assertTrue($bool === true || $bool === false); }
public function testResolveNewCollectionItems() { $bool = GameCollection::shouldReceiveCollectionItem(); $this->assertTrue(is_bool($bool)); Yii::app()->user->userModel = User::getByUsername('super'); $availableTypes = GameCollection::getAvailableTypes(); $this->assertCount(31, $availableTypes); $collection = GameCollection::resolveByTypeAndPerson($availableTypes[0], Yii::app()->user->userModel); $itemsData = $collection->getItemsData(); $randomItem = array_rand($itemsData, 1); $compareData = array('Gate' => 0, 'Passport' => 0, 'Pilot' => 0, 'Luggage' => 0, 'TowTruck' => 0); $this->assertTrue($randomItem == 'Gate' || $randomItem == 'Passport' || $randomItem == 'Pilot' || $randomItem == 'Luggage' || $randomItem == 'TowTruck'); $compareData[$randomItem] = $compareData[$randomItem] + 1; $itemsData[$randomItem] = $itemsData[$randomItem] + 1; $collection->setItemsData($itemsData); $collection->save(); $this->assertEquals($compareData, $collection->getItemsData()); }
public function actionGameDashboard($id) { $user = User::getById(intval($id)); UserAccessUtil::resolveAccessingASystemUser($user); $title = Zurmo::t('ZurmoModule', 'Dashboard'); $badgeData = GameBadge::getAllByPersonIndexedByType($user); $generalLevelData = GameLevelUtil::getStatisticsDataForAGivenLevelType($user, GameLevel::TYPE_GENERAL); $rankingData = GamePointUtil::getUserRankingData($user); $statisticsData = GameLevelUtil::getUserStatisticsData($user); $collectionData = GameCollection::resolvePersonAndAvailableTypes($user, GameCollection::getAvailableTypes()); $dashboardView = new UserGameDashboardView($this, $user, $generalLevelData, $badgeData, $rankingData, $statisticsData, $collectionData); $view = new AjaxPageView($dashboardView); echo $view->render(); }
public function testRedeemCollection() { $user = UserTestHelper::createBasicUser('Steven'); $gameCollection = new GameCollection(); $gameCollection->person = $user; $gameCollection->type = 'Basketball'; $itemsData = array('RedemptionItem' => 0, 'Items' => array('Backboard' => 0, 'Player' => 0, 'ScoreBoard' => 0, 'Uniform' => 0, 'Trophy' => 0)); $gameCollection->serializedData = serialize($itemsData); $this->assertTrue($gameCollection->save()); $id = $gameCollection->id; unset($gameCollection); $gameCollection = GameCollection::getById($id); $this->assertEquals('Basketball', $gameCollection->type); $this->assertEquals($user, $gameCollection->person); $this->assertEquals($itemsData, unserialize($gameCollection->serializedData)); $this->setGetArray(array('id' => $gameCollection->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('gamification/default/redeemCollection'); $this->assertContains('Basketball Collection', $content); }
public function actionClaimCollectionItem($key, $typeKey) { if (Yii::app()->request->isAjaxRequest) { $availableTypes = GameCollection::getAvailableTypes(); $collection = GameCollection::resolveByTypeAndPerson($availableTypes[$typeKey], Yii::app()->user->userModel); $itemsData = $collection->getItemsData(); $itemsData[$key] = $itemsData[$key] + 1; $collection->setItemsData($itemsData); if (!$collection->save()) { throw new FailedToSaveModelException(); } } }
protected static function renderCollectionItemsContent(User $user, GameCollection $collection, GameCollectionRules $gameCollectionRules) { $itemTypesAndLabels = $gameCollectionRules->getItemTypesAndLabels(); $content = null; $canCollect = true; foreach ($collection->getItemsData() as $itemType => $quantityCollected) { $itemLabel = $itemTypesAndLabels[$itemType]; $collectionItemImagePath = $gameCollectionRules::makeMediumCOllectionItemImagePath($itemType); $itemContent = static::resolveLazyLoadImage($collectionItemImagePath, $itemLabel, array('class' => 'qtip-shadow', 'data-tooltip' => $itemLabel)); $qtip = new ZurmoTip(array('options' => array('position' => array('my' => 'bottom center', 'at' => 'top center'), 'content' => array('attr' => 'data-tooltip')))); $qtip->addQTip(".gd-collection-item img"); $itemContent .= ZurmoHtml::tag('span', array('class' => 'num-collected'), 'x' . $quantityCollected); $classContent = 'gd-collection-item'; if ($quantityCollected == 0) { $classContent .= ' missing'; $canCollect = false; } $content .= ZurmoHtml::tag('div', array('class' => $classContent), $itemContent); } $itemRedeemContent = static::renderCompleteButton($collection->id, $user->id, $canCollect); $content .= ZurmoHtml::tag('div', array('class' => 'gd-collection-item-redeemed'), $itemRedeemContent); return ZurmoHtml::tag('div', array('class' => 'gd-collection-items clearfix'), $content); }
public function resolveNewCollectionItems() { if (Yii::app()->gameHelper->getModalCollectionsEnabled() && GameCollection::shouldReceiveCollectionItem()) { return GameCollection::getARandomCollectionItemForUser(Yii::app()->user->userModel); } }
/** * @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>"; }
public function testRemoveDuplicatesByModelsGameCollection() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $models = array(); $gameCollection = new GameCollection(); $gameCollection->person = $super; $gameCollection->type = 'Basketball'; $gameCollection->serializedData = serialize(array('something')); $gameCollection->save(); $models[] = $gameCollection; $gameCollection2 = new GameCollection(); $gameCollection2->person = $super; $gameCollection2->type = 'Basketball'; $gameCollection2->serializedData = serialize(array('something2')); $gameCollection2->save(); $models[] = $gameCollection2; $messageContent = null; $this->assertEquals(2, count(GameCollection::getAll())); GamificationUtil::removeDuplicatesByModels($models, $messageContent); $gameCollections = GameCollection::getAll(); $this->assertEquals(1, count($gameCollections)); $this->assertNotNull($messageContent); }
/** * Get a random collection item that can be collected by user * @param User $user * @return array */ public static function getARandomCollectionItemForUser(User $user) { $availableTypes = GameCollection::getAvailableTypes(); $randomTypeKey = array_rand($availableTypes, 1); $collection = GameCollection::resolveByTypeAndPerson($availableTypes[$randomTypeKey], $user); $itemsData = $collection->getItemsData(); $randomKey = array_rand($itemsData, 1); return array($collection, $randomKey, $randomTypeKey); }