diff --git a/include/class.search.php b/include/class.search.php index 3bc1ec35552ea4a7d7ecadb050e7c2aea18ff18e..2dbbe8c3dc8c01023d00e15e6904af5dcf4cf5fa 100755 --- a/include/class.search.php +++ b/include/class.search.php @@ -904,10 +904,22 @@ class SavedQueue extends CustomQueue { // Aggregate constraints foreach ($queues as $queue) { $Q = $queue->getBasicQuery(); - $expr = SqlCase::N()->when(new SqlExpr(new Q($Q->constraints)), new SqlField('ticket_id')); - $query->aggregate(array( - "q{$queue->id}" => SqlAggregate::COUNT($expr, true) - )); + if ($Q->constraints) { + $empty = false; + if (count($Q->constraints) > 1) { + foreach ($Q->constraints as $key => $value) { + if (!$value->constraints) + $empty = true; + } + } + + if (!$empty) { + $expr = SqlCase::N()->when(new SqlExpr(new Q($Q->constraints)), new SqlField('ticket_id')); + $query->aggregate(array( + "q{$queue->id}" => SqlAggregate::COUNT($expr, true) + )); + } + } // Add extra tables joins (if any) if ($Q->extra && isset($Q->extra['tables'])) {