Compare commits
No commits in common. "3b729f075b8a13597693d76eba5f2421e927a63d" and "fa74b1f50cd15877e6caff34ae1c9db36638ba03" have entirely different histories.
3b729f075b
...
fa74b1f50c
39
.drone.yml
39
.drone.yml
|
|
@ -1,39 +0,0 @@
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: ssh
|
|
||||||
name: Stay Safe | Back-End | Pipeline de déploiement
|
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
# DATAS DU SERVEUR DE BUILD
|
|
||||||
server:
|
|
||||||
host:
|
|
||||||
from_secret: build_server_host
|
|
||||||
user:
|
|
||||||
from_secret: build_server_user
|
|
||||||
password:
|
|
||||||
from_secret: build_server_password
|
|
||||||
steps:
|
|
||||||
- name: Clonage du Repo
|
|
||||||
commands:
|
|
||||||
- git clone https://git.deligraph.be/Antoine/lhoist-stay-safe__backend-theme.git
|
|
||||||
- name: Installation du package
|
|
||||||
commands:
|
|
||||||
- cd lhoist-stay-safe__backend-theme
|
|
||||||
- npm install
|
|
||||||
- name: Build du package
|
|
||||||
commands:
|
|
||||||
- cd lhoist-stay-safe__backend-theme
|
|
||||||
- npm run production
|
|
||||||
- name: Déploiement sur le serveur de prod
|
|
||||||
environment:
|
|
||||||
PROD_SERVER_PATH:
|
|
||||||
from_secret: prod_server_path
|
|
||||||
PROD_SERVER_PASSWORD:
|
|
||||||
from_secret: prod_server_password
|
|
||||||
PROD_SERVER_THEME_PATH:
|
|
||||||
from_secret: prod_server_theme_path
|
|
||||||
commands:
|
|
||||||
- cd lhoist-stay-safe__backend-theme
|
|
||||||
- rsync -avhpn -e 'ssh -p 22' ./ $PROD_SERVER_PATH:~/back/wp-content/themes/Deligraph_lhoist --delete
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once(__DIR__ . '/includes/errorlog.php');
|
require_once(__DIR__ . '/includes/errorlog.php');
|
||||||
require_once(__DIR__ . '/includes/utilities.php');
|
|
||||||
require_once(__DIR__ . '/includes/init.php');
|
require_once(__DIR__ . '/includes/init.php');
|
||||||
require_once(__DIR__ . '/includes/blocks.php');
|
require_once(__DIR__ . '/includes/blocks.php');
|
||||||
require_once(__DIR__ . '/includes/post_types.php');
|
require_once(__DIR__ . '/includes/post_types.php');
|
||||||
|
|
@ -10,7 +9,6 @@ require_once(__DIR__ . '/includes/logos.php');
|
||||||
require_once(__DIR__ . '/includes/api.php');
|
require_once(__DIR__ . '/includes/api.php');
|
||||||
require_once(__DIR__ . '/includes/statistics-page.php');
|
require_once(__DIR__ . '/includes/statistics-page.php');
|
||||||
require_once(__DIR__ . '/includes/search-find.php');
|
require_once(__DIR__ . '/includes/search-find.php');
|
||||||
require_once(__DIR__ . '/includes/permissions.php');
|
|
||||||
|
|
||||||
// require_once(__DIR__ . '/includes/widget.php');
|
// require_once(__DIR__ . '/includes/widget.php');
|
||||||
// require_once( __DIR__ . '/includes/taxonomy.php');
|
// require_once( __DIR__ . '/includes/taxonomy.php');
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,10 @@ function lhoist_datas_permission_callback(
|
||||||
$origin = $request->get_header('origin');
|
$origin = $request->get_header('origin');
|
||||||
$referer = $request->get_header('referer');
|
$referer = $request->get_header('referer');
|
||||||
|
|
||||||
// $isLocalHost = $origin === 'http://localhost:3000' && $referer === 'http://localhost:3000/';
|
$isLocalHost = $origin === 'http://localhost:3000' && $referer === 'http://localhost:3000/';
|
||||||
// $isVercelApp = $origin === 'https://lhoist-stay-safe.vercel.app' && $referer === 'https://lhoist-stay-safe.vercel.app/';
|
$isVercelApp = $origin === 'https://lhoist-stay-safe.vercel.app' && $referer === 'https://lhoist-stay-safe.vercel.app/';
|
||||||
$isFrontEndApp = $origin === 'https://stay-safe-lhoist.com' && $referer === 'https://stay-safe-lhoist.com/';
|
|
||||||
|
|
||||||
|
if ($isVercelApp || $isLocalHost) {
|
||||||
if ($isFrontEndApp) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -67,12 +65,6 @@ function get_latest_game_datas($request)
|
||||||
{
|
{
|
||||||
// $language = sanitize_text_field($request['language']);
|
// $language = sanitize_text_field($request['language']);
|
||||||
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
||||||
if ($currentLanguage === "my") {
|
|
||||||
$currentLanguage = "ms";
|
|
||||||
}
|
|
||||||
if ($currentLanguage === "pt") {
|
|
||||||
$currentLanguage = "pt-pt";
|
|
||||||
}
|
|
||||||
|
|
||||||
// SWITCH TO CURRENT REQUEST LANGUAGE
|
// SWITCH TO CURRENT REQUEST LANGUAGE
|
||||||
do_action('wpml_switch_language', $currentLanguage);
|
do_action('wpml_switch_language', $currentLanguage);
|
||||||
|
|
@ -123,12 +115,6 @@ function get_game_datas($request)
|
||||||
{
|
{
|
||||||
$id = $request->get_param('id');
|
$id = $request->get_param('id');
|
||||||
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
||||||
if ($currentLanguage === "my") {
|
|
||||||
$currentLanguage = "ms";
|
|
||||||
}
|
|
||||||
if ($currentLanguage === "pt") {
|
|
||||||
$currentLanguage = "pt-pt";
|
|
||||||
}
|
|
||||||
|
|
||||||
// SWITCH TO CURRENT REQUEST LANGUAGE
|
// SWITCH TO CURRENT REQUEST LANGUAGE
|
||||||
do_action('wpml_switch_language', $currentLanguage);
|
do_action('wpml_switch_language', $currentLanguage);
|
||||||
|
|
@ -170,12 +156,7 @@ function get_all_games_datas($request)
|
||||||
|
|
||||||
|
|
||||||
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
||||||
if ($currentLanguage === "my") {
|
|
||||||
$currentLanguage = "ms";
|
|
||||||
}
|
|
||||||
if ($currentLanguage === "pt") {
|
|
||||||
$currentLanguage = "pt-pt";
|
|
||||||
}
|
|
||||||
// SWITCH TO CURRENT REQUEST LANGUAGE
|
// SWITCH TO CURRENT REQUEST LANGUAGE
|
||||||
do_action('wpml_switch_language', $currentLanguage);
|
do_action('wpml_switch_language', $currentLanguage);
|
||||||
add_filter('acf/settings/current_language', 'acf_set_language');
|
add_filter('acf/settings/current_language', 'acf_set_language');
|
||||||
|
|
@ -190,6 +171,7 @@ function get_all_games_datas($request)
|
||||||
if (!$searchAndFindsQuery->post) {
|
if (!$searchAndFindsQuery->post) {
|
||||||
do_action('wpml_switch_language', "fr");
|
do_action('wpml_switch_language', "fr");
|
||||||
$searchAndFindsQuery = new WP_Query($args);
|
$searchAndFindsQuery = new WP_Query($args);
|
||||||
|
write_log("passed");
|
||||||
}
|
}
|
||||||
|
|
||||||
$gamesDatas = array();
|
$gamesDatas = array();
|
||||||
|
|
@ -234,12 +216,7 @@ function get_interface_page_screen($request)
|
||||||
|
|
||||||
$id = $request->get_param('id');
|
$id = $request->get_param('id');
|
||||||
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
$currentLanguage = strtolower($request->get_param('current-language')) ?? 'fr';
|
||||||
if ($currentLanguage === "my") {
|
|
||||||
$currentLanguage = "ms";
|
|
||||||
}
|
|
||||||
if ($currentLanguage === "pt") {
|
|
||||||
$currentLanguage = "pt-pt";
|
|
||||||
}
|
|
||||||
// SWITCH TO CURRENT REQUEST LANGUAGE
|
// SWITCH TO CURRENT REQUEST LANGUAGE
|
||||||
do_action('wpml_switch_language', $currentLanguage);
|
do_action('wpml_switch_language', $currentLanguage);
|
||||||
|
|
||||||
|
|
@ -257,7 +234,6 @@ function get_interface_page_screen($request)
|
||||||
|
|
||||||
// ################ POST GAME STATISTICS ################
|
// ################ POST GAME STATISTICS ################
|
||||||
|
|
||||||
|
|
||||||
function lhoist_sanitize_statistic_datas($datas)
|
function lhoist_sanitize_statistic_datas($datas)
|
||||||
{
|
{
|
||||||
$cleanDatas = array();
|
$cleanDatas = array();
|
||||||
|
|
@ -265,7 +241,6 @@ function lhoist_sanitize_statistic_datas($datas)
|
||||||
$cleanDatas['user_locale'] = isset($datas['user_locale']) ? sanitize_text_field($datas['user_locale']) : null;
|
$cleanDatas['user_locale'] = isset($datas['user_locale']) ? sanitize_text_field($datas['user_locale']) : null;
|
||||||
$cleanDatas['user_country'] = isset($datas['user_country']) ? sanitize_text_field($datas['user_country']) : null;
|
$cleanDatas['user_country'] = isset($datas['user_country']) ? sanitize_text_field($datas['user_country']) : null;
|
||||||
$cleanDatas['level_post_id'] = isset($datas['level_post_id']) ? (int) $datas['level_post_id'] : null;
|
$cleanDatas['level_post_id'] = isset($datas['level_post_id']) ? (int) $datas['level_post_id'] : null;
|
||||||
$cleanDatas['level_name'] = isset($datas['level_name']) ? sanitize_text_field($datas['level_name']) : null;
|
|
||||||
$cleanDatas['level_score'] = isset($datas['level_score']) ? (int) $datas['level_score'] : null;
|
$cleanDatas['level_score'] = isset($datas['level_score']) ? (int) $datas['level_score'] : null;
|
||||||
$cleanDatas['level_completion_time'] = isset($datas['level_completion_time']) ? (int) $datas['level_completion_time'] : null;
|
$cleanDatas['level_completion_time'] = isset($datas['level_completion_time']) ? (int) $datas['level_completion_time'] : null;
|
||||||
|
|
||||||
|
|
@ -295,25 +270,28 @@ function lhoist_check_statistics_datas_formats($datas)
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function lhoist_convert_post_id($id)
|
|
||||||
{
|
|
||||||
$convertedId = apply_filters('wpml_object_id', $id, 'search-and-find', true);
|
|
||||||
return $convertedId;
|
|
||||||
}
|
|
||||||
|
|
||||||
function lhoist_post_game_datas_statistics(WP_REST_Request $request)
|
function lhoist_post_game_datas_statistics(WP_REST_Request $request)
|
||||||
{
|
{
|
||||||
$datas = $request->get_json_params();
|
$datas = $request->get_json_params();
|
||||||
|
|
||||||
$datas['level_post_id'] = lhoist_convert_post_id($datas['level_post_id']);
|
|
||||||
$datas['level_name'] = html_entity_decode(get_the_title($datas['level_post_id']), ENT_QUOTES, 'UTF-8');
|
|
||||||
|
|
||||||
$cleanDatas = lhoist_sanitize_statistic_datas($datas);
|
$cleanDatas = lhoist_sanitize_statistic_datas($datas);
|
||||||
lhoist_check_statistics_datas_formats($cleanDatas);
|
lhoist_check_statistics_datas_formats($cleanDatas);
|
||||||
|
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
$datetime = new DateTime("now", new DateTimeZone('Europe/Brussels'));
|
||||||
|
|
||||||
|
$gameStats = array(
|
||||||
|
'session_ID' => "qsdqsdqsdqsd",
|
||||||
|
'user_locale' => "FR",
|
||||||
|
'user_country' => "France",
|
||||||
|
'level_post_id' => 43,
|
||||||
|
'level_is_completed' => $level_is_completed ?? "0",
|
||||||
|
'level_completion_time' => 200,
|
||||||
|
'level_score' => 3,
|
||||||
|
'date' => $datetime->format('Y-m-d H:i:s'),
|
||||||
|
);
|
||||||
$table_name = 'wp_app_users_statistics';
|
$table_name = 'wp_app_users_statistics';
|
||||||
$result_check = $wpdb->insert(
|
$result_check = $wpdb->insert(
|
||||||
$table_name,
|
$table_name,
|
||||||
|
|
@ -360,13 +338,12 @@ function lhoist_post_rating(WP_REST_Request $request)
|
||||||
$cleanDatas = lhoist_sanitize_ratings_datas($datas);
|
$cleanDatas = lhoist_sanitize_ratings_datas($datas);
|
||||||
lhoist_check_ratings_datas_formats($cleanDatas);
|
lhoist_check_ratings_datas_formats($cleanDatas);
|
||||||
|
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$datetime = new DateTime("now", new DateTimeZone('Europe/Brussels'));
|
$datetime = new DateTime("now", new DateTimeZone('Europe/Brussels'));
|
||||||
|
|
||||||
$ratingsDatas = array(
|
$ratingsDatas = array(
|
||||||
'rating' => $cleanDatas['note'],
|
'comment' => "super",
|
||||||
'comment' => $cleanDatas['comment'] ?? '',
|
'rating' => 3,
|
||||||
'date' => $datetime->format('Y-m-d H:i:s'),
|
'date' => $datetime->format('Y-m-d H:i:s'),
|
||||||
);
|
);
|
||||||
$table_name = 'wp_app_ratings';
|
$table_name = 'wp_app_ratings';
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
// function add_custom_capability_to_subscriber()
|
|
||||||
// {
|
|
||||||
// $role = get_role('subscriber');
|
|
||||||
// $role->add_cap('access_custom_options_page');
|
|
||||||
// }
|
|
||||||
// add_action('init', 'add_custom_capability_to_subscriber');
|
|
||||||
|
|
@ -20,7 +20,7 @@ function register_statistics_option_page()
|
||||||
add_menu_page(
|
add_menu_page(
|
||||||
'Statistiques des jeux',
|
'Statistiques des jeux',
|
||||||
'Statistiques des jeux',
|
'Statistiques des jeux',
|
||||||
'read',
|
'manage_options',
|
||||||
'session-datas-options',
|
'session-datas-options',
|
||||||
'render_statistics_option_page',
|
'render_statistics_option_page',
|
||||||
'dashicons-chart-area'
|
'dashicons-chart-area'
|
||||||
|
|
@ -46,7 +46,7 @@ add_action('admin_post_nopriv_download_pdf', 'handle_download_pdf_request');
|
||||||
function handle_download_pdf_request()
|
function handle_download_pdf_request()
|
||||||
{
|
{
|
||||||
// Vérifier les autorisations ou les conditions nécessaires
|
// Vérifier les autorisations ou les conditions nécessaires
|
||||||
if (!current_user_can('read')) {
|
if (!current_user_can('manage_options')) {
|
||||||
wp_die('Access Denied');
|
wp_die('Access Denied');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ function generate_pdf_from_html($html_content, $filename = 'export.pdf')
|
||||||
$pdf->SetKeywords('Keywords');
|
$pdf->SetKeywords('Keywords');
|
||||||
|
|
||||||
// Définir l'en-tête et le pied de page
|
// Définir l'en-tête et le pied de page
|
||||||
$pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, 'Statistiques de jeu ', 'Lhoist Stay safe');
|
$pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, 'Title', 'Header text');
|
||||||
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
|
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
|
||||||
|
|
||||||
// Définir la police
|
// Définir la police
|
||||||
|
|
@ -100,7 +100,7 @@ add_action('admin_post_nopriv_export_csv', 'handle_export_csv_request');
|
||||||
function handle_export_csv_request()
|
function handle_export_csv_request()
|
||||||
{
|
{
|
||||||
// Vérifier les autorisations ou les conditions nécessaires
|
// Vérifier les autorisations ou les conditions nécessaires
|
||||||
if (!current_user_can('read')) {
|
if (!current_user_can('manage_options')) {
|
||||||
wp_die('Access Denied');
|
wp_die('Access Denied');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,8 +133,7 @@ function export_data_to_csv()
|
||||||
|
|
||||||
// É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;
|
$row["level_completion_time"] = $row["level_completion_time"] / 100;
|
||||||
|
|
||||||
fputcsv($file, $row);
|
fputcsv($file, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function format_milliseconds_to_readable_time($timeInSeconds)
|
|
||||||
{
|
|
||||||
// Convert milliseconds to seconds with PHP_ROUND_HALF_UP.
|
|
||||||
$seconds = (int) $timeInSeconds;
|
|
||||||
|
|
||||||
// Calculate hours, minutes, and seconds
|
|
||||||
|
|
||||||
$minutes = floor($seconds / 60);
|
|
||||||
$seconds %= 60;
|
|
||||||
|
|
||||||
// Format the result in "H:i:s" format.(int) $string;
|
|
||||||
$timeFormat = sprintf('%02d:%02d', $minutes, $seconds);
|
|
||||||
|
|
||||||
return $timeFormat;
|
|
||||||
// Output: 00:20:35
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
.dashboard-widget {
|
.dashboard-widget {
|
||||||
@apply pb-12;
|
@apply pb-12;
|
||||||
&__title {
|
&__title {
|
||||||
@apply !text-2xl text-center !font-semibold !text-lhoist;
|
@apply !text-2xl text-center !font-semibold !text-blue-600;
|
||||||
}
|
}
|
||||||
&__preview-picture {
|
&__preview-picture {
|
||||||
@apply !w-full mx-auto my-8;
|
@apply !w-full mx-auto;
|
||||||
max-width: 240px;
|
max-width: 300px;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
&__cta {
|
&__cta {
|
||||||
@apply bg-lhoist text-lg !text-white py-4 px-6 rounded-full block w-fit mx-auto;
|
@apply bg-blue-500 text-lg !text-white py-4 px-6 rounded-full block w-fit mx-auto;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
cusror: pointer;
|
cusror: pointer;
|
||||||
|
|
@ -24,18 +24,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-sessions-datas {
|
.page-sessions-datas {
|
||||||
.game_stats,
|
.game_stats {
|
||||||
.rating_stats {
|
|
||||||
@apply bg-white my-12 !px-16 !py-6;
|
@apply bg-white my-12 !px-16 !py-6;
|
||||||
h2 {
|
|
||||||
@apply text-3xl font-semibold text-neutral-800 mt-0;
|
|
||||||
}
|
|
||||||
h3 {
|
|
||||||
@apply text-blue-600 uppercase font-bold text-base my-0 tracking-widest mb-4;
|
|
||||||
}
|
|
||||||
h4 {
|
|
||||||
@apply font-normal text-lg font-medium text-slate-400 my-0;
|
|
||||||
}
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
.page-title {
|
.page-title {
|
||||||
|
|
@ -44,12 +35,20 @@
|
||||||
&__stats-container {
|
&__stats-container {
|
||||||
@apply grid md:grid-cols-2 gap-16 overflow-hidden;
|
@apply grid md:grid-cols-2 gap-16 overflow-hidden;
|
||||||
}
|
}
|
||||||
|
&__game-title {
|
||||||
|
@apply text-3xl font-semibold text-neutral-800 mt-0;
|
||||||
|
}
|
||||||
&__statistics-section {
|
&__statistics-section {
|
||||||
p,
|
p,
|
||||||
li {
|
li {
|
||||||
@apply text-lg text-slate-600;
|
@apply text-lg text-slate-600;
|
||||||
}
|
}
|
||||||
|
h3 {
|
||||||
|
@apply text-blue-600 uppercase font-bold text-base my-0 tracking-widest mb-4;
|
||||||
|
}
|
||||||
|
h4 {
|
||||||
|
@apply font-normal text-lg font-medium text-slate-400 my-0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__scores-distribution {
|
&__scores-distribution {
|
||||||
|
|
@ -125,15 +124,6 @@
|
||||||
@apply capitalize;
|
@apply capitalize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.rating_stats {
|
|
||||||
@apply grid grid-cols-2;
|
|
||||||
h2 {
|
|
||||||
@apply col-span-2;
|
|
||||||
}
|
|
||||||
.average-score {
|
|
||||||
height: fit-content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.download-btns {
|
.download-btns {
|
||||||
@apply flex flex-col md:flex-row gap-x-12 gap-y-4 justify-center my-12;
|
@apply flex flex-col md:flex-row gap-x-12 gap-y-4 justify-center my-12;
|
||||||
.dowload-stats {
|
.dowload-stats {
|
||||||
|
|
@ -149,12 +139,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-rating-datas {
|
|
||||||
section {
|
|
||||||
@apply bg-white my-12 !px-16 !py-6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#graphic-rating-repartition,
|
|
||||||
#graphic-score-repartition {
|
#graphic-score-repartition {
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
@apply w-fit mt-8;
|
@apply w-fit mt-8;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,107 @@
|
||||||
import Chart from 'chart.js/auto';
|
import Chart from 'chart.js/auto';
|
||||||
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
||||||
|
|
||||||
function buildLevelDataCharts(level) {
|
function buildDataChart(level) {
|
||||||
|
const scoreDistribution = level.querySelectorAll(
|
||||||
|
'.game_stats__scores-distribution .score-data'
|
||||||
|
);
|
||||||
|
const scoreDistributionDataset = [];
|
||||||
|
|
||||||
|
for (const score of scoreDistribution) {
|
||||||
|
scoreDistributionDataset.push({
|
||||||
|
label: '# of Votes',
|
||||||
|
score: score.getAttribute('score') + 'points',
|
||||||
|
count: score.getAttribute('count'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('score', scoreDistribution);
|
||||||
|
// console.log(scoreDistributionDataset);
|
||||||
|
|
||||||
|
const colorPalettes = [
|
||||||
|
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
||||||
|
['#1d4ed8', '#3c67dc', '#5b81e0', '#7a9be3', '#99b5e7'],
|
||||||
|
['#1223C2', '#030E8E', '#3D49C7', '#6D77D0'],
|
||||||
|
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
||||||
|
['#1240a1', '#2e6ee0', '#548bf7', '#81aefd', '#a9d2ff'],
|
||||||
|
['#0a37a8', '#2d65d4', '#5794ff', '#7dbdff', '#a3dcff'],
|
||||||
|
['#1a3d9c', '#4271d9', '#75a7ff', '#9fc5ff', '#c6e2ff'],
|
||||||
|
['#084ba6', '#3a79d6', '#6ba5ff', '#96c3ff', '#badbff'],
|
||||||
|
['#1137a3', '#3267d6', '#5fa3ff', '#8fc1ff', '#b5e0ff'],
|
||||||
|
];
|
||||||
|
|
||||||
|
const dataTruc = {
|
||||||
|
labels: ['Red', 'Blue', 'Yellow'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'My First Dataset',
|
||||||
|
data: [300, 50, 100],
|
||||||
|
backgroundColor: [
|
||||||
|
'rgb(255, 99, 132)',
|
||||||
|
'rgb(54, 162, 235)',
|
||||||
|
'rgb(255, 205, 86)',
|
||||||
|
],
|
||||||
|
hoverOffset: 4,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const data = {
|
||||||
|
labels: ['Red', 'Blue', 'Yellow'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'My First Dataset',
|
||||||
|
data: [300, 50, 100],
|
||||||
|
backgroundColor: [
|
||||||
|
'rgb(255, 99, 132)',
|
||||||
|
'rgb(54, 162, 235)',
|
||||||
|
'rgb(255, 205, 86)',
|
||||||
|
],
|
||||||
|
hoverOffset: 4,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
new Chart(
|
||||||
|
document.getElementById('graphic-score-repartition'),
|
||||||
|
{
|
||||||
|
type: 'doughnut',
|
||||||
|
options: {
|
||||||
|
animation: true,
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 50,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
labels: scoreDistributionDataset.map(
|
||||||
|
(scoreData) => scoreData.score
|
||||||
|
),
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: scoreDistributionDataset.map(
|
||||||
|
(scoreData) => scoreData.count
|
||||||
|
),
|
||||||
|
backgroundColor: colorPalettes[4],
|
||||||
|
data: scoreDistributionDataset.map(
|
||||||
|
(scoreData) => scoreData.score
|
||||||
|
),
|
||||||
|
hoverOffset: 14,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function buildDataChart2(level) {
|
||||||
const scoreDistribution = level.querySelectorAll(
|
const scoreDistribution = level.querySelectorAll(
|
||||||
'.game_stats__scores-distribution .score-data'
|
'.game_stats__scores-distribution .score-data'
|
||||||
);
|
);
|
||||||
|
|
@ -13,6 +113,15 @@ function buildLevelDataCharts(level) {
|
||||||
count: score.getAttribute('count'),
|
count: score.getAttribute('count'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// const data = [
|
||||||
|
// { team: 'Red Jaguars', score: 8 },
|
||||||
|
// { team: 'Blue Barracudas', score: 23 },
|
||||||
|
// { team: 'Green Monkeys', score: 3 },
|
||||||
|
// { team: 'Orange Iguanas', score: 15 },
|
||||||
|
// { team: 'Purple Parrots', score: 7 },
|
||||||
|
// { team: 'Silver Snakes', score: 1 },
|
||||||
|
// ];
|
||||||
|
// console.log('dta', data);
|
||||||
const colorPalettes = [
|
const colorPalettes = [
|
||||||
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
||||||
['#1d4ed8', '#3c67dc', '#5b81e0', '#7a9be3', '#99b5e7'],
|
['#1d4ed8', '#3c67dc', '#5b81e0', '#7a9be3', '#99b5e7'],
|
||||||
|
|
@ -80,90 +189,25 @@ function buildLevelDataCharts(level) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function buildRatingsDataChart() {
|
|
||||||
const ratingDistribution = document.querySelectorAll(
|
|
||||||
'.rating_stats .rating-data'
|
|
||||||
);
|
|
||||||
const ratingDistributionDataset = [];
|
|
||||||
|
|
||||||
for (const rating of ratingDistribution) {
|
|
||||||
ratingDistributionDataset.push({
|
|
||||||
rating: rating.getAttribute('rating'),
|
|
||||||
count: rating.getAttribute('count'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const colorPalettes = [
|
|
||||||
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
|
||||||
['#1d4ed8', '#3c67dc', '#5b81e0', '#7a9be3', '#99b5e7'],
|
|
||||||
['#1223C2', '#030E8E', '#3D49C7', '#6D77D0'],
|
|
||||||
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
|
||||||
['#1240a1', '#2e6ee0', '#548bf7', '#81aefd', '#a9d2ff'],
|
|
||||||
['#0a37a8', '#2d65d4', '#5794ff', '#7dbdff', '#a3dcff'],
|
|
||||||
['#1a3d9c', '#4271d9', '#75a7ff', '#9fc5ff', '#c6e2ff'],
|
|
||||||
['#084ba6', '#3a79d6', '#6ba5ff', '#96c3ff', '#badbff'],
|
|
||||||
['#1137a3', '#3267d6', '#5fa3ff', '#8fc1ff', '#b5e0ff'],
|
|
||||||
];
|
|
||||||
|
|
||||||
// console.log('score', scoreDistributionDataset);
|
|
||||||
new Chart(
|
|
||||||
document.getElementById('graphic-rating-repartition'),
|
|
||||||
{
|
|
||||||
type: 'pie',
|
|
||||||
data: {
|
|
||||||
labels: ratingDistributionDataset.map(
|
|
||||||
(row) => row.rating
|
|
||||||
),
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
backgroundColor: colorPalettes[4],
|
|
||||||
label: 'Nombres de joueurs',
|
|
||||||
data: ratingDistributionDataset.map(
|
|
||||||
(row) => row.count
|
|
||||||
),
|
|
||||||
hoverOffset: 50,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [ChartDataLabels],
|
|
||||||
options: {
|
|
||||||
plugins: {
|
|
||||||
legend: {
|
|
||||||
display: false,
|
|
||||||
position: 'bottom',
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
display: false,
|
|
||||||
text: 'Custom Chart Title',
|
|
||||||
},
|
|
||||||
datalabels: {
|
|
||||||
color: '#fff',
|
|
||||||
anchor: 'center',
|
|
||||||
font: {
|
|
||||||
size: 20,
|
|
||||||
},
|
|
||||||
formatter: (value, context) => {
|
|
||||||
return context.chart.data.labels[
|
|
||||||
context.dataIndex
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
// align: 'center',
|
|
||||||
// offset: 10,
|
|
||||||
// borderWidth: 2,
|
|
||||||
// borderColor: '#fff',
|
|
||||||
// borderRadius: 25,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', (event) => {
|
window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const levels = document.querySelectorAll('.game_stats');
|
const levels = document.querySelectorAll('.game_stats');
|
||||||
levels.forEach((level) => {
|
levels.forEach((level) => {
|
||||||
buildLevelDataCharts(level);
|
buildDataChart2(level);
|
||||||
|
// function updatePercentage(percentage) {
|
||||||
|
// const overlay = document.querySelector(
|
||||||
|
// '.donut-chart__overlay'
|
||||||
|
// );
|
||||||
|
// const text = document.querySelector(
|
||||||
|
// '.donut-chart__percentage'
|
||||||
|
// );
|
||||||
|
// overlay.style.transform = `rotate(${
|
||||||
|
// (percentage / 100) * 360
|
||||||
|
// }deg)`;
|
||||||
|
// text.textContent = `${percentage}%`;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Exemple : mettre à jour le pourcentage à 75%
|
||||||
|
// updatePercentage(75);
|
||||||
});
|
});
|
||||||
buildRatingsDataChart();
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// if (!current_user_can('manage_options')) return;
|
if (!current_user_can('manage_options')) return;
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$table_name = "wp_app_users_statistics";
|
$table_name = "wp_app_users_statistics";
|
||||||
|
|
@ -11,13 +11,8 @@ $level_post_ids = $wpdb->get_col("
|
||||||
");
|
");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h1 class="page-title"><?php echo esc_html(get_admin_page_title()); ?></h1>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="page-sessions-datas">
|
<div class="page-sessions-datas">
|
||||||
|
<h1 class="page-title"><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php foreach ($level_post_ids as $level_post_id) : ?>
|
<?php foreach ($level_post_ids as $level_post_id) : ?>
|
||||||
<?php $levelPost = get_post($level_post_id); ?>
|
<?php $levelPost = get_post($level_post_id); ?>
|
||||||
|
|
@ -69,6 +64,7 @@ $level_post_ids = $wpdb->get_col("
|
||||||
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" />
|
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" />
|
||||||
</svg>
|
</svg>
|
||||||
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
||||||
|
<!-- <div class="donut-average"></div> -->
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
@ -117,50 +113,23 @@ $level_post_ids = $wpdb->get_col("
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<section class="rating_stats">
|
|
||||||
<?php
|
|
||||||
$ratings_table_name = "wp_app_ratings";
|
|
||||||
$ratings = $wpdb->get_results("
|
<?php
|
||||||
|
$ratings_table_name = "wp_app_ratings";
|
||||||
|
$ratings = $wpdb->get_results("
|
||||||
SELECT rating, COUNT(rating) as count
|
SELECT rating, COUNT(rating) as count
|
||||||
FROM $ratings_table_name
|
FROM $ratings_table_name
|
||||||
GROUP BY rating
|
GROUP BY rating
|
||||||
");
|
");
|
||||||
$average_app_rating = $wpdb->get_var("
|
|
||||||
SELECT AVG(rating)
|
|
||||||
FROM $ratings_table_name
|
|
||||||
");
|
|
||||||
?>
|
|
||||||
<h2>Répartition des notes de l'app</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <div class="rating_stats__average-score block-data-score"> -->
|
|
||||||
|
|
||||||
<?php if ($average_app_rating) : ?>
|
|
||||||
<div class="average-score">
|
|
||||||
<h3>Note moyenne</h3>
|
|
||||||
<svg viewBox="0 -1 40 40" class="circular-chart">
|
|
||||||
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" />
|
|
||||||
</svg>
|
|
||||||
<p class="text"><?php echo round($average_app_rating, 1) ?></p>
|
|
||||||
<!-- <div class="donut-average"></div> -->
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="repartition_score">
|
|
||||||
<h3>Répartition des notes</h3>
|
|
||||||
<canvas id="graphic-rating-repartition"></canvas>
|
|
||||||
<ul>
|
|
||||||
<li class="rating-data" rating="<?php echo "1" ?>" count="2"><span class="data-label"><?php echo "1" ?></span> : <span class="data-value"><?php echo "2" ?></span> <span class="joueurs">joueurs</span></li>
|
|
||||||
<?php foreach ($ratings as $rating): ?>
|
|
||||||
<li class="rating-data" rating="<?php echo $rating->rating ?>" count="<?php echo $rating->count ?>"><span class="data-label"><?php echo $rating->rating ?></span> : <span class="data-value"><?php echo $rating->count ?></span> <span class="joueurs">joueurs</span></li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<li class="rating-data" rating="<?php echo "2" ?>" count="2"><span class="data-label"><?php echo "2" ?></span> : <span class="data-value"><?php echo "2" ?></span> <span class="joueurs">joueurs</span></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
// echo '<pre>';
|
||||||
|
// print_r($ratings);
|
||||||
|
// echo '</pre>';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<section class="ratings">
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -45,11 +45,6 @@ $level_post_ids = $wpdb->get_col("
|
||||||
FROM $table_name
|
FROM $table_name
|
||||||
WHERE level_post_id = $level_post_id
|
WHERE level_post_id = $level_post_id
|
||||||
");
|
");
|
||||||
$average_level_time = $wpdb->get_var("
|
|
||||||
SELECT AVG(level_completion_time) as average
|
|
||||||
FROM $table_name
|
|
||||||
WHERE level_post_id = $level_post_id
|
|
||||||
");
|
|
||||||
$completeLevelsScores = $wpdb->get_results("
|
$completeLevelsScores = $wpdb->get_results("
|
||||||
SELECT level_score
|
SELECT level_score
|
||||||
FROM $table_name
|
FROM $table_name
|
||||||
|
|
@ -67,20 +62,13 @@ $level_post_ids = $wpdb->get_col("
|
||||||
<div class="average-score">
|
<div class="average-score">
|
||||||
<svg viewBox="0 -1 40 40" class="circular-chart">
|
<svg viewBox="0 -1 40 40" class="circular-chart">
|
||||||
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845
|
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845
|
||||||
a 15.9155 15.9155 0 0 1 0 31.831
|
a 15.9155 15.9155 0 0 1 0 31.831
|
||||||
a 15.9155 15.9155 0 0 1 0 -31.831" />
|
a 15.9155 15.9155 0 0 1 0 -31.831" />
|
||||||
</svg>
|
</svg>
|
||||||
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
||||||
<!-- <div class="donut-average"></div> -->
|
<!-- <div class="donut-average"></div> -->
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<h3>Temps moyen</h3>
|
|
||||||
<?php if ($average_level_time) : ?>
|
|
||||||
<div class="average-time">
|
|
||||||
<p class="text"><?php echo round($average_level_time, 1) ?> secondes</p>
|
|
||||||
<!-- <div class="donut-average"></div> -->
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="game_stats__scores-distribution ">
|
<div class="game_stats__scores-distribution ">
|
||||||
|
|
@ -104,7 +92,7 @@ $level_post_ids = $wpdb->get_col("
|
||||||
<h4>Répartition des langues</h4>
|
<h4>Répartition des langues</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach ($users_locales as $users_locale) : ?>
|
<?php foreach ($users_locales as $users_locale) : ?>
|
||||||
<li><span class="data-label"><?php echo $users_locale->user_locale ?></span> : <?php echo $users_locale->count ?><span class="joueurs">joueurs</span></li>
|
<li><span class="data-label"><?php echo $users_locale->user_locale ?></span> : <?php echo $users_locale->count ?></li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user