Exemplo n.º 1
0
 public static function createNew($request)
 {
     $word = Words::find('first', array('order' => 'RAND()'));
     // fires queryexception if word db is empty
     $game = Games::create(array("word_id" => $word->id, "max_wrong_tries" => self::MAX_WRONG_TRIES));
     $game->save();
     return $game->id;
 }
Exemplo n.º 2
0
 public function addGames()
 {
     if (!$this->league) {
         $redirectUrl = $this->request->env('HTTP_REFERER') ?: '/';
         $this->flashMessage('League not found.', array('alertType' => 'error'));
         return $this->redirect($redirectUrl);
     }
     if (isset($this->CURRENT_USER) and !$this->league->isManager($this->CURRENT_USER)) {
         $this->flashMessage('You don\'t have permission to view that page.', array('alertType' => 'error'));
         return $this->redirect('Leagues::index');
     }
     if ($this->request->data) {
         $numberOfGames = intval($this->request->data['number_of_games']);
         if ($numberOfGames > 0) {
             $params = $this->request->data;
             $newGame = array('league_id' => $this->league->_id);
             $game_time = $params['game_date'] ?: '';
             $game_time .= ' ' . ($params['game_time'] ?: '11:00:00');
             if (trim($game_time)) {
                 $newGame['game_time'] = strtotime($game_time);
             }
             if (trim($params['fieldsite_id'])) {
                 $newGame['fieldsite_id'] = new \MongoId(trim($params['fieldsite_id']));
             }
             if (trim($params['field'])) {
                 $newGame['field'] = trim($params['field']);
             }
             $created_games_id_list = array();
             for ($i = 0; $i < $numberOfGames; $i++) {
                 $g = Games::create($newGame);
                 $g->save(null, array('validate' => false));
                 $created_games_id_list[] = $g->_id;
             }
             $games = Games::find('all', array('conditions' => array('_id' => array('$in' => $created_games_id_list))));
         } else {
             $this->flashMessage('Invalid number of games.', array('alertType' => 'error'));
         }
     }
     return compact('games');
 }