b8d20a0b354f82fc538f9eefedd6f788d752c807
[kivitendo-erp.git] / SL / Presenter / Project.pm
1 package SL::Presenter::Project;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(project);
9
10 use Carp;
11
12 sub project {
13   my ($self, $project, %params) = @_;
14
15   return '' unless $project;
16
17   $params{display} ||= 'inline';
18
19   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
20
21   my $description = $project->full_description(style => $params{style});
22   my $callback    = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
23
24   my $text = join '', (
25     $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . $self->escape($project->id) . $callback . '">',
26     $self->escape($description),
27     $params{no_link} ? '' : '</a>',
28   );
29   return $self->escaped_text($text);
30 }
31
32 1;
33
34 __END__
35
36 =pod
37
38 =encoding utf8
39
40 =head1 NAME
41
42 SL::Presenter::Project - Presenter module for project Rose::DB objects
43
44 =head1 SYNOPSIS
45
46   my $project = SL::DB::Manager::Project->get_first;
47   my $html    = SL::Presenter->get->project($project, display => 'inline');
48
49 =head1 FUNCTIONS
50
51 =over 4
52
53 =item C<project $object, %params>
54
55 Returns a rendered version (actually an instance of
56 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
57
58 C<%params> can include:
59
60 =over 2
61
62 =item * display
63
64 Either C<inline> (the default) or C<table-cell>. At the moment both
65 representations are identical and produce the project's description
66 (controlled by the C<style> parameter) linked to the corresponding
67 'edit' action.
68
69 =item * style
70
71 Determines what exactly will be output. Can be one of the values with
72 C<both> being the default if it is missing:
73
74 =over 2
75
76 =item C<projectnumber> (or simply C<number>)
77
78 Outputs only the project's number.
79
80 =item C<projectdescription> (or simply C<description>)
81
82 Outputs only the project's description.
83
84 =item C<both>
85
86 Outputs the project's number followed by its description in
87 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
88 description is already part of the project's number then it will not
89 be appended.
90
91 =back
92
93 =item * no_link
94
95 If falsish (the default) then the project's description will be linked to
96 the "edit project" dialog from the master data menu.
97
98 =back
99
100 =back
101
102 =head1 BUGS
103
104 Nothing here yet.
105
106 =head1 AUTHOR
107
108 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
109
110 =cut