diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 9f0fa3db063861dab137ed1a7637a8e6b9d9e2e4..8f6a86ce857528594c9e6ee2c607d2ecdcb5485c 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -150,10 +150,7 @@ if (!$view_all_tickets) { if ($teams = array_filter($thisstaff->getTeams())) $assigned->add(array('team_id__in' => $teams)); - if ($status) - $visibility = Q::any(array($assigned)); - else - $visibility = Q::any(array('status__state'=>'open', $assigned)); + $visibility = Q::any(array('status__state'=>'open', $assigned)); // -- Routed to a department of mine if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts())) @@ -268,13 +265,18 @@ $tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_i // Add in annotations $tickets->annotate(array( - 'collab_count' => SqlAggregate::COUNT('thread__collaborators'), - 'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'), + 'collab_count' => SqlAggregate::COUNT('thread__collaborators', true), + 'attachment_count' => SqlAggregate::COUNT(SqlCase::N() + ->when(new SqlField('thread__entries__attachments__inline'), null) + ->otherwise(new SqlField('thread__entries__attachments')), + true + ), 'thread_count' => SqlAggregate::COUNT(SqlCase::N() ->when( new Q(array('thread__entries__flags__hasbit'=>ThreadEntry::FLAG_HIDDEN)), null) - ->otherwise(1) + ->otherwise(new SqlField('thread__entries__id')), + true ), ));