/** * * @return Ultimatum_Model_Ultgames */ public static function user_active_game($pUser = NULL) { $player = Ultimatum_Model_Ultplayers::user_active_player($pUser); if (!$player) { return NULL; } else { return $player->get_game(); } }
/** * * @return void */ public function _prep() { $user = Model_Users::current_user(); if (!$user) { $params = array('error' => 'You must be logged in to run a game. '); $this->_forward('index', 'index', NULL, $params); return FALSE; } $game_id = $this->_getParam('game'); // either actively select game or reactivate last played game if ($game_id) { $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id); $player = Ultimatum_Model_Ultplayers::for_user_game($user, $game)->activate(); } else { $player = Ultimatum_Model_Ultplayers::user_active_player($user); if (!$player) { $params = array('error' => 'cannot find active game'); $this->_forward('index', 'index', NULL, $params); return FALSE; } $game = $player->get_game(); } // at this point the player and game objects should be set. if (!$player) { $params = array('errror' => 'You are not a player in game ' . $id); $this->_forward('index', 'index', NULL, $params); return FALSE; } $this->view->game = $game; $game->activate(); $this->view->player = $player; // there may or may not be a player group specified by paramerters. // player_group refers to the group indirectly by the game group id. // group refers to the group id directly. if ($player_group = $this->_getParam('player_group')) { $this->view->player_group = Ultimatum_Model_Ultgamegroups::getInstance()->get($player_group); } elseif ($group = $this->_getParam("group", NULL)) { $this->view->player_group = $player->player_group($group); } // there may or may not be a target. // the target id is the group id NOT the game group id. if ($target = $this->_getParam('target')) { $this->view->target = $target_obj = Ultimatum_Model_Ultgroups::getInstance()->get($target); $this->view->target_scan = $player->get_scan($target); } return TRUE; }