diff --git a/includes/forms.php b/includes/forms.php index 2318217..d2dbc0c 100644 --- a/includes/forms.php +++ b/includes/forms.php @@ -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); +} diff --git a/includes/forms/export-paper-publication-entries.php b/includes/forms/export-paper-publication-entries.php index 1c2e040..504fa46 100644 --- a/includes/forms/export-paper-publication-entries.php +++ b/includes/forms/export-paper-publication-entries.php @@ -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.'; - // } } diff --git a/includes/forms/field-OrderBrochureList.php b/includes/forms/field-OrderBrochureList.php index d3d8c55..3cd60af 100644 --- a/includes/forms/field-OrderBrochureList.php +++ b/includes/forms/field-OrderBrochureList.php @@ -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; } diff --git a/includes/forms/field-OrderDocumentsList.php b/includes/forms/field-OrderDocumentsList.php index 8ee2286..cd64245 100644 --- a/includes/forms/field-OrderDocumentsList.php +++ b/includes/forms/field-OrderDocumentsList.php @@ -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; } diff --git a/includes/forms/field-OrderSynthese.php b/includes/forms/field-OrderSynthese.php index bf50d87..a7687e7 100644 --- a/includes/forms/field-OrderSynthese.php +++ b/includes/forms/field-OrderSynthese.php @@ -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; } diff --git a/includes/forms/template-field-order-brochures.php b/includes/forms/template-field-order-brochures.php index bb0e741..2bfc33b 100644 --- a/includes/forms/template-field-order-brochures.php +++ b/includes/forms/template-field-order-brochures.php @@ -4,10 +4,9 @@ ?>