Created
August 21, 2015 01:12
-
-
Save aiiddqd/9e4e61d58a8ebf1d7882 to your computer and use it in GitHub Desktop.
Отчет с кросстабуляцией для свода таблицы
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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