protected function finishProcessing() { // set game to next phase $game = ModelGame::getGame($this->id_game); $game->moveToNextPhase(); // update is_ready for user $iter = ModelInGamePhaseInfo::iterator(null, $this->id_game); while ($iter->hasNext()) { $igpi = $iter->next(); $igpi->setIsReady($this->id_phase, false); } // TODO: write mails // set game to processing done $game = ModelGame::getGame($this->id_game); $game->setProcessing(false); // commit everything DataSource::getInstance()->commit(); }
protected function checkFixate(array &$data, $id_phase) { $igpi = ModelInGamePhaseInfo::getInGamePhaseInfo(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId()); return $data['turnFixated'] = $igpi->getIsReadyForPhase((int) $id_phase) ? true : false; }
private function create_info($id_phase) { $query = 'set_new_game_phase_info'; $dict = array(); $dict[':id_user'] = $this->id_user; $dict[':id_game'] = $this->id_game; $dict[':id_phase'] = $id_phase; if ($this->id_game === 0) { $dict[':rule'] = true; $dict[':is_ready'] = false; } else { $_Rule = ModelInGamePhaseInfo::getInGamePhaseInfo($this->id_user); $dict[':rule'] = $_Rule->getNotificationRuleForPhase($id_phase); $dict[':is_ready'] = $_Rule->getIsReadyForPhase($id_phase); } DataSource::getInstance()->epp($query, $dict); $this->notification_rules[$id_phase] = $dict[':rule']; $this->is_ready[$id_phase] = $dict[':is_ready']; }
/** * sets is ready to true for given phase * * @param $is_ready boolean * @return void */ protected function fixatePhase($is_ready) { $igpi = ModelInGamePhaseInfo::getInGamePhaseInfo($this->id_user, $this->id_game); $igpi->setIsReady($this->id_phase, $is_ready); }
/** * deletes all tables,rows from database for this game * * @param int $id_game * @return bool - true if successfull * @throws GameAdministrationException - if game isn't loaded or the game isn't new */ public static function deleteGame($id_game) { try { $_Game = self::getGame($id_game); } catch (NullPointerException $ex) { throw new GameAdministrationException('Game not found.'); } if ($_Game->getStatus() !== GAME_STATUS_NEW) { throw new GameAdministrationException('Only new games can be deleted.'); } self::setGameSpecificQueries($id_game); try { DataSource::Singleton()->epp('drop_areas_table', array()); DataSource::Singleton()->epp('drop_moves_table', array()); DataSource::Singleton()->epp('drop_moves_areas_table', array()); DataSource::Singleton()->epp('drop_moves_units_table', array()); DataSource::Singleton()->epp('drop_units_table', array()); } catch (DataSourceException $ex) { if (!isset(self::$logger)) { self::$logger = Logger::getLogger('ModelGame'); } self::$logger->error($ex); } $dict = array(':id_game' => $id_game); DataSource::Singleton()->epp('delete_game', $dict); ModelIsInGameInfo::deleteIsInGameInfos(null, $id_game); ModelInGamePhaseInfo::deleteInGamePhaseInfos(null, $id_game); unset(self::$games[$id_game]); return true; }
/** * tries to create a new user, returns false if login is already in use * * @param string $name * @param string $lastname * @param string $login * @param string $password * @param string $email * @param string $verify (random string used for account activation) * @throws DataSourceException * @throws UserCreationException * @return ModelUser */ public static function create($name, $lastname, $login, $password, $email, $verify) { // check if login-name is taken $result = DataSource::Singleton()->epp('check_if_login_exists', array(':login' => $login)); if (!empty($result)) { throw new UserCreationException('Username already taken.'); } // check if email is taken $result = DataSource::Singleton()->epp('check_if_email_exists', array(':email' => $email)); if (!empty($result)) { throw new UserCreationException('E-Mail already taken.'); } $data = array(); $data[':name'] = $name; $data[':lastname'] = $lastname; $data[':login'] = $login; $data[':password'] = $password; $data[':email'] = $email; $data[':verify'] = $verify; DataSource::Singleton()->epp('create_new_user', $data); // create user $result = DataSource::Singleton()->epp('get_id_for_login', array(':login' => $login)); $id_newuser = intval($result[0]['id']); // user default setting for game infos ModelInGamePhaseInfo::getInGamePhaseInfo($id_newuser); return ModelUser::getUser($id_newuser); }
/** * delete user from game (also deletes notification infos) * * @param int $id_game * @param int $id_user * @return void */ public static function leaveGame($id_user, $id_game) { self::deleteIsInGameInfos($id_user, $id_game); ModelInGamePhaseInfo::deleteInGamePhaseInfos($id_user, $id_game); }