first export prototype for formulaire papier
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Antoine M 2024-10-02 16:19:34 +02:00
parent 7b9a44840c
commit 935d101c1e
5 changed files with 312 additions and 0 deletions

View File

@ -11,6 +11,7 @@ require_once(__DIR__ . '/forms/field-OrderBrochureList.php');
require_once(__DIR__ . '/forms/field-OrderDocumentsList.php'); require_once(__DIR__ . '/forms/field-OrderDocumentsList.php');
require_once(__DIR__ . '/forms/field-HomegradeRating.php'); require_once(__DIR__ . '/forms/field-HomegradeRating.php');
require_once(__DIR__ . '/forms/field-ClassicRating.php'); require_once(__DIR__ . '/forms/field-ClassicRating.php');
require_once(__DIR__ . '/forms/export-paper-publication-entries.php');
// ## Form hooks // ## Form hooks
require_once(__DIR__ . '/forms/form-satisfaction.php'); require_once(__DIR__ . '/forms/form-satisfaction.php');

View File

@ -0,0 +1,190 @@
<?php
add_filter('gform_addon_navigation', 'add_menu_item');
function add_menu_item($menu_items)
{
$menu_items[] = array("name" => "Homegrade Stats", "label" => "Homegrade Datas", "callback" => "homegrade_stats_option_page", "permission" => "edit_posts");
return $menu_items;
}
function homegrade_stats_option_page()
{
?>
<div class="wrap ">
<h1>Exports de données Homegrade</h1>
<div class="homegrade-data-exports-page">
<div class="card export-card">
<h2>Formulaire de commande <br />des brochures papier</h2>
<img class="export-card__illustration" src="<?php echo get_template_directory_uri() . '/resources/img/illustrations/homegrade_formations-peb.svg' ?>" alt="">
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<input type="hidden" name="action" value="export_paper_order_datas">
<input type="hidden" name="export_paper_order_datas_nonce" value="<?php echo wp_create_nonce('export_paper_order_datas_nonce'); ?>">
<button type="submit" name="custom_action_button" class="button button-primary">
<?php echo __("Exporter les données", "homegrade-theme__texte-fonctionnel"); ?>
</button>
</form>
</div>
</div>
</div>
<?php
}
add_action('admin_post_export_paper_order_datas', 'handle_download_pdf_request');
function handle_download_pdf_request()
{
// Vérifier la nonce pour des raisons de sécurité
if (!isset($_POST['export_paper_order_datas_nonce']) || !wp_verify_nonce($_POST['export_paper_order_datas_nonce'], 'export_paper_order_datas_nonce') || !current_user_can('read')) {
wp_die('Vérification de sécurité échouée.');
}
generate_order_datas_to_csv();
exit;
}
function generate_order_datas_to_csv()
{
$form_id = 18;
$entries = GFAPI::get_entries($form_id);
if (is_wp_error($entries)) {
wp_die('Erreur lors de la récupération des données du formulaire.');
}
$output_formatted_entries = array();
foreach ($entries as $key => $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.';
// }
}

View File

@ -1,3 +1,5 @@
@import './backend/data-exports-page.css';
.edit-post-visual-editor__post-title-wrapper { .edit-post-visual-editor__post-title-wrapper {
h1 { h1 {
font-weight: revert; font-weight: revert;

View File

@ -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;
}
}
}

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg id="formations-peb" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 415.33 357.29">
<defs>
<style>
.cls-1 {
fill: url(#Dégradé_sans_nom_3-3);
}
.cls-1, .cls-2, .cls-3, .cls-4, .cls-5 {
stroke-width: 0px;
}
.cls-2 {
fill: #767575;
opacity: .3;
}
.cls-3 {
fill: url(#Dégradé_sans_nom_3);
}
.cls-6 {
fill: #fff;
}
.cls-6, .cls-7 {
stroke: #000;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 2px;
}
.cls-4 {
fill: url(#Dégradé_sans_nom_3-2);
}
.cls-7 {
fill: none;
}
.cls-5 {
fill: url(#Dégradé_sans_nom_3-4);
}
</style>
<linearGradient id="Dégradé_sans_nom_3" data-name="Dégradé sans nom 3" x1="-9290.08" y1="2229.97" x2="-9288.84" y2="2228.66" gradientTransform="translate(-36367.33 11479.48) rotate(-165.95) scale(3.51 8.94)" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#f3281d"/>
<stop offset="1" stop-color="#fe766f"/>
</linearGradient>
<linearGradient id="Dégradé_sans_nom_3-2" data-name="Dégradé sans nom 3" x1="-9290.14" y1="2230.52" x2="-9288.9" y2="2229.21" gradientTransform="translate(-36357.47 11437.22) rotate(-165.95) scale(3.51 8.92)" xlink:href="#Dégradé_sans_nom_3"/>
<linearGradient id="Dégradé_sans_nom_3-3" data-name="Dégradé sans nom 3" x1="-9284.7" y1="2324.9" x2="-9283.46" y2="2323.59" gradientTransform="translate(-35049.47 5812.24) rotate(-165.95) scale(3.52 6.07)" xlink:href="#Dégradé_sans_nom_3"/>
<linearGradient id="Dégradé_sans_nom_3-4" data-name="Dégradé sans nom 3" x1="273.29" y1="124.8" x2="290.57" y2="124.8" gradientTransform="matrix(1,0,0,1,0,0)" xlink:href="#Dégradé_sans_nom_3"/>
</defs>
<ellipse class="cls-2" cx="58.24" cy="280.63" rx="33.62" ry="58.24" transform="translate(-222.7 337.35) rotate(-89.69)"/>
<ellipse class="cls-2" cx="284.21" cy="281.59" rx="75.7" ry="131.12" transform="translate(1.09 564.27) rotate(-89.69)"/>
<line class="cls-7" x1="215.28" y1="269.98" x2="245.35" y2="167.12"/>
<line class="cls-7" x1="310.23" y1="205.89" x2="322.88" y2="339.6"/>
<line class="cls-7" x1="330.21" y1="198.37" x2="353.41" y2="239.43"/>
<polygon class="cls-6" points="330.2 231.04 336.01 231.04 347.61 74.41 342.07 73.37 330.2 231.04"/>
<g id="Groupe_60" data-name="Groupe 60">
<path id="Tracé_173" data-name="Tracé 173" class="cls-6" d="m74.63,59.47c4.1,3.07,7.88,6.54,11.28,10.37,7.24,8.21,12.65,17.87,15.88,28.33,2.14-2.59,4.31-5.32,6.49-8.17,2.9-3.81,5.58-7.54,8.05-11.18l12.98,5.41c-2.48,7.51-6,14.63-10.46,21.15-4.86,7.08-8.17,11.75-13.7,12.5-5.27.71-10.16-2.45-12.73-4.1-3.02-1.96-5.64-4.48-7.7-7.43-3.37-15.62-6.73-31.25-10.09-46.87Z"/>
<path id="Tracé_174" data-name="Tracé 174" class="cls-6" d="m126.65,83.11c1.89-1.84,12.9-12.77,10.05-21.6-.25-.76-1.12-3.49-2.97-3.88-2.41-.5-5.68,3.1-8.48,9.28-.14-.84-.38-1.66-.72-2.43-.43-.97-1.65-3.35-2.43-3.33-.96.02-2.17,3.69-3.41,18.65l7.96,3.31Z"/>
</g>
<path id="Tracé_175" data-name="Tracé 175" class="cls-6" d="m73.98,263.48c1.17-12.22,2.34-37.35,3.51-49.57l6.5-67.6-31.85,13.07c2.72,30.87,5.44,74.65,8.17,105.53l13.68-1.42Z"/>
<path id="Tracé_176" data-name="Tracé 176" class="cls-6" d="m45.22,270.65c3.55-15.23,7.09-43.37,10.64-58.59,2.98-18.28,5.95-36.57,8.93-54.86H31.59s3.79,81.87,3.79,81.87c-.35,14.73-.7,17.85-1.05,32.58l10.89-1Z"/>
<g id="Groupe_61" data-name="Groupe 61">
<path id="Tracé_177" data-name="Tracé 177" class="cls-6" d="m72.82,44.2l.49,12.03c3.35,2.39,6.19,5.42,8.38,8.9,1.66,2.67,2.92,5.58,3.74,8.62,1.02,4.05,1.34,8.24.93,12.4-.3,8.04-.2,39.51.06,65.73-6.55,3.49-13.49,6.2-20.67,8.08-11.36,2.95-23.18,3.72-34.82,2.26-1.46-19.03-2.4-38.61-2.82-58.76.13-12.03,2.18-23.96,6.08-35.33,1.32-3.76,3.34-8.51,7.81-11.54,2.71-1.8,5.9-2.75,9.15-2.74l.99-12.14"/>
</g>
<polygon id="Ligne_15" data-name="Ligne 15" class="cls-6" points="73.37 279.51 72.27 264.56 72.27 263.66 63.69 264.56 64.79 279.51 73.37 279.51"/>
<polygon class="cls-6" points="35.86 271.65 43.74 270.79 43.74 282.57 35.82 282.57 35.86 271.65"/>
<path id="Tracé_178" data-name="Tracé 178" class="cls-6" d="m31.98,282.82c.28-4.03.58-4.69,1.17-5.14,1.39-1.05,2.87.26,7.12.16,3.49-.09,4.23-1.01,5.41-.25,1.71,1.11.11,3.07,1.98,7.48.73,1.72,1.9,3.61,1.77,6.48,0,.18,0,.28-.03.43-.5,3.02-2.77,5.45-5.75,6.16-2.18.43-4.03-.5-7.05-1.99-1.38-.52-2.65-1.33-3.71-2.35-1.53-1.83-1.35-4.9-.92-10.98Z"/>
<path id="Tracé_184" data-name="Tracé 184" class="cls-6" d="m58.32,277.23l1.59-4.36c.25-.71,1.03-1.07,1.74-.82.05.02.11.04.16.07,4.49,2.3,9.51,3.36,14.54,3.08,4.16,2.23,7.43,5.81,9.3,10.14.65,1.61,2.09,5.13.22,6.25-1.32.79-3.58-.04-11.72-3.32-10.92-4.41-16.75-6.92-16.58-9.02.04-.73.3-1.44.74-2.03Z"/>
<polygon class="cls-6" points="58.24 103.88 46.04 110.92 46.04 103.56 58.24 96.52 58.24 103.88"/>
<g id="Groupe_63" data-name="Groupe 63">
<g>
<path class="cls-6" d="m91.82,111.23l-2.87-2.03c-.19-.19-.41-.35-.67-.47l-.46-.32-.1.14c-.54-.12-1.14-.09-1.78.15l-23.09,8.47c-1.19.44-2.14,1.48-2.45,2.68l-9.07,35.21c-.26,1.01-.02,1.91.52,2.53h0c.19.21.41.39.67.53l3.6,2.87,2.93-4.08,17.33-5.62c1.21-.39,2.21-1.42,2.56-2.63l9.45-32.63,3.44-4.79Z"/>
<path class="cls-6" d="m63.85,122.29l-9.07,35.21c-.58,2.24,1.27,3.93,3.51,3.21l21.53-6.98c1.21-.39,2.21-1.42,2.56-2.63l10.63-36.69c.68-2.34-1.29-4.11-3.61-3.26l-23.09,8.47c-1.19.44-2.14,1.48-2.45,2.68Z"/>
</g>
<path id="Tracé_182" data-name="Tracé 182" class="cls-6" d="m39.19,59.07c-5.41,6.19-22.17,26.77-21.34,52.4.18,5.42.55,13.85,6.01,22.59,4.29,6.76,10.48,12.11,17.79,15.38l7.69-6.49c-15.41-16.01-17.7-40.54-5.53-59.13"/>
<path id="Tracé_183" data-name="Tracé 183" class="cls-6" d="m41.65,149.52c1.88,2.95,4.8,5.09,8.17,6.01,5.82,1.38,12.29-1.75,12.26-3.85-.02-1-1.52-1.4-5.29-3.61-2.59-1.51-5.08-3.2-7.45-5.05l-7.69,6.49"/>
</g>
<g id="Groupe_65" data-name="Groupe 65">
<path id="Tracé_185" data-name="Tracé 185" class="cls-6" d="m80.49,60.01l-27.71,7.93,6.95-27.79,17.65-19.11,10.06,11.19-6.95,27.78Z"/>
<path id="Tracé_186" data-name="Tracé 186" class="cls-6" d="m52.78,67.93l-20.71-20.04,6.95-27.78,20.71,20.04-6.95,27.78Z"/>
<path id="Tracé_187" data-name="Tracé 187" class="cls-6" d="m39.02,20.11L56.67,1l20.71,20.04-17.65,19.11-20.71-20.04Z"/>
</g>
<path id="Tracé_188" data-name="Tracé 188" class="cls-3" d="m63.59,51.71l4.85-1.39,1.68-6.71c.23-.91-.32-1.84-1.24-2.07-.29-.07-.6-.07-.88.01h0c-1.25.36-2.21,1.35-2.52,2.61l-1.89,7.54Z"/>
<path id="Tracé_189" data-name="Tracé 189" class="cls-4" d="m72.78,49.12l4.85-1.39,1.67-6.66c.23-.93-.33-1.87-1.26-2.1-.3-.07-.61-.07-.9.02h0c-1.21.35-2.15,1.32-2.46,2.54l-1.9,7.59Z"/>
<path id="Tracé_191" data-name="Tracé 191" class="cls-1" d="m66.27,59l4.87-1.39,1.22-4.88-4.87,1.39-1.22,4.88Z"/>
<polygon class="cls-6" points="226.35 171.08 330.2 231.04 342.07 73.37 238.22 13.41 226.35 171.08"/>
<polygon class="cls-6" points="248.28 145 260.27 151.92 262.34 123.16 250.35 116.24 248.28 145"/>
<polygon class="cls-5" points="273.29 158.63 285.28 165.55 290.57 90.96 278.58 84.04 273.29 158.63"/>
<polygon class="cls-6" points="298.67 174.94 310.65 181.86 314.86 126.64 302.87 119.72 298.67 174.94"/>
<g>
<polygon class="cls-6" points="232.09 14.14 343.01 78.84 350.38 76.78 350.38 66.43 238.69 2.82 232.09 5.05 232.09 14.14"/>
<polygon class="cls-6" points="232.09 5.05 343.01 68.48 350.38 66.43 238.69 2.82 232.09 5.05"/>
<line class="cls-6" x1="343.01" y1="78.84" x2="343.01" y2="68.48"/>
</g>
<g>
<polygon class="cls-6" points="218.84 172.95 329.76 237.65 337.13 235.59 337.13 225.24 225.43 161.64 218.84 163.86 218.84 172.95"/>
<polygon class="cls-6" points="218.84 163.86 329.76 227.29 337.13 225.24 225.43 161.64 218.84 163.86"/>
<line class="cls-6" x1="329.76" y1="237.65" x2="329.76" y2="227.29"/>
</g>
<polyline class="cls-7" points="240.6 96.81 255.38 83.46 271.38 110.15 310.29 90.71 329.83 109.93"/>
</svg>

After

Width:  |  Height:  |  Size: 8.0 KiB