diff --git a/include/class.export.php b/include/class.export.php index d361ed67f8c04b14128db11c9e11a5ea96050d7d..288cb68480c0d850f57e91cb81938eae9fc4aa88 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -57,11 +57,14 @@ class Export { $cdata[$key] = $f->getLocal('label'); } // Reset the $sql query - $tickets = TicketModel::objects() - ->filter($sql->constraints) + $tickets = $sql->models() ->select_related('user', 'user__default_email', 'dept', 'staff', - 'team', 'staff', 'cdata'); - call_user_func_array(array($tickets, 'order_by'), $sql->getSortFields()); + 'team', 'staff', 'cdata') + ->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, array( @@ -75,14 +78,14 @@ class Export { 'topic::getName' => __('Help Topic'), 'source' => __('Source'), 'status::getName' =>__('Current Status'), - '::getEffectiveDate' => __('Last Updated'), - 'duedate' => __('Due Date'), + 'lastupdate' => __('Last Updated'), + 'est_duedate' => __('Due Date'), 'isoverdue' => __('Overdue'), 'isanswered' => __('Answered'), 'staff::getName' => __('Agent Assigned'), 'team::getName' => __('Team Assigned'), - #'thread_count' => __('Thread Count'), - #'attachments' => __('Attachment Count'), + 'thread_count' => __('Thread Count'), + 'attachment_count' => __('Attachment Count'), ) + $cdata, $how, array('modify' => function(&$record, $keys) use ($fields) { @@ -254,7 +257,7 @@ class ResultSetExporter { } } // 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}(); } $record[] = (string) $current; diff --git a/include/class.orm.php b/include/class.orm.php index 85876e5cb6d4fa38bca68b7cbae2fd1519f0812b..ef615b39f63757fdd902ffe0627e2faf8ba9cf69 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -777,6 +777,12 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl return $this; } + function models() { + $this->iterator = 'ModelInstanceManager'; + $this->values = $this->related = array(); + return $this; + } + function values() { foreach (func_get_args() as $A) $this->values[$A] = $A; diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 516e46c0cd8a5418a1bf9621864682cfb87e31a5..edb325b288a66eab97a80b29283d15ddff8fca98 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -248,6 +248,7 @@ case 'updated': // // ATM, advanced search with keywords doesn't support the subquery approach if ($use_subquery) { + $orig_tickets = clone $tickets; $tickets2 = TicketModel::objects(); $tickets2->values = $tickets->values; $tickets2->filter(array('ticket_id__in' => $tickets->values_flat('ticket_id'))); @@ -271,7 +272,7 @@ $tickets->annotate(array( )); // Save the query to the session for exporting -$_SESSION[':Q:tickets'] = $tickets; +$_SESSION[':Q:tickets'] = $orig_tickets; ?>