public function fetchStartingTournaments() { $dateTimeNow = date('Y-m-d H:i:s', strtotime('+5 seconds')); $dateTimeSoon = date('Y-m-d H:i:s', strtotime('+600 seconds')); //echo $dateTimeNow . "<br>"; $tournaments = \App\Tournament::where('loaded_to_server', 0)->where('starts_at', '>', $dateTimeNow)->where('starts_at', '<', $dateTimeSoon)->with('collection.problems')->get(); // Set back info for each that we have loaded them // This should probably be done in a background job $tournaments->each(function ($tournament) { $tournament->loaded_to_server = 1; $tournament->save(); }); return response()->json($tournaments); }
public function loadClientApp(\Illuminate\Http\Request $request) { // Get tournament key $key = $request->route('key'); // Make sure tournament key matches to some tournament try { $tournament = \App\Tournament::where('key', $key)->firstOrFail(); } catch (ModelNotFoundException $e) { \Session::flash('errorMsg', 'Tournament not found!'); return \View::make('tournamentnotfound'); } // Validate user inputted data // Framework will catch any throws higher up in call tree $this->validate($request, ['username' => 'required|min:2|max:32|alpha_num']); // All is fine // Launch client app return \View::make('clientApp')->with('username', \Input::get('username'))->with('tournamentkey', $tournament->key); }
/** * [future description] * @return [type] [description] */ public function future() { return Tournament::where('start_date', '>', date('Y-m-d'))->orderBy('start_date'); }
private function createNewSecret($times = 0) { if ($times > 5) { return \App::abort(403, 'Could not create tournament secret key - contact administrator'); } $chars = "qwertyuipasdfghjklzxcvbnm12345678900"; $secret = ""; for ($i = 0; $i < 4; $i++) { $r = rand(0, strlen($chars) - 1); $secret .= $chars[$r]; } if (\App\Tournament::where('key', $secret)->first()) { return $this->createNewSecret($times + 1); } return $secret; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $tournaments = Tournament::where('user_id', Auth::user()->id)->get(); // $tournaments = Tournament::all(); return view('tournament.index', ['tournaments' => $tournaments]); }