diff --git a/include/class.export.php b/include/class.export.php index c5621e1f7828e6851e1ae66df24de2a0df8018eb..bcf509299946398a188bbcafa9a1552eca7ef883 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -59,12 +59,20 @@ class Export { // Reset the $sql query $tickets = $sql->models() ->select_related('user', 'user__default_email', 'dept', 'staff', - 'team', 'staff', 'cdata') + 'team', 'staff', 'cdata', 'topic', 'status', 'cdata.priority') ->annotate(array( - 'collab_count' => SqlAggregate::COUNT('thread__collaborators'), - 'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'), - 'thread_count' => SqlAggregate::COUNT('thread__entries'), - )); + 'collab_count' => TicketThread::objects() + ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1))) + ->aggregate(array('count' => SqlAggregate::COUNT('collaborators__id'))), + 'attachment_count' => TicketThread::objects() + ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1))) + ->filter(array('entries__attachments__inline' => 0)) + ->aggregate(array('count' => SqlAggregate::COUNT('entries__attachments__id'))), + 'thread_count' => TicketThread::objects() + ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1))) + ->exclude(array('entries__flags__hasbit' => ThreadEntry::FLAG_HIDDEN)) + ->aggregate(array('count' => SqlAggregate::COUNT('entries__id'))), + )); return self::dumpQuery($tickets, array( @@ -73,7 +81,7 @@ class Export { 'cdata.subject' => __('Subject'), 'user.name' => __('From'), 'user.default_email.address' => __('From Email'), - 'cdata.:priority.priority_desc' => __('Priority'), + 'cdata.priority.priority_desc' => __('Priority'), 'dept::getLocalName' => __('Department'), 'topic::getName' => __('Help Topic'), 'source' => __('Source'), @@ -100,14 +108,9 @@ class Export { } static function saveTickets($sql, $filename, $how='csv') { - ob_start(); + Http::download($filename, "text/$how"); self::dumpTickets($sql, $how); - $stuff = ob_get_contents(); - ob_end_clean(); - if ($stuff) - Http::download($filename, "text/$how", $stuff); - - return false; + exit; } diff --git a/include/class.orm.php b/include/class.orm.php index f31e209d0bc0791e2250170a77759bc8b641c3e8..72684b79991dfabeb95678d1c0beb85708ae980f 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -2512,7 +2512,7 @@ class MySqlCompiler extends SqlCompiler { $T = $A->toSql($this, $model, $alias); if ($fieldMap) { array_splice($fields, count($fieldMap[0][0]), 0, array($T)); - $fieldMap[0][0][] = $A->getAlias(); + $fieldMap[0][0][] = $alias; } else { // No field map — just add to end of field list diff --git a/include/class.ticket.php b/include/class.ticket.php index ae3d909648a004581e4724d40cc3db71a121ac40..c97607c959e6de649970f5fa551e4c4c86a04772 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -209,7 +209,7 @@ class TicketCData extends VerySimpleModel { 'ticket' => array( 'constraint' => array('ticket_id' => 'TicketModel.ticket_id'), ), - ':priority' => array( + 'priority' => array( 'constraint' => array('priority' => 'Priority.priority_id'), 'null' => true, ), diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 148af95c0a384478afa6c9c7d277198967e5e965..58363036bd02b50c5065ccecf5b141d875b86167 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -225,7 +225,7 @@ case 'number': break; case 'priority,created': - $tickets->order_by(($sort_dir ? '-' : '') . 'cdata__:priority__priority_urgency'); + $tickets->order_by(($sort_dir ? '-' : '') . 'cdata__priority__priority_urgency'); // Fall through to columns for `created` case 'created': $date_header = __('Date Created'); @@ -235,7 +235,7 @@ case 'created': break; case 'priority,due': - $tickets->order_by('cdata__:priority__priority_urgency', $orm_dir_r); + $tickets->order_by('cdata__priority__priority_urgency', $orm_dir_r); // Fall through to add in due date filter case 'due': $date_header = __('Due Date'); @@ -272,7 +272,7 @@ case 'relevance': default: case 'priority,updated': - $tickets->order_by('cdata__:priority__priority_urgency', $orm_dir_r); + $tickets->order_by('cdata__priority__priority_urgency', $orm_dir_r); // Fall through for columns defined for `updated` case 'updated': $date_header = __('Last Updated'); @@ -303,7 +303,7 @@ TicketForm::ensureDynamicDataView(); // Select pertinent columns // ------------------------------------------------------------ -$tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_id', 'number', 'cdata__subject', 'user__default_email__address', 'source', 'cdata__:priority__priority_color', 'cdata__:priority__priority_desc', 'status_id', 'status__name', 'status__state', 'dept_id', 'dept__name', 'user__name', 'lastupdate', 'isanswered'); +$tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_id', 'number', 'cdata__subject', 'user__default_email__address', 'source', 'cdata__priority__priority_color', 'cdata__priority__priority_desc', 'status_id', 'status__name', 'status__state', 'dept_id', 'dept__name', 'user__name', 'lastupdate', 'isanswered'); // Add in annotations $tickets->annotate(array( @@ -509,8 +509,8 @@ return false;"> $displaystatus="<b>$displaystatus</b>"; echo "<td>$displaystatus</td>"; } else { ?> - <td class="nohover" align="center" style="background-color:<?php echo $T['cdata__:priority__priority_color']; ?>;"> - <?php echo $T['cdata__:priority__priority_desc']; ?></td> + <td class="nohover" align="center" style="background-color:<?php echo $T['cdata__priority__priority_color']; ?>;"> + <?php echo $T['cdata__priority__priority_desc']; ?></td> <?php } ?>