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

export: Fixup nested query for exporting ticket queue

parent 2b89fca9
No related branches found
No related tags found
No related merge requests found
...@@ -57,11 +57,14 @@ class Export { ...@@ -57,11 +57,14 @@ class Export {
$cdata[$key] = $f->getLocal('label'); $cdata[$key] = $f->getLocal('label');
} }
// Reset the $sql query // Reset the $sql query
$tickets = TicketModel::objects() $tickets = $sql->models()
->filter($sql->constraints)
->select_related('user', 'user__default_email', 'dept', 'staff', ->select_related('user', 'user__default_email', 'dept', 'staff',
'team', 'staff', 'cdata'); 'team', 'staff', 'cdata')
call_user_func_array(array($tickets, 'order_by'), $sql->getSortFields()); ->annotate(array(
'collab_count' => SqlAggregate::COUNT('thread__collaborators'),
'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'),
'thread_count' => SqlAggregate::COUNT('thread__entries'),
));
return self::dumpQuery($tickets, return self::dumpQuery($tickets,
array( array(
...@@ -75,14 +78,14 @@ class Export { ...@@ -75,14 +78,14 @@ class Export {
'topic::getName' => __('Help Topic'), 'topic::getName' => __('Help Topic'),
'source' => __('Source'), 'source' => __('Source'),
'status::getName' =>__('Current Status'), 'status::getName' =>__('Current Status'),
'::getEffectiveDate' => __('Last Updated'), 'lastupdate' => __('Last Updated'),
'duedate' => __('Due Date'), 'est_duedate' => __('Due Date'),
'isoverdue' => __('Overdue'), 'isoverdue' => __('Overdue'),
'isanswered' => __('Answered'), 'isanswered' => __('Answered'),
'staff::getName' => __('Agent Assigned'), 'staff::getName' => __('Agent Assigned'),
'team::getName' => __('Team Assigned'), 'team::getName' => __('Team Assigned'),
#'thread_count' => __('Thread Count'), 'thread_count' => __('Thread Count'),
#'attachments' => __('Attachment Count'), 'attachment_count' => __('Attachment Count'),
) + $cdata, ) + $cdata,
$how, $how,
array('modify' => function(&$record, $keys) use ($fields) { array('modify' => function(&$record, $keys) use ($fields) {
...@@ -254,7 +257,7 @@ class ResultSetExporter { ...@@ -254,7 +257,7 @@ class ResultSetExporter {
} }
} }
// Evalutate :: function call on target current // Evalutate :: function call on target current
if ($func && method_exists($current, $func)) { if ($func && (method_exists($current, $func) || method_exists($current, '__call'))) {
$current = $current->{$func}(); $current = $current->{$func}();
} }
$record[] = (string) $current; $record[] = (string) $current;
......
...@@ -777,6 +777,12 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl ...@@ -777,6 +777,12 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
return $this; return $this;
} }
function models() {
$this->iterator = 'ModelInstanceManager';
$this->values = $this->related = array();
return $this;
}
function values() { function values() {
foreach (func_get_args() as $A) foreach (func_get_args() as $A)
$this->values[$A] = $A; $this->values[$A] = $A;
......
...@@ -248,6 +248,7 @@ case 'updated': ...@@ -248,6 +248,7 @@ case 'updated':
// //
// ATM, advanced search with keywords doesn't support the subquery approach // ATM, advanced search with keywords doesn't support the subquery approach
if ($use_subquery) { if ($use_subquery) {
$orig_tickets = clone $tickets;
$tickets2 = TicketModel::objects(); $tickets2 = TicketModel::objects();
$tickets2->values = $tickets->values; $tickets2->values = $tickets->values;
$tickets2->filter(array('ticket_id__in' => $tickets->values_flat('ticket_id'))); $tickets2->filter(array('ticket_id__in' => $tickets->values_flat('ticket_id')));
...@@ -271,7 +272,7 @@ $tickets->annotate(array( ...@@ -271,7 +272,7 @@ $tickets->annotate(array(
)); ));
// Save the query to the session for exporting // Save the query to the session for exporting
$_SESSION[':Q:tickets'] = $tickets; $_SESSION[':Q:tickets'] = $orig_tickets;
?> ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment