/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Con::index(1, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(2, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(3, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(4, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(5, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(7, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
     Con::index(8, ['y' => 0, 'time_start' => 0, 'time_end' => 0], 1);
 }
 public static function index($id, array $data = ['y' => 0, 'time_start' => 0, 'time_end' => 0])
 {
     $challenge = Challenge::find($id);
     $challenge_name = $challenge->name;
     $cha = Challenge::listGroup();
     $flag = true;
     //        if(!Round::where('challenge_id','=',$id)->first()){
     $stage = Stage::where('challenge_id', '=', $id)->where('back', '=', 0)->where('active', '=', 1)->get()->toArray();
     $team = Team::where('challenge_id', '=', $id)->where('active', '=', 1)->orderBy('id', 'RAND()')->get()->toArray();
     $numStage = count($stage) + $data['y'];
     if ($data['time_start'] == 0 && $data['time_end'] == 0) {
         $date = new DateTime(Settings::ScheTrial());
         $time = 0;
         $pag = false;
         $hora_start = $date->format('H:i:s');
         $hora_end = date('H:i:s', strtotime($date->format('H:i:s') . '+' . $time . ' 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);
     } else {
         $date = new DateTime($data['time_start']);
         $time = 0;
         $pag = false;
         $hora_start = $date->format('H:i:s');
         $hora_end = date('H:i:s', strtotime($date->format('H:i:s') . '+' . $time . ' 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);
     }
     $p = 0;
     for ($i = $data['y']; $i <= count($team) - 1; $i++) {
         if (!Round::where('team_id', '=', $team[$i]['id'])->first()) {
             Round::create(['team_id' => $team[$i]['id'], 'challenge_id' => $team[$i]['challenge_id'], 'schedule_start' => $hora_end, 'schedule_end' => $hora_start, 'stage_id' => $stage[$p]['id']]);
         }
         if ($i == $numStage - 1) {
             RoundController::index($id, $data = ['y' => $i + 1, 'time_start' => $hora_start, 'time_end' => $hora_end]);
             break;
         }
         $p++;
     }
     //        }
     if (!ENV('DEVELOP')) {
         $pag = RoundController::pagination($id);
         $flag = true;
         return view('round.index', compact('flag', 'pag', 'cha', 'challenge_name', 'id'));
     }
 }