From c1ed5100bfa247d2ebc0cf1045970a996aa8b97a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 13 Oct 2015 07:06:09 -0500
Subject: [PATCH] queue: Default columns look like those from v1.9

---
 include/class.queue.php                       | 60 ++++++++++++-------
 .../streams/core/98ad7d55-00000000.patch.sql  |  1 +
 setup/inc/streams/core/install-mysql.sql      |  1 +
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/include/class.queue.php b/include/class.queue.php
index 47e0f1041..7690a9023 100644
--- a/include/class.queue.php
+++ b/include/class.queue.php
@@ -58,12 +58,23 @@ class CustomQueue extends SavedSearch {
 
     function getColumns() {
         if (!count($this->columns)) {
+            if ($this->columns_id
+                && ($q = CustomQueue::lookup($this->columns_id))
+            ) {
+                // Use columns from cited queue
+                return $q->getColumns();
+            }
+
+            // Last resort — use standard columns
             foreach (array(
                 new QueueColumn(array(
                     "id" => 1,
                     "heading" => "Number",
                     "primary" => 'number',
                     "width" => 100,
+                    "filter" => "link:ticket",
+                    "annotations" => '[{"c":"TicketSourceDecoration","p":"b"}]',
+                    "conditions" => '[{"crit":["isanswered","set",null],"prop":{"font-weight":"bold"}}]',
                 )),
                 new QueueColumn(array(
                     "id" => 2,
@@ -76,6 +87,9 @@ class CustomQueue extends SavedSearch {
                     "heading" => "Subject",
                     "primary" => 'cdata__subject',
                     "width" => 250,
+                    "filter" => "link:ticket",
+                    "annotations" => '[{"c":"TicketThreadCount","p":">"},{"c":"ThreadAttachmentCount","p":"a"},{"c":"OverdueFlagDecoration","p":"<"}]',
+                    "truncate" => 'ellipsis',
                 )),
                 new QueueColumn(array(
                     "id" => 4,
@@ -685,24 +699,10 @@ extends VerySimpleModel {
         ),
     );
 
-    var $_annotations = array();
-    var $_conditions = array();
+    var $_annotations;
+    var $_conditions;
 
     function __onload() {
-        if ($this->annotations
-            && ($anns = JsonDataParser::decode($this->annotations))
-        ) {
-            foreach ($anns as $D)
-                if ($T = QueueColumnAnnotation::fromJson($D))
-                    $this->_annotations[] = $T;
-        }
-        if ($this->conditions
-            && ($conds = JsonDataParser::decode($this->conditions))
-        ) {
-            foreach ($conds as $C)
-                if ($T = QueueColumnCondition::fromJson($C))
-                    $this->_conditions[] = $T;
-        }
     }
 
     function getId() {
@@ -740,10 +740,10 @@ extends VerySimpleModel {
         }
 
         // annotations and conditions
-        foreach ($this->_annotations as $D) {
+        foreach ($this->getAnnotations() as $D) {
             $text = $D->render($row, $text);
         }
-        foreach ($this->_conditions as $C) {
+        foreach ($this->getConditions() as $C) {
             $text = $C->render($row, $text);
         }
         return $text;
@@ -814,12 +814,12 @@ extends VerySimpleModel {
             $query = $filter->mangleQuery($query, $this);
 
         // annotations
-        foreach ($this->_annotations as $D) {
+        foreach ($this->getAnnotations() as $D) {
             $query = $D->annotate($query);
         }
 
         // Conditions
-        foreach ($this->_conditions as $C) {
+        foreach ($this->getConditions() as $C) {
             $query = $C->annotate($query);
         }
 
@@ -860,10 +860,30 @@ extends VerySimpleModel {
     }
 
     function getAnnotations() {
+        if (!isset($this->_annotations)) {
+            $this->_annotations = array();
+            if ($this->annotations
+                && ($anns = JsonDataParser::decode($this->annotations))
+            ) {
+                foreach ($anns as $D)
+                    if ($T = QueueColumnAnnotation::fromJson($D))
+                        $this->_annotations[] = $T;
+            }
+        }
         return $this->_annotations;
     }
 
     function getConditions() {
+        if (!isset($this->_conditions)) {
+            $this->_conditions = array();
+            if ($this->conditions
+                && ($conds = JsonDataParser::decode($this->conditions))
+            ) {
+                foreach ($conds as $C)
+                    if ($T = QueueColumnCondition::fromJson($C))
+                        $this->_conditions[] = $T;
+            }
+        }
         return $this->_conditions;
     }
 
diff --git a/include/upgrader/streams/core/98ad7d55-00000000.patch.sql b/include/upgrader/streams/core/98ad7d55-00000000.patch.sql
index 7f31dacf1..22530ecb5 100644
--- a/include/upgrader/streams/core/98ad7d55-00000000.patch.sql
+++ b/include/upgrader/streams/core/98ad7d55-00000000.patch.sql
@@ -7,6 +7,7 @@
  */
 
 ALTER TABLE `%TABLE_PREFIX%queue`
+  ADD `columns_id` int(11) unsigned AFTER `parent_id`,
   ADD `filter` varchar(64) AFTER `config`,
   ADD `root` varchar(32) DEFAULT NULL AFTER `filter`,
   ADD `path` varchar(80) NOT NULL DEFAULT '/' AFTER `root`;
diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql
index 0bae1a0b8..643fe925e 100644
--- a/setup/inc/streams/core/install-mysql.sql
+++ b/setup/inc/streams/core/install-mysql.sql
@@ -827,6 +827,7 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%queue`;
 CREATE TABLE `%TABLE_PREFIX%queue` (
   `id` int(11) unsigned not null auto_increment,
   `parent_id` int(11) unsigned not null default 0,
+  `columns_id` int(11) unsigned,
   `flags` int(11) unsigned not null default 0,
   `staff_id` int(11) unsigned not null default 0,
   `sort` int(11) unsigned not null default 0,
-- 
GitLab