Skip to content

Commit

Permalink
Refactor how ticket count on open queue is done depending on 'show as…
Browse files Browse the repository at this point in the history
…signed tickets' settings.

 -> Open - only contains unasssined tickets if 'show assigned tickets' is off.
  • Loading branch information
protich committed Feb 22, 2013
1 parent 7fa2f56 commit 9b9dc57
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
11 changes: 6 additions & 5 deletions include/ajax.tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ function lookupByEmail() {
}

function search() {
global $thisstaff;
global $thisstaff, $cfg;

$result=array();
$select = 'SELECT count(ticket.ticket_id) as tickets ';
$select = 'SELECT count( DISTINCT ticket.ticket_id) as tickets ';
$from = ' FROM '.TICKET_TABLE.' ticket ';
$where = ' WHERE 1 ';

Expand All @@ -109,7 +109,7 @@ function search() {

//Status
switch(strtolower($_REQUEST['status'])) {
case 'open';
case 'open':
$where.=' AND ticket.status="open" ';
break;
case 'overdue':
Expand All @@ -133,7 +133,9 @@ function search() {
$where.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") ';

if($_REQUEST['staffId'] && !$_REQUEST['status']) //Assigned TO + Closed By
$where.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") ';
$where.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") ';
elseif(isset($_REQUEST['staffId'])) // closed by any
$where.= ' OR ticket.status="closed" ';

$where.= ' ) ';
} elseif($_REQUEST['staffId']) {
Expand Down Expand Up @@ -163,7 +165,6 @@ function search() {
." OR thread.title LIKE '%$queryterm%'"
." OR thread.body LIKE '%$queryterm%'"
.' )';
$groupby = 'GROUP BY ticket.ticket_id ';
}

$sql="$select $from $where $groupby";
Expand Down
27 changes: 17 additions & 10 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2013,20 +2013,31 @@ function getStaffStats($staff) {
if(!$staff || (!is_object($staff) && !($staff=Staff::lookup($staff))) || !$staff->isStaff() || $cfg->getDBVersion())
return null;


$sql='SELECT count(open.ticket_id) as open, count(answered.ticket_id) as answered '
.' ,count(overdue.ticket_id) as overdue, count(assigned.ticket_id) as assigned, count(closed.ticket_id) as closed '
.' FROM '.TICKET_TABLE.' ticket '
.' LEFT JOIN '.TICKET_TABLE.' open
ON (open.ticket_id=ticket.ticket_id AND open.status=\'open\' AND open.isanswered=0) '
ON (open.ticket_id=ticket.ticket_id
AND open.status=\'open\'
AND open.isanswered=0
'.((!($cfg->showAssignedTickets() || $staff->showAssignedTickets()))?
' AND open.staff_id=0 ':'').') '
.' LEFT JOIN '.TICKET_TABLE.' answered
ON (answered.ticket_id=ticket.ticket_id AND answered.status=\'open\' AND answered.isanswered=1) '
ON (answered.ticket_id=ticket.ticket_id
AND answered.status=\'open\'
AND answered.isanswered=1) '
.' LEFT JOIN '.TICKET_TABLE.' overdue
ON (overdue.ticket_id=ticket.ticket_id AND overdue.status=\'open\' AND overdue.isoverdue=1) '
ON (overdue.ticket_id=ticket.ticket_id
AND overdue.status=\'open\'
AND overdue.isoverdue=1) '
.' LEFT JOIN '.TICKET_TABLE.' assigned
ON (assigned.ticket_id=ticket.ticket_id AND assigned.status=\'open\' AND assigned.staff_id='.db_input($staff->getId()).')'
ON (assigned.ticket_id=ticket.ticket_id
AND assigned.status=\'open\'
AND assigned.staff_id='.db_input($staff->getId()).')'
.' LEFT JOIN '.TICKET_TABLE.' closed
ON (closed.ticket_id=ticket.ticket_id AND closed.status=\'closed\' AND closed.staff_id='.db_input($staff->getId()).')'
ON (closed.ticket_id=ticket.ticket_id
AND closed.status=\'closed\'
AND closed.staff_id='.db_input($staff->getId()).')'
.' WHERE (ticket.staff_id='.db_input($staff->getId());

if(($teams=$staff->getTeams()))
Expand All @@ -2037,10 +2048,6 @@ function getStaffStats($staff) {

$sql.=')';

if(!$cfg || !($cfg->showAssignedTickets() || $staff->showAssignedTickets()))
$sql.=' AND (ticket.staff_id=0 OR ticket.staff_id='.db_input($staff->getId()).') ';


return db_fetch_array(db_query($sql));
}

Expand Down
32 changes: 20 additions & 12 deletions include/staff/tickets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
$searchTerm='';
}
}
$showoverdue=$showanswered=$showassigned=false;
$showoverdue=$showanswered=false;
$staffId=0; //Nothing for now...TODO: Allow admin and manager to limit tickets to single staff level.
//show Assigned To column, if enabled. Admins and managers can overwrite system settings!
$showassigned=(($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets()) && !$search);
$showassigned= true; //show Assigned To column - defaults to true

//Get status we are actually going to use on the query...making sure it is clean!
$status=null;
Expand All @@ -32,7 +31,7 @@
break;
case 'closed':
$status='closed';
$showassigned=false;
$showassigned=true; //closed by.
break;
case 'overdue':
$status='open';
Expand Down Expand Up @@ -77,23 +76,29 @@
$qwhere.=' AND status='.db_input(strtolower($status));
}

//Overloaded sub-statuses - you've got to just have faith!
if($staffId && ($staffId==$thisstaff->getId())) { //Staff's assigned tickets.
//Queues: Overloaded sub-statuses - you've got to just have faith!
if($staffId && ($staffId==$thisstaff->getId())) { //My tickets
$results_type='Assigned Tickets';
$qwhere.=' AND ticket.staff_id='.db_input($staffId);
$showassigned=false; //My tickets...already assigned to the staff.
}elseif($showoverdue) { //overdue
$qwhere.=' AND isoverdue=1 ';
}elseif($showanswered) { ////Answered
$qwhere.=' AND isanswered=1 ';
}elseif(!$search && !$cfg->showAnsweredTickets() && !strcasecmp($status,'open')) {
$qwhere.=' AND isanswered=0 ';
}elseif(!strcasecmp($status, 'open') && !$search) { //Open queue (on search OPEN means all open tickets - regardless of state).
//Showing answered tickets on open queue??
if(!$cfg->showAnsweredTickets())
$qwhere.=' AND isanswered=0 ';

/* Showing assigned tickets on open queue?
Don't confuse it with show assigned To column -> F'it it's confusing - just trust me!
*/
if(!($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets())) {
$qwhere.=' AND ticket.staff_id=0 '; //XXX: NOT factoring in team assignments - only staff assignments.
$showassigned=false; //Not showing Assigned To column since assigned tickets are not part of open queue
}
}

//******* Showing assigned tickets? (don't confuse it with show assigned To column). F'it it's confusing - just trust me! ***/
if(!($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets()) && strcasecmp($status,'closed') && !$search)
$sql.=' AND (ticket.staff_id=0 OR ticket.staff_id='.db_input($thisstaff->getId()).') ';

//Search?? Somebody...get me some coffee
$deep_search=false;
if($search):
Expand Down Expand Up @@ -156,6 +161,9 @@
if($_REQUEST['staffId'] && !$_REQUEST['status']) { //Assigned TO + Closed By
$qwhere.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") ';
$qstr.='&staffId='.urlencode($_REQUEST['staffId']);
}elseif(isset($_REQUEST['staffId'])) {
$qwhere.= ' OR ticket.status="closed" ';
$qstr.='&staffId='.urlencode($_REQUEST['staffId']);
}

$qwhere.= ' ) ';
Expand Down
14 changes: 7 additions & 7 deletions scp/tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,23 +450,23 @@
//Navigation
$nav->setTabActive('tickets');
if($cfg->showAnsweredTickets()) {
$nav->addSubMenu(array('desc'=>'Open ('.($stats['open']+$stats['answered']).')',
$nav->addSubMenu(array('desc'=>'Open ('.number_format($stats['open']+$stats['answered']).')',
'title'=>'Open Tickets',
'href'=>'tickets.php',
'iconclass'=>'Ticket'),
(!$_REQUEST['status'] || $_REQUEST['status']=='open'));
} else {

if($stats) {
$nav->addSubMenu(array('desc'=>'Open ('.$stats['open'].')',
$nav->addSubMenu(array('desc'=>'Open ('.number_format($stats['open']).')',
'title'=>'Open Tickets',
'href'=>'tickets.php',
'iconclass'=>'Ticket'),
(!$_REQUEST['status'] || $_REQUEST['status']=='open'));
}

if($stats['answered']) {
$nav->addSubMenu(array('desc'=>'Answered ('.$stats['answered'].')',
$nav->addSubMenu(array('desc'=>'Answered ('.number_format($stats['answered']).')',
'title'=>'Answered Tickets',
'href'=>'tickets.php?status=answered',
'iconclass'=>'answeredTickets'),
Expand All @@ -478,15 +478,15 @@
if(!$ost->getWarning() && $stats['assigned']>10)
$ost->setWarning($stats['assigned'].' tickets assigned to you! Do something about it!');

$nav->addSubMenu(array('desc'=>'My Tickets ('.$stats['assigned'].')',
$nav->addSubMenu(array('desc'=>'My Tickets ('.number_format($stats['assigned']).')',
'title'=>'Assigned Tickets',
'href'=>'tickets.php?status=assigned',
'iconclass'=>'assignedTickets'),
($_REQUEST['status']=='assigned'));
}

if($stats['overdue']) {
$nav->addSubMenu(array('desc'=>'Overdue ('.$stats['overdue'].')',
$nav->addSubMenu(array('desc'=>'Overdue ('.number_format($stats['overdue']).')',
'title'=>'Stale Tickets',
'href'=>'tickets.php?status=overdue',
'iconclass'=>'overdueTickets'),
Expand All @@ -497,14 +497,14 @@
}

if($thisstaff->showAssignedOnly() && $stats['closed']) {
$nav->addSubMenu(array('desc'=>'My Closed Tickets ('.$stats['closed'].')',
$nav->addSubMenu(array('desc'=>'My Closed Tickets ('.number_format($stats['closed']).')',
'title'=>'My Closed Tickets',
'href'=>'tickets.php?status=closed',
'iconclass'=>'closedTickets'),
($_REQUEST['status']=='closed'));
} else {

$nav->addSubMenu(array('desc'=>'Closed Tickets',
$nav->addSubMenu(array('desc'=>'Closed Tickets ('.number_format($stats['closed']).')',
'title'=>'Closed Tickets',
'href'=>'tickets.php?status=closed',
'iconclass'=>'closedTickets'),
Expand Down

0 comments on commit 9b9dc57

Please sign in to comment.