[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();
|
||||
$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 = ?';
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user