<& MiniPlot, data => \%counts &>

<table style="width: 100%">
<tr class="titlerow">
<th>Queue</th><th>Activity</th><th>Date</th><th>Time</th><th>Ticket #</th><th>User</th><th>Short description</th>
</tr>
% for my $item (@items) {
<tr>
<td><% $item->{queue} %></td>
<td><% $item->{status} %></td>
<td><% $item->{date} %></td>
<td><% $item->{time} %></td>
<td><% $item->{id} %></td>
<td><% $item->{actor} %></td>
<td><% $item->{notes} %></td>
</tr>
% }
</table>

<%args>
$query => ''
$start => "2005/01/01"
$end   => "2006/01/01"
$actor => ''
</%args>
<%init>
use RT::Extension::ActivityReports qw( RelevantTxns );
my %counts;
my @items;
my $tickets = RT::Tickets->new($session{'CurrentUser'});
$tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
while (my $ticket = $tickets->Next) {
    my $txns = RelevantTxns( $ticket, start => $start, end => $end, query => $query );
    while (my $txn = $txns->Next) {
	# We have to filter for actor here, not in the query.  Alas.
	if( $actor ) {
	    next unless $txn->CreatorObj->Name eq $actor;
	}

	# For the summary report
        my $date = substr($txn->Created, 0, 10);
        # we don't have data on the status of a new ticket, default to 'new'
        $counts{$date}{$txn->NewValue || 'new'}++;

	# For the detail report
        push @items, { queue => $txn->TicketObj->QueueObj->Name,
                       id => $txn->TicketObj->id,
                       date => (split ' ', $txn->CreatedObj->ISO)[0],
                       time => (split ' ', $txn->CreatedObj->ISO)[1],
                       status => $txn->NewValue || 'new',
                       actor => $txn->CreatorObj->Name,
                       notes => ($txn->Content ne 'This transaction appears to have no content' ? substr($txn->Content, 0, 60) :  $txn->BriefDescription)
                     };
    }
}

@items = sort {
           $a->{queue}    cmp $b->{'queue'}
        || $a->{'status'} cmp $b->{'status'}
        || $a->{'id'}     <=> $b->{'id'}
        || $a->{'actor'}  cmp $b->{'actor'}
        || $a->{'notes'}  <=> $b->{'notes'}
} @items;

</%init>
