Skip to content
Snippets Groups Projects
Commit 80e39e31 authored by sebastien dupuy's avatar sebastien dupuy
Browse files

issue #10 Correction #1 [Évaluation] Niveau des mesures du plan d'action incorrect

parent 47415dc6
No related branches found
No related tags found
No related merge requests found
...@@ -20,10 +20,16 @@ ...@@ -20,10 +20,16 @@
use App\Models\MeasureLevel; use App\Models\MeasureLevel;
use App\Models\User; use App\Models\User;
use App\Repository\EvaluationRepository; use App\Repository\EvaluationRepository;
use App\Repository\GraphDataRepository;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
class EvaluationsController extends Controller class EvaluationsController extends Controller
{ {
public function __construct(GraphDataRepository $repository)
{
$this->repository = $repository;
}
public function all() public function all()
{ {
$user = Auth::user(); $user = Auth::user();
...@@ -126,7 +132,6 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques ...@@ -126,7 +132,6 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques
$previous_measures_array = MeasureLevel::where('evaluation_id', $evaluation['id'])->pluck('id')->toArray(); $previous_measures_array = MeasureLevel::where('evaluation_id', $evaluation['id'])->pluck('id')->toArray();
foreach ($data['measure_levels'] as $put_measure_level) { foreach ($data['measure_levels'] as $put_measure_level) {
$measure = Measure::find($put_measure_level['measure_id']); $measure = Measure::find($put_measure_level['measure_id']);
$fundamentalMeasure = $measure->fundamental;
if (isset($put_measure_level['id'])) { if (isset($put_measure_level['id'])) {
$measure_level = MeasureLevel::find($put_measure_level['id']); $measure_level = MeasureLevel::find($put_measure_level['id']);
...@@ -137,11 +142,7 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques ...@@ -137,11 +142,7 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques
$measure_level->measure_id = $put_measure_level['measure_id']; $measure_level->measure_id = $put_measure_level['measure_id'];
$measure_level->evaluation_id = $evaluation['id']; $measure_level->evaluation_id = $evaluation['id'];
$measure_level->actual_level = $put_measure_level['actual_level'] ?? null; $measure_level->actual_level = $put_measure_level['actual_level'] ?? null;
if ($fundamentalMeasure && 2 === (int) $evaluation->current_step) { $measure_level->expected_level = $put_measure_level['expected_level'] ?? null;
$measure_level->expected_level = $put_measure_level['actual_level'] < 3 ? $put_measure_level['actual_level'] + 1 : null;
} else {
$measure_level->expected_level = $put_measure_level['expected_level'] ?? null;
}
$measure_level->manager = $put_measure_level['manager'] ?? null; $measure_level->manager = $put_measure_level['manager'] ?? null;
$measure_level->end_date = $put_measure_level['end_date'] ?? null; $measure_level->end_date = $put_measure_level['end_date'] ?? null;
$measure_level->save(); $measure_level->save();
...@@ -193,6 +194,17 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques ...@@ -193,6 +194,17 @@ public function save(EvaluationRepository $repository, EvaluationRequest $reques
$evaluation->save(); $evaluation->save();
// Ajout du niveau supérieur pour les mesures preconisées
$preconizedMeasure = array_slice($this->repository->getBestMeasuresForEvaluation($evaluation),0,4);
foreach ($evaluation->measureLevels as $measureLevel) {
$measureLevelpreconized = MeasureLevel::whereId($measureLevel->id)
->first();
if ($measureLevelpreconized && in_array($measureLevelpreconized['measure_id'], $preconizedMeasure, true)) {
$measureLevelpreconized->expected_level = $measureLevelpreconized['actual_level'] < 3 ? $measureLevelpreconized['actual_level'] + 1 : null;
}
$measureLevelpreconized->save();
}
// si mofification d'un step, reinitialisation des steps suivants // si mofification d'un step, reinitialisation des steps suivants
if (isset($data['draft']) && $data['draft']) { if (isset($data['draft']) && $data['draft']) {
if (1 === $evaluation->current_step) { if (1 === $evaluation->current_step) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment