Exemplo n.º 1
0
 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 testResolvePersonAndAvailableTypes
  */
 public function testGetAvailableTypes()
 {
     $types = GameCollection::getAvailableTypes();
     $this->assertTrue(count($types) > 0);
 }
Exemplo n.º 3
0
 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());
 }
Exemplo n.º 4
0
 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 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();
         }
     }
 }
Exemplo n.º 6
0
 /**
  * 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);
 }