Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

validation rules for create game

  • Loading branch information...
commit 16892e17e34ac445b151ae6622d56eab7d89d30f 1 parent f93d153
@wooki authored
Showing with 31 additions and 5 deletions.
  1. +31 −5 application/controllers/games.php
View
36 application/controllers/games.php
@@ -2,7 +2,7 @@
class Games extends CI_Controller {
public function index() {
-
+
$this->view_data = array(
'title' => 'Joinable Games - Covert Mission - Group game with a star wars theme',
'description' => 'Covert Mission is a group game with a star wars theme based around player deception and deduction of player motives, in the same genre as werewolf and mafia.'
@@ -14,6 +14,21 @@ public function index() {
}
+ public function lobby($slug) {
+
+ // load the game
+
+ $this->view_data = array(
+ 'title' => $slug.'Joinable Games - Covert Mission - Group game with a star wars theme',
+ 'description' => 'Covert Mission is a group game with a star wars theme based around player deception and deduction of player motives, in the same genre as werewolf and mafia.'
+ );
+
+ $this->load->view('shared/_header.php', $this->view_data);
+ $this->load->view('games/index', $this->view_data);
+ $this->load->view('shared/_footer.php', $this->view_data);
+
+ }
+
public function create() {
$this->load->helper('form');
@@ -26,14 +41,22 @@ public function create() {
} else {
$game = Game::create($this->input->post('name'), $this->input->post('admin_name'));
- $this->form_validation->set_rules('name', 'Name', 'required');
- $this->form_validation->set_rules('name', 'Name', 'callback_gamename_check');
- $this->form_validation->set_rules('admin_name', 'admin_name', 'required');
+ $this->form_validation->set_rules('name', 'Game Name', 'required');
+ $this->form_validation->set_rules('name', 'Game Name', 'callback_gamename_check');
+ $this->form_validation->set_rules('admin_name', 'Player Name', 'required');
if ($this->form_validation->run() == FALSE) {
$this->_render_form($game);
} else {
- redirect('/', 'location');
+
+ // save the game and redirect to the game lobby
+ if (Game::save($game) == true) {
+ redirect('/lobby/'.$game->slug, 'location');
+ } else {
+ $this->form_validation->set_message('name', 'Error Saving Game');
+ $this->_render_form($game);
+ }
+
}
}
@@ -46,6 +69,9 @@ public function gamename_check($name) {
$games_list = new Game_List();
$games_list->load();
$game_exists = $games_list->game_exists($name, $slug);
+ if ($game_exists) {
+ $this->form_validation->set_message('gamename_check', 'The %s is already in use');
+ }
return !$game_exists;
}
Please sign in to comment.
Something went wrong with that request. Please try again.