diff --git a/include/ajax.search.php b/include/ajax.search.php index 2a7a9d7d41255f1f19e1fb01c97dbd956d7c8903..e6e362552c8c67417d3fe4a76097b74d1412b588 100644 --- a/include/ajax.search.php +++ b/include/ajax.search.php @@ -314,6 +314,26 @@ class SearchAjaxAPI extends AjaxController { $queues->filter(array('id__in' => $ids)); $query = Ticket::objects(); + + // Visibility contraints ------------------ + // TODO: Consider SavedSearch::ignoreVisibilityConstraints() + + // -- Open and assigned to me + $assigned = Q::any(array( + 'staff_id' => $thisstaff->getId(), + )); + // -- Open and assigned to a team of mine + if ($teams = array_filter($thisstaff->getTeams())) + $assigned->add(array('team_id__in' => $teams)); + + $visibility = Q::any(new Q(array('status__state'=>'open', $assigned))); + + // -- Routed to a department of mine + if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts())) + $visibility->add(array('dept_id__in' => $depts)); + + $query->filter($visibility); + foreach ($queues as $queue) { $Q = $queue->getBasicQuery(); $query->aggregate(array( diff --git a/include/class.queue.php b/include/class.queue.php index 3cdd0f0a6ff846a3146c91bc8e2ebb2211668ded..7fc7df986805a774e6a25821cb23090d70f039f9 100644 --- a/include/class.queue.php +++ b/include/class.queue.php @@ -37,6 +37,13 @@ class CustomQueue extends SavedSearch { } function getColumns() { + if ($this->parent_id + && $this->hasFlag(self::FLAG_INHERIT_COLUMNS) + && $this->parent + ) { + return $this->parent->getColumns(); + } + if (!count($this->columns)) { foreach (parent::getColumns() as $c) $this->addColumn($c); @@ -76,7 +83,12 @@ class CustomQueue extends SavedSearch { )); } - function getBasicQuery($form=false) { + /** + * Add critiera to a query based on the constraints configured for this + * queue. The criteria of the parent queue is also automatically added + * if the queue is configured to inherit the criteria. + */ + function getBasicQuery() { if ($this->parent && $this->inheritCriteria()) { $query = $this->parent->getBasicQuery(); } @@ -137,7 +149,8 @@ class CustomQueue extends SavedSearch { // Set basic queue information $this->filter = $vars['filter']; - $this->setFlag(self::FLAG_INHERIT_CRITERIA, isset($vars['inherit'])); + $this->setFlag(self::FLAG_INHERIT_CRITERIA, + $this->parent_id > 0 && isset($vars['inherit'])); // Update queue columns (but without save) if (isset($vars['columns'])) { @@ -172,6 +185,10 @@ class CustomQueue extends SavedSearch { // Re-sort the in-memory columns array $this->columns->sort(function($c) { return $c->sort; }); } + else { + // No columns -- imply column inheritance + $this->setFlag(self::FLAG_INHERIT_COLUMNS); + } return 0 === count($errors); } @@ -245,8 +262,8 @@ abstract class QueueColumnAnnotation { static $positions = array( '<' => '<span class="pull-left">%2$s</span>%1$s', '>' => '<span class="pull-right">%2$s</span>%1$s', - 'a' => '%1$s %2$s', - 'b' => '%2$s %1$s', + 'a' => '%1$s%2$s', + 'b' => '%2$s%1$s', ); $pos = $this->getPosition(); diff --git a/include/class.search.php b/include/class.search.php index 3fc0fa9210caa94752e1e6416947d4a07fc85c10..7fd631ffe9fa3d7a74ddf4dd268497778c761283 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -680,6 +680,7 @@ class SavedSearch extends VerySimpleModel { const FLAG_QUEUE = 0x0002; // Shows up in queue navigation const FLAG_CONTAINER = 0x0004; // Container for other queues ('Open') const FLAG_INHERIT_CRITERIA = 0x0008; // Include criteria from parent + const FLAG_INHERIT_COLUMNS = 0x0010; // Inherit column layout from parent var $criteria; private $columns; @@ -1062,6 +1063,12 @@ class SavedSearch extends VerySimpleModel { // Use columns from cited queue return $q->getColumns(); } + elseif ($this->parent_id + && $this->hasFlag(self::FLAG_INHERIT_COLUMNS) + && $this->parent + ) { + return $this->parent->getColumns(); + } if (isset($this->columns)) return $this->columns;