added completion count to export page
This commit is contained in:
@ -7,18 +7,31 @@ switch ($method) {
|
|||||||
case 'GET':
|
case 'GET':
|
||||||
[$pdo, $tmpDb, $lockFp] = qdb_open(false);
|
[$pdo, $tmpDb, $lockFp] = qdb_open(false);
|
||||||
try {
|
try {
|
||||||
$rows = $pdo->query("
|
[$rbacClause, $rbacParams] = rbac_client_filter($tokenRec, 'cl');
|
||||||
|
$sql = "
|
||||||
SELECT q.questionnaireID, q.name, q.version, q.state,
|
SELECT q.questionnaireID, q.name, q.version, q.state,
|
||||||
q.orderIndex, q.showPoints, q.conditionJson, q.categoryKey,
|
q.orderIndex, q.showPoints, q.conditionJson, q.categoryKey,
|
||||||
COUNT(qu.questionID) AS questionCount
|
COUNT(qu.questionID) AS questionCount,
|
||||||
|
(
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM completed_questionnaire cq
|
||||||
|
INNER JOIN client cl ON cl.clientCode = cq.clientCode
|
||||||
|
WHERE cq.questionnaireID = q.questionnaireID
|
||||||
|
AND $rbacClause
|
||||||
|
) AS completedCount
|
||||||
FROM questionnaire q
|
FROM questionnaire q
|
||||||
LEFT JOIN question qu ON qu.questionnaireID = q.questionnaireID
|
LEFT JOIN question qu ON qu.questionnaireID = q.questionnaireID
|
||||||
GROUP BY q.questionnaireID
|
GROUP BY q.questionnaireID
|
||||||
ORDER BY q.orderIndex, q.name
|
ORDER BY q.orderIndex, q.name
|
||||||
")->fetchAll(PDO::FETCH_ASSOC);
|
";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute($rbacParams);
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
foreach ($rows as &$r) {
|
foreach ($rows as &$r) {
|
||||||
$r['orderIndex'] = (int)$r['orderIndex'];
|
$r['orderIndex'] = (int)$r['orderIndex'];
|
||||||
$r['showPoints'] = (int)$r['showPoints'];
|
$r['showPoints'] = (int)$r['showPoints'];
|
||||||
|
$r['questionCount'] = (int)$r['questionCount'];
|
||||||
|
$r['completedCount'] = (int)$r['completedCount'];
|
||||||
$r['conditionJson'] = $r['conditionJson'] ?: '{}';
|
$r['conditionJson'] = $r['conditionJson'] ?: '{}';
|
||||||
}
|
}
|
||||||
unset($r);
|
unset($r);
|
||||||
|
|||||||
@ -56,6 +56,7 @@ function renderExport(questionnaires) {
|
|||||||
<th>Version</th>
|
<th>Version</th>
|
||||||
<th>State</th>
|
<th>State</th>
|
||||||
<th>Questions</th>
|
<th>Questions</th>
|
||||||
|
<th>Completed</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -66,6 +67,7 @@ function renderExport(questionnaires) {
|
|||||||
<td>${esc(q.version || '—')}</td>
|
<td>${esc(q.version || '—')}</td>
|
||||||
<td><span class="badge badge-${(q.state || 'draft').toLowerCase()}">${esc(q.state || 'draft')}</span></td>
|
<td><span class="badge badge-${(q.state || 'draft').toLowerCase()}">${esc(q.state || 'draft')}</span></td>
|
||||||
<td>${q.questionCount || 0}</td>
|
<td>${q.questionCount || 0}</td>
|
||||||
|
<td>${q.completedCount ?? 0}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-sm btn-primary export-btn" data-id="${q.questionnaireID}" data-name="${esc(q.name)}" data-version="${esc(q.version)}">
|
<button class="btn btn-sm btn-primary export-btn" data-id="${q.questionnaireID}" data-name="${esc(q.name)}" data-version="${esc(q.version)}">
|
||||||
Export CSV
|
Export CSV
|
||||||
|
|||||||
Reference in New Issue
Block a user