diff --git a/include/class.queue.php b/include/class.queue.php index 812f9da30f562f27f2ba2a0a26e2fa2b02e22853..b35f33b853851b870893e6b92ced743f744c1799 100644 --- a/include/class.queue.php +++ b/include/class.queue.php @@ -1339,23 +1339,35 @@ class CustomQueue extends VerySimpleModel { * visible queues. * $pid - <int> parent_id of root queue. Default is zero (top-level) */ - static function getHierarchicalQueues(Staff $staff, $pid=0) { - $all = static::objects() + static function getHierarchicalQueues(Staff $staff, $pid=0, + $primary=true) { + $query = static::objects() + ->annotate(array('_sort' => SqlCase::N() + ->when(array('sort' => 0), 999) + ->otherwise(new SqlField('sort')))) ->filter(Q::any(array( 'flags__hasbit' => self::FLAG_PUBLIC, 'flags__hasbit' => static::FLAG_QUEUE, 'staff_id' => $staff->getId(), ))) ->exclude(['flags__hasbit' => self::FLAG_DISABLED]) - ->asArray(); - + ->order_by('parent_id', '_sort', 'title'); + $all = $query->asArray(); // Find all the queues with a given parent - $for_parent = function($pid) use ($all, &$for_parent) { + $for_parent = function($pid) use ($primary, $all, &$for_parent) { $results = []; foreach (new \ArrayIterator($all) as $q) { - if ($q->parent_id == $pid) - $results[] = [ $q, $for_parent($q->getId()) ]; + if ($q->parent_id != $pid) + continue; + + if ($pid == 0 && ( + ($primary && !$q->isAQueue()) + || (!$primary && $q->isAQueue()))) + continue; + + $results[] = [ $q, $for_parent($q->getId()) ]; } + return $results; }; diff --git a/include/class.search.php b/include/class.search.php index f76aacf162a68c01fc21dbd297b8739ab7b7e2a4..eb720bcc26b3890b53a1d19d1430e8dd45def07a 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -701,6 +701,10 @@ class SavedQueue extends CustomQueue { return $this->_columns; } + static function getHierarchicalQueues(Staff $staff) { + return CustomQueue::getHierarchicalQueues($staff, 0, false); + } + /** * Fetch an AdvancedSearchForm instance for use in displaying or * configuring this search in the user interface. diff --git a/include/i18n/en_US/queue.yaml b/include/i18n/en_US/queue.yaml index b7325620c2df64ffb66322a400d05ca81879258e..34a35c28707db92ce80c80af9ed8728b1cd1ce7d 100644 --- a/include/i18n/en_US/queue.yaml +++ b/include/i18n/en_US/queue.yaml @@ -118,7 +118,7 @@ parent_id: 1 flags: 0x2b root: T - sort: 1 + sort: 2 sort_id: 4 config: '{"criteria":[["isanswered","set",null]],"conditions":[]}' columns: @@ -158,7 +158,7 @@ parent_id: 1 flags: 0x2b root: T - sort: 2 + sort: 3 sort_id: 4 config: '{"criteria":[["isoverdue","set",null]],"conditions":[]}' columns: diff --git a/include/staff/templates/queue-savedsearches-nav.tmpl.php b/include/staff/templates/queue-savedsearches-nav.tmpl.php index ef06cf06c91db2b6e5a32ea0395885cc8d05cd25..34a8aff168cb10326f1e8a927f506565d3de13fb 100644 --- a/include/staff/templates/queue-savedsearches-nav.tmpl.php +++ b/include/staff/templates/queue-savedsearches-nav.tmpl.php @@ -4,6 +4,10 @@ // $searches = All visibile saved searches // $child_selected - <bool> true if the selected queue is a descendent // $adhoc - not FALSE if an adhoc advanced search exists + +$searches = SavedQueue::getHierarchicalQueues($thisstaff); +if ($queue && !$queue->parent_id && $queue->staff_id) + $child_selected = true; ?> <li class="primary-only item <?php if ($child_selected) echo 'active'; ?>"> <?php @@ -16,14 +20,9 @@ <div class="customQ-dropdown"> <ul class="scroll-height"> <!-- Start Dropdown and child queues --> - <?php foreach ($searches->findAll(array( - 'staff_id' => $thisstaff->getId(), - 'parent_id' => 0, - Q::not(array( - 'flags__hasbit' => CustomQueue::FLAG_PUBLIC - )) - )) as $q) { - if ($q->checkAccess($thisstaff)) + <?php foreach ($searches as $search) { + list($q, $children) = $search; + if ($q->checkAccess($thisstaff)) include 'queue-subnavigation.tmpl.php'; } ?> <?php diff --git a/scp/tickets.php b/scp/tickets.php index 41ba485384d455527ff8dedeaff05d42c9406a78..86fec81f28395a49905bcd3a342bfaf159be5d15 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -466,7 +466,7 @@ foreach ($queues as $_) { || false !== strpos($queue->getPath(), "/{$q->getId()}/")); include STAFFINC_DIR . 'templates/queue-navigation.tmpl.php'; - return ($child_selected || $selected); + return $child_selected; }); } @@ -477,10 +477,7 @@ $nav->addSubMenu(function() use ($queue) { // A queue is selected if it is the one being displayed. It is // "child" selected if its ID is in the path of the one selected $child_selected = $queue instanceof SavedSearch; - $searches = SavedSearch::forStaff($thisstaff)->getIterator(); - include STAFFINC_DIR . 'templates/queue-savedsearches-nav.tmpl.php'; - return ($child_selected || $selected); });