Enhance participant data handling in PDF distribution and update version code to 4.72.761

This commit adds the original participant ID to the selection for better data integrity and introduces a new function to generate a key for mapping participant responses. The SQL queries are updated to reflect these changes, ensuring compatibility with legacy data structures. Additionally, the version code is incremented to 4.72.761 to reflect these updates.
This commit is contained in:
2026-07-08 12:07:54 -04:00
parent 21b28a0d06
commit 23ca040ac0
2 changed files with 35 additions and 17 deletions

View File

@ -8081,6 +8081,7 @@ function fxBibGetParticipantsForDistPrint($epr_id, $sort1, $sort2 = '', $strLang
$sql = "
SELECT
p.par_id,
p.par_id_original,
p.pec_id,
p.no_bib,
p.par_nom,
@ -8116,9 +8117,20 @@ function fxBibGetParticipantsForDistPrint($epr_id, $sort1, $sort2 = '', $strLang
return $tabOut;
}
/** MSIN-4433 — Clé de correspondance participant ↔ réponse question. */
function fxBibDistPrintAnswerKey(array $row) {
$intPecId = (int)($row['pec_id'] ?? 0);
$intParLookup = (int)($row['par_id_original'] ?? 0);
if ($intParLookup <= 0) {
$intParLookup = (int)($row['par_id'] ?? 0);
}
return $intParLookup . ':' . $intPecId;
}
/**
* MSIN-4433 — Réponses questions pour une liste de participants.
* @return array<string, array<int, string>> clé "par_id:pec_id" => [que_id => réponse]
* resultats_questions.par_id = resultats_participants.par_id_original (legacy MS1).
* @return array<string, array<int, string>> clé "par_lookup:pec_id" => [que_id => réponse]
*/
function fxBibGetDistPrintQuestionAnswers($epr_id, array $tabQueIds, array $tabParticipants, $strLangue = 'fr') {
global $objDatabase;
@ -8146,11 +8158,19 @@ function fxBibGetDistPrintQuestionAnswers($epr_id, array $tabQueIds, array $tabP
$strParIds = implode(',', $tabParIds);
$sql = "
SELECT par_id, pec_id, que_id, TRIM($strCol) AS ans
FROM resultats_questions
WHERE que_actif = 1
AND que_id IN ($strQueIds)
AND par_id IN ($strParIds)
SELECT
p.par_id,
p.par_id_original,
p.pec_id,
rq.que_id,
TRIM(COALESCE(NULLIF(rq.$strCol, ''), NULLIF(rq.pqu_note, ''), NULLIF(rq.que_choix_fr, ''))) AS ans
FROM resultats_participants p
INNER JOIN resultats_questions rq
ON rq.pec_id = p.pec_id
AND rq.par_id = IF(p.par_id_original > 0, p.par_id_original, p.par_id)
WHERE p.epr_id = $epr_id
AND p.par_id IN ($strParIds)
AND rq.que_id IN ($strQueIds)
";
$rows = $objDatabase->fxGetResults($sql);
if (!is_array($rows)) {
@ -8159,7 +8179,7 @@ function fxBibGetDistPrintQuestionAnswers($epr_id, array $tabQueIds, array $tabP
$out = [];
foreach ($rows as $row) {
$strKey = (int)($row['par_id'] ?? 0) . ':' . (int)($row['pec_id'] ?? 0);
$strKey = fxBibDistPrintAnswerKey($row);
$intQueId = (int)($row['que_id'] ?? 0);
$out[$strKey][$intQueId] = trim((string)($row['ans'] ?? ''));
}
@ -8260,6 +8280,12 @@ function fxBibOutputDistPrintPdf($int_eve_id, $strLangue = 'fr', $strPrintedBy =
}
list($strSort1, $strSort2) = fxBibGetEpreuveDefaultSortKeys($tabEprRow);
$tabParticipants = fxBibGetParticipantsForDistPrint($epr_id, $strSort1, $strSort2, $strLangue);
// MSIN-4433 — Épreuve sans dossard assigné : ne pas imprimer la section.
if (empty($tabParticipants)) {
continue;
}
$tabSelectedQue = $tabEpr['selected'] ?? [];
$tabQueCols = [];
foreach ($tabEpr['questions'] as $opt) {
@ -8282,14 +8308,6 @@ function fxBibOutputDistPrintPdf($int_eve_id, $strLangue = 'fr', $strPrintedBy =
$pdf->Cell(0, 7, utf8_decode(fxBibDistPrintTruncate($tabEpr['epr_label'] ?? '', 90)), 0, 1, 'L');
$pdf->Ln(1);
$tabParticipants = fxBibGetParticipantsForDistPrint($epr_id, $strSort1, $strSort2, $strLangue);
if (empty($tabParticipants)) {
$pdf->SetFont('Arial', 'I', 9);
$pdf->Cell(0, 5, utf8_decode(fxBibTexte('bib_v4_dist_print_empty_epr', 0)), 0, 1, 'L');
$pdf->Ln(3);
continue;
}
$tabAnswers = fxBibGetDistPrintQuestionAnswers($epr_id, $tabSelectedQue, $tabParticipants, $strLangue);
$pdf->SetFont('Arial', 'B', 8);
@ -8308,7 +8326,7 @@ function fxBibOutputDistPrintPdf($int_eve_id, $strLangue = 'fr', $strPrintedBy =
$pdf->SetFont('Arial', '', 8);
foreach ($tabParticipants as $row) {
$strKey = (int)($row['par_id'] ?? 0) . ':' . (int)($row['pec_id'] ?? 0);
$strKey = fxBibDistPrintAnswerKey($row);
$pdf->Cell(18, 5, utf8_decode((string)(int)($row['no_bib'] ?? 0)), 1, 0, 'C');
$pdf->Cell(42, 5, utf8_decode(fxBibDistPrintTruncate($row['par_nom'] ?? '', 24)), 1, 0, 'L');
$pdf->Cell(42, 5, utf8_decode(fxBibDistPrintTruncate($row['par_prenom'] ?? '', 24)), 1, 0, 'L');

View File

@ -7,7 +7,7 @@
* Constantes *
*
**************/
define('_VERSION_CODE', '4.72.759');
define('_VERSION_CODE', '4.72.761');
define('_DATE_CODE', '2026-07-08');
//MSIN-4290
define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');