public function admin()
 {
     $teams = team::all()->get();
     $teamnames = array();
     foreach ($teams as $t) {
         array_push($teamnames, $teams[0]->teamName);
     }
     return view('admin', compact('teamnames'));
 }
示例#2
0
 public function redoAssignments(Requests\RedoTeamAssignmentRequest $request)
 {
     $minTeamSize = $request->all()['min'];
     $maxTeamSize = $request->all()['max'];
     // Return to teams page if form was empty
     if ($minTeamSize == "" || $maxTeamSize == "") {
         return redirect('/teams');
     }
     // max must be greater than min for team assignments to work
     if (!($minTeamSize < $maxTeamSize)) {
         return redirect('/teams');
     }
     // Create array of student IDs
     $studentIDs = \App\User::leftJoin('UserRole', 'users.id', '=', 'UserRole.userID')->where('role', 'student')->get()->pluck('id')->toArray();
     // max must be less than the number of students
     if (!($minTeamSize <= count($studentIDs))) {
         return redirect('/teams');
     }
     // Sort students by the number of courses they have taken.
     $sortedStudentIDs = array();
     for ($i = 0; $i <= 4; $i++) {
         foreach ($studentIDs as $studentID) {
             $coursesTaken = \App\userCourseTaken::where('userID', $studentID)->get()->toArray();
             if (count($coursesTaken) == $i) {
                 array_push($sortedStudentIDs, $studentID);
             }
         }
     }
     // Create an array to store the appropriate number of teams
     $teams = array();
     $maxNumberOfTeams = floor(count($studentIDs) / $minTeamSize);
     $teams = array_fill(0, $maxNumberOfTeams, array_fill(0, $maxTeamSize, -1));
     // Place each student in a team using the following priorities:
     // - 1 - try to place student in team with matching language and team style
     // - 2 - try to place student in team with matching language
     // - 3 - try to place student in a brand new team
     // - 4 - try to place student in a team with matching team style
     // - 5 - place the student anywhere
     foreach ($sortedStudentIDs as $studentID) {
         $studentPlaced = false;
         $studentLanguage = \App\userKnownLanguages::where('userID', $studentID)->get()->pluck('languageName')->toArray()[0];
         $studentStyle = \App\userPreferredTeamStyle::where('userID', $studentID)->get()->pluck('teamStyle')->toArray()[0];
         // language + team style
         for ($team = 0; $team < count($teams); $team++) {
             if ($teams[$team][0] == -1) {
                 continue;
             }
             $teamLanguage = \App\userKnownLanguages::where('userID', $teams[$team][0])->get()->pluck('languageName')->toArray()[0];
             $teamStyle = \App\userPreferredTeamStyle::where('userID', $teams[$team][0])->get()->pluck('teamStyle')->toArray()[0];
             if ($studentLanguage == $teamLanguage && $studentStyle == $teamStyle) {
                 for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                     if ($teams[$team][$slot] == -1) {
                         $studentPlaced = true;
                         $teams[$team][$slot] = $studentID;
                         break;
                     }
                 }
                 if ($studentPlaced) {
                     break;
                 }
             }
         }
         if ($studentPlaced) {
             continue;
         }
         // language
         for ($team = 0; $team < count($teams); $team++) {
             if ($teams[$team][0] == -1) {
                 continue;
             }
             $teamLanguage = \App\userKnownLanguages::where('userID', $teams[$team][0])->get()->pluck('languageName')->toArray()[0];
             if ($studentLanguage == $teamLanguage) {
                 for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                     if ($teams[$team][$slot] == -1) {
                         $studentPlaced = true;
                         $teams[$team][$slot] = $studentID;
                         break;
                     }
                 }
                 if ($studentPlaced) {
                     break;
                 }
             }
         }
         if ($studentPlaced) {
             continue;
         }
         // new team
         for ($team = 0; $team < count($teams); $team++) {
             if ($teams[$team][0] == -1) {
                 $studentPlaced = true;
                 $teams[$team][0] = $studentID;
                 break;
             }
         }
         if ($studentPlaced) {
             continue;
         }
         // team style
         for ($team = 0; $team < count($teams); $team++) {
             if ($teams[$team][0] == -1) {
                 continue;
             }
             $teamStyle = \App\userPreferredTeamStyle::where('userID', $teams[$team][0])->get()->pluck('teamStyle')->toArray()[0];
             if ($studentStyle == $teamStyle) {
                 for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                     if ($teams[$team][$slot] == -1) {
                         $studentPlaced = true;
                         $teams[$team][$slot] = $studentID;
                         break;
                     }
                 }
                 if ($studentPlaced) {
                     break;
                 }
             }
         }
         if ($studentPlaced) {
             continue;
         }
         // place anywhere
         for ($team = 0; $team < count($teams); $team++) {
             if ($teams[$team][count($teams[$team]) - 1] == -1) {
                 for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                     if ($teams[$team][$slot] == -1) {
                         $teams[$team][$slot] = $studentID;
                         break;
                     }
                 }
                 break;
             }
         }
     }
     // Locate any teams that are too small
     $studentsRemaining = array();
     $invalidTeams = array();
     for ($team = 0; $team < count($teams); $team++) {
         $studentsInCurrentTeam = array();
         for ($slot = 0; $slot < count($teams[$team]); $slot++) {
             if ($teams[$team][$slot] == -1 && $slot < $minTeamSize) {
                 $studentsRemaining = array_merge($studentsRemaining, $studentsInCurrentTeam);
                 array_push($invalidTeams, $team);
                 break;
             }
             array_push($studentsInCurrentTeam, $teams[$team][$slot]);
         }
     }
     // Determine if students in small teams can be moved to other teams
     $spotsRemaining = 0;
     for ($team = 0; $team < count($teams); $team++) {
         if (!in_array($team, $invalidTeams)) {
             for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                 if ($teams[$team][$slot] == -1) {
                     $spotsRemaining++;
                 }
             }
         }
     }
     // Rearrange students by removing teams that are too small
     if ($spotsRemaining >= count($studentsRemaining) && count($studentsRemaining) > 0) {
         for ($team = 0; $team < count($teams); $team++) {
             if (in_array($team, $invalidTeams)) {
                 $teams[$team] = array_fill(0, $maxTeamSize, -1);
             }
         }
         foreach ($studentsRemaining as $studentID) {
             for ($team = 0; $team < count($teams); $team++) {
                 if ($teams[$team][count($teams[$team]) - 1] == -1 && $teams[$team][0] != -1) {
                     for ($slot = 0; $slot < count($teams[$team]); $slot++) {
                         if ($teams[$team][$slot] == -1) {
                             $teams[$team][$slot] = $studentID;
                             break;
                         }
                     }
                     break;
                 }
             }
         }
     } else {
         if (count($studentsRemaining) > 0) {
             foreach ($invalidTeams as $invalidTeam) {
                 $teamValid = false;
                 while (!$teamValid) {
                     $teamValid = true;
                     $studentToMove = -1;
                     // Find a student to add, and remove them from their old team
                     for ($team = 0; $team < count($teams); $team++) {
                         if (!in_array($team, $invalidTeams) && $teams[$team][$minTeamSize] != -1) {
                             for ($slot = $maxTeamSize - 1; $slot >= 0; $slot--) {
                                 if ($teams[$team][$slot] != -1) {
                                     $studentToMove = $teams[$team][$slot];
                                     $teams[$team][$slot] = -1;
                                 }
                                 if ($studentToMove != -1) {
                                     break;
                                 }
                             }
                         }
                         if ($studentToMove != -1) {
                             break;
                         }
                     }
                     // Add the student to the smaller team
                     for ($slot = 0; $slot < $maxTeamSize; $slot++) {
                         if ($teams[$invalidTeam][$slot] == -1) {
                             $teams[$invalidTeam][$slot] = $studentToMove;
                             if ($slot == $minTeamSize - 1) {
                                 $teamValid = true;
                             }
                             break;
                         }
                     }
                 }
             }
         }
     }
     // Remove empty teams from array
     for ($team = 0; $team < count($teams); $team++) {
         if ($teams[$team][0] == -1) {
             unset($teams[$team]);
         }
     }
     $teams = array_values($teams);
     // Delete and recreate teams
     \App\userTeamAssociation::truncate();
     \App\team::truncate();
     for ($team = 0; $team < count($teams); $team++) {
         if ($teams[$team][0] != -1) {
             $teamName = 'Team ' . ($team + 1);
             $teamLanguage = \App\userKnownLanguages::where('userID', $teams[$team][0])->get()->pluck('languageName')->toArray()[0];
             \App\team::create(['teamName' => $teamName, 'language' => $teamLanguage]);
         }
     }
     // Create new team associations
     for ($team = 0; $team < count($teams); $team++) {
         for ($slot = 0; $slot < count($teams[$team]); $slot++) {
             if ($teams[$team][$slot] != -1) {
                 \App\userTeamAssociation::create(['userID' => $teams[$team][$slot], 'teamID' => $team + 1]);
             }
         }
     }
     return redirect('/teams');
 }
示例#3
0
 public function admin()
 {
     $this->recalcTeamLanguages();
     $teams = \App\team::all();
     $members = DB::table('teams')->join('teamMembers', 'teams.id', '=', 'teamMembers.teamId')->join('users', 'teamMembers.studentId', '=', 'users.id')->select('teams.id', 'users.name', 'teamMembers.studentId')->get();
     $leftovers = DB::table('teamMembers')->join('students', 'students.id', '=', 'teamMembers.studentId')->join('users', 'teamMembers.studentId', '=', 'users.id')->select('users.name', 'users.id', 'students.c', 'students.java', 'students.python')->where('teamMembers.teamId', '=', '0')->get();
     return view('admin/teamInfo', compact('teams', 'members', 'leftovers'));
 }
 public function run()
 {
     DB::table('team')->delete();
     team::create(['teamName' => 'Flying Circus', 'competition' => '1']);
     team::create(['teamName' => 'Bladed Maze', 'competition' => '1']);
     team::create(['teamName' => 'Random Namers', 'competition' => '2']);
     team::create(['teamName' => 'Team 404', 'competition' => '2']);
     team::create(['teamName' => 'Out of Time', 'competition' => '3']);
     team::create(['teamName' => 'Seedy Fellows', 'competition' => '3']);
 }