public function store() { $seven_days = 60 * 60 * 24 * 7; $two_hours = 60 * 60 * 2; $season = $_REQUEST['season']; $venue_id = $_REQUEST['venue_id']; $activity = $_REQUEST['activity']; $lastSeasonsLeague = League::where('season', $season - 1)->where('venue_id', $venue_id)->where('activity', $activity)->first(); $lastSeasonsLastGame = Event::where('league_id', $lastSeasonsLeague->id)->where('week_num', 'Wild Card')->where('game_num', 1)->first(); $start_dt = $_REQUEST['start_dt']; $start_dt = $start_dt ? strtotime($start_dt) : strtotime($lastSeasonsLastGame->date) + $seven_days; $start_wk = $_REQUEST['start_wk']; $start_wk -= 1; $week_cnt = $_REQUEST['week_cnt']; $game_cnt = $_REQUEST['game_cnt']; $games_tm = $_REQUEST['games_tm']; $games_tm = $games_tm ? strtotime($games_tm) : strtotime($lastSeasonsLastGame->time); $events = []; for ($i = $start_wk; $i <= $week_cnt; $i++) { $week_num = $i == $week_cnt ? 'Wild Card' : $i + 1; for ($j = 0; $j < $game_cnt; $j++) { $datetime = date('Y-m-d', $start_dt + $seven_days * $i) . ' ' . date('H:i:s', $games_tm + $two_hours * $j); $game_num = $j + 1; $league = League::where('season', $season)->where('venue_id', $venue_id)->where('activity', $activity)->first(); if (!$league) { $league = new League(); $league->season = $season; $league->venue_id = $venue_id; $league->activity = $activity; $league->save(); } $event = new Event(); $event->league_id = $league->id; $event->season = $league->season; $event->venue_id = $league->venue_id; $event->datetime = $datetime; $event->week_num = $week_num; $event->game_num = $game_num; $event->activity = $league->activity; $events[] = $event; } } try { DB::transaction(function () use($events) { foreach ($events as $event) { $event->save(); } }); $_SESSION['ALERT'] = alert('Season Added!', "Season {$season} for " . Venue::find($venue_id)->name . " was created successfully.", 'success'); } catch (Excepton $e) { print_r($e); exit; $_SESSION['ALERT'] = alert('Season Not Added!', "Season {$season} for " . Venue::find($venue_id)->name . " could not be created.", 'error'); } return redirect('/seasons'); }
public function index() { $season = $_REQUEST['season'] ?: $this->season; $activity = $_REQUEST['activity'] ?: 'Poker'; $venue_id = $_REQUEST['venue_id'] ?: League::where('season', $season)->where('activity', $activity)->value('venue_id'); $league = League::where('season', $season)->where('activity', $activity)->where('venue_id', $venue_id)->first(); if (!$league->id) { $_SESSION['ALERT'] = alert("No League Found!", "There were no leagues found matching the specified parameters.", "warning"); return sizeof($_REQUEST) ? redirect("/rankings") : redirect("/"); } $rankings_query = ' select s.player_id as id, concat(p.lastname, ", ", p.forename) as name, concat(p.forename, " ", p.lastname) as fullname, count(*) as games, sum(s.points) as total '; $rankings_query .= ' from t_scores s '; $rankings_query .= ' join t_events e on e.id = s.event_id '; $rankings_query .= ' join t_players p on p.id = s.player_id '; $rankings_query .= ' where e.league_id=? '; $rankings_query .= ' group by s.player_id '; $rankings = DB::select($rankings_query, [$league->id]); $points_query = ' select points '; $points_query .= ' from t_scores '; $points_query .= ' where player_id=? '; $points_query .= ' and event_id in ( '; $points_query .= ' select id '; $points_query .= ' from t_events '; $points_query .= ' where league_id=? '; $points_query .= ' ) '; $points_query .= ' order by points desc '; $points_query .= ' limit ' . $league->ranked_at; array_walk($rankings, function (&$ranking) use($points_query, $league) { $ranking->points = DB::select($points_query, [$ranking->id, $league->id]); $ranking->points = array_map(function ($p) { return $p->points; }, $ranking->points); $ranking->value = $ranking->games >= $league->ranked_at ? $league->ranking == 'AVG' ? floor(array_sum($ranking->points) / $league->ranked_at) : array_sum($ranking->points) : -1; }); $ranked = array_filter($rankings, function ($ranking) { return $ranking->value !== -1; }); usort($ranked, function ($a, $b) { return $b->value - $a->value; }); $unranked = array_filter($rankings, function ($ranking) { return $ranking->value === -1; }); usort($unranked, function ($a, $b) { return $b->total - $a->total; }); $seasonPointsLeaders = array_filter($rankings, function ($ranking) { return $ranking->total > 0; }); usort($seasonPointsLeaders, function ($a, $b) { return $b->total - $a->total; }); $seasonPointsLeaders = array_slice($seasonPointsLeaders, 0, 1); $wildCardWinners = User::whereHas('scores', function ($query) use($league) { $query->where('finished', '1')->whereHas('event', function ($query) use($league) { $query->where('league_id', $league->id)->where('week_num', 'Wild Card'); }); })->get(); return view('pages.rankings', compact('league', 'ranked', 'unranked', 'seasonPointsLeaders', 'wildCardWinners')); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $leagues = League::all(); $stadiums = Stadium::all(); $teams = Team::all(); return view('admin.fixtures.create', compact('leagues', $leagues, 'teams', $teams, 'stadiums', $stadiums)); }
/** * Execute the console command. * * @return mixed */ public function handle() { $year = date('Y'); $month = date('n'); $day = date('j'); $question = Question::where('year', $year)->where('month', $month)->where('day', $day)->first(); if (count($question)) { $leagues = League::where('year', $question->leagueYear())->where('month', $question->leagueMonth())->get(); foreach ($leagues as $key => $league) { $players = json_decode($league->users); foreach ($players as $key => $player) { $user = User::find($player); if ($user->deadline_reminder && $user->active) { $answers = Answer::where('question_id', $question->id)->where('user_id', $user->id)->first(); if (!count($answers)) { Mail::send('emails.deadlinereminder', [], function ($message) use($user) { $message->from('*****@*****.**', 'Liga Quiz Portugal'); $message->to($user->email, $user->fullName())->subject('Quiz ainda não respondido'); }); } } } } } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('leagues')->delete(); League::create(['league_id' => '1', 'name' => 'Winter 2015 Monday A/B League', 'start_date' => '2015-10-01', 'end_date' => '2016-02-18', 'url' => '???', 'format_id' => 1, 'location_id' => 1]); League::create(['league_id' => '2', 'name' => 'Winter 2015 Wednesday C/D League', 'start_date' => '2015-10-01', 'end_date' => '2016-02-18', 'url' => '???', 'format_id' => 1, 'location_id' => 1]); League::create(['league_id' => '3', 'name' => 'Spring 2016 Monday A/B League', 'start_date' => '2016-01-15', 'end_date' => '2016-03-20', 'url' => '???', 'format_id' => 1, 'location_id' => 1]); League::create(['league_id' => '4', 'name' => 'Spring 2016 Wednesday C/D League', 'start_date' => '2016-01-15', 'end_date' => '2016-03-20', 'url' => '???', 'format_id' => 1, 'location_id' => 1]); }
public function index() { $season = $_REQUEST['season'] ?: $this->season; $activity = $_REQUEST['activity'] ?: 'Poker'; $venue_id = $_REQUEST['venue_id'] ?: League::where('season', $season)->where('activity', $activity)->value('venue_id'); $league = League::where('season', $season)->where('activity', $activity)->where('venue_id', $venue_id)->first(); return view('pages.billing', compact('league')); }
/** * Fills tournaments table * */ public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { $t = Tournament::create(['name' => $faker->name(), 'min_number_of_teams' => $faker->numberBetween(2, 4), 'max_number_of_teams' => $faker->numberBetween(4, 16), 'start_date' => $faker->date('YYYY-MM-DD'), 'end_date' => $faker->date('YYYY-MM-DD'), 'type' => $faker->realText(100)]); $t->league()->associate(League::first())->save(); //associate tournamnet with first league } }
/** * Fills leagues table * */ public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { $l = League::create(['name' => $faker->name(), 'abbreviation' => $faker->realText(10), 'description' => $faker->realText(150)]); $l->game()->associate(Game::first())->save(); //associate league with first game } }
/** * Bootstrap any application services. * * @return void */ public function boot() { Validator::extend('quiz_already_created', function ($attribute, $value, $parameters, $validator) { $date = explode('/', $value); $questions = Question::where('year', $date[2])->where('month', $date[1])->where('day', $date[0])->get()->count(); if ($questions) { return false; } else { return true; } }); Validator::extend('league_already_created', function ($attribute, $value, $parameters, $validator) { $date = explode('/', $value); $league = League::where('year', $date[1])->where('month', $date[0])->where('leaguename_id', $validator->getData()['league'])->get()->count(); if ($league) { return false; } else { return true; } }); Validator::extend('specialquiz_already_created', function ($attribute, $value, $parameters, $validator) { $date = explode('/', $value); $quiz = Specialquiz::where('year', $date[2])->where('month', $date[1])->where('day', $date[0])->get()->count(); if ($quiz) { return false; } else { return true; } }); $year = date('Y'); $month = date('n'); $day = date('j'); $specialquiz = Specialquiz::where('year', $year)->where('month', $month)->where('day', $day)->first(); $globalSpecialQuiz = null; if (count($specialquiz)) { $globalSpecialQuiz = $specialquiz; } view()->share('global_specialquiz', $globalSpecialQuiz); $quiz = Question::where('year', $year)->where('month', $month)->where('day', $day)->first(); if (count($quiz)) { view()->share('global_leaguequiz', true); } else { view()->share('global_leaguequiz', false); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $year = date('Y'); $month = date('n'); $day = date('j'); $question = Question::where('year', $year)->where('month', $month)->where('day', $day)->first(); if (count($question)) { $leagues = League::where('year', $question->leagueYear())->where('month', $question->leagueMonth())->get(); foreach ($leagues as $key => $league) { $players = json_decode($league->users); foreach ($players as $key => $player) { $user = User::find($player); if ($user->daily_reminder && $user->active) { Mail::send('emails.dailyreminder', [], function ($message) use($user) { $message->from('*****@*****.**', 'Liga Quiz Portugal'); $message->to($user->email, $user->fullName())->subject('Novo quiz já disponível'); }); } } } } $specialquiz = Specialquiz::where('year', $year)->where('month', $month)->where('day', $day)->first(); if (count($specialquiz)) { $users = User::all(); if ($specialquiz->user_id) { $author = User::find($specialquiz->user_id)->fullName(); } else { $author = 'Quiz Portugal'; } foreach ($users as $key => $user) { if (strtotime("+1 day", strtotime($user->subscription)) > time() || $user->isAdmin()) { if ($user->daily_reminder && $user->active) { $data = array('specialquiz' => $specialquiz, 'author' => $author); Mail::send('emails.specialquiz', $data, function ($message) use($user) { $message->from('*****@*****.**', 'Liga Quiz Portugal'); $message->to($user->email, $user->fullName())->subject('Quiz especial disponível'); }); } } } } }
public function index() { $season = $_REQUEST['season'] ?: $this->season; $activity = $_REQUEST['activity'] ?: 'Poker'; $venue_id = $_REQUEST['venue_id'] ?: League::where('season', $season)->where('activity', $activity)->value('venue_id'); $league = League::where('season', $season)->where('activity', $activity)->where('venue_id', $venue_id)->first(); if (!$league->id) { $_SESSION['ALERT'] = alert("No Event Found!", "There were no events found matching the specified parameters.", "warning"); return sizeof($_REQUEST) ? redirect("/events") : redirect("/"); } $week_num = $_REQUEST['week_num'] ?: $league->events()->where('datetime', '<=', date('Y-m-d'))->max('week_num') ?: 1; //DB::select('select max(week_num) as week_num from t_events where league_id=? and datetime<=?', [$league->id, date('Y-m-d')])[0]->week_num ?: 1; $game_num = $_REQUEST['game_num'] ?: 1; $event_id = $league->events()->where('week_num', $week_num)->where('game_num', $game_num)->first()->id; if (!$event_id) { $_SESSION['ALERT'] = alert("No Event Found!", "There were no events found matching the specified parameters.", "warning"); return redirect("/events"); } return redirect("/events/{$event_id}"); }
public function index() { $season = League::whereHas('events', function ($query) { $query->where('datetime', '<=', date('Y-m-d')); })->max('season'); $venues = \App\Venue::where(function ($query) { $query->whereRaw('private is not true'); $query->orWhereRaw('id in (select venue_id from t_venue_players where player_id = ' . (Auth::user()->id ?: 0) . ')'); }); $venuesLive = with(clone $venues)->whereHas('leagues', function ($query) use($season) { $query->where('season', '>=', $season); })->get(); $venuesPast = with(clone $venues)->whereDoesntHave('leagues', function ($query) use($season) { $query->where('season', '>=', $season); })->get(); $venuesLive->each(function ($venue) { $venue->current = 1; }); $venuesPast->each(function ($venue) { $venue->current = null; }); $venues = array_merge($venuesLive->all(), $venuesPast->all()); return view('venues.index', compact('venues')); }
public function insertLeague(Request $request) { $this->validate($request, ['date' => ['required', 'league_already_created'], 'league' => ['required'], 'users' => ['required']]); $input = $request->all(); $date = explode('/', $input['date']); $month = $date[0]; $year = $date[1]; $league = new League(); $league->leaguename_id = $input['league']; $league->year = $year; $league->month = $month; $league->users = json_encode($input['users']); $league->save(); $players = $input['users']; $rounds = 9; $schedule = []; for ($leg = 0; $leg < 2; $leg++) { for ($round = 1; $round <= $rounds; $round++) { $realRound = $round + $leg * 10; $schedule[$realRound] = []; for ($game = 1; $game <= count($players) / 2; $game++) { $pos1 = $game - 1; $pos2 = count($players) - ($game - 1) - 1; $schedule[$realRound][$game]['home'] = $players[$pos1]; $schedule[$realRound][$game]['away'] = $players[$pos2]; Game::create(['league_id' => $league->id, 'round' => $realRound, 'user_1_id' => $players[$pos1], 'user_2_id' => $players[$pos2]]); } // ROTATE ARRAY $playersTemp = $players; $top = array_shift($playersTemp); $last = array_pop($playersTemp); $players = [$last]; foreach ($playersTemp as $value) { $players[] = $value; } array_unshift($players, $top); } } return redirect()->route('admin.leagues'); }
public function getAllLeague() { $allLeagues = League::getAllLeague(); return \Response::json($allLeagues, 200); }
<?php namespace App\ViewComposers; use View; use App\League; View::composer('partials.select-league', function ($view) { $activities = League::groupBy('activity')->get(['activity'])->pluck('activity'); $view->with('activities', $activities); });
public function bowlers() { $baseURL = '../public/'; $allBowlers = User::getAllBolwerDetails(); if (empty($allBowlers)) { $allBowlers = 0; } foreach ($allBowlers as $bowler) { $Bowlers[$bowler->id][] = ['data' => $bowler]; } $userDetails = Auth::user(); $jackpotCount = Lottery::getJackpotCountOfUser($userDetails->id); $totalTickets = Lottery::getTotalLotteryCount($userDetails->id); $totalJackpot = Lottery::getTotaljackpotAmountofUser($userDetails->id); $totalLeagues = League::getLeagueByBowler($userDetails->id); return \View::make('bowlers')->with('Bowlers', $Bowlers)->with('userDetails', $userDetails)->with('jackpotCount', $jackpotCount)->with('totalTickets', $totalTickets)->with('totalJackpot', $totalJackpot)->with('totalLeagues', $totalLeagues)->with('baseURL', $baseURL); }
<?php namespace App\ViewComposers; use View; use Auth; use App\Venue; use App\League; View::composer('partials.select-venue', function ($view) { $season = League::whereHas('events', function ($query) { $query->where('datetime', '<=', date('Y-m-d')); })->max('season'); $venues = Venue::where(function ($query) { $query->whereRaw('private is not true'); $query->orWhereRaw('id in (select venue_id from t_venue_players where player_id = ' . (Auth::user()->id ?: 0) . ')'); }); $venuesLive = with(clone $venues)->whereHas('leagues', function ($query) use($season) { $query->where('season', '>=', $season); })->get(); $venuesPast = with(clone $venues)->whereDoesntHave('leagues', function ($query) use($season) { $query->where('season', '>=', $season); })->get(); $view->with('venuesLive', $venuesLive)->with('venuesPast', $venuesPast); });
public function viewTodayQuiz() { $user_id = Auth::user()->id; $year = date('Y'); $month = date('n'); $day = date('j'); $firstMonday = date("j", strtotime('first monday of ' . $year . '-' . $month)); $leagueYear = $year; if ($firstMonday > $day) { $leagueMonth = $month - 1; if (!$leagueMonth) { $leagueMonth = 12; $leagueYear--; } } else { $leagueMonth = $month; } $dayOffset = 0; $round = 0; for ($i = 0; $i < 20; $i++) { $round++; if (date("d-m-Y") == date("d-m-Y", strtotime('first monday of ' . $leagueYear . '-' . $leagueMonth) + 86400 * $dayOffset)) { break; } if (($i + 1) % 5 == 0) { $dayOffset = $dayOffset + 3; } else { $dayOffset++; } } if ($round % 10 == 0) { $solo = true; } else { $solo = false; } $leagues = League::where('year', $year)->where('month', $leagueMonth)->get(); $league_id = 0; foreach ($leagues as $key => $league) { $players = json_decode($league->users); if (in_array($user_id, $players)) { $league_id = $league->id; } } $opponent = 0; $roundGame = Game::where('user_1_id', $user_id)->where('round', $round)->where('league_id', $league_id)->first(); if (!count($roundGame)) { $roundGame = Game::where('user_2_id', $user_id)->where('round', $round)->where('league_id', $league_id)->first(); if (count($roundGame)) { $opponent = $roundGame->user_1_id; } } else { $opponent = $roundGame->user_2_id; } if ($opponent) { $start = (new Carbon('now'))->hour(0)->minute(0)->second(0); $end = (new Carbon('now'))->hour(23)->minute(59)->second(59); $answers = Answer::where('submitted', 1)->where('user_id', $opponent)->whereNotBetween('updated_at', [$start, $end])->get(); $genresCollection = Genre::all(); $subgenresCollection = Subgenre::all(); $genres = array(); foreach ($genresCollection as $key => $genre) { $genres[$genre->id] = array(); $genres[$genre->id]['info'] = $genre; $genres[$genre->id]['corrects'] = 0; $genres[$genre->id]['total'] = 0; $genres[$genre->id]['percentage'] = 0; } $subgenres = array(); foreach ($subgenresCollection as $key => $subgenre) { $subgenres[$subgenre->id] = array(); $subgenres[$subgenre->id]['info'] = $subgenre; $subgenres[$subgenre->id]['corrects'] = 0; $subgenres[$subgenre->id]['total'] = 0; $subgenres[$subgenre->id]['percentage'] = 0; } foreach ($answers as $key => $answer) { $answerQuestion = $answer->question()[0]; $answerGenre = $answerQuestion->genre_id; $answerSubgenre = $answerQuestion->subgenre_id; if ($answer->correct) { $genres[$answerGenre]['corrects']++; $subgenres[$answerSubgenre]['corrects']++; } $genres[$answerGenre]['total']++; $subgenres[$answerSubgenre]['total']++; } foreach ($genres as $key => $genre) { if ($genres[$key]['total']) { $genres[$key]['percentage'] = round($genre['corrects'] / $genre['total'] * 100, 2); } } $percentage = array(); foreach ($subgenres as $key => $subgenre) { if ($subgenres[$key]['total']) { $subgenres[$key]['percentage'] = round($subgenre['corrects'] / $subgenre['total'] * 100, 2); $percentage[$key] = $subgenres[$key]['percentage']; } else { $subgenres[$key]['percentage'] = 0; $percentage[$key] = 0; } } if ($percentage) { array_multisort($percentage, SORT_DESC, $subgenres); } $opponent = User::find($opponent); } else { $genres = []; $subgenres = []; } $questions = Question::where('year', $year)->where('month', $month)->where('day', $day)->get(); $filetype = []; $answers = []; foreach ($questions as $key => $question) { $filetype[$question->genre_id] = pathinfo($question->filename, PATHINFO_EXTENSION); $answers[$question->genre_id] = ''; } $submitted = false; foreach ($questions as $key => $question) { $answer = Answer::where('question_id', $question['id'])->where('user_id', $user_id)->orderBy('id', 'desc')->first(); $answers[$question->genre_id] = $answer; if ($answer) { if ($answer->submitted) { $submitted = true; } } } if ($submitted) { return view('quiz_answered')->with(['questions' => $questions, 'answers' => $answers, 'filetype' => $filetype, 'year' => $year, 'month' => $month, 'day' => $day, 'solo' => $solo]); } else { return view('quiz')->with(['questions' => $questions, 'filetype' => $filetype, 'answers' => $answers, 'solo' => $solo, 'genres' => $genres, 'subgenres' => $subgenres, 'opponent' => $opponent]); } }
public function GetLeagueByCode($code) { return League::where('code', $code)->first(); }
/** * Remove the league from storage. * * @param int $id * @return Response */ public function destroy($id) { $league = League::findOrFail($id); $league->delete(); return redirect('/leagues'); }
/** * Display the form to edit a match * @param [type] $league_id [description] * @param [type] $match_id [description] * @return [type] [description] */ public function editMatch($league_id, $match_id) { $league = League::find($league_id); $players = \DB::table('league_players')->where('leage_id', '=', $league_id)->orderby('last_name')->orderby('first_name'); //dropdown list $players_list = Player::orderby('last_name')->orderby('first_name')->get(); $players_list = $players_list->lists('last_first_name', 'player_id'); //get the match $match = Match::find($match_id); if (!is_null($match)) { //Get the game $match_game = MatchGame::find($match_id); if (!is_null($match_game)) { $game = Game::find($match_game->game_id); } else { $game = new Game(); } } return view('pages/tools.league.match.edit', compact('match', 'game', 'league', 'players_list')); }
public function getBowlersInLeague($leagueId) { $isValidToken = User::checkAuth(); if ($isValidToken != 0) { $allBowlers = League::getBowlersinLeague($leagueId); if (empty($allBowlers)) { return "Invalid League ID or No Bowlers in this League"; } return \Response::json($allBowlers, 200); } else { return json_encode("Please enter valid Authentication Token"); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $league = League::find($id); $path = $league->logo_path; $name = $league->logo_name; $file = $path . $name; if (\File::isFile($file)) { \File::delete($file); } $league->delete(); flash()->success('', 'Lyga ištrinta!'); return redirect()->back(); }
/** * Update the specified tournament in storage. * * @param int $id id of tournament which should be updated * @return Response route where to redirect after update */ public function update($id) { $validator = Validator::make(Input::all(), Tournament::rules($id)); if ($validator->fails()) { return redirect('/tournaments/edit/' . $id)->withInput()->withErrors($validator); } $tournament = Tournament::findOrFail($id); $tournament->name = htmlspecialchars(Input::get('name')); $tournament->type = htmlspecialchars(Input::get('type')); $tournament->min_number_of_teams = Input::get('min_number_of_teams'); $tournament->max_number_of_teams = Input::get('max_number_of_teams'); $tournament->start_date = Input::get('start_date'); $tournament->end_date = Input::get('end_date'); $tournament->description = htmlspecialchars(Input::get('description')); $tournament->league()->associate(League::findOrFail(Input::get('league_id'))); $tournament->save(); return redirect('/tournaments'); // }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { League::destroy($id); return redirect()->route('league.index'); }