Skip to content

Instantly share code, notes, and snippets.

@Yemolai
Last active October 24, 2017 15:00
Show Gist options
  • Save Yemolai/55301d775db043b9da623d8a3de63e47 to your computer and use it in GitHub Desktop.
Save Yemolai/55301d775db043b9da623d8a3de63e47 to your computer and use it in GitHub Desktop.
<?php
/**
* This snippet includes a status counting to anywhere you require this
* file and run _stats($_s) to write a line with tickets status info to client
* To style it accordingly you can refer the .tickets-stats class.
*/
require_once(INCLUDE_DIR.'class.ticket.php');
/* Inspired by function getStaffStats() in class.ticket.php */
function _spte($_stat, $_text) {
return ($_stat == 0 ? 'nenhum' : $_stat) . ' ' . $_text . ($_stat > 1 ? 's' : '');
}
// Variables
function _stats($s) {
$t = ['open' => 'tickets', 'assigned' => 'assigned', 'overdue' => 'overdue', 'and' => 'and', 'pre' => 'We have'];
return '<div class="clear"></div>'.
'<div class="tickets-stats"><b>Status:</b> ' . $t['pre'] . ' ' .
_spte($s['open'], $t['open']) . ', ' .
_spte($s['assigned'], $t['assigned']) . ' ' . $t['and'] . ' ' .
_spte($s['overdue'], $t['overdue']) . '.</div>';
}
$visibility = Q::any(new Q(array('status__state'=>'open')));
$blocks = Ticket::objects()
->filter(array('status__state' => 'open'))
->aggregate(array('count' => SqlAggregate::COUNT('ticket_id')))
->values('status__state', 'isanswered', 'isoverdue','staff_id', 'team_id');
$_s = array();
foreach ($blocks as $S) {
$_s['open'] += $S['count'];
if ($S['isoverdue'])
$_s['overdue'] += $S['count'];
if (!$S['staff_id'] == 0)
$_s['assigned'] += $S['count'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment