/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($id)
 {
     $challenge = Challenge::find($id);
     $name_challenge = $challenge->name;
     $cha = Challenge::listGroup();
     $pag = $this->pagination($id);
     return view('stages.index', compact('pag', 'cha', 'id', 'name_challenge'));
 }
 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'));
     }
 }