public function generateTeam(Request $request)
 {
     //DB::table('team_contents')->truncate();
     $min = $request->get('min');
     $max = $request->get('max');
     $compName = $request->get('competitionName');
     $students_p = student_preferences::all();
     $students_c = student_classes::all();
     $std_j = array();
     $std_p = array();
     $std_c = array();
     $std_u = array();
     foreach ($students_p as $a) {
         if ($a->java > $a->python and $a->java > $a->c) {
             $std_j[$a->id] = $a->java;
         } elseif ($a->python > $a->c and $a->python > $a->c) {
             $std_p[$a->id] = $a->python;
         } elseif ($a->c > $a->python and $a->c > $a->java) {
             $std_c[$a->id] = $a->c;
         } else {
             $std_u[$a->id] = $a->c;
         }
     }
     foreach ($students_c as $c) {
         if (array_key_exists($c->id, $std_j)) {
             $std_j[$c->id] = $std_j[$c->id] + $c->classID;
         }
         if (array_key_exists($c->id, $std_p)) {
             $std_p[$c->id] = $std_p[$c->id] + $c->classID;
         }
         if (array_key_exists($c->id, $std_c)) {
             $std_c[$c->id] = $std_c[$c->id] + $c->classID;
         }
         if (array_key_exists($c->id, $std_u)) {
             $std_u[$c->id] = $std_u[$c->id] + $c->classID;
         }
     }
     asort($std_j);
     asort($std_c);
     asort($std_p);
     asort($std_u);
     return $this->divideTeam($std_u, $min, $max);
     if (count($std_j) > $max) {
     } elseif (count($std_j) < $max and count($std_j) > $min) {
     }
     return $std_u;
 }
 public function generateTeam(Request $request)
 {
     if (!$this->auth()) {
         return "You have no Permissions!";
     }
     //DB::table('team_contents')->truncate();
     $this->validate($request, ['min' => 'required|integer', 'max' => 'required|integer|greater_than_field:min', 'competition' => 'required']);
     $min = $request->get('min');
     $max = $request->get('max');
     $compId = $request->get('competition');
     $students_p = \DB::table('student_competition')->join('student_preferences', 'student_competition.studentID', '=', 'student_preferences.id')->select('student_competition.studentID', 'student_preferences.python', 'student_preferences.java', 'student_preferences.c', 'student_preferences.teamStyle')->where('student_competition.compID', '=', $compId)->get();
     $students_c = student_classes::all();
     $std_j = array();
     $std_p = array();
     $std_c = array();
     $std_u = array();
     foreach ($students_p as $a) {
         if ($a->java > $a->python and $a->java > $a->c) {
             $std_j[$a->studentID] = $a->java;
         } elseif ($a->python > $a->c and $a->python > $a->c) {
             $std_p[$a->studentID] = $a->python;
         } elseif ($a->c > $a->python and $a->c > $a->java) {
             $std_c[$a->studentID] = $a->c;
         } else {
             $std_u[$a->studentID] = $a->c;
         }
     }
     foreach ($students_c as $c) {
         if (array_key_exists($c->studentID, $std_j)) {
             $std_j[$c->studentID] = $std_j[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_p)) {
             $std_p[$c->studentID] = $std_p[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_c)) {
             $std_c[$c->studentID] = $std_c[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_u)) {
             $std_u[$c->studentID] = $std_u[$c->studentID] + $c->classID;
         }
     }
     asort($std_j);
     asort($std_c);
     asort($std_p);
     asort($std_u);
     $std_j = array_keys($std_j);
     $std_c = array_keys($std_c);
     $std_p = array_keys($std_p);
     $std_u = array_keys($std_u);
     $unsorted = array();
     $std_j = $this->arraysplit($std_j);
     $std_c = $this->arraysplit($std_c);
     $std_p = $this->arraysplit($std_p);
     $std_u = $this->arraysplit($std_u);
     $std_j = $this->divideTeamone($std_j, $min, $max, $compId);
     $std_c = $this->divideTeamone($std_c, $min, $max, $compId);
     $std_p = $this->divideTeamone($std_p, $min, $max, $compId);
     $std_u = $this->divideTeamone($std_u, $min, $max, $compId);
     $noTeam = array_merge($std_j, $std_c, $std_p, $std_u);
     $noTeam = $this->divideTeamone($noTeam, $min, $max, $compId);
     $teams = team::all();
     $competitions = competition::all();
     $compID = array();
     $compName = array();
     $teamnames = array();
     foreach ($competitions as $c) {
         array_push($compID, $c->compID);
         array_push($compName, $c->compName);
     }
     foreach ($teams as $t) {
         array_push($teamnames, $t->teamName);
     }
     return view('admin', compact('teams', 'competitions'));
 }
 public function generateTeam(Request $request)
 {
     //DB::table('team_contents')->truncate();
     $min = $request->get('min');
     $max = $request->get('max');
     $compId = $request->get('comp');
     $students_p = \DB::table('student_competition')->join('student_preferences', 'student_competition.studentID', '=', 'student_preferences.id')->select('student_competition.studentID', 'student_preferences.python', 'student_preferences.java', 'student_preferences.c', 'student_preferences.teamStyle')->where('student_competition.compID', '=', $compId)->get();
     $students_c = student_classes::all();
     $std_j = array();
     $std_p = array();
     $std_c = array();
     $std_u = array();
     foreach ($students_p as $a) {
         if ($a->java > $a->python and $a->java > $a->c) {
             $std_j[$a->studentID] = $a->java;
         } elseif ($a->python > $a->c and $a->python > $a->c) {
             $std_p[$a->studentID] = $a->python;
         } elseif ($a->c > $a->python and $a->c > $a->java) {
             $std_c[$a->studentID] = $a->c;
         } else {
             $std_u[$a->studentID] = $a->c;
         }
     }
     foreach ($students_c as $c) {
         if (array_key_exists($c->studentID, $std_j)) {
             $std_j[$c->studentID] = $std_j[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_p)) {
             $std_p[$c->studentID] = $std_p[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_c)) {
             $std_c[$c->studentID] = $std_c[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_u)) {
             $std_u[$c->studentID] = $std_u[$c->studentID] + $c->classID;
         }
     }
     asort($std_j);
     asort($std_c);
     asort($std_p);
     asort($std_u);
     $unsorted = array();
     //return $this->divideTeam($std_j, $min, $max);
     //return count($std_p) + count($std_c) + count($std_p) + count($std_u);
     // return $unsorted + $this->divideTeam($std_u, $min, $max, true, $compId);
     //$unsorted = $unsorted + $this->divideTeam($std_j, $min, $max, true, $compId);
     //print_r($unsorted);
     //$unsorted = $unsorted + $this->divideTeam($std_c, $min, $max, true, $compId);
     //print_r($unsorted);
     //$unsorted = $unsorted + $this->divideTeam($std_p, $min, $max, true, $compId);
     //print_r($unsorted);
     //$unsorted = $unsorted + $this->divideTeam($std_u, $min, $max, true, $compId);
     $ss = array();
     $ss = $std_c + $std_j + $std_p + $std_u;
     $ss = array_keys($ss);
     shuffle($ss);
     $totteam = array();
     while (count($ss) > 0) {
         $a = array();
         while (count($a) < $min) {
             array_push($a, array_pop($ss));
         }
         array_push($totteam, $a);
     }
     //print_r($totteam);
     $notAdded = array();
     $added = array();
     foreach ($totteam as $t) {
         $test = false;
         foreach ($t as $g) {
             if ($g == null) {
                 $test = true;
                 break;
             }
         }
         if ($test) {
             array_push($notAdded, $t);
         } else {
             array_push($added, $t);
         }
     }
     $i = 0;
     if ($min != $max) {
         if (count($notAdded) > 0) {
             foreach ($notAdded[0] as $nA) {
                 if ($nA != null) {
                     while ($i < count($added[$i])) {
                         if (count($added[$i]) < $max) {
                             array_shift($notAdded[0]);
                             array_push($added[$i], $nA);
                             //array_push($finalAdd, $a);
                             $i++;
                             break;
                         }
                         $i++;
                         break;
                     }
                 } else {
                     array_shift($notAdded[0]);
                 }
             }
         }
     }
     $notAdded = $notAdded[0];
     $stdc = count($notAdded);
     //return $notAdded;
     foreach ($added as $t) {
         team::create(['competition' => $compId, 'teamName' => 'Unnamed Team']);
         $val = \DB::select(\DB::raw('(SELECT max(teamID) as i FROM team)'));
         $teamID = $val[0]->i;
         foreach ($t as $s) {
             //print_r($s);
             //print_r(',');
             team_contents::create(['teamID' => $teamID, 'studentID' => $s]);
             \DB::table('student_competition')->where('studentID', '=', $s)->delete();
         }
     }
     $teams = team::all();
     $competitions = competition::all();
     $compID = array();
     $compName = array();
     $teamnames = array();
     foreach ($competitions as $c) {
         array_push($compID, $c->compID);
         array_push($compName, $c->compName);
     }
     foreach ($teams as $t) {
         array_push($teamnames, $t->teamName);
     }
     return view('admin', compact('teamnames', 'compID', 'compName', 'notAdded'));
 }
 public function generateTeam(Request $request)
 {
     //DB::table('team_contents')->truncate();
     $min = $request->get('min');
     $max = $request->get('max');
     $compId = $request->get('comp');
     $students_p = \DB::table('student_competition')->join('student_preferences', 'student_competition.studentID', '=', 'student_preferences.id')->select('student_competition.studentID', 'student_preferences.python', 'student_preferences.java', 'student_preferences.c', 'student_preferences.teamStyle')->where('student_competition.compID', '=', $compId)->get();
     $students_c = student_classes::all();
     $std_j = array();
     $std_p = array();
     $std_c = array();
     $std_u = array();
     foreach ($students_p as $a) {
         if ($a->java > $a->python and $a->java > $a->c) {
             $std_j[$a->studentID] = $a->java;
         } elseif ($a->python > $a->c and $a->python > $a->c) {
             $std_p[$a->studentID] = $a->python;
         } elseif ($a->c > $a->python and $a->c > $a->java) {
             $std_c[$a->studentID] = $a->c;
         } else {
             $std_u[$a->studentID] = $a->c;
         }
     }
     foreach ($students_c as $c) {
         if (array_key_exists($c->studentID, $std_j)) {
             $std_j[$c->studentID] = $std_j[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_p)) {
             $std_p[$c->studentID] = $std_p[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_c)) {
             $std_c[$c->studentID] = $std_c[$c->studentID] + $c->classID;
         }
         if (array_key_exists($c->studentID, $std_u)) {
             $std_u[$c->studentID] = $std_u[$c->studentID] + $c->classID;
         }
     }
     asort($std_j);
     asort($std_c);
     asort($std_p);
     asort($std_u);
     $unsorted = array();
     //return $this->divideTeam($std_j, $min, $max);
     //return count($std_p) + count($std_c) + count($std_p) + count($std_u);
     // return $unsorted + $this->divideTeam($std_u, $min, $max, true, $compId);
     $unsorted = $unsorted + $this->divideTeam($std_j, $min, $max, true, $compId);
     //print_r($unsorted);
     $unsorted = $unsorted + $this->divideTeam($std_c, $min, $max, true, $compId);
     //print_r($unsorted);
     $unsorted = $unsorted + $this->divideTeam($std_p, $min, $max, true, $compId);
     //print_r($unsorted);
     $unsorted = $unsorted + $this->divideTeam($std_u, $min, $max, true, $compId);
     //print_r($unsorted);
     return $this->divideTeam($unsorted, $min, $max, false, $compId);
     return $std_u;
 }