modifying permissions to allow simple user to see stats
This commit is contained in:
parent
b710fcd5fd
commit
2e236f4653
|
|
@ -10,6 +10,7 @@ require_once(__DIR__ . '/includes/logos.php');
|
|||
require_once(__DIR__ . '/includes/api.php');
|
||||
require_once(__DIR__ . '/includes/statistics-page.php');
|
||||
require_once(__DIR__ . '/includes/search-find.php');
|
||||
require_once(__DIR__ . '/includes/permissions.php');
|
||||
|
||||
// require_once(__DIR__ . '/includes/widget.php');
|
||||
// require_once( __DIR__ . '/includes/taxonomy.php');
|
||||
|
|
|
|||
8
includes/permissions.php
Normal file
8
includes/permissions.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?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(
|
||||
'Statistiques des jeux',
|
||||
'Statistiques des jeux',
|
||||
'manage_options',
|
||||
'read',
|
||||
'session-datas-options',
|
||||
'render_statistics_option_page',
|
||||
'dashicons-chart-area'
|
||||
|
|
@ -46,7 +46,7 @@ add_action('admin_post_nopriv_download_pdf', 'handle_download_pdf_request');
|
|||
function handle_download_pdf_request()
|
||||
{
|
||||
// Vérifier les autorisations ou les conditions nécessaires
|
||||
if (!current_user_can('manage_options')) {
|
||||
if (!current_user_can('read')) {
|
||||
wp_die('Access Denied');
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ add_action('admin_post_nopriv_export_csv', 'handle_export_csv_request');
|
|||
function handle_export_csv_request()
|
||||
{
|
||||
// Vérifier les autorisations ou les conditions nécessaires
|
||||
if (!current_user_can('manage_options')) {
|
||||
if (!current_user_can('read')) {
|
||||
wp_die('Access Denied');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,107 +1,7 @@
|
|||
import Chart from 'chart.js/auto';
|
||||
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
||||
|
||||
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) {
|
||||
function buildLevelDataCharts(level) {
|
||||
const scoreDistribution = level.querySelectorAll(
|
||||
'.game_stats__scores-distribution .score-data'
|
||||
);
|
||||
|
|
@ -113,15 +13,6 @@ function buildDataChart2(level) {
|
|||
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 = [
|
||||
['#1d4ed8', '#3b82f6', '#60a5fa', '#93c5fd', '#c3dafe'],
|
||||
['#1d4ed8', '#3c67dc', '#5b81e0', '#7a9be3', '#99b5e7'],
|
||||
|
|
@ -189,25 +80,90 @@ function buildDataChart2(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) => {
|
||||
const levels = document.querySelectorAll('.game_stats');
|
||||
levels.forEach((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);
|
||||
buildLevelDataCharts(level);
|
||||
});
|
||||
buildRatingsDataChart();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
if (!current_user_can('manage_options')) return;
|
||||
// if (!current_user_can('manage_options')) return;
|
||||
|
||||
global $wpdb;
|
||||
$table_name = "wp_app_users_statistics";
|
||||
|
|
@ -11,9 +11,14 @@ $level_post_ids = $wpdb->get_col("
|
|||
");
|
||||
|
||||
?>
|
||||
<div class="page-sessions-datas">
|
||||
<h1 class="page-title"><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||
|
||||
|
||||
<div class="page-sessions-datas">
|
||||
|
||||
|
||||
|
||||
|
||||
<?php foreach ($level_post_ids as $level_post_id) : ?>
|
||||
<?php $levelPost = get_post($level_post_id); ?>
|
||||
|
||||
|
|
@ -64,7 +69,6 @@ $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" />
|
||||
</svg>
|
||||
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
||||
<!-- <div class="donut-average"></div> -->
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
@ -113,9 +117,7 @@ $level_post_ids = $wpdb->get_col("
|
|||
</section>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
|
||||
<section class="rating_stats">
|
||||
<?php
|
||||
$ratings_table_name = "wp_app_ratings";
|
||||
$ratings = $wpdb->get_results("
|
||||
|
|
@ -123,13 +125,42 @@ $level_post_ids = $wpdb->get_col("
|
|||
FROM $ratings_table_name
|
||||
GROUP BY rating
|
||||
");
|
||||
|
||||
// echo '<pre>';
|
||||
// print_r($ratings);
|
||||
// echo '</pre>';
|
||||
$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>
|
||||
|
||||
|
||||
<section class="ratings">
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user