From 1b7cb2ee20948b0fcf5ceed1beeb779789b76b3c Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 3 Aug 2026 15:55:18 -0400 Subject: [PATCH] =?UTF-8?q?MSIN-4554=20=E2=80=94=20Enhance=20team-related?= =?UTF-8?q?=20question=20handling=20in=20distribution=20print=20functions.?= =?UTF-8?q?=20Implement=20logic=20to=20ensure=20team=20names=20are=20corre?= =?UTF-8?q?ctly=20retrieved=20and=20displayed=20based=20on=20participant?= =?UTF-8?q?=20roles.=20Increment=20version=20code=20to=204.72.955=20to=20r?= =?UTF-8?q?eflect=20these=20changes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/inc_fx_bib_dist_print.php | 11 ++++ php/inc_fx_promoteur.php | 120 ++++++++++++++++++++++++++++++++++ php/inc_settings.php | 2 +- 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/php/inc_fx_bib_dist_print.php b/php/inc_fx_bib_dist_print.php index 7779b36..bc23bbd 100644 --- a/php/inc_fx_bib_dist_print.php +++ b/php/inc_fx_bib_dist_print.php @@ -312,6 +312,7 @@ function fxBibSaveDistPrintOrient($int_eve_id, $strOrient) { /** * MSIN-4512 — Valeur cellule PDF pour une clé optionnelle. + * MSIN-4554 — nom_equipe : pec (comme assignation) ; que: déjà enrichies en équipe via fxBibGetDistPrintQuestionAnswers. */ function fxBibDistPrintResolveColValue($strKey, array $row, array $tabAnswersByQue, $strLangue = 'fr') { $strKey = trim((string)$strKey); @@ -328,7 +329,17 @@ function fxBibDistPrintResolveColValue($strKey, array $row, array $tabAnswersByQ if ($strKey === 'par_sexe') { return fxBibDistPrintSexeLabel($row['par_sexe'] ?? '', $strLangue); } + // MSIN-4554 — Champ cœur : même priorité que l'écran d'assignation. + if ($strKey === 'nom_equipe') { + $strPec = trim((string)($row['pec_nom_equipe'] ?? '')); + if ($strPec !== '') { + return $strPec; + } + return trim((string)($row['par_nom_equipe'] ?? '')); + } if (preg_match('/^que:(\d+)$/', $strKey, $m)) { + // MSIN-4554 — Sur épreuve équipe les réponses (dont nom d'équipe) sont + // déjà enrichies dans fxBibGetDistPrintQuestionAnswers. return trim((string)($tabAnswersByQue[(int)$m[1]] ?? '')); } diff --git a/php/inc_fx_promoteur.php b/php/inc_fx_promoteur.php index 45d8ad5..51b9c6e 100644 --- a/php/inc_fx_promoteur.php +++ b/php/inc_fx_promoteur.php @@ -10717,9 +10717,37 @@ function fxBibDistPrintAnswerKey(array $row) { return $intParLookup . ':' . $intPecId; } +/** + * MSIN-4554 — Libellé = question « Nom d'équipe » (formulaire) ? + */ +function fxBibDistPrintIsTeamNameQuestionLabel($strLabel) { + $str = function_exists('mb_strtolower') + ? mb_strtolower(trim((string)$strLabel), 'UTF-8') + : strtolower(trim((string)$strLabel)); + if ($str === '') { + return false; + } + if (preg_match('/\bteam\s*name\b/u', $str)) { + return true; + } + if (preg_match('/^(équipe|equipe|team)$/u', $str)) { + return true; + } + // « Nom d'équipe », « Nom de l'équipe », « Nom de votre équipe », etc. + if (preg_match('/nom/u', $str) && preg_match('/équip/u', $str)) { + return true; + } + if (preg_match('/nom/u', $str) && preg_match('/\bequipe\b/u', $str)) { + return true; + } + return false; +} + /** * MSIN-4433 — Réponses questions pour une liste de participants. * resultats_questions.par_id = resultats_participants.par_id_original (legacy MS1). + * MSIN-4554 — Épreuve équipe : (1) réponses vides = celles du capitaine même pec_id ; + * (2) questions « Nom d'équipe » = pec_nom_equipe (même source que l'assignation). * @return array> clé "par_lookup:pec_id" => [que_id => réponse] */ function fxBibGetDistPrintQuestionAnswers($epr_id, array $tabQueIds, array $tabParticipants, $strLangue = 'fr') { @@ -10774,6 +10802,98 @@ function fxBibGetDistPrintQuestionAnswers($epr_id, array $tabQueIds, array $tabP $out[$strKey][$intQueId] = trim((string)($row['ans'] ?? '')); } + // MSIN-4554 — Règle épreuve en équipe seulement. + $tabEprMeta = $objDatabase->fxGetRow( + "SELECT epr_equipe FROM inscriptions_epreuves WHERE epr_id = $epr_id LIMIT 1" + ); + if (!is_array($tabEprMeta) || (int)($tabEprMeta['epr_equipe'] ?? 0) !== 1) { + return $out; + } + + // Index participants : clé réponse + pec + rôle + nom équipe commande. + $tabByAnsKey = []; + $tabCaptainAnsKeyByPec = []; + foreach ($tabParticipants as $row) { + if (!is_array($row)) { + continue; + } + $strKey = fxBibDistPrintAnswerKey($row); + $intPec = (int)($row['pec_id'] ?? 0); + $tabByAnsKey[$strKey] = $row; + if ($intPec > 0 && (int)($row['rol_id'] ?? 0) === 1 && !isset($tabCaptainAnsKeyByPec[$intPec])) { + $tabCaptainAnsKeyByPec[$intPec] = $strKey; + } + } + + // (1) Coéquipier sans réponse → réponse du capitaine (même commande). + foreach ($tabByAnsKey as $strKey => $row) { + $intPec = (int)($row['pec_id'] ?? 0); + if ($intPec <= 0 || !isset($tabCaptainAnsKeyByPec[$intPec])) { + continue; + } + $strCapKey = $tabCaptainAnsKeyByPec[$intPec]; + if ($strCapKey === $strKey) { + continue; + } + $tabCapAns = $out[$strCapKey] ?? []; + if (!is_array($tabCapAns) || empty($tabCapAns)) { + continue; + } + if (!isset($out[$strKey]) || !is_array($out[$strKey])) { + $out[$strKey] = []; + } + foreach ($tabQueIds as $intQueId) { + $strMine = trim((string)($out[$strKey][$intQueId] ?? '')); + if ($strMine !== '') { + continue; + } + $strCap = trim((string)($tabCapAns[$intQueId] ?? '')); + if ($strCap !== '') { + $out[$strKey][$intQueId] = $strCap; + } + } + } + + // (2) Questions « Nom d'équipe » → toujours pec_nom_equipe (comme l'assignation). + $strColQ = ($strLangue === 'en') ? 'que_question_en' : 'que_question_fr'; + $strColCart = ($strLangue === 'en') ? 'que_cart_label_en' : 'que_cart_label_fr'; + $tabQueLabels = $objDatabase->fxGetResults( + "SELECT que_id, + COALESCE( + NULLIF(TRIM($strColCart), ''), + NULLIF(TRIM($strColQ), ''), + CONCAT('Question #', que_id) + ) AS que_label + FROM inscriptions_questions + WHERE que_id IN ($strQueIds)" + ); + $tabTeamNameQueIds = []; + if (is_array($tabQueLabels)) { + foreach ($tabQueLabels as $tabQueRow) { + $intQueId = (int)($tabQueRow['que_id'] ?? 0); + if ($intQueId > 0 && fxBibDistPrintIsTeamNameQuestionLabel($tabQueRow['que_label'] ?? '')) { + $tabTeamNameQueIds[] = $intQueId; + } + } + } + if (!empty($tabTeamNameQueIds)) { + foreach ($tabByAnsKey as $strKey => $row) { + $strPecNom = trim((string)($row['pec_nom_equipe'] ?? '')); + if ($strPecNom === '') { + $strPecNom = trim((string)($row['par_nom_equipe'] ?? '')); + } + if ($strPecNom === '') { + continue; + } + if (!isset($out[$strKey]) || !is_array($out[$strKey])) { + $out[$strKey] = []; + } + foreach ($tabTeamNameQueIds as $intQueId) { + $out[$strKey][$intQueId] = $strPecNom; + } + } + } + return $out; } diff --git a/php/inc_settings.php b/php/inc_settings.php index a991fa0..91f0b64 100644 --- a/php/inc_settings.php +++ b/php/inc_settings.php @@ -7,7 +7,7 @@ * Constantes * * **************/ -define('_VERSION_CODE', '4.72.954'); // MSIN-4553 — nom + plaque dans barre titre Détails (replié) +define('_VERSION_CODE', '4.72.955'); // MSIN-4554 — liste dist. : nom d'équipe = assignation (épreuve équipe) define('_DATE_CODE', '2026-08-03'); //MSIN-4290 define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');