From 396831c4a53af5d8d43d762ee464356502cfaec0 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 31 Jan 2024 19:44:37 +0100 Subject: [PATCH] introducing api features --- functions.php | 2 + includes/api.php | 112 ++++++++++++++++++++++++++++++++++ resources/css/admin-style.css | 55 ++++++++++++++++- 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 includes/api.php diff --git a/functions.php b/functions.php index f3b9089..a366752 100644 --- a/functions.php +++ b/functions.php @@ -6,6 +6,8 @@ require_once(__DIR__ . '/includes/blocks.php'); require_once(__DIR__ . '/includes/post_types.php'); require_once(__DIR__ . '/includes/admin.php'); require_once(__DIR__ . '/includes/logos.php'); +require_once(__DIR__ . '/includes/api.php'); +require_once(__DIR__ . '/includes/dashboard.php'); // require_once(__DIR__ . '/includes/widget.php'); // require_once( __DIR__ . '/includes/taxonomy.php'); diff --git a/includes/api.php b/includes/api.php new file mode 100644 index 0000000..10c15b6 --- /dev/null +++ b/includes/api.php @@ -0,0 +1,112 @@ + 'GET', + 'callback' => 'get_interface_welcome_screen', + 'permission_callback' => '__return_true', + + )); + + // ################ POST ################ + register_rest_route('lhoist-datas/statistics', '/post', array( + 'methods' => 'POST', + 'callback' => 'wp_learn_create_database_table', + 'permission_callback' => 'lhoist_datas_permission_callback', + + )); +}); +function wp_learn_create_database_table(WP_REST_Request $request) +{ + $data = $request->get_json_params(); // Récupération des données envoyées avec la requête POST + $user_name = $data['user_name'] ?? null; + $user_locale = $data['user_locale'] ?? null; + $user_country = $data['user_country'] ?? null; + $level_post_id = $data['level_post_id'] ?? null; + $level_is_completed = $data['level_is_completed'] ?? null; + $level_completion_time = $data['level_completion_time'] ?? null; + $level_score = $data['level_score'] ?? null; + + if (!$data) { + return rest_ensure_response(array('success' => false, 'message' => 'Erreur lors de l\'enregistrement des données.')); + exit; + } + + global $wpdb; + + $table_name = 'wp_app_users_statistics'; + $post_id = uniqid(); + write_log("user_locale : " . $user_locale); + + $result_check = $wpdb->insert( + $table_name, + array( + 'session_ID' => $post_id, + 'user_name' => $user_name, + 'user_locale' => $user_locale, + 'user_country' => $user_country, + 'level_post_id' => $level_post_id, + 'level_is_completed' => $level_is_completed, + 'level_completion_time' => $level_completion_time, + 'level_score' => $level_score, + + ) + ); + + if ($result_check) { + return rest_ensure_response(array('success' => true, 'message' => 'Données enregistrées avec succès.')); + } else { + return rest_ensure_response(array('success' => false, 'message' => 'Erreur lors de l\'enregistrement des données.')); + } +} + +function lhoist_datas_permission_callback() +{ + if (is_user_logged_in() && current_user_can('administrator')) { + return true; + } + return false; +} + + +// ################ WELCOME SCREEN ################ + +function get_interface_welcome_screen($request) +{ + // $language = sanitize_text_field($request['language']); + $currentLanguage = $request->get_param('current-page-language') ?? 'fr'; + + + $option_id = icl_object_id('option_id', 'option', false, $currentLanguage); + + do_action('wpml_switch_language', $currentLanguage); + function acf_set_language() + { + return apply_filters('wpml_current_language', null); + } + add_filter('acf/settings/current_language', 'acf_set_language'); + $args = array( + 'post_type' => 'search-and-find', + 'posts_per_page' => -1, + ); + $posts = new WP_Query($args); + + $applicationTitle = get_field('application_title', 'option'); + $applicationSubtitle = get_field('application_subtitle', 'option'); + $applicationDescription = get_field('application_description', 'option'); + // write_log("current language : " . $currentLanguage); + // write_log($posts->posts[0]->post_title); + // write_log($applicationDescription); + + $response_data = array( + 'applicationTitle' => $applicationTitle, + 'applicationSubtitle' => $applicationSubtitle, + 'applicationDescription' => $applicationDescription, + ); + + $response = new WP_REST_Response($response_data); + $response->set_status(200); + + return $response; +} diff --git a/resources/css/admin-style.css b/resources/css/admin-style.css index 49c6001..8cc1edf 100644 --- a/resources/css/admin-style.css +++ b/resources/css/admin-style.css @@ -2,5 +2,58 @@ background: red !important; } */ #menu-posts { - border-top: 1px solid rgba(255, 255, 255, 0.2) !important; + border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} +h1, +h2, +h3, +h4, +h5, +h6 { + font-size: revert; + font-weight: revert; +} + +#menu-posts-search-and-find { + margin-bottom: 12px !important; + padding-bottom: 8px !important; + border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important; +} + +#toplevel_page_theme-general-settings { + margin-top: 12px !important; + padding-top: 8px !important; + padding-bottom: 0px !important; + border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} + +.toplevel_page_session-datas-options { + /* @apply bg-white; */ +} +.wrap { + .page-title { + @apply text-5xl font-semibold text-neutral-800 pb-16; + } + @apply py-12 text-base max-w-screen-xl mx-auto px-4; + p, + li { + @apply text-lg; + } + h2 { + @apply text-blue-700 font-medium text-2xl my-0; + } + h3 { + @apply font-medium text-blue-500 my-0; + } + + .geography, + .game { + @apply grid grid-cols-2 overflow-hidden; + } + .section-title { + @apply col-span-2 mb-4; + } + .data-label { + @apply font-semibold; + } }