From 8578cb5c31b7c1100cda90935228dbefaa8e485d Mon Sep 17 00:00:00 2001 From: DevEnv nis2-agile Date: Mon, 9 Mar 2026 10:22:40 +0100 Subject: [PATCH] [FIX] ServicesController: query assessment_responses reale + NonConformityController: getPagination named keys --- .../controllers/NonConformityController.php | 6 ++-- .../controllers/ServicesController.php | 34 ++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/application/controllers/NonConformityController.php b/application/controllers/NonConformityController.php index 085b213..efc59d5 100644 --- a/application/controllers/NonConformityController.php +++ b/application/controllers/NonConformityController.php @@ -60,8 +60,10 @@ class NonConformityController extends BaseController $this->requireOrgAccess(); $orgId = $this->getCurrentOrgId(); - [$page, $perPage] = $this->getPagination(); - $offset = ($page - 1) * $perPage; + $pagination = $this->getPagination(); + $page = $pagination['page']; + $perPage = $pagination['per_page']; + $offset = $pagination['offset']; // Filters $where = 'n.organization_id = ?'; diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 20c8326..9782ea0 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -801,34 +801,30 @@ class ServicesController extends BaseController $recommendations = []; if ($assessment) { - // Calcola score per dominio (10 categorie Art.21) + // Calcola score per dominio — response_value: not_implemented=0, partial=2, implemented=4, not_applicable=null $responses = Database::fetchAll( - 'SELECT ar.*, q.category, q.weight - FROM assessment_responses ar - JOIN ( - SELECT question_code, category, weight - FROM ( - SELECT question_code, - JSON_UNQUOTE(JSON_EXTRACT(question_data, "$.category")) as category, - CAST(JSON_UNQUOTE(JSON_EXTRACT(question_data, "$.weight")) AS DECIMAL(3,1)) as weight - FROM assessment_responses - WHERE assessment_id = ? - ) t GROUP BY question_code - ) q ON q.question_code = ar.question_code - WHERE ar.assessment_id = ?', - [$assessment['id'], $assessment['id']] + 'SELECT question_code, category, response_value + FROM assessment_responses + WHERE assessment_id = ?', + [$assessment['id']] ); - // Semplificato: score per categoria $byCategory = []; foreach ($responses as $r) { $cat = $r['category'] ?? 'uncategorized'; if (!isset($byCategory[$cat])) { $byCategory[$cat] = ['total' => 0, 'count' => 0]; } - $val = (int) ($r['response_value'] ?? 0); - $byCategory[$cat]['total'] += $val; - $byCategory[$cat]['count']++; + $val = match($r['response_value'] ?? 'not_implemented') { + 'implemented' => 4, + 'partial' => 2, + 'not_implemented' => 0, + default => 0, + }; + if ($r['response_value'] !== 'not_applicable') { + $byCategory[$cat]['total'] += $val; + $byCategory[$cat]['count']++; + } } $totalScore = 0;