passing country names in english when exports game datas to csv
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Antoine M 2024-10-14 14:55:35 +02:00
parent 25ab5d7aaf
commit 951f30e56e
2 changed files with 7940 additions and 2 deletions

7915
includes/countries.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -109,10 +109,29 @@ function handle_export_csv_request()
}
//##### Fonction pour obtenir le nom anglais du pays
function getCountryNameInEnglish($countryName, $countryDatas)
{
foreach ($countryDatas as $key => $countryData) {
if (strtolower($countryName) === strtolower($countryData['fr'])) {
return $countryData['en'];
}
continue;
}
return $countryName;
}
function export_data_to_csv()
{
global $wpdb;
$table_name = "wp_app_users_statistics";
$jsonFilePath = __DIR__ . '/countries.json';
if (file_exists($jsonFilePath)) {
$jsonContents = file_get_contents($jsonFilePath);
$countryDatas = json_decode($jsonContents, true);
}
// Récupérer les données de la base de données
$data = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A);
@ -132,9 +151,13 @@ function export_data_to_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;
foreach ($data as $row) {;
$countryName = $row["user_country"] ?? '';
if (isset($row["user_country"])) {
$countryName = getCountryNameInEnglish($row["user_country"], $countryDatas);
}
$row["user_country"] = $countryName;
fputcsv($file, $row);
}