Example #1
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     // $schedule->command('inspire')
     //          ->hourly();
     /** 
      * Ranking system to calculate Ranks in the 
      * test 7 minutes after the test is completed.
      * This cron job will be called hourly.
      */
     $schedule->call(function () {
         $rounds = Round::where('end_date_time', '<', Carbon::now()->subMinutes(7))->where('ranked', false)->get();
         foreach ($rounds as $round) {
             $qualifiers = Qualifier::where('round_id', $round->id)->orderBy('score', 'desc')->orderBy('completion_time', 'asc')->get();
             $i = 1;
             foreach ($qualifiers as $qualifier) {
                 $qualifier->rank = $i;
                 $qualifier->save();
                 $i++;
             }
             if ($round->cutoff) {
                 $next_qualifiers = Qualifier::where('round_id', $round->id)->where('rank', '<=', $round->cutoff)->get();
                 $next_round = $round->event->rounds->where('no', strval($round->no + 1))->first();
                 foreach ($next_qualifiers as $next_qualifier) {
                     $qualifier = new Qualifier();
                     $qualifier->save();
                     $next_round->qualifiers()->save($qualifier);
                     $next_qualifier->student->qualifiers()->save($qualifier);
                 }
             }
             $round->ranked = true;
             $round->save();
         }
     })->everyMinute();
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public static function index($id, array $data = ['y' => 0])
 {
     $challenge = Challenge::find($id);
     $challenge_name = $challenge->name;
     $group = Group::where('challenge_id', '=', $id)->get()->toArray();
     $teamRound = Round::where('challenge_id', '=', $id)->orderBy('team_id', 'DESC')->get()->toArray();
     $countTeamRound = count($teamRound);
     $countGroup = count($group) + $data['y'];
     $div = $countTeamRound / $countGroup;
     $p = 0;
     for ($i = $data['y']; $i <= count($teamRound) - 1; $i++) {
         if (!Groupsta::where('round_id', '=', $teamRound[$i]['id'])->first()) {
             Groupsta::create(['round_id' => $teamRound[$i]['id'], 'group_id' => $group[$p]['id'], 'challenge_id' => $id]);
         }
         if ($i == $countGroup - 1) {
             GroupstaController::index($id, $data = ['y' => $i + 1]);
             break;
         }
         $p++;
     }
     if (!ENV('DEVELOP')) {
         $data = GroupstaController::pagination($id);
         $dataG = [];
         $dataG += ['' => '-- Seleciona Grupo --'];
         $datagro = Group::where('challenge_id', '=', $id)->lists('name', 'id')->toArray();
         $dataG += $datagro;
         return view('groupsstage.index', compact('data', 'challenge_name', 'dataG'));
     }
 }
Example #3
0
 public function getDoDelete($round_id)
 {
     $round = \App\Round::find($round_id);
     if (is_null($round)) {
         \Session::flash('flash_message', 'Round not found.');
         return redirect('/handicap');
     }
     $round->delete();
     \Session::flash('flash_message', $round->id . ' was deleted.');
     return redirect('/handicap');
 }
Example #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $liendivision = $this->argument('liendivision');
     $id = $this->argument('id');
     $matchs = xml_result_equ('', $liendivision);
     foreach ($matchs as $match) {
         $round = Round::where('team_id', $id)->where('equa', $match->equa)->where('equb', $match->equb)->first();
         if ($round == null) {
             $round = new Round();
         }
         $round->team_id = $id;
         $round->libelle = $match->libelle;
         $round->equa = $match->equa;
         $round->equb = $match->equb;
         $round->scorea = $match->scorea;
         $round->scoreb = $match->scoreb;
         $round->lien = $match->lien;
         $round->save();
         Artisan::queue('FFTT:Games', ['lien' => $match->lien, 'id' => $round->id]);
     }
 }
Example #5
0
 public function ShowDetail($id)
 {
     $round = Round::find($id);
     return view('front.championship.showDetail', array('round' => $round));
 }
 public function checkRoundBelongsToUser($userId, $roundId)
 {
     return Round::where('user_id', $userId)->where('id', $roundId)->exists();
 }
 public function create_event(Request $request)
 {
     $event_image = null;
     $background_image = null;
     $json['messages'] = [];
     $json['errors'] = [];
     $validator = Validator::make($request->all(), ['name' => 'required', 'no_of_rounds' => 'required|integer|max:3|min:1', 'category' => 'required|in:Computer Science,Electronics,History,Others', 'description' => 'required', 'prizes' => 'required', 'event_image' => 'required', 'background_image' => 'required', 'rounds' => 'required|array']);
     $validator->after(function ($validator) use($request, &$event_image, &$background_image) {
         if (!Session::has('id')) {
             $validator->errors()->add('user', 'Please login to continue');
         }
         if (($event_image = base64_decode($request->event_image)) && ($background_image = base64_decode($request->background_image))) {
             if (strlen($event_image) > 2097152 || strlen($background_image) > 2097152) {
                 $validator->errors()->add('image', 'image size exceeded');
             }
         } else {
             $validator->errors()->add('image', 'curropted image');
         }
         if (count($request->rounds) != $request->no_of_rounds) {
             $validator->errors()->add('round', 'Enter the correct no of rounds');
         } else {
             foreach ($request->rounds as $round) {
                 $subvalidator = Validator::make($round, ['no_of_questions' => 'required|integer|min:1', 'date' => 'required|date_format:Y-m-d|after:' . date('Y-m-d'), 'time' => 'required|date_format:H:i', 'cutoff' => 'integer', 'duration' => 'required|integer|min:1|max:3', 'questions' => 'required|array']);
                 $subvalidator->after(function ($subvalidator) use($round) {
                     foreach ($round['questions'] as $question) {
                         $subsubvalidator = Validator::make($question, ['question' => 'required', 'option1' => 'required', 'option2' => 'required', 'option3' => 'required', 'option4' => 'required', 'answer' => 'required|in:"' . $question['option1'] . '","' . $question['option2'] . '","' . $question['option3'] . '","' . $question['option4'] . '"']);
                         if ($subsubvalidator->fails()) {
                             $subvalidator->errors()->merge($subsubvalidator->errors()->toArray());
                             break;
                         }
                     }
                 });
                 if ($subvalidator->fails()) {
                     $validator->errors()->merge($subvalidator->errors()->toArray());
                     break;
                 }
             }
         }
     });
     if ($validator->fails()) {
         $json['errors'] = $validator->errors()->toArray();
         return response()->json($json);
     } else {
         $student = Student::where('id', Session::get('id'))->where('validated', true)->first();
         $event = new Event();
         $event->name = $request->name;
         $event->no_of_rounds = $request->no_of_rounds;
         $event->category = $request->category;
         $event->description = $request->description;
         $event->prizes = $request->prizes;
         $event->background_image = "abcd";
         $event->event_image = "abcd";
         $event->save();
         $tempslug = str_slug($event->name, "-");
         if (!Event::where('slug', $tempslug)->first()) {
             $event->slug = $tempslug;
         } else {
             $event->slug = $tempslug . "-" . $event->id;
         }
         $event->background_image = "/img/uploaded/background_" . $event->id . ".jpg";
         $event->event_image = "/img/uploaded/event_" . $event->id . ".jpg";
         $fh = fopen(public_path("img/uploaded/event_" . $event->id . ".jpg"), "w");
         fwrite($fh, $event_image);
         fclose($fh);
         $fh = fopen(public_path("img/uploaded/background_" . $event->id . ".jpg"), "w");
         fwrite($fh, $background_image);
         fclose($fh);
         $student->events()->save($event);
         foreach ($request->rounds as $i => $r) {
             $round = new Round();
             $round->no = $i;
             $tz = new \DateTimeZone('Asia/Calcutta');
             $round->start_date_time = new \DateTime($r['date'] . " " . $r['time'] . ":00", $tz);
             $round->duration = $r['duration'];
             $round->end_date_time = new \DateTime($r['date'] . " " . $r['time'] . ":00", $tz);
             $round->end_date_time->add(new \DateInterval('PT' . $r['duration'] . 'H'));
             $round->cutoff = isset($r['cutoff']) ? $r['cutoff'] : null;
             $round->no_of_questions = $r['no_of_questions'];
             $round->save();
             $event->rounds()->save($round);
             foreach ($r['questions'] as $j => $q) {
                 $question = new Question();
                 $question->no = $j;
                 $question->question = $q['question'];
                 $question->options = serialize([$q['option1'], $q['option2'], $q['option3'], $q['option4']]);
                 $question->answer = $q['answer'];
                 $question->save();
                 $round->questions()->save($question);
             }
         }
         $json['messages'] = "successfull";
         return response()->json($json);
     }
 }
 public function modification(Request $request)
 {
     if ($request->type == 1) {
         $dataRoundGet = Round::find($request->round_id);
         $dataRoundGet->active = 0;
         $dataRoundGet->save();
         $dataRound = Round::where('challenge_id', '=', $request->challenge_id)->where('stage_id', '=', $dataRoundGet->stage_id)->orderBy('id', 'DESC')->first();
         $date = new DateTime($dataRound->schedule_end);
         $hora_end = date('H:i:s', strtotime($date->format('H:i:s') . '+' . Settings::durationTrial() . ' minute'));
         $date_end = new DateTime($hora_end);
         $time_dos = Settings::durationTrial();
         $hora_start = strtotime('-' . $time_dos . ' minute', strtotime($date_end->format('H:i:s')));
         $hora_start = date('H:i:s', $hora_start);
         $dia = date('Y-m-d ', strtotime($date->format('H:i:s') . '+' . env('TIME') . ' minute'));
         Round::create(['team_id' => $dataRoundGet->team_id, 'challenge_id' => $dataRoundGet->challenge_id, 'schedule_start' => $hora_start, 'schedule_end' => $hora_end, 'stage_id' => $dataRoundGet->stage_id]);
     } else {
         $Round = Round::find($request->round_id);
         if ($request->typeText == 'active') {
             $Round->active = 1;
         } else {
             $Round->active = 0;
         }
         $Round->save();
     }
     return $this->index($request->challenge_id);
 }
 public function getUserBestRounds($courseId, $userId)
 {
     return Round::join('scores', 'scores.round_id', '=', 'rounds.id')->join('tee_sets', 'tee_sets.id', '=', 'rounds.tee_set_id')->join('courses', 'courses.id', '=', 'tee_sets.course_id')->where('courses.id', '=', $courseId)->where('rounds.user_id', $userId)->select('rounds.id', 'rounds.date', 'rounds.user_id', 'courses.slug as course_slug', 'courses.name as course_name', DB::raw('sum(scores.strokes) as total_strokes'))->groupBy('rounds.id', 'courses.id')->orderBy('total_strokes', 'asc')->orderBy('rounds.date', 'desc')->take(5)->get();
 }
Example #10
0
 public function storeCompetition($season, $num)
 {
     $this->rounds()->where('season_id', '=', $season->id)->delete();
     $clubs = $this->clubs()->wherePivot('season_id', '=', $season->id)->get();
     $match = array('home' => $clubs[0], 'away' => $clubs[$num - 1]);
     $round = array($match);
     $newRound = Round::firstOrNew(array('round_number' => 1, 'competition_id' => $this->id, 'season_id' => $season->id));
     $newRound->save();
     $this->rounds()->save($newRound);
     $season->rounds()->save($newRound);
     $newRound->matches()->save($clubs[0]->storeOpponent($clubs[$num - 1], $newRound));
     for ($matchNum = 1; $matchNum < $num / 2; $matchNum++) {
         $match = array('home' => $clubs[$matchNum], 'away' => $clubs[$num - 1 - $matchNum]);
         array_push($round, $match);
         $newRound->matches()->save($clubs[$matchNum]->storeOpponent($clubs[$num - 1 - $matchNum], $newRound));
     }
     $lastRound = $round;
     unset($round);
     $round = array();
     for ($roundNum = 1; $roundNum < $num - 1; $roundNum++) {
         $newRound = Round::firstOrNew(array('round_number' => $roundNum + 1, 'competition_id' => $this->id, 'season_id' => $season->id));
         $newRound->save();
         $this->rounds()->save($newRound);
         $season->rounds()->save($newRound);
         if ($roundNum % 2 != 0) {
             $home = $clubs[$num - 1];
             $away = $lastRound[intval($num / 2) - 1]['away'];
         } else {
             $home = $lastRound[intval($num / 2) - 1]['away'];
             $away = $clubs[$num - 1];
         }
         $match = array('home' => $home, 'away' => $away);
         array_push($round, $match);
         $newRound->matches()->save($home->storeOpponent($away, $newRound));
         for ($matchNum = 1; $matchNum < $num / 2 - 1; $matchNum++) {
             $home = $lastRound[intval($num / 2) - 1 - $matchNum]['away'];
             $away = $lastRound[intval($num / 2) - 1 - $matchNum + 1]['home'];
             $match = array('home' => $home, 'away' => $away);
             array_push($round, $match);
             $newRound->matches()->save($home->storeOpponent($away, $newRound));
         }
         if ($roundNum % 2 != 0) {
             $home = $lastRound[0]['home'];
             $away = $lastRound[1]['home'];
         } else {
             $home = $lastRound[0]['away'];
             $away = $lastRound[1]['home'];
         }
         $match = array('home' => $home, 'away' => $away);
         array_push($round, $match);
         $newRound->matches()->save($home->storeOpponent($away, $newRound));
         unset($lastRound);
         $lastRound = $round;
         unset($round);
         $round = array();
     }
     unset($round);
     return $this->getRounds($season);
 }
 public function getUserPaginatedFeed($userId, $perPage)
 {
     return Round::with('user', 'teeSet.course')->whereIn('user_id', function ($query) use($userId) {
         $query->select('follow_id')->from('user_follows')->where('user_id', $userId);
     })->orderBy('rounds.date', 'desc')->paginate($perPage);
 }