From b33ca0d05a48e20339cc8b190aa7d9ad04c05a66 Mon Sep 17 00:00:00 2001 From: Kurniandha Sukma Yunastrian <13516106@std.stei.itb.ac.id> Date: Sun, 11 Jul 2021 00:58:31 +0700 Subject: [PATCH] Refactor to change phase sequence --- app/Http/Controllers/PhaseController.php | 126 ++++++----------------- resources/views/phase/phase02.blade.php | 78 +------------- resources/views/phase/phase03.blade.php | 104 ++++++++++++++----- resources/views/phase/phase04.blade.php | 64 +++++------- 4 files changed, 135 insertions(+), 237 deletions(-) diff --git a/app/Http/Controllers/PhaseController.php b/app/Http/Controllers/PhaseController.php index d3badf1..dac20af 100644 --- a/app/Http/Controllers/PhaseController.php +++ b/app/Http/Controllers/PhaseController.php @@ -62,10 +62,10 @@ class PhaseController extends Controller { $currentPhaseNumber = DB::table('projects')->where('id', $request->projectId)->first()->phase; - if ($currentPhaseNumber == 2) { + if ($currentPhaseNumber == 3) { PhaseController::calculateCriteriaVotes($request->projectId); } else if ($currentPhaseNumber == 4) { - PhaseController::calculateCriteriaWeightVotes($request->projectId); + //PhaseController::calculateCriteriaWeightVotes($request->projectId); } else if ($currentPhaseNumber == 5) { PhaseController::calculateScores($request->projectId); PhaseController::determineScorestatus($request->projectId); @@ -161,6 +161,22 @@ class PhaseController extends Controller * Open view second phase. */ public function phase02View($project, $phaseNumber, $userRole) + { + // To do + } + + /** + * Submit second phase. + */ + public function phase02Submit(Request $request) + { + // To do + } + + /** + * Open view third phase. + */ + public function phase03View($project, $phaseNumber, $userRole) { if ($userRole == 1) { $members = DB::table('userprojects')->where('idProject', $project->id)->where('role', 2)->get(); @@ -182,18 +198,18 @@ class PhaseController extends Controller $users[] = $userWithStatus; } - return view('phase.phase02', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Criteria', 'role' => $userRole, 'users' => $users]); + return view('phase.phase03', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Criteria', 'role' => $userRole, 'users' => $users]); } else { $criterias = DB::table('criterias')->where('idProject', $project->id)->get(); - return view('phase.phase02', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Criteria', 'role' => $userRole, 'criterias' => $criterias]); + return view('phase.phase03', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Criteria', 'role' => $userRole, 'criterias' => $criterias]); } } /** - * Submit second phase. + * Submit third phase. */ - public function phase02Submit(Request $request) + public function phase03Submit(Request $request) { if ($request->criteria1) { DB::table('criteriavotes')->updateOrInsert([ @@ -232,13 +248,13 @@ class PhaseController extends Controller DB::table('userprojects')->where('idUser', Auth::id())->increment('phase'); - return redirect()->route('project', ['id' => $request->projectId])->with('msg', 'Phase 2 submitted successfully'); + return redirect()->route('project', ['id' => $request->projectId])->with('msg', 'Phase 3 submitted successfully'); } /** - * Open view third phase. + * Open view fourth phase. */ - public function phase03View($project, $phaseNumber, $userRole) + public function phase04View($project, $phaseNumber, $userRole) { if ($userRole == 1) { $members = DB::table('userprojects')->where('idProject', $project->id)->where('role', 2)->get(); @@ -260,18 +276,18 @@ class PhaseController extends Controller $users[] = $userWithStatus; } - return view('phase.phase03', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Submit Weight of Criteria', 'role' => $userRole, 'users' => $users]); + return view('phase.phase04', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Submit Weight of Criteria', 'role' => $userRole, 'users' => $users]); } else { $criterias = DB::table('criterias')->where('idProject', $project->id)->where('used', 1)->get(); - return view('phase.phase03', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Submit Weight of Criteria', 'role' => $userRole, 'criterias' => $criterias]); + return view('phase.phase04', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Submit Weight of Criteria', 'role' => $userRole, 'criterias' => $criterias]); } } /** - * Submit third phase. + * Submit fourth phase. */ - public function phase03Submit(Request $request) + public function phase04Submit(Request $request) { DB::table('criteriaweights')->updateOrInsert( ['idCriteria' => $request->criteria1, 'weight' => $request->weight1], @@ -300,90 +316,6 @@ class PhaseController extends Controller DB::table('userprojects')->where('idUser', Auth::id())->increment('phase'); - return redirect()->route('project', ['id' => $request->projectId])->with('msg', 'Phase 3 submitted successfully'); - } - - /** - * Open view fourth phase. - */ - public function phase04View($project, $phaseNumber, $userRole) - { - if ($userRole == 1) { - $members = DB::table('userprojects')->where('idProject', $project->id)->where('role', 2)->get(); - - $users = []; - foreach($members as $member) { - $user = DB::table('users')->where('id', $member->idUser)->first(); - - $status = "Done"; - if ($member->phase == 4) { - $status = "WIP"; - } - - $userWithStatus = array( - "name" => $user->name, - "status" => $status - ); - - $users[] = $userWithStatus; - } - - return view('phase.phase04', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Weight', 'role' => $userRole, 'users' => $users]); - } else { - $criterias = DB::table('criterias')->where('idProject', $project->id)->where('used', 1)->get(); - - $weights = []; - - foreach($criterias as $criteria) { - $weights[] = DB::table('criteriaweights')->where('idCriteria', $criteria->id)->get(); - } - - return view('phase.phase04', ['project' => $project, 'phaseNumber' => $phaseNumber, 'phaseName' => 'Vote Weight', 'role' => $userRole, 'criterias' => $criterias, 'weights' => $weights]); - } - } - - /** - * Submit fourth phase. - */ - public function phase04Submit(Request $request) - { - if ($request->weight1) { - DB::table('criteriaweightvotes')->updateOrInsert([ - 'idUser' => Auth::id(), - 'idWeight' => $request->weight1 - ]); - } - - if ($request->weight2) { - DB::table('criteriaweightvotes')->updateOrInsert([ - 'idUser' => Auth::id(), - 'idWeight' => $request->weight2 - ]); - } - - if ($request->weight3) { - DB::table('criteriaweightvotes')->updateOrInsert([ - 'idUser' => Auth::id(), - 'idWeight' => $request->weight3 - ]); - } - - if ($request->weight4) { - DB::table('criteriaweightvotes')->updateOrInsert([ - 'idUser' => Auth::id(), - 'idWeight' => $request->weight4 - ]); - } - - if ($request->weight5) { - DB::table('criteriaweightvotes')->updateOrInsert([ - 'idUser' => Auth::id(), - 'idWeight' => $request->weight5 - ]); - } - - DB::table('userprojects')->where('idUser', Auth::id())->increment('phase'); - return redirect()->route('project', ['id' => $request->projectId])->with('msg', 'Phase 4 submitted successfully'); } diff --git a/resources/views/phase/phase02.blade.php b/resources/views/phase/phase02.blade.php index 5975815..0399c53 100644 --- a/resources/views/phase/phase02.blade.php +++ b/resources/views/phase/phase02.blade.php @@ -42,85 +42,11 @@ <div class="card-body"> <b>Instruction:</b> <br> - Select criterias those you think are most suitable for used (minimum 1, maximum 5) <br> - <i>make sure not to select the same criteria</i> + Moderator Eliminate </div> <div class="card-body"> - <div class="row justify-content-around"> - <div class="col-md-5"> - <b>Criteria List:</b> - <table class="table"> - <thead> - <tr> - <th scope="col">#</th> - <th scope="col">Criteria</th> - </tr> - </thead> - <tbody> - @foreach($criterias as $index => $criteria) - <tr> - <th scope="row" class="align-middle">{{ $index + 1 }}</th> - <td class="align-middle">{{ $criteria->name }}</td> - </tr> - @endforeach - </tbody> - </table> - </div> - - <div class="col-md-5"> - <b>Vote for criteria:</b> - <div class="form-group"> - <label for="criteria1">Criteria 1</label> - <select class="form-control" id="criteria1" name="criteria1"> - <option></option> - @foreach($criterias as $index => $criteria) - <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> - @endforeach - </select> - </div> - - <div class="form-group"> - <label for="criteria2">Criteria 2</label> - <select class="form-control" id="criteria2" name="criteria2"> - <option></option> - @foreach($criterias as $index => $criteria) - <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> - @endforeach - </select> - </div> - - <div class="form-group"> - <label for="criteria3">Criteria 3</label> - <select class="form-control" id="criteria3" name="criteria3"> - <option></option> - @foreach($criterias as $index => $criteria) - <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> - @endforeach - </select> - </div> - - <div class="form-group"> - <label for="criteria4">Criteria 4</label> - <select class="form-control" id="criteria4" name="criteria4"> - <option></option> - @foreach($criterias as $index => $criteria) - <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> - @endforeach - </select> - </div> - - <div class="form-group"> - <label for="criteria5">Criteria 5</label> - <select class="form-control" id="criteria5" name="criteria5"> - <option></option> - @foreach($criterias as $index => $criteria) - <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> - @endforeach - </select> - </div> - </div> - </div> + <!-- To do --> <input type="hidden" id="projectId" name="projectId" value="{{ $project->id }}"> </div> diff --git a/resources/views/phase/phase03.blade.php b/resources/views/phase/phase03.blade.php index 0799262..95eebac 100644 --- a/resources/views/phase/phase03.blade.php +++ b/resources/views/phase/phase03.blade.php @@ -42,36 +42,86 @@ <div class="card-body"> <b>Instruction:</b> <br> - Submit the weight for each criteria<br> - Rules: - <ul> - <li>1: very unimportant</li> - <li>10: very important</li> - <ul> + Select criterias those you think are most suitable for used (minimum 1, maximum 5) <br> + <i>make sure not to select the same criteria</i> </div> <div class="card-body"> - <table class="table"> - <thead> - <tr> - <th scope="col">#</th> - <th scope="col">Criteria</th> - <th scope="col">Proposed Weight</th> - </tr> - </thead> - <tbody> - @foreach($criterias as $index => $criteria) - <tr> - <th scope="row" class="align-middle">{{ $index + 1 }}</th> - <td class="align-middle">{{ $criteria->name }}</td> - <td class="align-middle"> - <input type="hidden" name="criteria{{ $index + 1 }}" value="{{ $criteria->id }}"> - <input type="number" class="form-control col-md-2" required="required" id="weight{{ $index + 1 }}" name="weight{{ $index + 1 }}" min="1" max="10"> - </td> - </tr> - @endforeach - </tbody> - </table> + <div class="row justify-content-around"> + <div class="col-md-5"> + <b>Criteria List:</b> + <table class="table"> + <thead> + <tr> + <th scope="col">#</th> + <th scope="col">Criteria</th> + </tr> + </thead> + <tbody> + @foreach($criterias as $index => $criteria) + <tr> + <th scope="row" class="align-middle">{{ $index + 1 }}</th> + <td class="align-middle">{{ $criteria->name }}</td> + </tr> + @endforeach + </tbody> + </table> + </div> + + <div class="col-md-5"> + <b>Vote for criteria:</b> + <div class="form-group"> + <label for="criteria1">Criteria 1</label> + <select class="form-control" id="criteria1" name="criteria1"> + <option></option> + @foreach($criterias as $index => $criteria) + <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> + @endforeach + </select> + </div> + + <div class="form-group"> + <label for="criteria2">Criteria 2</label> + <select class="form-control" id="criteria2" name="criteria2"> + <option></option> + @foreach($criterias as $index => $criteria) + <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> + @endforeach + </select> + </div> + + <div class="form-group"> + <label for="criteria3">Criteria 3</label> + <select class="form-control" id="criteria3" name="criteria3"> + <option></option> + @foreach($criterias as $index => $criteria) + <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> + @endforeach + </select> + </div> + + <div class="form-group"> + <label for="criteria4">Criteria 4</label> + <select class="form-control" id="criteria4" name="criteria4"> + <option></option> + @foreach($criterias as $index => $criteria) + <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> + @endforeach + </select> + </div> + + <div class="form-group"> + <label for="criteria5">Criteria 5</label> + <select class="form-control" id="criteria5" name="criteria5"> + <option></option> + @foreach($criterias as $index => $criteria) + <option value="{{ $criteria->id }}">{{ $criteria->name }}</option> + @endforeach + </select> + </div> + </div> + </div> + <input type="hidden" id="projectId" name="projectId" value="{{ $project->id }}"> </div> diff --git a/resources/views/phase/phase04.blade.php b/resources/views/phase/phase04.blade.php index 6f96ac4..f5b6324 100644 --- a/resources/views/phase/phase04.blade.php +++ b/resources/views/phase/phase04.blade.php @@ -42,46 +42,36 @@ <div class="card-body"> <b>Instruction:</b> <br> - Select weight that you think are most suitable for each criteria + Submit the weight for each criteria<br> + Rules: + <ul> + <li>1: very unimportant</li> + <li>10: very important</li> + <ul> </div> <div class="card-body"> - @for ($i = 0; $i < count($weights); $i++) - <div class="row justify-content-around"> - <div class="col-md-4"> - Criteria: <b>{{ $criterias[$i]->name }}</b> - <table class="table"> - <thead> - <tr> - <th scope="col">#</th> - <th scope="col">Proposed Weight</th> - </tr> - </thead> - <tbody> - @foreach($weights[$i] as $index => $weight) - <tr> - <th scope="row" class="align-middle">{{ $index + 1 }}</th> - <td class="align-middle">{{ $weight->weight }}</td> - </tr> - @endforeach - </tbody> - </table> - </div> - - <div class="col-md-4"> - <div class="form-group"> - <label for="weight{{ $i + 1 }}">Weight for criteria <b>{{ $criterias[$i]->name }}</b></label> - <select class="form-control" id="weight{{ $i + 1 }}" name="weight{{ $i + 1 }}"> - <option></option> - @foreach($weights[$i] as $index => $weight) - <option value="{{ $weight->id }}">{{ $weight->weight }}</option> - @endforeach - </select> - </div> - </div> - </div> - @endfor - + <table class="table"> + <thead> + <tr> + <th scope="col">#</th> + <th scope="col">Criteria</th> + <th scope="col">Proposed Weight</th> + </tr> + </thead> + <tbody> + @foreach($criterias as $index => $criteria) + <tr> + <th scope="row" class="align-middle">{{ $index + 1 }}</th> + <td class="align-middle">{{ $criteria->name }}</td> + <td class="align-middle"> + <input type="hidden" name="criteria{{ $index + 1 }}" value="{{ $criteria->id }}"> + <input type="number" class="form-control col-md-2" required="required" id="weight{{ $index + 1 }}" name="weight{{ $index + 1 }}" min="1" max="10"> + </td> + </tr> + @endforeach + </tbody> + </table> <input type="hidden" id="projectId" name="projectId" value="{{ $project->id }}"> </div> -- GitLab