diff --git a/include/class.pagenate.php b/include/class.pagenate.php index 190e0c3d37005a0c3a870bd8ab82790e91b9cb81..5873862c05617843c1c716665f43ada93b2d111c 100644 --- a/include/class.pagenate.php +++ b/include/class.pagenate.php @@ -58,6 +58,14 @@ class PageNate { return max($this->start - $this->slack, 0); } + function getStop() { + return min($this->getStart() + $this->getLimit(), $this->total); + } + + function getCount() { + return $this->total; + } + function getLimit() { return $this->limit; } diff --git a/include/class.ticket.php b/include/class.ticket.php index dc9651775c4df11589b56ecc986d9ea1c930aa6b..c93b9856ad462f002da8b07e85d832b91958d356 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2765,66 +2765,44 @@ implements RestrictedAccess, Threadable { if(!$staff || (!is_object($staff) && !($staff=Staff::lookup($staff))) || !$staff->isStaff()) return null; - $where = array('(ticket.staff_id='.db_input($staff->getId()) .' AND - status.state="open")'); - $where2 = ''; - - if(($teams=$staff->getTeams())) - $where[] = ' ( ticket.team_id IN('.implode(',', db_input(array_filter($teams))) - .') AND status.state="open")'; - - if(!$staff->showAssignedOnly() && ($depts=$staff->getDepts())) //Staff with limited access just see Assigned tickets. - $where[] = 'ticket.dept_id IN('.implode(',', db_input($depts)).') '; - - if (($cfg && !$cfg->showAssignedTickets()) && !$staff->showAssignedTickets()) - $where2 =' AND (ticket.staff_id=0 OR ticket.team_id=0)'; - $where = implode(' OR ', $where); - if ($where) $where = 'AND ( '.$where.' ) '; - - $sql = 'SELECT \'open\', count( ticket.ticket_id ) AS tickets ' - .'FROM ' . TICKET_TABLE . ' ticket ' - .'INNER JOIN '.TICKET_STATUS_TABLE. ' status - ON (ticket.status_id=status.id - AND status.state=\'open\') ' - .'WHERE ticket.isanswered = 0 ' - . $where . $where2 - - .'UNION SELECT \'answered\', count( ticket.ticket_id ) AS tickets ' - .'FROM ' . TICKET_TABLE . ' ticket ' - .'INNER JOIN '.TICKET_STATUS_TABLE. ' status - ON (ticket.status_id=status.id - AND status.state=\'open\') ' - .'WHERE ticket.isanswered = 1 ' - . $where . ($cfg->showAnsweredTickets() ? $where2 : '') - - .'UNION SELECT \'overdue\', count( ticket.ticket_id ) AS tickets ' - .'FROM ' . TICKET_TABLE . ' ticket ' - .'INNER JOIN '.TICKET_STATUS_TABLE. ' status - ON (ticket.status_id=status.id - AND status.state=\'open\') ' - .'WHERE ticket.isoverdue =1 ' - . $where - - .'UNION SELECT \'assigned\', count( ticket.ticket_id ) AS tickets ' - .'FROM ' . TICKET_TABLE . ' ticket ' - .'INNER JOIN '.TICKET_STATUS_TABLE. ' status - ON (ticket.status_id=status.id - AND status.state=\'open\') ' - .'WHERE ticket.staff_id = ' . db_input($staff->getId()) . ' ' - . $where - - .'UNION SELECT \'closed\', count( ticket.ticket_id ) AS tickets ' - .'FROM ' . TICKET_TABLE . ' ticket ' - .'INNER JOIN '.TICKET_STATUS_TABLE. ' status - ON (ticket.status_id=status.id - AND status.state=\'closed\' ) ' - .'WHERE 1 ' - . $where; - - $res = db_query($sql); + // -- Open and assigned to me + $assigned = Q::any(array( + 'staff_id' => $staff->getId(), + )); + // -- Open and assigned to a team of mine + if ($teams = array_filter($staff->getTeams())) + $assigned->add(array('team_id__in' => $teams)); + + $visibility = Q::any(new Q(array('status__state'=>'open', $assigned))); + + // -- Routed to a department of mine + if (!$staff->showAssignedOnly() && ($depts = $staff->getDepts())) + $visibility->add(array('dept_id__in' => $depts)); + + $blocks = Ticket::objects() + ->filter(Q::any($visibility)) + ->filter(array('status__state' => 'open')) + ->aggregate(array('count' => SqlAggregate::COUNT('ticket_id'))) + ->values('status__state', 'isanswered', 'isoverdue','staff_id', 'team_id'); + $stats = array(); - while($row = db_fetch_row($res)) { - $stats[$row[0]] = $row[1]; + $hideassigned = ($cfg && !$cfg->showAssignedTickets()) && !$staff->showAssignedTickets(); + $showanswered = $cfg->showAnsweredTickets(); + $id = $staff->getId(); + foreach ($blocks as $S) { + if ($showanswered || !$S['isanswered']) { + if (!($hideassigned && ($S['staff_id'] || $S['team_id']))) + $stats['open'] += $S['count']; + } + else { + $stats['answered'] += $S['count']; + } + if ($S['isoverdue']) + $stats['overdue'] += $S['count']; + if ($S['staff_id'] == $id) + $stats['assigned'] += $S['count']; + elseif ($S['team_id'] && $S['staff_id'] == 0) + $stats['assigned'] += $S['count']; } return $stats; } diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 616d3a8a22e9ddbff8a71abe97a41f9c14cbd879..5d982b1b0264625cd9eb37b2a9aa856fc26fc448 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -56,7 +56,10 @@ case 'assigned': $status='open'; $staffId=$thisstaff->getId(); $results_type=__('My Tickets'); - $tickets->filter(array('staff_id'=>$thisstaff->getId())); + $tickets->filter(Q::any(array( + 'staff_id'=>$thisstaff->getId(), + Q::all(array('staff_id' => 0, 'team_id__gt' => 0)), + ))); $queue_sort_options = array('updated', 'priority,updated', 'priority,created', 'priority,due', 'due', 'answered', 'number', 'hot'); @@ -153,7 +156,7 @@ case 'open': if ($status != 'closed' && $queue_name != 'assigned') { $hideassigned = ($cfg && !$cfg->showAssignedTickets()) && !$thisstaff->showAssignedTickets(); $showassigned = !$hideassigned; - if ($status == 'open' && $hideassigned) + if ($queue_name == 'open' && $hideassigned) $tickets->filter(array('staff_id'=>0, 'team_id'=>0)); } @@ -535,7 +538,10 @@ return false;"> </table> <?php if ($total>0) { //if we actually had any tickets returned. - echo '<div> '.__('Page').':'.$pageNav->getPageLinks().' '; +?> <div> + <span class="faded pull-right"><?php echo $pageNav->showing(); ?></span> +<?php + echo __('Page').':'.$pageNav->getPageLinks().' '; echo sprintf('<a class="export-csv no-pjax" href="?%s">%s</a>', Http::build_query(array( 'a' => 'export', 'h' => $hash, diff --git a/scp/tickets.php b/scp/tickets.php index e5e03aa2ea37dbe603e5e53f916bc9c4b35db038..c08e3d5ac4a429d2d0c7e2d6150086379d5ef253 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -393,14 +393,14 @@ if($stats['overdue']) { } if($thisstaff->showAssignedOnly() && $stats['closed']) { - $nav->addSubMenu(array('desc'=>__('My Closed Tickets').' ('.number_format($stats['closed']).')', + $nav->addSubMenu(array('desc'=>__('My Closed Tickets'), 'title'=>__('My Closed Tickets'), 'href'=>'tickets.php?status=closed', 'iconclass'=>'closedTickets'), ($_REQUEST['status']=='closed')); } else { - $nav->addSubMenu(array('desc' => __('Closed').' ('.number_format($stats['closed']).')', + $nav->addSubMenu(array('desc' => __('Closed'), 'title'=>__('Closed Tickets'), 'href'=>'tickets.php?status=closed', 'iconclass'=>'closedTickets'),