/** * Create a new event instance. * * @return void */ public function __construct($user_id, $game_id) { $user = \App\Models\User::find($user_id); $game_users = \App\Models\Game_User::where('game_id', $game_id)->where('has_left', 0)->get(); for ($i = 0; $i < $game_users->count(); $i++) { if ($game_users[$i]['user_id'] == $user_id) { $game_users[$i]['have_turn'] = false; $game_users[$i]['cons_turn'] = true; $game_users[$i]->save(); if ($i + 1 == $game_users->count()) { $game_users[0]['have_turn'] = true; $game_users[0]->save(); } else { $game_users[$i + 1]['have_turn'] = true; $game_users[$i + 1]->save(); } } } $msg = 'El jugador ' . $user->first_name . ' paso turno.'; $cont = 0; foreach ($game_users as $key) { if ($key->cons_turn) { $cont++; } } if ($cont == $game_users->count()) { $game = \App\Models\Game::find($game_id); $game->ended = true; $game->save(); $msg = 'El juego a terminado.'; } $this->data = ['game_id' => $game_id, 'msg' => $msg]; }
public function actionRegister($gameName, $port, $hostname = null) { $ip = ip2long(Yii::$app->request->userIP); $Game = Game::find()->where(['ip_address' => $ip, 'port' => $port])->one(); if (!$Game) { $Game = new Game(); $Game->name = $gameName; $Game->ip_address = $ip; $Game->port = $port; } return $Game->save(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Game::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionUpdateGame() { $data = Yii::$app->request->post(); $ip = ip2long(Yii::$app->request->userIP); foreach ($data['Games'] as $game) { $Game = Game::find()->where(['id' => $game['id'], 'ip_address' => $ip])->one(); if (!$Game) { $Game = new Game(); } $Game->attributes = $game; $Game->ip_address = $ip; $Game->save(); } return true; }
public static function saveQuickVisit(Request $request) { if (!Game::find($request->get('game_id'))) { return; } self::removeVisits($request->get('game_id')); foreach ($request->all() as $key => $input) { if (strpos($key, 'player_') !== false && $input > 0) { $id = str_replace('player_', '', $key); if (Player::find($id)) { StatRepository::addVisit($request->get('game_id'), $id, $input); } } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Game::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->where(['>', 'updated_at', time() - Yii::$app->params['game_list_timeout']]); $query->andFilterWhere(['id' => $this->id, 'ip_address' => $this->ip_address]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'launch_url', $this->host_search]); return $dataProvider; }
/** * Handle the event. * * @param GameVisitChange $event * @return void */ public function handle(GameVisitChange $event) { $player = Player::find($event->playerId); $game = Game::find($event->gameId); $users = \App\Models\User::whereNotNull('email')->where('email', '!=', '')->get(); $visitList = Stat::$visitList; if (isset($event->visit) && $event->visit) { $status = $visitList[$event->visit]; } else { $status = 'Cancelled'; } $subject = str_limit($player->name, 50) . ' ' . str_limit($game->team, 20) . ' ' . $status; Mail::send('emails.game_visit', ['player' => $player, 'game' => $game, 'status' => $status], function ($m) use($users, $subject) { foreach ($users as $user) { if ($user->isAdmin()) { $m->to($user->email); } } $m->subject($subject); }); }
public static function has_ended($game_id) { $game = \App\Models\Game::find($game_id); if ($game->ended) { return true; } return false; }
<?php use app\models\Game; $game = array_column(Game::find()->select(['id'])->asArray()->all(), 'id'); return ['type' => $faker->randomElement($array = ['audio', 'photo', 'group', 'video']), 'url' => $faker->url, 'content_name' => $faker->word, 'game_id' => $faker->randomElement($game), 'has_been_played' => 0];
/** * Tests if the remove method * is working correclty. */ public function testRepoRemoveGameRemovalSuccess() { $game = Factory::create('App\\Models\\Game'); $this->repository->removeGame($game->name); $this->assertNull(Game::find($game->id)); }
public function pass_turn(Request $request) { $users = UserGame::getUsersGame($request->gameid); $users_ready = UserGame::users_ready($request->gameid); $cant_turn = UserGame::count_users_game($request->gameid); $game = Game::find($request->gameid); $nextturn = ""; $turn = intval(substr($game->user_playing, -1, 1)); if ($cant_turn == $users_ready) { Game::change_State($request->gameid, 'X'); } else { if ($turn == $cant_turn) { $nextturn = "player1"; foreach ($users as $user) { UserGame::updateReady($request->gameid, $user->id, 'N'); } } else { $nextturn = "player" . ($turn + 1); } Game::passturn($request->gameid, $nextturn); } }
/** * Checks if any new games have been created and adds them to the processing list */ public function checkForNewGames() { $Games = \app\models\Game::find()->all(); foreach ($Games as $Game) { if (!isset($this->Games[$Game->id])) { $this->Games[$Game->id] = new Game($Game->name); } } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $games = Game::find($id); return response()->json($games, 200); }