public static function createGameRewardByNameForOwner($name, $owner)
 {
     $gameReward = new GameReward();
     $gameReward->name = $name;
     $gameReward->owner = $owner;
     $gameReward->quantity = 5;
     $gameReward->cost = 5;
     $saved = $gameReward->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     return $gameReward;
 }
 public function makeAll(&$demoDataHelper)
 {
     assert('$demoDataHelper instanceof DemoDataHelper');
     assert('$demoDataHelper->isSetRange("User")');
     $gameRewards = array();
     $gameRewardRandomData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('GameRewardsModule', 'GameReward');
     for ($i = 0; $i < 10; $i++) {
         $gameReward = new GameReward();
         $gameReward->name = $gameRewardRandomData['names'][$i];
         $gameReward->owner = $demoDataHelper->getRandomByModelName('User');
         $gameReward->cost = mt_rand(1, 10);
         $gameReward->quantity = mt_rand(1, 20);
         for ($j = 0; $j < 5; $j++) {
             $gameRewardTransaction = new GameRewardTransaction();
             $gameRewardTransaction->person = $demoDataHelper->getRandomByModelName('User');
             $gameRewardTransaction->quantity = mt_rand(1, 3);
             $gameReward->transactions->add($gameRewardTransaction);
         }
         $gameReward->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
         $saved = $gameReward->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
         $gameReward = GameReward::getById($gameReward->id);
         AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($gameReward, Group::getByName(Group::EVERYONE_GROUP_NAME));
         $gameReward->save();
         $gameRewards[] = $gameReward->id;
     }
     $demoDataHelper->setRangeByModelName('GameReward', $gameRewards[0], $gameRewards[count($gameRewards) - 1]);
 }
Exemplo n.º 3
0
 /**
  * Special method to load each type of game notification.  New badge, badge grade change, and level up.
  */
 public function actionLoadTransaction($id)
 {
     if (Yii::app()->user->userModel->username != 'super') {
         throw new NotSupportedException();
     }
     $gameReward = GameReward::getById($id);
     $gameRewardTransaction = new GameRewardTransaction();
     $gameRewardTransaction->quantity = 1;
     $gameRewardTransaction->person = Yii::app()->user->userModel;
     $gameReward->transactions->add($gameRewardTransaction);
     $gameReward->save();
     echo "Demo data has been loaded. Go back to the application.";
 }
 public function testRedeemReward()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $super->save();
     Yii::app()->user->userModel = $super;
     $gameRewards = GameReward::getByName('myNewGameReward');
     //not enough coins
     $this->setGetArray(array('id' => $gameRewards[0]->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward');
     $this->assertContains('You do not have enough coins to redeem this reward', $content);
     //enough coins
     $gameCoin = new GameCoin();
     $gameCoin->person = $super;
     $gameCoin->value = 100;
     $this->assertTrue($gameCoin->save());
     $notifications = Notification::getAll();
     //check for no notification
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, count($notifications));
     $this->setGetArray(array('id' => $gameRewards[0]->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward');
     $this->assertContains('myNewGameReward has been redeemed.', $content);
     //check for notification
     $notifications = Notification::getAll();
     $this->assertEquals(1, count($notifications));
     //email content
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $notifications[0]->notificationMessage->htmlContent);
     //check url
     $this->assertContains('/gameRewards/default/details?id=13', $notifications[0]->notificationMessage->htmlContent);
     // Not Coding Standard
     //check for email notification
     $emailMessages = EmailMessage::getAll();
     $this->assertCount(1, $emailMessages);
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->htmlContent);
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->textContent);
 }
Exemplo n.º 5
0
 /**
  * @depends testCreateAndGetGameRewardById
  */
 public function testUpdateGameRewardFromForm()
 {
     $gameRewards = GameReward::getByName('50 dollar giftcard to somewhere');
     $gameReward = $gameRewards[0];
     $this->assertEquals($gameReward->name, '50 dollar giftcard to somewhere');
     $postData = array('name' => 'New Name');
     $gameReward->setAttributes($postData);
     $this->assertTrue($gameReward->save());
     $id = $gameReward->id;
     unset($gameReward);
     $gameReward = GameReward::getById($id);
     $this->assertEquals('New Name', $gameReward->name);
 }
Exemplo n.º 6
0
 public function actionDelete($id)
 {
     $gameReward = GameReward::GetById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($gameReward);
     $gameReward->delete();
     $this->redirect(array($this->getId() . '/index'));
 }