Skip to content
Snippets Groups Projects
Commit 32565aa9 authored by Jared Hancock's avatar Jared Hancock
Browse files

Send advanced search criteria to backend

parent 36b7312e
Branches
Tags
No related merge requests found
...@@ -101,6 +101,8 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -101,6 +101,8 @@ class TicketsAjaxAPI extends AjaxController {
global $thisstaff, $cfg, $ost; global $thisstaff, $cfg, $ost;
$result=array(); $result=array();
$criteria = array();
$select = 'SELECT ticket.ticket_id'; $select = 'SELECT ticket.ticket_id';
$from = ' FROM '.TICKET_TABLE.' ticket $from = ' FROM '.TICKET_TABLE.' ticket
LEFT JOIN '.TICKET_STATUS_TABLE.' status LEFT JOIN '.TICKET_STATUS_TABLE.' status
...@@ -119,29 +121,38 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -119,29 +121,38 @@ class TicketsAjaxAPI extends AjaxController {
$where.=' ) '; $where.=' ) ';
//Department //Department
if($req['deptId']) if ($req['deptId']) {
$where.=' AND ticket.dept_id='.db_input($req['deptId']); $where.=' AND ticket.dept_id='.db_input($req['deptId']);
$criteria['dept_id'] = $req['deptId'];
}
//Help topic //Help topic
if($req['topicId']) if($req['topicId']) {
$where.=' AND ticket.topic_id='.db_input($req['topicId']); $where.=' AND ticket.topic_id='.db_input($req['topicId']);
$criteria['topic_id'] = $req['topicId'];
}
//Status //Status
switch(strtolower($req['status'])) { switch(strtolower($req['status'])) {
case 'open': case 'open':
$where.=' AND status.state="open" '; $where.=' AND status.state="open" ';
$criteria['status'] = 'open';
break; break;
case 'answered': case 'answered':
$where.=' AND status.state="open" AND ticket.isanswered=1 '; $where.=' AND status.state="open" AND ticket.isanswered=1 ';
$criteria += array('status' => 'open', 'isanswered'=>1);
break; break;
case 'overdue': case 'overdue':
$where.=' AND status.state="open" AND ticket.isoverdue=1 '; $where.=' AND status.state="open" AND ticket.isoverdue=1 ';
$criteria += array('status' => 'open', 'isoverdue'=>1);
break; break;
case 'resolved': case 'resolved':
$where.=' AND status.state="resolved" '; $where.=' AND status.state="resolved" ';
$criteria += array('status' => 'resolved', 'isoverdue'=>1);
break; break;
case 'closed': case 'closed':
$where.=' AND status.state="closed" '; $where.=' AND status.state="closed" ';
$criteria['status'] = 'closed';
break; break;
} }
...@@ -150,10 +161,14 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -150,10 +161,14 @@ class TicketsAjaxAPI extends AjaxController {
$id=preg_replace("/[^0-9]/", "", $req['assignee']); $id=preg_replace("/[^0-9]/", "", $req['assignee']);
$assignee = $req['assignee']; $assignee = $req['assignee'];
$where.= ' AND ( ( status.state="open" '; $where.= ' AND ( ( status.state="open" ';
if($assignee[0]=='t') if($assignee[0]=='t') {
$where.=' AND ticket.team_id='.db_input($id); $where.=' AND ticket.team_id='.db_input($id);
elseif($assignee[0]=='s') $criteria['team_id'] = $id;
}
elseif($assignee[0]=='s') {
$where.=' AND ticket.staff_id='.db_input($id); $where.=' AND ticket.staff_id='.db_input($id);
$criteria['staff_id'] = $id;
}
elseif(is_numeric($id)) elseif(is_numeric($id))
$where.=' AND ticket.staff_id='.db_input($id); $where.=' AND ticket.staff_id='.db_input($id);
...@@ -177,28 +192,22 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -177,28 +192,22 @@ class TicketsAjaxAPI extends AjaxController {
if( ($startTime && $startTime>time()) or ($startTime>$endTime && $endTime>0)) if( ($startTime && $startTime>time()) or ($startTime>$endTime && $endTime>0))
$startTime=$endTime=0; $startTime=$endTime=0;
if($startTime) if($startTime) {
$where.=' AND ticket.created>=FROM_UNIXTIME('.$startTime.')'; $where.=' AND ticket.created>=FROM_UNIXTIME('.$startTime.')';
$criteria['created__gte'] = $startTime;
}
if($endTime) if($endTime) {
$where.=' AND ticket.created<=FROM_UNIXTIME('.$endTime.')'; $where.=' AND ticket.created<=FROM_UNIXTIME('.$endTime.')';
$criteria['created__lte'] = $startTime;
}
//Query //Query
$joins = array(); $joins = array();
if($req['query']) { if($req['query']) {
$queryterm=db_real_escape($req['query'], false);
// Setup sets of joins and queries // Setup sets of joins and queries
if ($s = $ost->searcher) if ($s = $ost->searcher)
$ids = $s->find($req['query'], null, 'Ticket'); return $s->find($req['query'], $criteria, 'Ticket');
if (!$ids)
return array();
$joins[] = array(
'from' => '',
'where' => 'ticket.ticket_id IN (' . implode(',', $ids) . ')'
);
} }
// Dynamic fields // Dynamic fields
......
...@@ -291,8 +291,16 @@ class MysqlSearchBackend extends SearchBackend { ...@@ -291,8 +291,16 @@ class MysqlSearchBackend extends SearchBackend {
case 'staff_id': case 'staff_id':
case 'dept_id': case 'dept_id':
case 'user_id': case 'user_id':
case 'isanswered':
case 'isoverdue':
$where[] = sprintf('A1.%s = %s', $name, db_input($value)); $where[] = sprintf('A1.%s = %s', $name, db_input($value));
break; break;
case 'created__gte':
$where[] = sprintf('A1.created >= %s', db_input($value));
break;
case 'created__lte':
$where[] = sprintf('A1.created <= %s', db_input($value));
break;
case 'email': case 'email':
case 'org_id': case 'org_id':
case 'form_id': case 'form_id':
...@@ -357,8 +365,6 @@ class MysqlSearchBackend extends SearchBackend { ...@@ -357,8 +365,6 @@ class MysqlSearchBackend extends SearchBackend {
* not index in the _search table and add it to the index. * not index in the _search table and add it to the index.
*/ */
function IndexOldStuff() { function IndexOldStuff() {
print 'Indexing old stuff!';
$class = get_class(); $class = get_class();
$auto_create = function($db_error) use ($class) { $auto_create = function($db_error) use ($class) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment