From 0cbdc66584f6189218c98cbef4d595208a4e756e Mon Sep 17 00:00:00 2001 From: Damien Labat <labat@datakode.fr> Date: Tue, 8 Nov 2022 14:16:24 +0100 Subject: [PATCH] fix: Export evaluation & organizations features - fix filename + cells formats --- app/Http/Controllers/ExportController.php | 2 +- .../Resources/EvaluationExportResource.php | 11 ++++---- .../Resources/OrganizationExportResource.php | 26 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index d4b48eb8..c914e8f2 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -38,7 +38,7 @@ public function organizations(Request $request): Collection|null public function evaluations(Request $request): Collection|null { $ext = $request->route('ext'); - $filename = "structures.$ext"; + $filename = "evaluations.$ext"; $data = Evaluation::with(['dangerLevels'])->get(); $rows = EvaluationExportResource::collection($data)->toArray($request); $header = $this->_getRowsHeader($rows[0], 'exports.evaluation'); diff --git a/app/Http/Resources/EvaluationExportResource.php b/app/Http/Resources/EvaluationExportResource.php index 5974ff00..8e343378 100644 --- a/app/Http/Resources/EvaluationExportResource.php +++ b/app/Http/Resources/EvaluationExportResource.php @@ -27,7 +27,6 @@ public function toArray($request): array $evaluation = $this->resource; $res = [ - 'id' => $evaluation->id, 'organizationId' => $evaluation->organization_id, // -Collectivité id 'updatedDate' => $evaluation->updated_at->isoFormat('DD/MM/YYYY'), // - Date de modification 'updatedBy' => $evaluation->updated_by, // - Modifié par @@ -44,7 +43,7 @@ public function toArray($request): array foreach ([1, 2, 3, 4, 5, 6] as $dangerId) { /** @var ?DangerLevelEvaluation $dangerLevelEvaluation */ $dangerLevelEvaluation = $dangerLevelEvaluations->where('danger_id', '=', $dangerId)->first(); - $res["dangerLevel_$dangerId"] = $dangerLevelEvaluation?->level?->name; // - perception du danger X + $res["dangerLevel_$dangerId"] = (string) $dangerLevelEvaluation?->level?->name; // - perception du danger X } $mesures = Measure::orderBy('fundamental', 'ASC')->get(); @@ -66,10 +65,10 @@ public function toArray($request): array return [...$res, 'actionPlan' => $this->_getActionPlanString($mesureLevels), // - Plan d’action - 'motivation' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::MOTIVATION)?->name, // - Motivation - 'execution' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::EXECUTION)?->name, // - Execution - 'fundamental' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::FUNDAMENTALS)?->name, // - Fondamentaux - 'organization' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::ORGANIZATION)?->name, // - Organisation + 'motivation' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::MOTIVATION)?->name, // - Motivation + 'execution' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::EXECUTION)?->name, // - Execution + 'fundamental' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::FUNDAMENTALS)?->name, // - Fondamentaux + 'organization' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::ORGANIZATION)?->name, // - Organisation 'maturityCyber' => $evaluation->maturity_cyber, // - Indice de maturité ]; } diff --git a/app/Http/Resources/OrganizationExportResource.php b/app/Http/Resources/OrganizationExportResource.php index 42aa0350..87bef68e 100644 --- a/app/Http/Resources/OrganizationExportResource.php +++ b/app/Http/Resources/OrganizationExportResource.php @@ -46,8 +46,8 @@ public function toArray($request): array 'info' => $organization->info, // - infos complementaire 'fullAddress' => (string) $organization->address, // - adresses (tous les chamsp) 'ref' => implode(PHP_EOL, $referentsStringArray), // - référents et responsable (tous les champs) - 'lastEvaluation.cyberMaturity' => $lastEvaluation?->maturity_cyber, // - score indice maturité cyber - 'previousEvaluation.cyberMaturity' => $previousEvaluation?->maturity_cyber, // - score indice maturité cyber n-1 + 'lastEvaluation.cyberMaturity' => (float) $lastEvaluation?->maturity_cyber, // - score indice maturité cyber + 'previousEvaluation.cyberMaturity' => (float) $previousEvaluation?->maturity_cyber, // - score indice maturité cyber n-1 ]; $measureLevels = $lastEvaluation?->measureLevels ?? collect(); @@ -55,23 +55,23 @@ public function toArray($request): array foreach ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as $measureKey) { /** @var ?MeasureLevel $measureLevel */ $measureLevel = $measureLevels->get($measureKey - 1); - $res["measure$measureKey.actualLevel"] = $measureLevel?->actual_level; // - niveau de mise en œuvre mesure X + $res["measure$measureKey.actualLevel"] = (string) $measureLevel?->actual_level; // - niveau de mise en œuvre mesure X } foreach ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as $measureKey) { /** @var ?MeasureLevel $measureLevel */ $measureLevel = $measureLevels->get($measureKey - 1); - $res["measure$measureKey.expectedLevel"] = $measureLevel?->expected_level; // - niveau de planification mesure X + $res["measure$measureKey.expectedLevel"] = (string) $measureLevel?->expected_level; // - niveau de planification mesure X } $maturityLevelAnswers = $lastEvaluation?->maturityLevels()->with(['question', 'answer'])->get(); $res = [...$res, - 'executionLevel' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::EXECUTION)?->name, // niveau d'exécution + 'executionLevel' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::EXECUTION)?->name, // niveau d'exécution 'createdDate' => $organization->created_at->isoFormat('DD/MM/YYYY'), // date création de la collectivité - 'lastEvaluation.reference' => $lastEvaluation?->reference, // - version du référentiel - 'lastEvaluation.updatedBy' => $lastEvaluation?->updated_by, // - évaluation modifiée par - 'lastEvaluation.author' => $lastEvaluation?->author, // - évaluation crée par + 'lastEvaluation.reference' => (string) $lastEvaluation?->reference, // - version du référentiel + 'lastEvaluation.updatedBy' => (string) $lastEvaluation?->updated_by, // - évaluation modifiée par + 'lastEvaluation.author' => (string) $lastEvaluation?->author, // - évaluation crée par ]; $dangerLevelEvaluations = $lastEvaluation?->dangerLevels ?? collect(); @@ -79,15 +79,15 @@ public function toArray($request): array foreach ([1, 2, 3, 4, 5, 6] as $dangerId) { /** @var ?DangerLevelEvaluation $dangerLevelEvaluation */ $dangerLevelEvaluation = $dangerLevelEvaluations->where('danger_id', '=', $dangerId)->first(); - $res["dangerLevel$dangerId"] = $dangerLevelEvaluation?->level->name; // - perception du danger X + $res["dangerLevel$dangerId"] = (string) $dangerLevelEvaluation?->level->name; // - perception du danger X } return [...$res, - 'maturityLevel.knowledge' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::KNOWLEDGE)?->name, // - niveau de connaissance - 'maturityLevel.organization' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::ORGANIZATION)?->name, // - niveau d'organisation - 'maturityLevel.motivation' => $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::MOTIVATION)?->name, // - niveau de motivation + 'maturityLevel.knowledge' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::KNOWLEDGE)?->name, // - niveau de connaissance + 'maturityLevel.organization' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::ORGANIZATION)?->name, // - niveau d'organisation + 'maturityLevel.motivation' => (string) $this->_getAnswerForQuestionName($maturityLevelAnswers, MaturityQuestionNames::MOTIVATION)?->name, // - niveau de motivation - 'alert' => $lastEvaluation?->isThresholdExceeded(), // - alerte seuil dépassé (true/false) + 'alert' => (bool) $lastEvaluation?->isThresholdExceeded(), // - alerte seuil dépassé (true/false) ]; } -- GitLab