From 9ea4dd2ecfb1a6d5748cf4ee54a274d4b545d423 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 3 Jul 2026 09:14:47 -0400 Subject: [PATCH] Refactor ChronoTrack API event handling and synchronization logic This commit updates the ChronoTrack API to improve event handling and synchronization features. Changes include enhanced messaging for closed events, adjustments to the push panel functionality, and refined status handling for event synchronization. The logic for managing event states is streamlined, allowing for clearer user interactions and better management of synchronization processes. These improvements aim to enhance the overall usability and effectiveness of the ChronoTrack API in event management. --- php/chronotrack_api/fx_chronotrack_admin.php | 35 +++++++++++++------ php/chronotrack_api/fx_chronotrack_config.php | 7 +++- php/chronotrack_api/fx_chronotrack_sync.php | 4 +-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/php/chronotrack_api/fx_chronotrack_admin.php b/php/chronotrack_api/fx_chronotrack_admin.php index 049ef5d..4fe1ca4 100644 --- a/php/chronotrack_api/fx_chronotrack_admin.php +++ b/php/chronotrack_api/fx_chronotrack_admin.php @@ -65,7 +65,8 @@ function fxChronotrackApiAdminRenderEventPage($intEveId, $strLangue = 'fr', $bln } if ($blnClosed) { - echo '
Cet événement est fermé. Aucune modification ni sync automatique.
'; + echo '
Statut fermé : plus de sync auto ni modification du lien/mapping. '; + echo 'Le push manuel reste disponible ci-dessous.
'; } $blnEventLinked = ($arrConfig !== null && intval($arrConfig['ct_event_id'] ?? 0) > 0); @@ -73,7 +74,7 @@ function fxChronotrackApiAdminRenderEventPage($intEveId, $strLangue = 'fr', $bln fxChronotrackApiAdminRenderEventLinkPicker($blnClosed); } - if ($arrConfig !== null && !$blnClosed) { + if ($arrConfig !== null) { fxChronotrackApiAdminRenderStatusActions($intEveId, $strStatus, $blnEventLinked); } @@ -81,8 +82,8 @@ function fxChronotrackApiAdminRenderEventPage($intEveId, $strLangue = 'fr', $bln fxChronotrackApiAdminRenderRaceMapping($intEveId, $arrConfig, $strLangue, $blnClosed, $blnEventLinked); } - if ($arrConfig !== null && $blnEventLinked && $blnConfigured && !$blnClosed) { - fxChronotrackApiAdminRenderPushPanel($intEveId); + if ($arrConfig !== null && $blnEventLinked && $blnConfigured) { + fxChronotrackApiAdminRenderPushPanel($intEveId, $blnClosed); } if ($blnEventLinked && $blnConfigured) { @@ -101,7 +102,7 @@ function fxChronotrackApiAdminRenderEventPage($intEveId, $strLangue = 'fr', $bln function fxChronotrackApiAdminRenderStatusActions($intEveId, $strStatus, $blnEventLinked = true) { $strStep = $blnEventLinked ? '1' : '2'; echo '
' . $strStep . '. Cycle de vie sync
'; - echo '

Activer avant la course ; Terminer après la course pour bloquer tout envoi vers ChronoTrack.

'; + echo '

Activer avant la course ; Terminer après la course pour bloquer la sync auto et les changements de config.

'; echo '
'; if ($strStatus === MSIN_API_CHRONOTRACK_SYNC_LIE) { echo ''; @@ -110,6 +111,10 @@ function fxChronotrackApiAdminRenderStatusActions($intEveId, $strStatus, $blnEve echo 'Sync active'; echo ''; } + if ($strStatus === MSIN_API_CHRONOTRACK_SYNC_FERME) { + echo 'Fermé'; + echo ''; + } echo '
'; } @@ -194,10 +199,13 @@ function fxChronotrackApiAdminRenderRaceMapping($intEveId, $arrConfig, $strLangu echo ''; } -function fxChronotrackApiAdminRenderPushPanel($intEveId) { +function fxChronotrackApiAdminRenderPushPanel($intEveId, $blnClosed = false) { echo '
'; echo '
3. Synchronisation manuelle (participants)
'; echo '
'; + if ($blnClosed) { + echo '
Événement fermé — push manuel autorisé pour tests ou rattrapage.
'; + } echo '

Lit resultats_participants (comme le rapport chrono). '; echo 'External ID = par_id_original. POST vers ChronoTrack — aucune modification MS1.

'; echo '
Chargement…
'; @@ -322,9 +330,14 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed $('.ct-api-set-status').on('click', function () { var strStatus = $(this).data('status'); - var strConfirm = (strStatus === 'ferme') - ? 'Terminer la course ? Aucun changement ne sera plus envoyé à ChronoTrack.' - : 'Activer la synchronisation automatique pour cet événement ?'; + var strConfirm; + if (strStatus === 'ferme') { + strConfirm = 'Terminer la course ? La sync auto et les changements de config seront bloqués (push manuel toujours possible).'; + } else if (strStatus === 'lie') { + strConfirm = 'Rouvrir cet événement ChronoTrack (statut Lié) ?'; + } else { + strConfirm = 'Activer la synchronisation automatique pour cet événement ?'; + } if (!window.confirm(strConfirm)) { return; } @@ -584,7 +597,7 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed function loadPushPreview() { var $sum = $('#ct_api_push_summary'); - if (!$sum.length || blnClosed) { + if (!$sum.length) { return; } $sum.html('Calcul du diff MS1 ↔ ChronoTrack…'); @@ -595,7 +608,7 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed }); } - if ($('#ct_api_push_card').length && !blnClosed) { + if ($('#ct_api_push_card').length) { loadPushPreview(); $('#ct_api_btn_push_refresh').on('click', function () { diff --git a/php/chronotrack_api/fx_chronotrack_config.php b/php/chronotrack_api/fx_chronotrack_config.php index 3dbf336..1a3cc8a 100644 --- a/php/chronotrack_api/fx_chronotrack_config.php +++ b/php/chronotrack_api/fx_chronotrack_config.php @@ -85,7 +85,9 @@ function fxChronotrackApiConfigSetStatus($intEveId, $strStatus, $intUsaId) { } if ($arrExisting['sync_status'] === MSIN_API_CHRONOTRACK_SYNC_FERME) { - return array('state' => 'error', 'message' => 'Événement déjà fermé'); + if ($strStatus !== MSIN_API_CHRONOTRACK_SYNC_LIE) { + return array('state' => 'error', 'message' => 'Événement fermé — seule la réouverture (Lié) est permise.'); + } } $strStatus = trim($strStatus); @@ -100,6 +102,9 @@ function fxChronotrackApiConfigSetStatus($intEveId, $strStatus, $intUsaId) { if ($strStatus === MSIN_API_CHRONOTRACK_SYNC_FERME) { $strExtra = ", closed_at = '" . fxGetDateTime() . "', closed_by_usa_id = " . intval($intUsaId); } + if ($strStatus === MSIN_API_CHRONOTRACK_SYNC_LIE && $arrExisting['sync_status'] === MSIN_API_CHRONOTRACK_SYNC_FERME) { + $strExtra = ", closed_at = NULL, closed_by_usa_id = NULL"; + } $sql = "UPDATE api_chronotrack_config SET sync_status = '" . $objDatabase->fxEscape($strStatus) . "'" . $strExtra diff --git a/php/chronotrack_api/fx_chronotrack_sync.php b/php/chronotrack_api/fx_chronotrack_sync.php index 1ede1b3..44a1788 100644 --- a/php/chronotrack_api/fx_chronotrack_sync.php +++ b/php/chronotrack_api/fx_chronotrack_sync.php @@ -256,9 +256,7 @@ function fxChronotrackApiSyncBuildPreview($intEveId) { if ($arrConfig === null) { return array('state' => 'error', 'message' => 'Événement non lié à ChronoTrack'); } - if ($arrConfig['sync_status'] === MSIN_API_CHRONOTRACK_SYNC_FERME) { - return array('state' => 'error', 'message' => 'Sync fermée pour cet événement'); - } + if (!fxChronotrackApiSettingsConfigured()) { return array('state' => 'error', 'message' => fxChronotrackApiSettingsErrorMessage()); }