From 935d101c1ec760a006e22dad05f0764a715cdcce Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 2 Oct 2024 16:19:34 +0200 Subject: [PATCH] first export prototype for formulaire papier --- includes/forms.php | 1 + .../export-paper-publication-entries.php | 190 ++++++++++++++++++ resources/css/admin-style.css | 2 + resources/css/backend/data-exports-page.css | 15 ++ .../homegrade_formations-peb.svg | 104 ++++++++++ 5 files changed, 312 insertions(+) create mode 100644 includes/forms/export-paper-publication-entries.php create mode 100644 resources/css/backend/data-exports-page.css create mode 100644 resources/img/illustrations/homegrade_formations-peb.svg diff --git a/includes/forms.php b/includes/forms.php index 2a9659a..2318217 100644 --- a/includes/forms.php +++ b/includes/forms.php @@ -11,6 +11,7 @@ require_once(__DIR__ . '/forms/field-OrderBrochureList.php'); require_once(__DIR__ . '/forms/field-OrderDocumentsList.php'); require_once(__DIR__ . '/forms/field-HomegradeRating.php'); require_once(__DIR__ . '/forms/field-ClassicRating.php'); +require_once(__DIR__ . '/forms/export-paper-publication-entries.php'); // ## Form hooks require_once(__DIR__ . '/forms/form-satisfaction.php'); diff --git a/includes/forms/export-paper-publication-entries.php b/includes/forms/export-paper-publication-entries.php new file mode 100644 index 0000000..1c2e040 --- /dev/null +++ b/includes/forms/export-paper-publication-entries.php @@ -0,0 +1,190 @@ + "Homegrade Stats", "label" => "Homegrade Datas", "callback" => "homegrade_stats_option_page", "permission" => "edit_posts"); + return $menu_items; +} + + + +function homegrade_stats_option_page() +{ +?> +
+

Exports de données Homegrade

+ +
+ +
+

Formulaire de commande
des brochures papier

+ +
+ + + +
+
+
+
+ $entry) { + + $clientFirstName = $entry['3']; + $clientLastName = $entry['2']; + $zipCode = $entry['9.5']; + + + $synthesePrimes = $entry['24'] ? unserialize($entry['24']) : []; + $brochures = $entry['25'] ? unserialize($entry['25']) : []; + $autrePublications = $entry['26'] ? unserialize($entry['26']) : []; + + + + + $explodedEntryDocuments = array_merge($synthesePrimes, $brochures, $autrePublications); + + + foreach ($explodedEntryDocuments as $key => $document) { + $document_quantity_fr = $document['quantity_fr'] ?? null; + $document_quantity_nl = $document['quantity_nl'] ?? null; + + + + if (!$document_quantity_fr && !$document_quantity_nl) { + continue; + } + + + if ($document_quantity_nl) { + // $document_formatted_order_nl = $clientFirstName . ' ' . $clientLastName . ' | ' . $zipCode . ' | ' . $key . ' | ' . $document_quantity_nl . ' NL'; + + $document_formatted_order_nl = [ + 'client' => $clientFirstName . ' ' . $clientLastName, + 'zipCode' => $zipCode, + 'publication' => $key, + 'quantity' => $document_quantity_nl, + 'language' => 'NL' + ]; + array_push($output_formatted_entries, $document_formatted_order_nl); + } + + if ($document_quantity_fr) { + // $document_formatted_order_fr = $clientFirstName . ' ' . $clientLastName . ' | ' . $zipCode . ' | ' . $key . ' | ' . $document_quantity_fr . ' FR'; + $document_formatted_order_fr = [ + 'client' => $clientFirstName . ' ' . $clientLastName, + 'zipCode' => $zipCode, + 'publication' => $key, + 'quantity' => $document_quantity_fr, + 'language' => 'FR' + ]; + array_push($output_formatted_entries, $document_formatted_order_fr); + } + } + } + // write_log($output_formatted_entries); + + // Définir le nom du fichier CSV + $filename = 'order_data_' . date('Ymd_His') . '.csv'; + + // Ouvrir un fichier CSV en mode écriture + $file = fopen($filename, 'w'); + + if ($file === false) { + wp_die('Erreur lors de la création du fichier CSV.'); + } + + // Ajouter les en-têtes du CSV + fputcsv($file, ['Client', 'Code Postal', 'Publication', 'Quantité', 'Langue']); + + // Boucler sur chaque entrée formatée et l'écrire dans le CSV + foreach ($output_formatted_entries as $entry) { + fputcsv($file, $entry); + } + + // Fermer le fichier + fclose($file); + + // Télécharger le fichier CSV + header('Content-Type: text/csv'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + readfile($filename); + + // Supprimer le fichier après téléchargement + unlink($filename); + + exit(); + + + // if ($output_formatted_entries) { + // // 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) { + // // $row["level_completion_time"] = $row["level_completion_time"] / 100; + + // 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/admin-style.css b/resources/css/admin-style.css index ac343e2..a64e979 100644 --- a/resources/css/admin-style.css +++ b/resources/css/admin-style.css @@ -1,3 +1,5 @@ +@import './backend/data-exports-page.css'; + .edit-post-visual-editor__post-title-wrapper { h1 { font-weight: revert; diff --git a/resources/css/backend/data-exports-page.css b/resources/css/backend/data-exports-page.css new file mode 100644 index 0000000..ba0817a --- /dev/null +++ b/resources/css/backend/data-exports-page.css @@ -0,0 +1,15 @@ +.homegrade-data-exports-page { + @apply grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4; + .export-card { + @apply !rounded-2xl border-none + flex flex-col items-center justify-center !p-8 + gap-8 text-center; + max-width: unset; + h2 { + @apply !m-0 text-secondary max-w-xs leading-5 pb-2; + } + &__illustration { + max-width: 200px; + } + } +} diff --git a/resources/img/illustrations/homegrade_formations-peb.svg b/resources/img/illustrations/homegrade_formations-peb.svg new file mode 100644 index 0000000..1aab298 --- /dev/null +++ b/resources/img/illustrations/homegrade_formations-peb.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file