diff --git a/application/modules/program/controllers/Selectiveprocess.php b/application/modules/program/controllers/Selectiveprocess.php index ee0784a4..ce0697fe 100755 --- a/application/modules/program/controllers/Selectiveprocess.php +++ b/application/modules/program/controllers/Selectiveprocess.php @@ -379,7 +379,9 @@ public function showResults($processId){ $allProcessCandidates = $this->selectiveprocessevaluation->getCandidates($allProcessCandidates); $candidatesResults = []; - $approvedCandidates = []; + $resultCandidatesByPhase = []; + $status = $selectiveProcess->getStatus(); + $phasesResultPerCandidate = []; if($allProcessCandidates){ foreach ($allProcessCandidates as $candidateId => $evaluations) { @@ -392,7 +394,7 @@ public function showResults($processId){ foreach ($candidatesResults as $key => $results) { $hasResult = TRUE; $phase = $this->process_evaluation_model->getPhaseNameByPhaseProcessId($key); - $approvedCandidatesInPhase = array(); + $resultOfCandidatesInPhase = array(); foreach ($results as $candidateId => $result) { if($phase->phase_name == SelectionProcessConstants::HOMOLOGATION_PHASE){ $hasResult = TRUE; @@ -401,25 +403,75 @@ public function showResults($processId){ $hasResult = $result['hasResult'] && $hasResult; } - if($hasResult && ($result['approved'] || $phase->phase_name == SelectionProcessConstants::HOMOLOGATION_PHASE)){ - $approvedCandidatesInPhase[] = $candidateId; + if($hasResult){ + $label = $this->selectiveprocessevaluation->getCandidatePhaseResultLabel($result); + $result['label'] = $label; + $resultOfCandidatesInPhase[$candidateId] = $result; + + if($status === SelectionProcessConstants::FINISHED){ + $phaseInfo = array('phase_weight' => $phase->weight); + $phasesResultPerCandidate[$candidateId][$phase->phase_name] = $result + $phaseInfo; + } } } - if(!empty($approvedCandidatesInPhase)){ - $approvedCandidates[$phase->phase_name] = $approvedCandidatesInPhase; + if(!empty($resultOfCandidatesInPhase)){ + $resultCandidatesByPhase[$phase->phase_name] = $resultOfCandidatesInPhase; } } } } + if($phasesResultPerCandidate){ + $quantityOfPhases = sizeof($resultCandidatesByPhase); + $selectedCandidates = $this->getFinalResult($quantityOfPhases, $phasesResultPerCandidate); + $resultCandidatesByPhase = $selectedCandidates + $resultCandidatesByPhase; + } + $data = array( - 'approvedCandidates' => $approvedCandidates, + 'resultCandidatesByPhase' => $resultCandidatesByPhase, 'process' => $selectiveProcess ); loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/results", $data); } + private function getFinalResult($quantityOfPhases, $phasesResultPerCandidate){ + + $selectedCandidates = array(); + $candidatesScore = array(); + $quantityOfPhases = $quantityOfPhases - 1; + if($phasesResultPerCandidate){ + foreach ($phasesResultPerCandidate as $candidateId => $phasesResults) { + unset($phasesResults[SelectionProcessConstants::HOMOLOGATION_PHASE]); + $candidatePoints = 0; + $totalWeight = 0; + $approvedTimes = 0; + foreach ($phasesResults as $phaseName => $phaseResult) { + $phaseWeight = $phaseResult['phase_weight']; + $candidatePoints += ($phaseWeight * $phaseResult['average']); + $totalWeight += $phaseWeight; + + $candidatesScore[$candidateId][] = array( + 'phaseName' => $phaseName, + 'average' => $phaseResult['average'], + 'phaseWeight' => $phaseWeight, + ); + $approvedTimes = $phaseResult['approved'] ? $approvedTimes + 1 : $approvedTimes; + } + + $candidatePointsAverage = $candidatePoints/$totalWeight; + $candidatesScore[$candidateId]['final_average'] = $candidatePointsAverage; + $selected = $approvedTimes == $quantityOfPhases ? TRUE : FALSE; + $candidatesScore[$candidateId]['selected'] = $selected; + } + } + + arsort($candidatesScore); + $selectedCandidates['Final'] = $candidatesScore; + + return $selectedCandidates; + } + public function generatePDF(){ $candidates = $this->input->post('candidates'); diff --git a/application/modules/program/controllers/Selectiveprocessevaluation.php b/application/modules/program/controllers/Selectiveprocessevaluation.php index a8eacdbc..3c16308f 100644 --- a/application/modules/program/controllers/Selectiveprocessevaluation.php +++ b/application/modules/program/controllers/Selectiveprocessevaluation.php @@ -94,11 +94,9 @@ public function getCandidates($evaluations, $resultInLabelForm = FALSE){ $candidateId = $subscription['candidate_id']; $idProcessPhase = $evaluation['id_process_phase']; $candidatesEvaluations[$candidateId][$idProcessPhase][$idSubscription][] = $evaluation; + $phaseResult = $this->getCandidatePhaseResult($evaluation['id_subscription'], $idProcessPhase); if($resultInLabelForm){ - $phaseResult = $this->getCandidatePhaseResultLabel($evaluation['id_subscription'], $idProcessPhase); - } - else{ - $phaseResult = $this->getCandidatePhaseResult($evaluation['id_subscription'], $idProcessPhase); + $phaseResult = $this->getCandidatePhaseResultLabel($phaseResult); } $candidatesEvaluations[$candidateId][$idProcessPhase]['phase_result'] = $phaseResult; } @@ -158,7 +156,8 @@ private function saveGrade(){ $data = ['grade' => $grade]; $saved = $this->process_evaluation_model->saveOrUpdate($subscriptionId, $teacherId, $phaseprocessId, $data); if($saved){ - $labelCandidate = $this->getCandidatePhaseResultLabel($subscriptionId, $phaseprocessId); + $phaseResult = $this->getCandidatePhaseResult($subscriptionId, $phaseprocessId); + $labelCandidate = $this->getCandidatePhaseResultLabel($phaseResult); $response = array( 'type' => "success", @@ -191,6 +190,7 @@ public function getCandidatePhaseResult($subscriptionId, $phaseprocessId){ $phaseEvaluationElements = $this->process_evaluation_model->getPhaseEvaluationElementsOfPhaseByProcessPhaseId($phaseprocessId); $totalGrade = 0; + $knockoutPhase = $phaseEvaluationElements->knockout_phase; foreach ($candidateGradesOnPhase as $result) { if(is_null($result['grade'])){ @@ -205,37 +205,28 @@ public function getCandidatePhaseResult($subscriptionId, $phaseprocessId){ } $approvedOnPhase = FALSE; - $knockoutPhase = $phaseEvaluationElements->knockout_phase; $passingScore = $phaseEvaluationElements->grade; + $average = 0; if($hasResult && $knockoutPhase){ - if(($totalGrade/2) >= $passingScore){ + $average = $totalGrade/2; + if($average >= $passingScore){ $approvedOnPhase = TRUE; } } elseif (!$knockoutPhase) { + $average = $totalGrade/2; $approvedOnPhase = TRUE; } - $phaseResult = ['hasResult' => $hasResult, 'approved' => $approvedOnPhase, 'knockoutPhase' => $knockoutPhase]; + $phaseResult = ['hasResult' => $hasResult, 'approved' => $approvedOnPhase, 'knockoutPhase' => $knockoutPhase, 'average' => $average]; return $phaseResult; } - public function getCandidatePhaseResultLabel($subscriptionId, $phaseprocessId){ - - $phaseResult = $this->getCandidatePhaseResult($subscriptionId, $phaseprocessId); + public function getCandidatePhaseResultLabel($phaseResult){ if($phaseResult['hasResult']){ - if($phaseResult['approved'] && $phaseResult['knockoutPhase']){ - $labelCandidate = "Aprovado"; - } - elseif ($phaseResult['approved'] && !$phaseResult['knockoutPhase']) { - $labelCandidate = "Classificado"; - } - else{ - - $labelCandidate = "Reprovado"; - } + $labelCandidate = $phaseResult['approved'] ? "Aprovado" : "Eliminado"; } else{ diff --git a/application/modules/program/models/Selectiveprocessevaluation_model.php b/application/modules/program/models/Selectiveprocessevaluation_model.php index 5acca964..aee30239 100644 --- a/application/modules/program/models/Selectiveprocessevaluation_model.php +++ b/application/modules/program/models/Selectiveprocessevaluation_model.php @@ -60,7 +60,7 @@ public function getProcessesOnObject($processes){ public function getPhaseNameByPhaseProcessId($processphaseId){ - $this->db->select("phase.phase_name"); + $this->db->select("phase.phase_name, pp.weight"); $this->db->join("phase", "phase.id_phase = pp.id_phase"); $this->db->where("id", $processphaseId); @@ -132,7 +132,7 @@ public function getProcessCandidates($processId){ $query = "SELECT * FROM `selection_process_evaluation`"; $query .= "WHERE `id_process_phase` IN (SELECT `id` FROM `process_phase` WHERE `id_process` = {$processId}) "; - $query .= "ORDER BY `id_subscription`"; + $query .= "ORDER BY `id_process_phase`"; $evaluations = $this->db->query($query); diff --git a/application/modules/program/views/selection_process/course_process.php b/application/modules/program/views/selection_process/course_process.php index 8ceadf34..20f032fb 100755 --- a/application/modules/program/views/selection_process/course_process.php +++ b/application/modules/program/views/selection_process/course_process.php @@ -299,7 +299,7 @@ function createNextPhaseModal($process){ } else{ $question = "Deseja finalizar o processo?"; - $formPath = "selection_process/finalize_process/{$processId}/{$courseId}"; + $formPath = "selection_process/next_phase/{$processId}/{$courseId}"; } diff --git a/application/modules/program/views/selection_process/phase_result.php b/application/modules/program/views/selection_process/phase_result.php index a38c7981..6f300d59 100644 --- a/application/modules/program/views/selection_process/phase_result.php +++ b/application/modules/program/views/selection_process/phase_result.php @@ -1,16 +1,19 @@