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(), ]) ```
This commit is contained in:
@@ -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 @@ class CustomQueue extends VerySimpleModel {
|
||||
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 @@ class CustomQueue extends VerySimpleModel {
|
||||
// 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 @@ extends SavedSearch {
|
||||
'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 (!$ticket) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user