diff --git a/includes/statistics-page.php b/includes/statistics-page.php new file mode 100644 index 0000000..b7a5bff --- /dev/null +++ b/includes/statistics-page.php @@ -0,0 +1,156 @@ +SetCreator(PDF_CREATOR); + $pdf->SetAuthor('Your Name'); + $pdf->SetTitle('Title'); + $pdf->SetSubject('Subject'); + $pdf->SetKeywords('Keywords'); + + // Définir l'en-tête et le pied de page + $pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, 'Title', 'Header text'); + $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128)); + + // Définir la police + $pdf->SetFont('helvetica', '', 12); + + // Ajouter une page + $pdf->AddPage(); + + // Écrire le contenu HTML dans le PDF + $pdf->writeHTML($html_content, true, false, true, false, ''); + + + // Sortie PDF + $pdf->Output($filename, 'I'); + // $pdf->Output('report.pdf', 'F',); +} +// ###### EXPORT IN CSV + +add_action('admin_post_export_csv', 'handle_export_csv_request'); +add_action('admin_post_nopriv_export_csv', 'handle_export_csv_request'); + +function handle_export_csv_request() +{ + // Vérifier les autorisations ou les conditions nécessaires + if (!current_user_can('manage_options')) { + wp_die('Access Denied'); + } + + // Appeler la fonction pour exporter les données vers CSV + export_data_to_csv(); +} + + +function export_data_to_csv() +{ + global $wpdb; + $table_name = "wp_app_users_statistics"; + + // Récupérer les données de la base de données + $data = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A); + + // Vérifier s'il y a des données à exporter + if ($data) { + // Nom du fichier CSV + $filename = 'export.csv'; + + // Entête du fichier CSV + $header_row = array_keys($data[0]); + + // Ouvrir le fichier en écriture + $file = fopen($filename, 'w'); + + // Écrire l'entête dans le fichier CSV + fputcsv($file, $header_row); + + // Écrire les données dans le fichier CSV + foreach ($data as $row) { + fputcsv($file, $row); + } + + // Fermer le fichier + fclose($file); + + // Télécharger le fichier CSV + header("Content-Disposition: attachment; filename=\"$filename\""); + header("Content-Type: application/csv"); + readfile($filename); + + // Supprimer le fichier après téléchargement + unlink($filename); + + exit(); + } else { + // Aucune donnée à exporter + echo 'Aucune donnée à exporter.'; + } +} diff --git a/resources/css/pages/stats-dashboard.css b/resources/css/pages/stats-dashboard.css index 0935f6b..32e79cc 100644 --- a/resources/css/pages/stats-dashboard.css +++ b/resources/css/pages/stats-dashboard.css @@ -1,5 +1,3 @@ -@import '../components/circle.css'; - .dashboard-widget { @apply pb-12; &__title { @@ -28,9 +26,35 @@ .page-sessions-datas { .game_stats { @apply bg-white my-12 !px-16 !py-6; + box-sizing: border-box; - .stats-container { - @apply grid grid-cols-2 gap-16 overflow-hidden; + + .page-title { + @apply text-5xl font-semibold text-neutral-800 pb-16; + } + &__stats-container { + @apply grid md:grid-cols-2 gap-16 overflow-hidden; + } + &__game-title { + @apply text-3xl font-semibold text-neutral-800 mt-0; + } + &__statistics-section { + p, + li { + @apply text-lg text-slate-600; + } + h3 { + @apply text-blue-600 uppercase font-bold text-base my-0 tracking-widest mb-4; + } + h4 { + @apply font-normal text-lg font-medium text-slate-400 my-0; + } + } + + &__scores-distribution { + ul { + @apply flex gap-x-8; + } } .donut-average { @@ -74,34 +98,6 @@ } } - &__game-title { - @apply text-3xl font-semibold text-neutral-800 mt-0; - } - &__statistics-section { - p, - li { - @apply text-lg text-slate-600; - } - h3 { - @apply text-blue-600 uppercase font-bold text-base my-0 tracking-widest mb-4; - } - h4 { - @apply font-normal text-lg font-medium text-slate-400 my-0; - } - } - - &__scores-distribution { - ul { - @apply flex gap-x-8; - } - } - - .block-data-score { - @apply mb-16; - } - .page-title { - @apply text-5xl font-semibold text-neutral-800 pb-16; - } @apply py-12 text-base max-w-screen-xl mx-auto px-4; /* .geopraphy-statistics, @@ -128,6 +124,19 @@ @apply capitalize; } } + .download-btns { + @apply flex flex-col md:flex-row gap-x-12 gap-y-4 justify-center my-12; + .dowload-stats { + @apply bg-blue-600 text-white font-medium uppercase tracking-widest block py-4 px-6 rounded-full w-fit; + transition: all 0.3s; + } + .dowload-stats:hover { + transform: scale(1.05); + } + } + .block-data-score { + @apply mb-16; + } } #graphic-score-repartition { diff --git a/resources/js/stats-dashboard.js b/resources/js/stats-dashboard.js index 8b279fd..575b566 100644 --- a/resources/js/stats-dashboard.js +++ b/resources/js/stats-dashboard.js @@ -15,8 +15,8 @@ function buildDataChart(level) { }); } - console.log('score', scoreDistribution); - console.log(scoreDistributionDataset); + // console.log('score', scoreDistribution); + // console.log(scoreDistributionDataset); const colorPalettes = [ ['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'], @@ -134,7 +134,7 @@ function buildDataChart2(level) { ['#1137a3', '#3267d6', '#5fa3ff', '#8fc1ff', '#b5e0ff'], ]; - console.log('score', scoreDistributionDataset); + // console.log('score', scoreDistributionDataset); new Chart( document.getElementById('graphic-score-repartition'), { @@ -194,20 +194,20 @@ window.addEventListener('DOMContentLoaded', (event) => { const levels = document.querySelectorAll('.game_stats'); levels.forEach((level) => { buildDataChart2(level); - function updatePercentage(percentage) { - const overlay = document.querySelector( - '.donut-chart__overlay' - ); - const text = document.querySelector( - '.donut-chart__percentage' - ); - overlay.style.transform = `rotate(${ - (percentage / 100) * 360 - }deg)`; - text.textContent = `${percentage}%`; - } + // function updatePercentage(percentage) { + // const overlay = document.querySelector( + // '.donut-chart__overlay' + // ); + // const text = document.querySelector( + // '.donut-chart__percentage' + // ); + // overlay.style.transform = `rotate(${ + // (percentage / 100) * 360 + // }deg)`; + // text.textContent = `${percentage}%`; + // } - // Exemple : mettre à jour le pourcentage à 75% - updatePercentage(75); + // // Exemple : mettre à jour le pourcentage à 75% + // updatePercentage(75); }); }); diff --git a/template-parts/statistics/dashboard-widget.php b/template-parts/statistics/dashboard-widget.php new file mode 100644 index 0000000..48a5052 --- /dev/null +++ b/template-parts/statistics/dashboard-widget.php @@ -0,0 +1,9 @@ + +
\ No newline at end of file diff --git a/includes/dashboard.php b/template-parts/statistics/dashboard.php similarity index 66% rename from includes/dashboard.php rename to template-parts/statistics/dashboard.php index 925010b..ce9d78d 100644 --- a/includes/dashboard.php +++ b/template-parts/statistics/dashboard.php @@ -1,74 +1,16 @@ - - - - get_col(" SELECT DISTINCT level_post_id FROM $table_name "); - ?> +?>