[FIX] ServicesController: query assessment_responses reale + NonConformityController: getPagination named keys
This commit is contained in:
parent
159d783ed7
commit
8578cb5c31
@ -60,8 +60,10 @@ class NonConformityController extends BaseController
|
|||||||
$this->requireOrgAccess();
|
$this->requireOrgAccess();
|
||||||
$orgId = $this->getCurrentOrgId();
|
$orgId = $this->getCurrentOrgId();
|
||||||
|
|
||||||
[$page, $perPage] = $this->getPagination();
|
$pagination = $this->getPagination();
|
||||||
$offset = ($page - 1) * $perPage;
|
$page = $pagination['page'];
|
||||||
|
$perPage = $pagination['per_page'];
|
||||||
|
$offset = $pagination['offset'];
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
$where = 'n.organization_id = ?';
|
$where = 'n.organization_id = ?';
|
||||||
|
|||||||
@ -801,34 +801,30 @@ class ServicesController extends BaseController
|
|||||||
$recommendations = [];
|
$recommendations = [];
|
||||||
|
|
||||||
if ($assessment) {
|
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(
|
$responses = Database::fetchAll(
|
||||||
'SELECT ar.*, q.category, q.weight
|
'SELECT question_code, category, response_value
|
||||||
FROM assessment_responses ar
|
FROM assessment_responses
|
||||||
JOIN (
|
WHERE assessment_id = ?',
|
||||||
SELECT question_code, category, weight
|
[$assessment['id']]
|
||||||
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']]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Semplificato: score per categoria
|
|
||||||
$byCategory = [];
|
$byCategory = [];
|
||||||
foreach ($responses as $r) {
|
foreach ($responses as $r) {
|
||||||
$cat = $r['category'] ?? 'uncategorized';
|
$cat = $r['category'] ?? 'uncategorized';
|
||||||
if (!isset($byCategory[$cat])) {
|
if (!isset($byCategory[$cat])) {
|
||||||
$byCategory[$cat] = ['total' => 0, 'count' => 0];
|
$byCategory[$cat] = ['total' => 0, 'count' => 0];
|
||||||
}
|
}
|
||||||
$val = (int) ($r['response_value'] ?? 0);
|
$val = match($r['response_value'] ?? 'not_implemented') {
|
||||||
$byCategory[$cat]['total'] += $val;
|
'implemented' => 4,
|
||||||
$byCategory[$cat]['count']++;
|
'partial' => 2,
|
||||||
|
'not_implemented' => 0,
|
||||||
|
default => 0,
|
||||||
|
};
|
||||||
|
if ($r['response_value'] !== 'not_applicable') {
|
||||||
|
$byCategory[$cat]['total'] += $val;
|
||||||
|
$byCategory[$cat]['count']++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$totalScore = 0;
|
$totalScore = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user