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']; }
/** * 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); }
/** * 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); }
/** * joins the user in given game * * @param $id_user int * @param $id_game int * @param $id_color int * @throws NullPointerException * @throws JoinUserException * @return ModelIsInGameInfo */ public static function joinGame($id_user, $id_game, $id_color = null) { $id_user = intval($id_user); $id_game = intval($id_game); if ($id_color !== null) { $id_color = intval($id_color); } // check if user and game exist $user = ModelUser::getUser($id_user); $game = ModelGame::getGame($id_game); if ($game->getFreeSlots() <= 0) { throw new JoinUserException('Game is full.'); } // check if user is in the game $iter = ModelUser::iterator($id_game); while ($iter->hasNext()) { if ($iter->next() === $user) { throw new JoinUserException('User allready in this game.'); } } // check if color is free if ($id_color !== null && !$game->checkIfColorIsFree($id_color)) { $id_color = null; } // get first free color if ($id_color === null) { $color_iter = ModelColor::iterator(); while ($color_iter->hasNext()) { $color = $color_iter->next(); if (!$game->checkIfColorIsFree($color->getId())) { continue; } $id_color = $color->getId(); break; } } if ($id_color === null) { throw new JoinUserException('No free color found.'); } // insert player $dict = array(); $dict[':id_user'] = $id_user; $dict[':id_game'] = $id_game; $dict[':id_color'] = $id_color; DataSource::Singleton()->epp('join_game', $dict); // set user notification rules ModelInGamePhaseInfo::getInGamePhaseInfo($id_user, $id_game); return self::getIsInGameInfo($id_user, $id_game); }