function support_charts_build_graph in Support Ticketing System 6
Same name and namespace in other branches
- 7 support_charts/support_charts.module \support_charts_build_graph()
Gather data and build a chart API structure.
Return value
array chart API structure.
1 call to support_charts_build_graph()
- support_charts_display in support_charts/
support_charts.module - Display charts and content in context to the current page.
File
- support_charts/
support_charts.module, line 241 - Support charting. @author Jeremy Andrews <jeremy@tag1consulting.com> @package Support
Code
function support_charts_build_graph($id, $type = 'global', $object = NULL) {
$chart = array();
$chart['#type'] = CHART_TYPE_LINE;
$chart['#size'] = chart_size(620, 250);
$chart['#grid_lines'] = chart_grid_lines(25, 9.5, 1, 3);
$chart['#adjust_resolution'] = TRUE;
$now = isset($_GET['year']) && isset($_GET['month']) ? mktime(0, 0, 0, $_GET['month'], 30, $_GET['year']) : time();
switch ($id) {
case 'tickets_created':
if ($type == 'user') {
$chart['#title'] = chart_title(t('Tickets created by !user in !date', array(
'!date' => date('F Y', $now),
'!user' => check_plain($object->name),
)));
$filter = "AND n.uid = {$object->uid}";
}
else {
$chart['#title'] = chart_title(t('Tickets created in !date', array(
'!date' => date('F Y', $now),
)));
$filter = '';
}
$chart['#chart_id'] = $id;
$result = db_query("SELECT n.created AS timestamp FROM {node} n WHERE n.type = 'support_ticket' AND n.created < %d AND n.created > %d {$filter} ORDER BY n.created", $now, mktime(0, 0, 0, date('m', $now), 1, date('Y', $now)));
break;
case 'tickets_updated':
if ($type == 'user') {
$chart['#title'] = chart_title(t('Tickets updated by !user in !date', array(
'!date' => date('F Y', $now),
'!user' => check_plain($object->name),
)));
$filter = "AND n.uid = {$object->uid}";
}
else {
$chart['#title'] = chart_title(t('Tickets updated in !date', array(
'!date' => date('F Y', $now),
)));
$filter = '';
}
$chart['#chart_id'] = $id;
$time = mktime(0, 0, 0, date('m', $now), 1, date('Y', $now));
$result = db_query("SELECT GREATEST(n.changed, l.last_comment_timestamp) AS timestamp FROM {node} n LEFT JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'support_ticket' AND (n.changed < %d OR l.last_comment_timestamp < %d) AND (n.changed > %d OR l.last_comment_timestamp > %d) {$filter} ORDER BY timestamp", $now, $now, $time, $time);
break;
case 'tickets_closed':
if ($type == 'user') {
$chart['#title'] = chart_title(t('Tickets closed by !user in !date', array(
'!date' => date('F Y', $now),
'!user' => check_plain($object->name),
)));
$filter = "AND n.uid = {$object->uid}";
}
else {
$chart['#title'] = chart_title(t('Tickets closed in !date', array(
'!date' => date('F Y', $now),
)));
$filter = '';
}
$chart['#chart_id'] = $id;
$time = mktime(0, 0, 0, date('m', $now), 1, date('Y', $now));
$result = db_query("SELECT GREATEST(n.changed, l.last_comment_timestamp) AS timestamp FROM {node} n LEFT JOIN {node_comment_statistics} l ON n.nid = l.nid LEFT JOIN {support_ticket} t ON n.nid = t.nid LEFT JOIN {support_states} s ON t.state = s.sid WHERE s.isclosed = 1 AND n.type = 'support_ticket' AND (n.changed < %d OR l.last_comment_timestamp < %d) AND (n.changed > %d OR l.last_comment_timestamp > %d) {$filter} ORDER BY timestamp", $now, $now, $time, $time);
break;
}
$max = array();
$counts = array();
$types = array();
while ($data = db_fetch_object($result)) {
$day = ltrim(date('d', $data->timestamp), '0');
$types[$type] = $type;
$counts[$day][$type]++;
$max[$type]++;
}
// Generate data and labels
if (count($counts) && count($types)) {
for ($i = 0; $i <= date('d', $now); $i++) {
$chart['#labels'][] = $i;
foreach ($types as $type) {
if ($counts[$i][$type]) {
$chart['#data'][$type][] = $counts[$i][$type];
}
else {
$chart['#data'][$type][] = '0';
}
}
}
}
// Data colors, legends, line styles, and labels
if (count($types)) {
foreach ($types as $type) {
$chart['#data_colors'][] = chart_unique_color($type);
$chart['#legends'][] = $type;
$chart['#line_styles'][] = chart_line_style(2);
}
}
$max = count($max) ? max($max) : 0;
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0, $max);
return chart_render($chart);
}