From aa0924a8d31462f599008331bf85dabc3f6417d5 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Tue, 11 Sep 2018 17:52:49 +0000
Subject: [PATCH] Add Queue Columns Annotation as Fields.

---
 include/ajax.search.php  |  2 +-
 include/class.queue.php  | 11 ++++++++++
 include/class.search.php | 45 ++++++++++++++++++++++++++++++++++++++++
 include/class.ticket.php | 12 +++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/include/ajax.search.php b/include/ajax.search.php
index 93da251e7..dbc0a291b 100644
--- a/include/ajax.search.php
+++ b/include/ajax.search.php
@@ -135,7 +135,7 @@ class SearchAjaxAPI extends AjaxController {
             $_SESSION[$key] = $keep;
         }
     }
-    
+
     function _hashCriteria($criteria, $size=10) {
         $parts = array();
         foreach ($criteria as $C) {
diff --git a/include/class.queue.php b/include/class.queue.php
index 9dd9b36e3..1741d4f96 100644
--- a/include/class.queue.php
+++ b/include/class.queue.php
@@ -1508,6 +1508,17 @@ abstract class QueueColumnAnnotation {
     function isVisible($row) {
         return true;
     }
+
+    static function addToQuery($query, $name=false) {
+        $name = $name ?: static::$qname;
+        $annotation = new Static(array());
+        return $annotation->annotate($query, $name);
+    }
+
+    static function from_query($row, $name=false) {
+        $name = $name ?: static::$qname;
+        return $row[$name];
+    }
 }
 
 class TicketThreadCount
diff --git a/include/class.search.php b/include/class.search.php
index 51629ccdb..c32916504 100644
--- a/include/class.search.php
+++ b/include/class.search.php
@@ -1436,6 +1436,7 @@ class OpenClosedTicketStatusList extends TicketStatusList {
         return $rv;
     }
 }
+
 class TicketStatusChoiceField extends SelectionField {
     static $widget = 'ChoicesWidget';
 
@@ -1468,6 +1469,50 @@ class TicketStatusChoiceField extends SelectionField {
     }
 }
 
+class TicketThreadCountField extends NumericField {
+
+    function addToQuery($query, $name=false) {
+        return TicketThreadCount::addToQuery($query, $name);
+    }
+
+    function from_query($row, $name=false) {
+         return TicketThreadCount::from_query($row, $name);
+    }
+}
+
+class TicketReopenCountField extends NumericField {
+
+    function addToQuery($query, $name=false) {
+        return TicketReopenCount::addToQuery($query, $name);
+    }
+
+    function from_query($row, $name=false) {
+         return TicketReopenCount::from_query($row, $name);
+    }
+}
+
+class ThreadAttachmentCountField extends NumericField {
+
+    function addToQuery($query, $name=false) {
+        return ThreadAttachmentCount::addToQuery($query, $name);
+    }
+
+    function from_query($row, $name=false) {
+         return ThreadAttachmentCount::from_query($row, $name);
+    }
+}
+
+class ThreadCollaboratorCountField extends NumericField {
+
+    function addToQuery($query, $name=false) {
+        return ThreadCollaboratorCount::addToQuery($query, $name);
+    }
+
+    function from_query($row, $name=false) {
+         return ThreadCollaboratorCount::from_query($row, $name);
+    }
+}
+
 interface Searchable {
     // Fetch an array of [ orm__path => Field() ] pairs. The field label is
     // used when this list is rendered in a dropdown, and the field search
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 8174989cb..1b84762c6 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2182,6 +2182,18 @@ implements RestrictedAccess, Threadable, Searchable {
             'isassigned' => new AssignedField(array(
                         'label' => __('Assigned'),
             )),
+            'thread_count' => new TicketThreadCountField(array(
+                        'label' => __('Thread Count'),
+            )),
+            'attachment_count' => new ThreadAttachmentCountField(array(
+                        'label' => __('Attachment Count'),
+            )),
+            'collaborator_count' => new ThreadCollaboratorCountField(array(
+                        'label' => __('Collaborator Count'),
+            )),
+            'reopen_count' => new TicketReopenCountField(array(
+                        'label' => __('Reopen Count'),
+            )),
             'ip_address' => new TextboxField(array(
                 'label' => __('IP Address'),
                 'configuration' => array('validator' => 'ip'),
-- 
GitLab