This commit was generated by cvs2svn to compensate for changes in r3880,
[freeside.git] / rt / html / Ticket / Elements / FindAttachments
1 <%INIT>
2 my %documents;
3
4 #A default implementation here loops through all transactions and pulls out all their attachments.
5 # We end up doing an end-run around that to get a bit more performance
6
7 # We force the cache of ticket transactions to get populated up front. otherwise, the 
8 # code that looks at attachments will look at each one in turn.
9 my $transactions = $Ticket->Transactions->First;
10
11
12 my $attachments = RT::Attachments->new( $session{'CurrentUser'} );
13
14 $attachments->Columns( qw( Id Filename ContentType Headers Subject Parent ContentEncoding ContentType TransactionId Created));
15
16 if ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
17     my $transactions = $attachments->NewAlias('Transactions');
18     $attachments->Join( ALIAS1 => 'main',
19                                            FIELD1 => 'TransactionId',
20                                            ALIAS2 => $transactions,
21                                            FIELD2 => 'id' );
22     
23     my $tickets = $attachments->NewAlias('Tickets');
24
25     $attachments->Join( ALIAS1 => $transactions,
26                         FIELD1 => 'Ticket',
27                         ALIAS2 => $tickets,
28                         FIELD2 => 'id' );
29
30     $attachments->Limit( ALIAS => $tickets,
31                          FIELD => 'EffectiveId',
32                          VALUE => $Ticket->id() );
33     # if the user may not see comments do not return them
34     unless ( $Ticket->CurrentUserHasRight('ShowTicketComments') ) {
35         $attachments->Limit( ALIAS    => $transactions,
36                              FIELD    => 'Type',
37                              OPERATOR => '!=',
38                              VALUE    => "Comment" );
39     }
40 }
41 return ($attachments);
42 </%INIT>
43 <%ARGS>
44 $Ticket => undef
45 </%ARGS>
46