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'));
 }
Exemplo n.º 2
0
 /**
  * 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');
                         });
                     }
                 }
             }
         }
     }
 }
 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'));
 }
Exemplo n.º 4
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $league = League::where('slug', $slug)->first();
     if (empty($league) || !isset($league)) {
         return abort(404);
     }
     return view('league.show', ['league' => $league]);
 }
 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');
 }
 /**
  * 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);
     }
 }
Exemplo n.º 7
0
 /**
  * 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}");
 }
Exemplo n.º 9
0
 public function GetLeagueByCode($code)
 {
     return League::where('code', $code)->first();
 }
Exemplo n.º 10
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $league = League::where('id', '=', $id)->first();
     return view('admin.leagues.edit', compact('league', $league));
 }
Exemplo n.º 11
0
 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]);
     }
 }