Пример #1
0
 public function getGroupedGames()
 {
     // show all if in draft mode
     $mode = Versioned::get_reading_mode();
     if ($mode == 'Stage.Stage') {
         $items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID))->sort('Session'));
     } else {
         $items = GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID, 'Status' => true))->sort('Session'));
     }
     return $items;
 }
 public function getAllTags($current = false)
 {
     if ($current) {
         $games = $this->getCurrentGames();
     } else {
         $games = Game::get();
     }
     $list = array();
     $result = new ArrayList();
     foreach ($games as $game) {
         $tags = $game->getGenresArray();
         for ($i = 0; $i < count($tags); $i++) {
             $list[$tags[$i]] = $tags[$i];
         }
     }
     asort($list);
     foreach ($list as $item) {
         $result->push(new ArrayData(array('Title' => $item)));
     }
     return $result;
 }
 /**
  * Attempts to save a game
  *
  * @return Game|null
  */
 protected function addGame($form)
 {
     $siteConfig = SiteConfig::current_site_config();
     $member = Member::currentUser();
     $params = $this->request->allParams();
     $fields = $form->Fields();
     $id = $fields->dataFieldByName('ID')->Value();
     $game = Game::get()->byID($id);
     if (!$game) {
         $game = Game::create();
     }
     $form->saveInto($game);
     $game->FacilitatorID = $game->FacilitatorID ? $game->FacilitatorID : $member->ID;
     $game->ParentID = $siteConfig->CurrentEventID;
     try {
         $game->write();
     } catch (ValidationException $e) {
         $form->sessionMessage($e->getResult()->message(), 'bad');
         return;
     }
     return $game;
 }
Пример #4
0
 public function joined_duel($id)
 {
     foreach ($this->joined_duels as $i => $duel) {
         if ($duel->id == $id) {
             return $duel;
         }
     }
     $duel = Game::get($id);
     if ($duel == null) {
         return false;
     }
     $duel->type = 'joineduel';
     $this->joined_duels[] = $duel;
     return $duel;
 }
 /**
  * Attempts to save a game
  *
  * @return Game|null
  */
 protected function addPlayerGame($data, $form)
 {
     $fields = $form->Fields();
     $event = $this->getCurrentEvent();
     $currentID = $event->ID;
     $prefNum = $event->PreferencesPerSession;
     $regID = $data['RegistrationID'];
     $reg = Registration::get()->byID($regID);
     if (!$reg) {
         return false;
     }
     // @todo - handle a proper 'change game' case
     if ($reg->PlayerGames()->Count() > 0) {
         foreach ($reg->PlayerGames() as $playerGame) {
             $reg->PlayerGames()->removeByID($playerGame->ID);
             $playerGame->delete();
         }
     }
     $favouriteID = $data["FavouriteID"];
     for ($session = 1; $session <= $event->NumberOfSessions; $session++) {
         $notPlay = $data["NotPlaying_" . $session];
         $games = Game::get()->filter(array('Session' => $session, 'ParentID' => $currentID, 'Status' => true));
         // Alter prefnumber so it stops when it encounters "not Playing"
         if ($notPlay != 0 && $notPlay < $prefNum) {
             $prefNum = $notPlay;
         }
         // if first choice is to not play, don't create any games
         if ($notPlay === 1) {
             continue;
         }
         foreach ($games as $game) {
             $gamePref = $data["GameID_" . $game->ID];
             // only store games with a preference higher than our threshold
             if ($gamePref > $prefNum || !isset($gamePref)) {
                 continue;
             }
             $playerGame = PlayerGame::create();
             $form->saveInto($playerGame);
             $playerGame->GameID = $game->ID;
             $playerGame->ParentID = $regID;
             $playerGame->Preference = $gamePref;
             if ($favouriteID == $game->ID) {
                 $playerGame->Favourite = true;
             }
             try {
                 $playerGame->write();
             } catch (ValidationException $e) {
                 $form->sessionMessage($e->getResult()->message(), 'bad');
                 return;
             }
         }
     }
     return $playerGame;
 }
Пример #6
0
 public function doAssignTeams($data, Form $form)
 {
     // assign teams to the game
     $game = Game::get()->filter('ID', $data['GameID'])->first();
     $teamsCount = $game->Teams()->count();
     if ($teamsCount < 2) {
         // add the teams
         $game->Teams->add($data['TeamOne']);
         $game->Teams->add($data['TeamTwo']);
     }
     $redirectLink = $this->Link() . '?success=1';
     return $this->redirect($redirectLink);
 }
Пример #7
0
 public function getGroupedGames()
 {
     return GroupedList::create(Game::get()->filter(array('ParentID' => $this->getCurrentEvent()->ID, 'Status' => true))->sort('Session'));
 }
Пример #8
0
 /**
  * Display a listing of games
  *
  * @return Response
  */
 public function index()
 {
     $games['inProgress'] = Game::get();
     $games['completed'] = Game::onlyTrashed()->get();
     return View::make('games.index', compact('games'));
 }