From 038bd7bd26bb25afde25d787ef27debcd89a5588 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 24 Jul 2026 17:49:14 -0400 Subject: [PATCH] Implement fxImportResultatsEnsureQuestionsVisibleFiche function to activate questions during import for MSIN-4482. Update SQL queries to manage visibility of questions based on event type and ensure correct filtering of pec_id. Adjust logic in fxInscrGestionFetchFicheProfile to accommodate non-online registration scenarios. Increment version code. --- php/inc_fx_import_resultats.php | 34 ++++++++++++ php/inc_fx_inscriptions_gestion.php | 34 ++++++++++-- sql/MSIN-4482-fix-questions-fiche-import.sql | 56 ++++++++++++++++++++ 3 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 sql/MSIN-4482-fix-questions-fiche-import.sql diff --git a/php/inc_fx_import_resultats.php b/php/inc_fx_import_resultats.php index 350f33b..ddeb2e8 100644 --- a/php/inc_fx_import_resultats.php +++ b/php/inc_fx_import_resultats.php @@ -952,9 +952,43 @@ function fxImportResultatsResolveQuestionIds($intEveId, array $tabHeaders, array $tabOut[(string)$intCol] = $intQueId; } } + fxImportResultatsEnsureQuestionsVisibleFiche($intEveId, $tabOut); return $tabOut; } +/** + * MSIN-4482 — la fiche exige que_cart_show=1 ; activer les questions utilisées à l'import + * (matchées OU créées), sans toucher aux autres événements. + */ +function fxImportResultatsEnsureQuestionsVisibleFiche($intEveId, array $tabQueIdsByCol) { + global $objDatabase; + + $intEveId = intval($intEveId); + $tabIds = array(); + foreach ($tabQueIdsByCol as $mixId) { + $intId = intval($mixId); + if ($intId > 0) { + $tabIds[$intId] = true; + } + } + if ($intEveId <= 0 || count($tabIds) < 1) { + return; + } + $strIn = implode(',', array_map('intval', array_keys($tabIds))); + $objDatabase->fxQuery( + "UPDATE inscriptions_questions SET" + . " que_cart_show = 1," + . " que_cart_label_fr = IF(TRIM(IFNULL(que_cart_label_fr, '')) = '', que_question_fr, que_cart_label_fr)," + . " que_cart_label_en = IF(" + . " TRIM(IFNULL(que_cart_label_en, '')) = ''," + . " IF(TRIM(IFNULL(que_question_en, '')) = '', que_question_fr, que_question_en)," + . " que_cart_label_en" + . " )" + . " WHERE eve_id = " . $intEveId + . " AND que_id IN (" . $strIn . ")" + ); +} + function fxImportResultatsSaveQuestionAnswer($intParIdOriginal, $intPecId, $intQueId, $strHeader, $strValue) { global $objDatabase; diff --git a/php/inc_fx_inscriptions_gestion.php b/php/inc_fx_inscriptions_gestion.php index 1538c56..56b4fe1 100644 --- a/php/inc_fx_inscriptions_gestion.php +++ b/php/inc_fx_inscriptions_gestion.php @@ -1254,9 +1254,22 @@ function fxInscrGestionFetchFicheProfile($arrRow, $strLangue) { $intParId = (int)$arrRow['par_id']; $intPecId = (int)$arrRow['pec_id_original']; + $intPecPk = isset($arrRow['pec_id']) ? (int)$arrRow['pec_id'] : 0; $intEveId = (int)$arrRow['eve_id']; $strLangCol = ($strLangue === 'en') ? 'en' : 'fr'; + // MSIN-4482 — type hors inscription en ligne : assouplir filtres fiche (sans toucher au flux payant) + $blnHorsTx = false; + if ($intEveId > 0) { + $tabTe = $objDatabase->fxGetRow( + "SELECT t.te_nom_fr FROM inscriptions_evenements e" + . " INNER JOIN inscriptions_types_evenements t ON t.te_id = e.te_id" + . " WHERE e.eve_id = " . $intEveId . " LIMIT 1" + ); + $blnHorsTx = is_array($tabTe) + && trim((string)($tabTe['te_nom_fr'] ?? '')) === 'Sans inscription en ligne'; + } + // Le titre "Capitaine" n'a de sens qu'en epreuve d'equipe : meme condition que le champ "Type" // de la fiche (cf. fxInscrGestionRenderFiche). En individuel, on ne l'affiche pas, meme si rol_id=1. $blnEquipe = (intval($arrRow['pec_equipe']) === 1) @@ -1290,17 +1303,32 @@ function fxInscrGestionFetchFicheProfile($arrRow, $strLangue) { } $intParIdOriginal = (int)$tabProfile['par_id_original']; + + // MSIN-4482 hors tx : réponses souvent sur e.pec_id (PK) alors que la fiche filtre pec_id_original ; + // que_cart_show / que_actif parfois absents sur l'import initial. + $strPecFilter = 'rq.pec_id = ' . $intPecId; + if ($blnHorsTx && $intPecPk > 0 && $intPecPk !== $intPecId) { + $strPecFilter = '(rq.pec_id = ' . $intPecId . ' OR rq.pec_id = ' . $intPecPk . ')'; + } elseif ($blnHorsTx) { + $strPecFilter = '(rq.pec_id = ' . $intPecId + . ($intPecPk > 0 ? (' OR rq.pec_id = ' . $intPecPk) : '') + . ')'; + } + + $strCartFilter = $blnHorsTx ? '1=1' : 'iq.que_cart_show = 1'; + $strActifFilter = $blnHorsTx ? 'IFNULL(rq.que_actif, 1) = 1' : 'rq.que_actif = 1'; + $sqlQuestions = 'SELECT rq.que_choix_' . $strLangCol . ' AS que_choix,' . ' iq.que_cart_label_' . $strLangCol . ' AS que_label,' . ' rq.que_question_' . $strLangCol . ' AS que_question,' . ' iq.que_tri, iq.que_id' . ' FROM resultats_questions rq' . ' INNER JOIN inscriptions_questions iq ON iq.que_id = rq.que_id' - . ' WHERE iq.que_cart_show = 1' + . ' WHERE ' . $strCartFilter . ' AND iq.eve_id = ' . $intEveId - . ' AND rq.pec_id = ' . $intPecId + . ' AND ' . $strPecFilter . ' AND (rq.par_id = ' . $intParId . ' OR rq.par_id = ' . $intParIdOriginal . ')' - . ' AND rq.que_actif = 1' + . ' AND ' . $strActifFilter . " AND TRIM(COALESCE(rq.que_choix_" . $strLangCol . ", '')) <> ''" . ' ORDER BY iq.que_tri, iq.que_id'; diff --git a/sql/MSIN-4482-fix-questions-fiche-import.sql b/sql/MSIN-4482-fix-questions-fiche-import.sql new file mode 100644 index 0000000..7c624a1 --- /dev/null +++ b/sql/MSIN-4482-fix-questions-fiche-import.sql @@ -0,0 +1,56 @@ +-- MSIN-4482 — Réparer questions import pour affichage fiche (eve hors inscription en ligne) +-- Contexte : réponses en BD mais fiche vide (pec_id / que_actif / que_cart_show) +-- Notes : exécution UNIQUEMENT sur dev préprod ; autres env = Navicat structure + sync_static_db +-- Cible : eve_id 1284 + par_origine = import_fichier seulement (ne touche pas au payant) + +SET @eve := 1284; + +-- Diagnostic : combien de réponses import vs ce que la fiche classique verrait +SELECT COUNT(*) AS n_reponses_via_par +FROM resultats_questions rq +INNER JOIN resultats_participants p + ON (rq.par_id = p.par_id OR rq.par_id = p.par_id_original) +WHERE p.eve_id = @eve AND p.par_origine = 'import_fichier'; + +-- 1) Aligner rq.pec_id sur e.pec_id_original (clé utilisée par la fiche) +UPDATE resultats_questions rq +INNER JOIN resultats_participants p + ON p.eve_id = @eve + AND p.par_origine = 'import_fichier' + AND (rq.par_id = p.par_id OR rq.par_id = p.par_id_original) +INNER JOIN resultats_epreuves_commandees e + ON e.eve_id = @eve + AND (e.pec_id_original = p.pec_id OR e.pec_id = p.pec_id OR e.pec_id = rq.pec_id) +SET rq.pec_id = e.pec_id_original +WHERE e.pec_id_original > 0 + AND rq.pec_id <> e.pec_id_original; + +-- 2) Activer les réponses import +UPDATE resultats_questions rq +INNER JOIN resultats_participants p + ON p.eve_id = @eve + AND p.par_origine = 'import_fichier' + AND (rq.par_id = p.par_id OR rq.par_id = p.par_id_original) +SET rq.que_actif = 1 +WHERE IFNULL(rq.que_actif, 0) <> 1; + +-- 3) Afficher en fiche (que_cart_show) les questions du catalogue liées à cet import +UPDATE inscriptions_questions iq +INNER JOIN resultats_questions rq ON rq.que_id = iq.que_id +INNER JOIN resultats_participants p + ON p.eve_id = @eve + AND p.par_origine = 'import_fichier' + AND (rq.par_id = p.par_id OR rq.par_id = p.par_id_original) +SET iq.que_cart_show = 1, + iq.que_cart_label_fr = IF( + TRIM(IFNULL(iq.que_cart_label_fr, '')) = '', + iq.que_question_fr, + iq.que_cart_label_fr + ), + iq.que_cart_label_en = IF( + TRIM(IFNULL(iq.que_cart_label_en, '')) = '', + IF(TRIM(IFNULL(iq.que_question_en, '')) = '', iq.que_question_fr, iq.que_question_en), + iq.que_cart_label_en + ) +WHERE iq.eve_id = @eve + AND IFNULL(iq.que_cart_show, 0) <> 1;