passing country names in english when exports game datas to csv
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
25ab5d7aaf
commit
951f30e56e
7915
includes/countries.json
Normal file
7915
includes/countries.json
Normal file
File diff suppressed because it is too large
Load Diff
|
|
@ -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()
|
function export_data_to_csv()
|
||||||
{
|
{
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$table_name = "wp_app_users_statistics";
|
$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
|
// Récupérer les données de la base de données
|
||||||
$data = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A);
|
$data = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A);
|
||||||
|
|
@ -132,9 +151,13 @@ function export_data_to_csv()
|
||||||
fputcsv($file, $header_row);
|
fputcsv($file, $header_row);
|
||||||
|
|
||||||
// Écrire les données dans le fichier CSV
|
// Écrire les données dans le fichier CSV
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {;
|
||||||
// $row["level_completion_time"] = $row["level_completion_time"] / 100;
|
$countryName = $row["user_country"] ?? '';
|
||||||
|
if (isset($row["user_country"])) {
|
||||||
|
$countryName = getCountryNameInEnglish($row["user_country"], $countryDatas);
|
||||||
|
}
|
||||||
|
|
||||||
|
$row["user_country"] = $countryName;
|
||||||
fputcsv($file, $row);
|
fputcsv($file, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user