Skip to content

Commit

Permalink
Issue #292 - Showing phase result for teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiliemorais committed Apr 28, 2017
1 parent 50df58d commit fad4ea3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(MODULESPATH."/auth/constants/PermissionConstants.php");
require_once(MODULESPATH."/auth/constants/GroupConstants.php");
require_once(MODULESPATH."/program/constants/SelectionProcessConstants.php");
require_once(MODULESPATH."/program/exception/SelectionProcessException.php");
Expand Down Expand Up @@ -74,7 +75,7 @@ public function showTeacherCandidates($processId, $phaseId){
);


loadTemplateSafelyByGroup(GroupConstants::TEACHER_GROUP, "program/selection_process_evaluation/evaluate", $data);
loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_EVALUATION, "program/selection_process_evaluation/evaluate", $data);
}

private function getPhasesNames($candidates){
Expand All @@ -98,7 +99,7 @@ private function groupCandidates($candidates){
$candidateId = $candidate['candidate_id'];
unset($candidate['candidate_id']);
$candidatesEvaluations[$candidateId][] = $candidate;
}
}
}

$candidatesEvaluations = $this->groupByProcessPhase($candidatesEvaluations);
Expand All @@ -114,7 +115,9 @@ private function groupByProcessPhase($candidatesEvaluations){
foreach ($candidatesEvaluations as $key => $candidateEvaluation) {
foreach ($candidateEvaluation as $evaluation) {
$idProcessPhase = $evaluation['id_process_phase'];
$evaluations[$key][$idProcessPhase][] = $evaluation;
$evaluations[$key][$idProcessPhase]['evaluations'][] = $evaluation;
$phaseResult = $this->getCandidatePhaseResult($evaluation['id_subscription'], $idProcessPhase);
$evaluations[$key][$idProcessPhase]['phase_result'] = $phaseResult;
}
}
}
Expand All @@ -126,7 +129,7 @@ public function saveCandidateGrade(){
$self = $this;
withPermissionAnd(PermissionConstants::SELECTION_PROCESS_EVALUATION,
function() use($self){
$self->checkIfIsLoggedTeacher();
return $self->checkIfIsLoggedTeacher();
},
function() use($self){
$self->saveGrade();
Expand Down Expand Up @@ -156,17 +159,14 @@ private function saveGrade(){
"evaluation_service"
);

$saved = $this->process_evaluation_model->saveCandidateGrade($grade, $teacherId, $subscriptionId, $phaseprocessId, $approved);
$saved = $this->process_evaluation_model->saveCandidateGrade($grade, $teacherId, $subscriptionId, $phaseprocessId);
if($saved){
$data = array('grade' => $grade, 'approved' => $approved);
// $labelCandidate = $this->getCandidateFinalResult($);
// $phase = $this->process_evaluation_model->getPassingScoreOfPhaseByProcessPhaseId($phaseprocessId);
// $approved = $grade >= $phase->grade ? TRUE : FALSE;
// $labelCandidate = $approved ? "<b class='text text-success'>Aprovado</b>" : "<b class='text text-warning'>Reprovado</b>";
$labelCandidate = $this->getCandidatePhaseResult($subscriptionId, $phaseprocessId);

$response = array(
'type' => "success",
'message' => "Nota salva com sucesso"
// 'label' => $labelCandidate
'message' => "Nota salva com sucesso",
'label' => $labelCandidate
);
}
else{
Expand All @@ -186,7 +186,40 @@ private function saveGrade(){

echo json_encode($response);
}

private function getCandidatePhaseResult($subscriptionId, $phaseprocessId){

$phaseResult = FALSE;
$candidateGradesOnPhase = $this->process_evaluation_model->getCandidatePhaseEvaluations($subscriptionId, $phaseprocessId);
$passingScore = $this->process_evaluation_model->getPassingScoreOfPhaseByProcessPhaseId($phaseprocessId);

$totalGrade = 0;
foreach ($candidateGradesOnPhase as $result) {

if(is_null($result['grade'])){
$phaseResult = FALSE;
break;
}
else{
$phaseResult = TRUE;
$totalGrade += $result['grade'];
}

}

if($phaseResult){
$approvedOnPhase = FALSE;
if(($totalGrade/2) >= $passingScore){
$approvedOnPhase = TRUE;
}
$labelCandidate = $approvedOnPhase ? "<b class='text text-success'>Aprovado</b>" : "<b class='text text-danger'>Reprovado</b>";
}
else{
$labelCandidate = "<b class='text text-warning'>-</b>";
}

return $labelCandidate;
}

}

// $candidateApproved = ($candidateApproved && $evaluation['approved']) || FALSE;
// $evaluatedForAll = ($evaluatedForAll && !is_null($evaluation['grade'])) || FALSE;
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getPassingScoreOfPhaseByProcessPhaseId($idPhaseProcess){
$this->db->where("id", $idPhaseProcess);
$phase = $this->db->get("process_phase")->row();

return $phase;
return $phase->grade;
}

public function getTeacherCandidates($teacherId, $idProcess){
Expand Down Expand Up @@ -114,13 +114,13 @@ private function getCandidates($evaluations){
return $evaluations;
}

public function saveCandidateGrade($grade, $teacherId, $subscriptionId, $phaseprocessId, $approved){
public function saveCandidateGrade($grade, $teacherId, $subscriptionId, $phaseprocessId){

$this->db->where('id_teacher', $teacherId);
$this->db->where('id_subscription', $subscriptionId);
$this->db->where('id_process_phase', $phaseprocessId);

$saved = $this->db->update("selection_process_evaluation", $data);
$saved = $this->db->update("selection_process_evaluation", array('grade' => $grade));

return $saved;
}
Expand All @@ -135,4 +135,14 @@ public function getEvaluationTeachers($subscriptionId){

return $teachers;
}

public function getCandidatePhaseEvaluations($idSubscription, $idPhaseProcess){

$this->db->select("grade");
$this->db->from($this->TABLE);
$this->db->where("id_subscription", $idSubscription);
$this->db->where("id_process_phase", $idPhaseProcess);

return $this->db->get()->result_array();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<script src=<?=base_url("js/selective_process_evaluation.js")?>></script>
<h2 class="principal">Candidatos</h2>
<h2 class="principal">Avaliação de Candidatos<b></b>
<br>
<small>Fase atual: <b><?= $phasesNames[$currentPhaseProcessId]->phase_name ?></b></small>
</h2>

<div class="row">

<div class="col-md-10 col-md-offset-1">
<?php
alert(function(){
echo '<p>Você só poderá salvar a nota do candidato para a fase atual.</p>';
});
?>
</div>

<br>
<br>
<?php if ($candidates){
foreach ($candidates as $candidateId => $candidate) {
Expand All @@ -26,19 +30,19 @@
<div class="box-body">
<?php
foreach ($candidate as $processPhase => $phaseEvaluations) :
$idSubscription = $phaseEvaluations[0]['id_subscription'];
$idSubscription = $phaseEvaluations['evaluations'][0]['id_subscription'];
$idForLabel = $processPhase."_".$idSubscription."_label";
$phaseName = $phasesNames[$processPhase]->phase_name;?>
<div class="row">
<div class="col-lg-6">
<h4>Fase: <b> <?=$phaseName ?></b> </h4>
</div>
<div class="col-lg-6">
<h4 id=<?=$idForLabel?>></h4>
<h4 id=<?=$idForLabel?>>Resultado: <b><?= $phaseEvaluations['phase_result'] ?></b></h4>
</div>
</div>
<div class="row">
<?php showEvaluations($phaseEvaluations, $teacherId, $phaseName, $currentPhaseProcessId);?>
<?php showEvaluations($phaseEvaluations['evaluations'], $teacherId, $phaseName, $currentPhaseProcessId);?>
</div> <!-- /. row -->
<?php endforeach ?>
</div> <!-- /. box-body -->
Expand All @@ -48,14 +52,12 @@
}
} ?>
</div>
<?php echo anchor("selection_process_evaluation", "Voltar", "class='btn btn-danger pull-left'"); ?>

<?php
function showEvaluations($phaseEvaluations, $teacherId, $phaseName, $currentPhaseProcessId){

if($phaseEvaluations){
$candidateApproved = TRUE;
$evaluatedForAll = TRUE;

foreach ($phaseEvaluations as $evaluation) {
echo "<div class='col-lg-6'>";
showForm($evaluation, $teacherId, $currentPhaseProcessId);
Expand Down
7 changes: 5 additions & 2 deletions js/selective_process_evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ function saveGrade(teacherId, subscriptionId, phaseprocessId){
var response = JSON.parse(responseJson);
var id = "#" + phaseprocessId + "_" + subscriptionId + "_label";
var id = "#" + phaseprocessId + "_" + subscriptionId + "_label";
if(response.type === "success"){
if(response.type === "success" && typeof response.label !== 'undefined'){
$(id).html("Resultado: " + response.label);
}
else{
else if(typeof response.label !== 'undefined'){
$(id).html("Resultado: " + response.label);
}
else{
$(id).html("Resultado: -");
}
var message ="<p class='alert-" + response.type + "'>" + response.message + "</p>";
$("#status_" + fieldId).html(message);
}
Expand Down

0 comments on commit fad4ea3

Please sign in to comment.