diff --git a/include/class.thread.php b/include/class.thread.php index 46c0182822e9e7f6beb8d94f91dabca4c3397927..c13014848800056842f7ab7f7df41bcb82c8e345 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -39,18 +39,14 @@ class Thread { $sql='SELECT ticket.ticket_id as id ' .' ,count(DISTINCT attach.attach_id) as attachments ' - .' ,count(DISTINCT message.id) as messages ' - .' ,count(DISTINCT response.id) as responses ' - .' ,count(DISTINCT note.id) as notes ' + ." ,count(DISTINCT CASE WHEN thread.thread_type = 'M' THEN thread.id ELSE NULL END) as messages " + ." ,count(DISTINCT CASE WHEN thread.thread_type = 'R' THEN thread.id ELSE NULL END) as responses " + ." ,count(DISTINCT CASE WHEN thread.thread_type = 'N' THEN thread.id ELSE NULL END) as notes " .' FROM '.TICKET_TABLE.' ticket ' .' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (' .'ticket.ticket_id=attach.ticket_id) ' - .' LEFT JOIN '.TICKET_THREAD_TABLE.' message ON (' - ."ticket.ticket_id=message.ticket_id AND message.thread_type = 'M') " - .' LEFT JOIN '.TICKET_THREAD_TABLE.' response ON (' - ."ticket.ticket_id=response.ticket_id AND response.thread_type = 'R') " - .' LEFT JOIN '.TICKET_THREAD_TABLE.' note ON ( ' - ."ticket.ticket_id=note.ticket_id AND note.thread_type = 'N') " + .' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON (' + .'ticket.ticket_id=thread.ticket_id) ' .' WHERE ticket.ticket_id='.db_input($this->getTicketId()) .' GROUP BY ticket.ticket_id';