Compare commits

..

No commits in common. "030ba4d38fea59a805897cd55ffe4725e2d5aa72" and "935d101c1ec760a006e22dad05f0764a715cdcce" have entirely different histories.

9 changed files with 91 additions and 139 deletions

View File

@ -101,6 +101,7 @@ function load_more_fiches_infos()
// $isQueryEmpty = $ajax_query->have_posts() ? false : true; // $isQueryEmpty = $ajax_query->have_posts() ? false : true;
$isQueryEmpty = $offset + 1 >= $ajax_query->max_num_pages ? true : false; $isQueryEmpty = $offset + 1 >= $ajax_query->max_num_pages ? true : false;
// write_log($isQueryEmpty);
// BREAK IF QUERY IS EMPTY // BREAK IF QUERY IS EMPTY
if ($ajax_query->have_posts() == false) { if ($ajax_query->have_posts() == false) {

View File

@ -24,7 +24,6 @@ add_filter('gform_pre_validation_18', 'homegrade_paper_publications_form_limit_c
add_filter('gform_pre_submission_filter_18', 'homegrade_paper_publications_form_limit_countries'); add_filter('gform_pre_submission_filter_18', 'homegrade_paper_publications_form_limit_countries');
add_filter('gform_admin_pre_render_18', 'homegrade_paper_publications_form_limit_countries'); add_filter('gform_admin_pre_render_18', 'homegrade_paper_publications_form_limit_countries');
function homegrade_paper_publications_form_limit_countries($form) function homegrade_paper_publications_form_limit_countries($form)
{ {
@ -34,21 +33,3 @@ function homegrade_paper_publications_form_limit_countries($form)
return $form; return $form;
} }
add_action('gform_after_submission', 'add_user_language_to_submission', 10, 2);
function add_user_language_to_submission($entry, $form)
{
// Obtenir la langue actuelle via WPML
$current_language = apply_filters('wpml_current_language', NULL);
// Ajouter la langue à l'entrée de formulaire
GFAPI::update_entry_field($entry['id'], 'language', 'lol ' . $current_language);
}
add_filter('gform_field_value_user_language', 'fill_user_language');
function fill_user_language($value)
{
return apply_filters('wpml_current_language', NULL);
}

View File

@ -47,6 +47,7 @@ function populate_note_comment_based_on_rating($form)
$stringified_information_accessibility_rating = isset($field["choices"][$global_user_rating - 1]['text']) ? $field["choices"][$global_user_rating - 1]['text'] : ''; $stringified_information_accessibility_rating = isset($field["choices"][$global_user_rating - 1]['text']) ? $field["choices"][$global_user_rating - 1]['text'] : '';
write_log($stringified_information_accessibility_rating);
$_POST["input_{$nextHiddenLabelField->id}"] = $stringified_information_accessibility_rating; $_POST["input_{$nextHiddenLabelField->id}"] = $stringified_information_accessibility_rating;
} }

View File

@ -46,20 +46,15 @@ function handle_download_pdf_request()
exit; exit;
} }
function generate_order_datas_to_csv() function generate_order_datas_to_csv()
{ {
$form_id = 18; $form_id = 18;
$entries = GFAPI::get_entries($form_id);
$search_criteria = array("status" => "active");
$sorting = array();
$paging = array(
'offset' => 0,
'page_size' => 9000,
);
$entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
if (is_wp_error($entries)) { if (is_wp_error($entries)) {
wp_die('Erreur lors de la récupération des données du formulaire.'); wp_die('Erreur lors de la récupération des données du formulaire.');
@ -70,62 +65,59 @@ function generate_order_datas_to_csv()
foreach ($entries as $key => $entry) { foreach ($entries as $key => $entry) {
// $clientFirstName = $entry['3']; $clientFirstName = $entry['3'];
// $clientLastName = $entry['2']; $clientLastName = $entry['2'];
$companyType = $entry['7'];
$zipCode = $entry['9.5']; $zipCode = $entry['9.5'];
$userLanguage = strtoupper($entry['27']) ?? null;
$synthesePrimes = isset($entry['24']) ? unserialize($entry['24']) : [];
$brochures = isset($entry['25']) ? unserialize($entry['25']) : []; $synthesePrimes = $entry['24'] ? unserialize($entry['24']) : [];
$autrePublications = isset($entry['26']) ? unserialize($entry['26']) : []; $brochures = $entry['25'] ? unserialize($entry['25']) : [];
$autrePublications = $entry['26'] ? unserialize($entry['26']) : [];
$explodedEntryDocuments = array_merge($synthesePrimes, $brochures, $autrePublications); $explodedEntryDocuments = array_merge($synthesePrimes, $brochures, $autrePublications);
foreach ($explodedEntryDocuments as $key => $document) { foreach ($explodedEntryDocuments as $key => $document) {
$document_id_fr = $document['id_fr'] ?? null;
$document_quantity_fr = $document['quantity_fr'] ?? null; $document_quantity_fr = $document['quantity_fr'] ?? null;
$document_id_nl = $document['id_nl'] ?? null;
$document_quantity_nl = $document['quantity_nl'] ?? null; $document_quantity_nl = $document['quantity_nl'] ?? null;
if (!$document_quantity_fr && !$document_quantity_nl) { if (!$document_quantity_fr && !$document_quantity_nl) {
continue; continue;
} }
if ($document_quantity_nl) { if ($document_quantity_nl) {
$thematique = getPostMainThematique($document_id_nl)->name ?? ''; // $document_formatted_order_nl = $clientFirstName . ' ' . $clientLastName . ' | ' . $zipCode . ' | ' . $key . ' | ' . $document_quantity_nl . ' NL';
$document_formatted_order_nl = [ $document_formatted_order_nl = [
'publication' => $document_id_nl ? get_the_title($document_id_nl) : $key, 'client' => $clientFirstName . ' ' . $clientLastName,
'quantity' => $document_quantity_nl,
'document_language' => 'NL',
'thematique' => $thematique,
'brochureID' => $document_id_nl,
'company_type' => $companyType,
'zipCode' => $zipCode, 'zipCode' => $zipCode,
'userLanguage' => $userLanguage, 'publication' => $key,
'quantity' => $document_quantity_nl,
'language' => 'NL'
]; ];
array_push($output_formatted_entries, $document_formatted_order_nl); array_push($output_formatted_entries, $document_formatted_order_nl);
} }
if ($document_quantity_fr) { if ($document_quantity_fr) {
$thematique = getPostMainThematique($document_id_fr)->name ?? ''; // $document_formatted_order_fr = $clientFirstName . ' ' . $clientLastName . ' | ' . $zipCode . ' | ' . $key . ' | ' . $document_quantity_fr . ' FR';
$document_formatted_order_fr = [ $document_formatted_order_fr = [
'publication' => $document_id_fr ? get_the_title($document_id_fr) : $key, 'client' => $clientFirstName . ' ' . $clientLastName,
'quantity' => $document_quantity_fr,
'document_language' => 'FR',
'thematique' => $thematique,
'brochureID' => $document_id_fr,
'company_type' => $companyType,
'zipCode' => $zipCode, 'zipCode' => $zipCode,
'userLanguage' => $userLanguage, 'publication' => $key,
'quantity' => $document_quantity_fr,
'language' => 'FR'
]; ];
array_push($output_formatted_entries, $document_formatted_order_fr); array_push($output_formatted_entries, $document_formatted_order_fr);
} }
} }
} }
// write_log($output_formatted_entries);
// Définir le nom du fichier CSV // Définir le nom du fichier CSV
$filename = 'order_data_' . date('Ymd_His') . '.csv'; $filename = 'order_data_' . date('Ymd_His') . '.csv';
@ -138,7 +130,7 @@ function generate_order_datas_to_csv()
} }
// Ajouter les en-têtes du CSV // Ajouter les en-têtes du CSV
fputcsv($file, ['Publication', 'Quantité', 'Langue de la publication', 'Thématique', 'ID de la brochure', 'Type d\'organisme', 'Code Postal', 'Langue de l\'utilisateur']); fputcsv($file, ['Client', 'Code Postal', 'Publication', 'Quantité', 'Langue']);
// Boucler sur chaque entrée formatée et l'écrire dans le CSV // Boucler sur chaque entrée formatée et l'écrire dans le CSV
foreach ($output_formatted_entries as $entry) { foreach ($output_formatted_entries as $entry) {
@ -157,4 +149,42 @@ function generate_order_datas_to_csv()
unlink($filename); unlink($filename);
exit(); 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

@ -96,25 +96,9 @@ if (class_exists('GF_Field')) {
$counter = 0; $counter = 0;
foreach ($this->choices as $brochure) { foreach ($this->choices as $brochure) {
// $isEmpty = empty($value[$counter]) && empty($value[$counter + 1]);
// if ($isEmpty) {
// $counter += 4;
// continue;
// }
$currentUserLanguage = apply_filters('wpml_current_language', null);
$ID_FR = apply_filters('wpml_object_id', $brochure['ID'], 'brochures', false, 'fr') ?? 0;
$ID_NL = apply_filters('wpml_object_id', $brochure['ID'], 'brochures', false, 'nl') ?? 0;
$table_value[$brochure['text']]['quantity_fr'] = $value[$counter] ?? 0; $table_value[$brochure['text']]['quantity_fr'] = $value[$counter] ?? 0;
$table_value[$brochure['text']]['quantity_nl'] = $value[$counter + 1] ?? 0; $table_value[$brochure['text']]['quantity_nl'] = $value[$counter + 1] ?? 0;
$counter += 2;
$table_value[$brochure['text']]['id_fr'] = $ID_FR;
$table_value[$brochure['text']]['id_nl'] = $ID_NL;
$counter += 4;
} }
return $table_value; return $table_value;
} }

View File

@ -26,18 +26,16 @@ if (class_exists('GF_Field')) {
], ],
]; ];
$currentLang = apply_filters('wpml_current_language', null); $currentLang = apply_filters('wpml_current_language', null);
foreach ($posts_array as $post) { foreach ($posts_array as $post) {
$current_lang_id = $currentLang === 'nl' ? $post['ID_nl'] : $post['ID_fr']; $id = $currentLang === 'nl' ? $post['ID_nl'] : $post['ID_fr'];
$choices[] = [ $choices[] = [
'title' => get_the_title($current_lang_id), 'title' => get_the_title($id),
'text' => get_the_title($current_lang_id), 'text' => get_the_title($id),
'ID_fr' => $post['ID_nl'], 'ID' => $id,
'ID_nl' => $post['ID_fr'],
]; ];
} }
$this->choices = $choices; $this->choices = $choices;
@ -100,22 +98,9 @@ if (class_exists('GF_Field')) {
$counter = 0; $counter = 0;
foreach ($this->choices as $document) { foreach ($this->choices as $document) {
// $isEmpty = empty($value[$counter]) && empty($value[$counter + 1]);
// if ($isEmpty) {
// $counter += 4;
// continue;
// }
$ID_FR = $document['ID_fr'];
$ID_NL = $document['ID_nl'];
$table_value[$document['text']]['quantity_fr'] = $value[$counter] ?? 0; $table_value[$document['text']]['quantity_fr'] = $value[$counter] ?? 0;
$table_value[$document['text']]['quantity_nl'] = $value[$counter + 1] ?? 0; $table_value[$document['text']]['quantity_nl'] = $value[$counter + 1] ?? 0;
$counter += 2;
$table_value[$document['text']]['id_fr'] = $ID_FR;
$table_value[$document['text']]['id_nl'] = $ID_NL;
$counter += 4;
} }
return $table_value; return $table_value;
} }

View File

@ -9,19 +9,21 @@ if (class_exists('GF_Field')) {
private function buildChoicesArray() private function buildChoicesArray()
{ {
$ID_FR = 6538;
$ID_NL = 6541;
$ID_related_fiche_info_fr = 6538;
$ID_related_fiche_info_nl = 6541;
$currentLang = apply_filters('wpml_current_language', null); $currentLang = apply_filters('wpml_current_language', null);
$current_lang_id = apply_filters('wpml_object_id', $ID_FR, 'post', false, $currentLang);
$document_pdf = get_field('brochure_pdf', $current_lang_id); $document_pdf = $currentLang === 'nl' ? get_field('brochure_pdf', $ID_related_fiche_info_nl) : get_field('brochure_pdf', $ID_related_fiche_info_fr);
$document_ID = $currentLang === 'nl' ? $ID_related_fiche_info_nl : $ID_related_fiche_info_fr;
$choices[] = [ $choices[] = [
'title' => $document_pdf['title'], 'title' => $document_pdf['title'],
'text' => $document_pdf['title'], 'text' => $document_pdf['title'],
'ID_fr' => $ID_FR, 'ID' => $document_ID,
'ID_nl' => $ID_NL,
]; ];
$this->choices = $choices; $this->choices = $choices;
@ -84,21 +86,9 @@ if (class_exists('GF_Field')) {
$counter = 0; $counter = 0;
foreach ($this->choices as $document) { foreach ($this->choices as $document) {
// $isEmpty = empty($value[$counter]) && empty($value[$counter + 1]);
// if ($isEmpty) {
// $counter += 4;
// continue;
// }
$ID_FR = $document['ID_fr'];
$ID_NL = $document['ID_nl'];
$table_value[$document['text']]['quantity_fr'] = $value[$counter] ?? 0; $table_value[$document['text']]['quantity_fr'] = $value[$counter] ?? 0;
$table_value[$document['text']]['quantity_nl'] = $value[$counter + 1] ?? 0; $table_value[$document['text']]['quantity_nl'] = $value[$counter + 1] ?? 0;
$counter += 2;
$table_value[$document['text']]['id_fr'] = $ID_FR;
$table_value[$document['text']]['id_nl'] = $ID_NL;
$counter += 4;
} }
return $table_value; return $table_value;
} }

View File

@ -4,9 +4,10 @@
?> ?>
<fieldset class="field-order-paper-publications"> <fieldset class="field-order-paper-publications">
<?php
?>
<?php foreach ($this->choices as $index => $brochurePost) : ?> <?php foreach ($this->choices as $index => $brochurePost) : ?>
<?php <?php
$thematique = getPostMainThematique($brochurePost['ID']); $thematique = getPostMainThematique($brochurePost['ID']);
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id); $thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id);
$brochure_pdf_link = get_field('brochure_pdf', $brochurePost['ID']); $brochure_pdf_link = get_field('brochure_pdf', $brochurePost['ID']);
@ -27,12 +28,6 @@
<a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank"><?php echo __("Voir la brochure", "homegrade-theme__texte-fonctionnel") ?></a> <a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank"><?php echo __("Voir la brochure", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container"> <div class="inputs-container">
<?php
$ID_FR = apply_filters('wpml_object_id', $brochurePost['ID'], 'brochures', false, 'fr');
$ID_NL = apply_filters('wpml_object_id', $brochurePost['ID'], 'brochures', false, 'nl');
?>
<div class="publications-amount-fr"> <div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label> <label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" /> <input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
@ -41,8 +36,7 @@
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label> <label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" /> <input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div> </div>
<input type="hidden" name="<?php echo 'input_' . $id . '[]' ?>" value="<?php echo $ID_FR ?>" />
<input type="hidden" name="<?php echo 'input_' . $id . '[]' ?>" value="<?php echo $ID_NL ?>" />
</div> </div>
</div> </div>

View File

@ -11,20 +11,9 @@
<?php foreach ($otherPublicationsArray as $index => $document) : ?> <?php foreach ($otherPublicationsArray as $index => $document) : ?>
<?php <?php
// write_log($document);
?>
<?php
$ID_FR = $document['ID_fr'];
$ID_NL = $document['ID_nl'];
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143"); $thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
$current_lang = apply_filters('wpml_current_language', null); $documentPost = get_post($document['ID']);
$current_lang_id = $current_lang === 'nl' ? $ID_NL : $ID_FR; $metadata = wp_get_attachment_metadata($document['ID']);
$documentPost = get_post($current_lang_id);
$metadata = wp_get_attachment_metadata($current_lang_id);
?> ?>
<div class=" gchoice brochure-order-field"> <div class=" gchoice brochure-order-field">
@ -38,9 +27,8 @@
</p> </p>
</div> </div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $documentPost->post_title ?></legend> <legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $documentPost->post_title ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($current_lang_id) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a> <a class="preview-brochure" href="<?php echo get_the_permalink($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container"> <div class="inputs-container">
<div class="publications-amount-fr"> <div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label> <label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" /> <input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
@ -49,8 +37,6 @@
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label> <label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" /> <input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div> </div>
<input type="hidden" name="<?php echo 'input_' . $current_lang_id . '[]' ?>" value="<?php echo $ID_FR ?>" />
<input type="hidden" name="<?php echo 'input_' . $current_lang_id . '[]' ?>" value="<?php echo $ID_NL ?>" />
</div> </div>