Skip to content
Permalink
Browse files

queue: Add Filtering To Queues

This adds the ability to use Qs instead of Queue Criteria to better filter
Queues. This updates class Queue and adds two new functions `filter()` and
`getFilters()`. `filter()` simply adds the Q(s) to the new `filters`
property for later access. `getFilters()` simply returns all of the queue
filters (if any). In addition, this updates the `AdhocSearch::load()` method
to detect if the Queue's Config is an instanceof Q and if so we filter the
queue by that Q else we will use the Queue Criteria (if any).

Currently we can't search for tickets with the User's email address equal to
`example@domain.com` **OR** Collaborator’s email address equal to
`example@domain.com` as Queue Criteria is only seen as **AND** statements.
The queue criteria for this would look like:
```
array(
    array('user__emails__address', 'equal', $user->getEmail()->email),
    array('thread__collaborators__user__emails__address', 'equal',
$user->getEmail()->email),
)
```

With the new filter methods we could actually find those tickets with a Q
like:
```
Q::any([
    'user__emails__address' => $user->getDefaultEmailAddress(),
    'thread__collaborators__user__emails__address' =>
$user->getDefaultEmailAddress(),
])
```
  • Loading branch information...
JediKev committed Aug 21, 2019
1 parent 6db9507 commit cedd61210c2eb023e5f2d68ea5d81bba9db17158
Showing with 26 additions and 7 deletions.
  1. +13 −0 include/class.queue.php
  2. +6 −1 include/class.search.php
  3. +7 −6 scp/tickets.php
@@ -68,6 +68,7 @@ class CustomQueue extends VerySimpleModel {
const FLAG_INHERIT_EVERYTHING = 0x158; // Maskf or all INHERIT flags
var $filters;
var $criteria;
var $_conditions;
@@ -112,6 +113,14 @@ function getPath() {
return $this->path ?: $this->buildPath();
}
function filter($filter) {
$this->filters[] = $filter;
}
function getFilters() {
return $this->filters ?: array();
}
function criteriaRequired() {
return true;
}
@@ -893,6 +902,10 @@ function getQuery($form=false, $quick_filter=null) {
// Start with basic criteria
$query = $this->getBasicQuery($form);
// Apply filers if any.
foreach ($this->getFilters() as $filter)
$query->filter($filter);
// Apply quick filter
if (isset($quick_filter)
&& ($qf = $this->getQuickFilterField($quick_filter))
@@ -1043,7 +1043,12 @@ function load($key) {
'staff_id' => $thisstaff->getId(),
'title' => __('Advanced Search'),
));
$queue->config = $config;
// if instance of Q then assume filters otherwise it's criteria.
if ($config instanceof Q)
$queue->filter($config);
else
$queue->config = $config;
return $queue;
}
@@ -57,14 +57,15 @@
if ($user
&& $_GET['a'] !== 'open'
) {
$criteria = [
['user__emails__address', 'equal', $user->getDefaultEmailAddress()],
['user_id', 'equal', $user->id],
];
$Q = Q::any([
'user__emails__address' => $user->getDefaultEmailAddress(),
'user_id' => $user->id,
]);
if ($S = $_GET['status'])
// The actual state is tracked by the key
$criteria[] = ['status__state', 'includes', [$S => $S]];
$_SESSION['advsearch']['uid'] = $criteria;
$Q = Q::all(array('status__state' => $S, $Q));
$_SESSION['advsearch']['uid'] = $Q;
$queue_id = "adhoc,uid";
}
// Search for organization tickets

0 comments on commit cedd612

Please sign in to comment.
You can’t perform that action at this time.