updating form commandes papiers
This commit is contained in:
parent
935d101c1e
commit
5965f09b03
|
|
@ -24,6 +24,7 @@ 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_admin_pre_render_18', 'homegrade_paper_publications_form_limit_countries');
|
||||
|
||||
|
||||
function homegrade_paper_publications_form_limit_countries($form)
|
||||
{
|
||||
|
||||
|
|
@ -33,3 +34,21 @@ function homegrade_paper_publications_form_limit_countries($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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,15 +46,20 @@ function handle_download_pdf_request()
|
|||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function generate_order_datas_to_csv()
|
||||
{
|
||||
$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)) {
|
||||
wp_die('Erreur lors de la récupération des données du formulaire.');
|
||||
|
|
@ -65,59 +70,62 @@ function generate_order_datas_to_csv()
|
|||
|
||||
foreach ($entries as $key => $entry) {
|
||||
|
||||
$clientFirstName = $entry['3'];
|
||||
$clientLastName = $entry['2'];
|
||||
// $clientFirstName = $entry['3'];
|
||||
// $clientLastName = $entry['2'];
|
||||
$companyType = $entry['7'];
|
||||
$zipCode = $entry['9.5'];
|
||||
$userLanguage = strtoupper($entry['27']) ?? null;
|
||||
|
||||
|
||||
$synthesePrimes = $entry['24'] ? unserialize($entry['24']) : [];
|
||||
$brochures = $entry['25'] ? unserialize($entry['25']) : [];
|
||||
$autrePublications = $entry['26'] ? unserialize($entry['26']) : [];
|
||||
|
||||
|
||||
|
||||
$synthesePrimes = isset($entry['24']) ? unserialize($entry['24']) : [];
|
||||
$brochures = isset($entry['25']) ? unserialize($entry['25']) : [];
|
||||
$autrePublications = isset($entry['26']) ? unserialize($entry['26']) : [];
|
||||
|
||||
$explodedEntryDocuments = array_merge($synthesePrimes, $brochures, $autrePublications);
|
||||
|
||||
|
||||
foreach ($explodedEntryDocuments as $key => $document) {
|
||||
$document_id_fr = $document['id_fr'] ?? null;
|
||||
$document_quantity_fr = $document['quantity_fr'] ?? null;
|
||||
|
||||
$document_id_nl = $document['id_nl'] ?? 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';
|
||||
|
||||
$thematique = getPostMainThematique($document_id_nl)->name ?? '';
|
||||
$document_formatted_order_nl = [
|
||||
'client' => $clientFirstName . ' ' . $clientLastName,
|
||||
'zipCode' => $zipCode,
|
||||
'publication' => $key,
|
||||
'publication' => $document_id_nl ? get_the_title($document_id_nl) : $key,
|
||||
'quantity' => $document_quantity_nl,
|
||||
'language' => 'NL'
|
||||
'document_language' => 'NL',
|
||||
'thematique' => $thematique,
|
||||
'brochureID' => $document_id_nl,
|
||||
'company_type' => $companyType,
|
||||
'zipCode' => $zipCode,
|
||||
'userLanguage' => $userLanguage,
|
||||
];
|
||||
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';
|
||||
$thematique = getPostMainThematique($document_id_fr)->name ?? '';
|
||||
|
||||
$document_formatted_order_fr = [
|
||||
'client' => $clientFirstName . ' ' . $clientLastName,
|
||||
'zipCode' => $zipCode,
|
||||
'publication' => $key,
|
||||
'publication' => $document_id_fr ? get_the_title($document_id_fr) : $key,
|
||||
'quantity' => $document_quantity_fr,
|
||||
'language' => 'FR'
|
||||
'document_language' => 'FR',
|
||||
'thematique' => $thematique,
|
||||
'brochureID' => $document_id_fr,
|
||||
'company_type' => $companyType,
|
||||
'zipCode' => $zipCode,
|
||||
'userLanguage' => $userLanguage,
|
||||
];
|
||||
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';
|
||||
|
|
@ -130,7 +138,7 @@ function generate_order_datas_to_csv()
|
|||
}
|
||||
|
||||
// Ajouter les en-têtes du CSV
|
||||
fputcsv($file, ['Client', 'Code Postal', 'Publication', 'Quantité', 'Langue']);
|
||||
fputcsv($file, ['Publication', 'Quantité', 'Langue de la publication', 'Thématique', 'ID de la brochure', 'Type d\'organisme', 'Code Postal', 'Langue de l\'utilisateur']);
|
||||
|
||||
// Boucler sur chaque entrée formatée et l'écrire dans le CSV
|
||||
foreach ($output_formatted_entries as $entry) {
|
||||
|
|
@ -149,42 +157,4 @@ function generate_order_datas_to_csv()
|
|||
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.';
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,25 @@ if (class_exists('GF_Field')) {
|
|||
$counter = 0;
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,18 @@ if (class_exists('GF_Field')) {
|
|||
],
|
||||
];
|
||||
|
||||
|
||||
$currentLang = apply_filters('wpml_current_language', null);
|
||||
|
||||
|
||||
foreach ($posts_array as $post) {
|
||||
$id = $currentLang === 'nl' ? $post['ID_nl'] : $post['ID_fr'];
|
||||
$current_lang_id = $currentLang === 'nl' ? $post['ID_nl'] : $post['ID_fr'];
|
||||
|
||||
$choices[] = [
|
||||
'title' => get_the_title($id),
|
||||
'text' => get_the_title($id),
|
||||
'ID' => $id,
|
||||
'title' => get_the_title($current_lang_id),
|
||||
'text' => get_the_title($current_lang_id),
|
||||
'ID_fr' => $post['ID_nl'],
|
||||
'ID_nl' => $post['ID_fr'],
|
||||
];
|
||||
}
|
||||
$this->choices = $choices;
|
||||
|
|
@ -98,9 +100,22 @@ if (class_exists('GF_Field')) {
|
|||
$counter = 0;
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,21 +9,19 @@ if (class_exists('GF_Field')) {
|
|||
private function buildChoicesArray()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
$ID_related_fiche_info_fr = 6538;
|
||||
$ID_related_fiche_info_nl = 6541;
|
||||
$ID_FR = 6538;
|
||||
$ID_NL = 6541;
|
||||
|
||||
$currentLang = apply_filters('wpml_current_language', null);
|
||||
$current_lang_id = apply_filters('wpml_object_id', $ID_FR, 'post', false, $currentLang);
|
||||
|
||||
$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;
|
||||
$document_pdf = get_field('brochure_pdf', $current_lang_id);
|
||||
|
||||
$choices[] = [
|
||||
'title' => $document_pdf['title'],
|
||||
'text' => $document_pdf['title'],
|
||||
'ID' => $document_ID,
|
||||
'ID_fr' => $ID_FR,
|
||||
'ID_nl' => $ID_NL,
|
||||
];
|
||||
|
||||
$this->choices = $choices;
|
||||
|
|
@ -86,9 +84,21 @@ if (class_exists('GF_Field')) {
|
|||
$counter = 0;
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
?>
|
||||
|
||||
<fieldset class="field-order-paper-publications">
|
||||
<?php
|
||||
?>
|
||||
<?php foreach ($this->choices as $index => $brochurePost) : ?>
|
||||
<?php
|
||||
|
||||
$thematique = getPostMainThematique($brochurePost['ID']);
|
||||
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id);
|
||||
$brochure_pdf_link = get_field('brochure_pdf', $brochurePost['ID']);
|
||||
|
|
@ -28,6 +27,12 @@
|
|||
|
||||
<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">
|
||||
<?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">
|
||||
<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 . '[]' ?>" />
|
||||
|
|
@ -36,7 +41,8 @@
|
|||
<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 . '[]' ?>" />
|
||||
</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>
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,20 @@
|
|||
<?php foreach ($otherPublicationsArray as $index => $document) : ?>
|
||||
|
||||
<?php
|
||||
// write_log($document);
|
||||
?>
|
||||
<?php
|
||||
$ID_FR = $document['ID_fr'];
|
||||
$ID_NL = $document['ID_nl'];
|
||||
|
||||
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
|
||||
$documentPost = get_post($document['ID']);
|
||||
$metadata = wp_get_attachment_metadata($document['ID']);
|
||||
$current_lang = apply_filters('wpml_current_language', null);
|
||||
$current_lang_id = $current_lang === 'nl' ? $ID_NL : $ID_FR;
|
||||
|
||||
$documentPost = get_post($current_lang_id);
|
||||
|
||||
$metadata = wp_get_attachment_metadata($current_lang_id);
|
||||
|
||||
?>
|
||||
|
||||
<div class=" gchoice brochure-order-field">
|
||||
|
|
@ -27,8 +38,9 @@
|
|||
</p>
|
||||
</div>
|
||||
<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($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
|
||||
<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>
|
||||
<div class="inputs-container">
|
||||
|
||||
<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>
|
||||
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
|
||||
|
|
@ -37,6 +49,8 @@
|
|||
<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 . '[]' ?>" />
|
||||
</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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user