Skip to content

Instantly share code, notes, and snippets.

@uptimizt
Created August 21, 2015 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uptimizt/9e4e61d58a8ebf1d7882 to your computer and use it in GitHub Desktop.
Save uptimizt/9e4e61d58a8ebf1d7882 to your computer and use it in GitHub Desktop.
Отчет с кросстабуляцией для свода таблицы
<?php
//Проверяем наличие комментария о нарушении срока
$cases = get_posts(array(
'post_type' => 'cases',
'numberposts' => 333,
'tax_query' => array(
array(
'taxonomy' => 'functions',
'field' => 'slug',
'terms' => array( 'zakazy' ),
),
),
));
//Создаем массив и помещаем туда данные комментов
$data = array();
foreach($cases as $case):
//Если пользователь не относится к списку, то пропуск
//if(! in_array($case->post_author, array(52, 68, 3))) continue;
$day = date_format(date_create($case->post_date),'Y-m-d');
$week = date_format(date_create($case->post_date),'W');
$month = date_format(date_create($case->post_date),'Y-m');
$year = date_format(date_create($case->post_date),'Y');
//if($year < 2014) continue;
$term = wp_get_post_terms(
$case->ID,
'functions',
array('fields' => 'names')
);
if($term[0]) {
$cat = $term[0];
} else {
$cat = 'Отсутствует';
}
$user = get_userdata($case->post_author);
$sum = get_post_meta($case->ID, 'sum', true);
$data[] = array(
'day' => $day,
'week' => $week,
'month'=> $month,
'user_id' => $case->post_author,
'name' => $cat,
'c_id' => $case->ID,
'sum' => $sum,
);
endforeach;
$pivot_table = array_pivot_s($src_array = $data, $d_col = 'sum', $d_method = 'sum', $h_col = 'name', $v_col = 'month');
?>
<div id="chart_div" style="height: 555px;"></div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($pivot_table)?>);
var options = {
vAxis: {minValue: 0},
isStacked: true,
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment