public function scoreboard()
 {
     $results = DB::select(DB::raw("select users.name as name, sum(challenges.point_value) as Total from users\n                                        inner join submitted_flags\n                                        on submitted_flags.user_id = users.id\n                                        inner join challenges\n                                        on challenges.id = submitted_flags.challenge_id\n                                        group by users.name\n                                        order by Total DESC"));
     $game = Game::first();
     $data = array('game' => $game, 'scores' => $results);
     return view('pages.scoreboard')->with('data', $data);
 }
 public function challenges()
 {
     $startd = DB::table('Games')->select('start')->first();
     $endd = DB::table('Games')->select('stop')->first();
     if ($startd->start > Carbon::now()) {
         return view("pages.countdown");
     } elseif ($endd->stop < Carbon::now()) {
         return view('pages.closed');
     }
     $num_users = User::count();
     $completed = Submitted_flag::count();
     $num_challenges = Challenge::count();
     $average_c = $completed / $num_users / $num_challenges * 100;
     $stats = array('num_users' => $num_users, 'completed' => $completed, 'average' => $average_c);
     $mycompleted = Submitted_flag::where('user_id', Auth::user()->id)->get()->toArray();
     $game = Game::first();
     $categories = Category::get();
     $categories = $categories->toArray();
     foreach ($categories as $category) {
         $challenges = Challenge::where('category_id', $category['id'])->orderby('point_value', 'ASC')->get()->toArray();
         $categories[(int) $category['id'] - 1]['challenges'] = $challenges;
     }
     $directory = base_path() . '/public/Challenges_Repo/';
     $files = scandir($directory);
     $startd = DB::table('Games')->select('start')->first();
     if ($startd->start > Carbon::now()) {
         $start = true;
     } else {
         $start = false;
     }
     $data = array('user' => Auth::user(), 'game' => $game, 'categories' => $categories, 'stats' => $stats, 'files' => $files, 'completed' => $mycompleted, 'start' => $start);
     return view("pages.challenges")->with('data', $data);
 }
 public function challenges()
 {
     /*$game = Game::first();
             $categories = Category::get();
             $categories = $categories->toArray();
     
             foreach($categories as $category)
             {
                 $challenges = Challenge::where('category_id', $category['id'])->get()->toArray();
                 $categories[(int)$category['id'] - 1]['challenges'] =  $challenges;
             }
     
     
             $data = array('game' => $game, 'categories' => $categories);*/
     $num_users = User::count();
     $completed = Submitted_flag::count();
     $num_challenges = Challenge::count();
     $average_c = $completed / $num_users / $num_challenges * 100;
     $stats = array('num_users' => $num_users, 'completed' => $completed, 'average' => $average_c);
     $game = Game::first();
     $categories = Category::get();
     $categories = $categories->toArray();
     foreach ($categories as $category) {
         $challenges = Challenge::where('category_id', $category['id'])->get()->toArray();
         $categories[(int) $category['id'] - 1]['challenges'] = $challenges;
     }
     $directory = base_path() . '/public/Challenges_Repo/';
     $files = scandir($directory);
     $data = array('user' => Auth::user(), 'game' => $game, 'categories' => $categories, 'stats' => $stats, 'files' => $files);
     return view("pages.challenges")->with('data', $data);
 }
Esempio n. 4
0
 /**
  * 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
     }
 }
 public function scoreboard()
 {
     $results = DB::table('Games')->select('start')->first();
     if ($results->start > Carbon::now()) {
         return view("pages.countdown");
     }
     $results = DB::select(DB::raw("select users.name as name, sum(challenges.point_value) as Total, submitted_flags.created_at as time from users\n                                        inner join submitted_flags\n                                        on submitted_flags.user_id = users.id\n                                        inner join challenges\n                                        on challenges.id = submitted_flags.challenge_id\n                                        group by users.name\n                                        order by Total DESC, submitted_flags.created_at "));
     $game = Game::first();
     $startd = DB::table('Games')->select('start')->first();
     if ($startd->start > Carbon::now()) {
         $start = true;
     } else {
         $start = false;
     }
     $data = array('game' => $game, 'scores' => $results, 'start' => $start);
     return view('pages.scoreboard')->with('data', $data);
 }