/** * 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(); }
public function register($event_slug) { $json['errors'] = []; $json['messages'] = []; $event = Event::where('slug', $event_slug)->where('verified', true)->first(); if (Session::has('id')) { $student = Student::where('id', Session::get('id'))->first(); if ($event) { if (Registration::where('student_id', Session::get('id'))->where('event_id', $event->id)->first()) { $json['errors'][] = "Already Registered"; } else { $round = $event->rounds->where('no', '1')->first(); $qualifier = new Qualifier(); $qualifier->save(); $round->qualifiers()->save($qualifier); $student->qualifiers()->save($qualifier); $registration = new Registration(); $registration->save(); $student->registrations()->save($registration); $event->registrations()->save($registration); $json['messages'][] = "successfull"; } } else { $json['errors'][] = "Event dont exist"; } } else { $json['errors'][] = "Please login to continue"; } return response()->json($json); }