62671eaeb0197a8488a39e76ca6bef1a9a540be2
[kivitendo-erp.git] / SL / Presenter / FileObject.pm
1 package SL::Presenter::FileObject;
2
3 use strict;
4
5 use SL::Presenter::EscapedText qw(escape is_escaped);
6
7 use Exporter qw(import);
8 our @EXPORT_OK = qw(file_object);
9
10 use Carp;
11
12 sub file_object {
13   my ($file_object, %params) = @_;
14
15   my $link_start  = '<a href="controller.pl?action=File/download&id=' . $file_object->id;
16   $link_start    .= '&version=' . $file_object->version if $file_object->version;
17   $link_start    .= '">';
18
19   my $link_end    = '</a>';
20
21   my $text = join '', (
22     $params{no_link} ? '' : $link_start,
23     escape($file_object->file_name),
24     $params{no_link} ? '' : $link_end,
25   );
26
27   is_escaped($text);
28 }
29
30 1;
31
32
33 __END__
34
35 =pod
36
37 =encoding utf8
38
39 =head1 NAME
40
41 SL::Presenter::FileObject - Presenter module for SL::File::Object(s), the
42 file objects of the filemanagement. (Note, that this are not instances of
43 SL::DB::File)
44
45 =head1 SYNOPSIS
46
47   my $file_object = SL::File->get(id => 1);
48   my $html        = SL::Presenter::File::file_object($file_object, no_link => 1);
49
50 =head1 FUNCTIONS
51
52 =over 4
53
54 =item C<file_object $file_object, %params>
55
56 Returns a rendered version (actually an instance of
57 L<SL::Presenter::EscapedText>) of the file object
58 C<$file_object>.
59
60 C<%params> can include:
61
62 =over 2
63
64 =item * no_link
65
66 If falsish (the default) then the file name of the object will be linked
67 to the "download action" for that file.
68
69 =back
70
71 =back
72
73 =head1 BUGS
74
75 Nothing here yet.
76
77 =head1 AUTHOR
78
79 Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
80
81 =cut