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

Consider ticket CDATA criteria in search bk

parent ace9bc05
No related branches found
No related tags found
No related merge requests found
......@@ -202,14 +202,6 @@ class TicketsAjaxAPI extends AjaxController {
$criteria['created__lte'] = $startTime;
}
//Query
$joins = array();
if($req['query']) {
// Setup sets of joins and queries
if ($s = $ost->searcher)
return $s->find($req['query'], $criteria, 'Ticket');
}
// Dynamic fields
$cdata_search = false;
foreach (TicketForm::getInstance()->getFields() as $f) {
......@@ -218,10 +210,14 @@ class TicketsAjaxAPI extends AjaxController {
&& strlen(trim($val))) {
$name = $f->get('name') ? $f->get('name')
: 'field_'.$f->get('id');
if ($f->getImpl()->hasIdValue() && is_numeric($val))
if ($f->getImpl()->hasIdValue() && is_numeric($val)) {
$cwhere = "cdata.`{$name}_id` = ".db_input($val);
else
$criteria["cdata.{$name}_id"] = $val;
}
else {
$cwhere = "cdata.`$name` LIKE '%".db_real_escape($val)."%'";
$criteria["cdata.{$name}"] = $val;
}
$where .= ' AND ('.$cwhere.')';
$cdata_search = true;
}
......@@ -230,6 +226,14 @@ class TicketsAjaxAPI extends AjaxController {
$from .= 'LEFT JOIN '.TABLE_PREFIX.'ticket__cdata '
." cdata ON (cdata.ticket_id = ticket.ticket_id)";
//Query
$joins = array();
if($req['query']) {
// Setup sets of joins and queries
if ($s = $ost->searcher)
return $s->find($req['query'], $criteria, 'Ticket');
}
$sections = array();
foreach ($joins as $j) {
$sections[] = "$select $from {$j['from']} $where AND ({$j['where']})";
......
......@@ -309,9 +309,19 @@ class MysqlSearchBackend extends SearchBackend {
case 'email':
case 'org_id':
case 'form_id':
default:
if (strpos($name, 'cdata.') === 0) {
// Search ticket CDATA table
$cdata_search = true;
$name = substr($name, 6);
$where[] = sprintf("cdata.%s = %s", $name, db_input($value));
}
}
}
}
if ($cdata_search)
$tables[] = TABLE_PREFIX.'ticket__cdata cdata'
.' ON (cdata.ticket_id = A1.ticket_id)';
// Always consider the current staff's access
$thisstaff->getDepts();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment