RTx-Statistics in 2.1 / 3.8
[freeside.git] / rt / html / RTx / Statistics / Elements / StatColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# END BPS TAGGED BLOCK }}}
46 <%ARGS>
47 $Name => undef
48 $Attr => undef
49 </%ARGS>
50
51
52 <%ONCE>
53 our ( $STAT_COLUMN_MAP );
54
55 sub StatColumnMap {
56     my $name = shift;
57     my $attr = shift;
58
59     # First deal with the simple things from the map
60     if ( $STAT_COLUMN_MAP->{$name} ) {
61         return ( $STAT_COLUMN_MAP->{$name}->{$attr} );
62     }
63
64     # now, let's deal with harder things, like Custom Fields
65
66     elsif ( $name =~ /^(?:CF|CustomField)\.\{(.+)\}$/ ) {
67         my $field = $1;
68
69         if ( $attr eq 'attribute' ) {
70             return (undef);
71         }
72         elsif ( $attr eq 'title' ) {
73             return ( $field );
74         }
75         elsif ( $attr eq 'value' ) {
76             # Display custom field contents, separated by newlines.
77             # For Image custom fields we also show a thumbnail here.
78             return sub {
79                 my $values = $_[0]->CustomFieldValues($field);
80                 return map {
81                     (
82                         ($_->CustomFieldObj->Type eq 'Image')
83                             ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
84                             : $_->Content
85                     ),
86                     \'<br>',
87                 } @{ $values->ItemsArrayRef }
88             };
89         }
90     }
91 }
92
93 sub LinkCallback {
94     my $method = shift;
95
96     my $mode            = $RT::Ticket::LINKTYPEMAP{$method}{Mode};
97     my $type            = $RT::Ticket::LINKTYPEMAP{$method}{Type};
98     my $mode_uri        = $mode.'URI';
99     my $local_type      = 'Local'.$mode;
100
101     return sub {
102         map {
103             \'<A HREF="',
104             $_->$mode_uri->Resolver->HREF,
105             \'">',
106             ( $_->$mode_uri->IsLocal ? $_->$local_type : $_->$mode ),
107             \'</A><BR>',
108         } @{ $_[0]->Links($mode,$type)->ItemsArrayRef }
109     }
110 }
111
112 $STAT_COLUMN_MAP = {
113     LastUpdated => {
114         attribute => 'LastUpdated',
115         title     => 'Last Updated',
116         value     => sub { return $_[0]->LastUpdatedObj->AsString }
117     },
118
119     Statistics_Date => {
120         title => 'Date',
121         value => sub { return $_[0]{values}{Statistics_Date} }
122     },
123
124     Statistics_Created_Count => {
125         title => 'Created',
126         value => sub { return $_[0]{values}{Statistics_Created_Count} }
127     },
128
129     Statistics_Resolved_Count => {
130         title => 'Resolved',
131         value => sub { return $_[0]{values}{Statistics_Resolved_Count} }
132     },
133
134     Statistics_Deleted_Count => {
135         title => 'Deleted',
136         value => sub { return $_[0]{values}{Statistics_Deleted_Count} }
137     },
138
139     Statistics_Totals => {
140         title => 'Totals',
141         value => sub { return $_[0]{values}{Statistics_Totals} }
142     },
143
144     Statistics_Status => {
145         title => 'Status',
146         value => sub { return $_[0]{values}{Statistics_Status} }
147     },
148
149     Statistics_Dynamic => {
150         # Depends on having a KEY as second param
151         value => sub { 
152             my $record = shift;
153             my $line = shift;
154             my $key = shift;
155             return $$record{values}{$key} 
156         }
157     },
158
159     # Everything from LINKTYPEMAP
160     (map {
161         $_ => { value => LinkCallback( $_ ) }
162     } keys %RT::Ticket::LINKTYPEMAP),
163
164     '_CLASS' => {
165         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
166     },
167
168 };
169 </%ONCE>
170 <%init>
171 $m->comp( '/Elements/Callback', STAT_COLUMN_MAP    => $STAT_COLUMN_MAP, _CallbackName => 'StatColumnMap');
172 return StatColumnMap($Name, $Attr);
173 </%init>