Presenter-Module für Listen von Verkaufs-/Einkaufsobjekte
[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   $params{style} ||= 'both';
22   my $description;
23
24   if ($params{style} =~ m/number/) {
25     $description = $project->projectnumber;
26
27   } elsif ($params{style} =~ m/description/) {
28     $description = $project->description;
29
30   } else {
31     $description = $project->projectnumber;
32     if ($project->description && do { my $desc = quotemeta $project->description; $project->projectnumber !~ m/$desc/ }) {
33       $description .= ' (' . $project->description . ')';
34     }
35   }
36
37   my $text = join '', (
38     $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . $self->escape($project->id) . '">',
39     $self->escape($description),
40     $params{no_link} ? '' : '</a>',
41   );
42   return $self->escaped_text($text);
43 }
44
45 1;
46
47 __END__
48
49 =pod
50
51 =encoding utf8
52
53 =head1 NAME
54
55 SL::Presenter::Project - Presenter module for project Rose::DB objects
56
57 =head1 SYNOPSIS
58
59   my $project = SL::DB::Manager::Project->get_first;
60   my $html    = SL::Presenter->get->project($project, display => 'inline');
61
62 =head1 FUNCTIONS
63
64 =over 4
65
66 =item C<project $object, %params>
67
68 Returns a rendered version (actually an instance of
69 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
70
71 C<%params> can include:
72
73 =over 2
74
75 =item * display
76
77 Either C<inline> (the default) or C<table-cell>. At the moment both
78 representations are identical and produce the project's description
79 (controlled by the C<style> parameter) linked to the corresponding
80 'edit' action.
81
82 =item * style
83
84 Determines what exactly will be output. Can be one of the values with
85 C<both> being the default if it is missing:
86
87 =over 2
88
89 =item C<projectnumber> (or simply C<number>)
90
91 Outputs only the project's number.
92
93 =item C<projectdescription> (or simply C<description>)
94
95 Outputs only the project's description.
96
97 =item C<both>
98
99 Outputs the project's number followed by its description in
100 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
101 description is already part of the project's number then it will not
102 be appended.
103
104 =back
105
106 =item * no_link
107
108 If falsish (the default) then the project's description will be linked to
109 the "edit project" dialog from the master data menu.
110
111 =back
112
113 =back
114
115 =head1 BUGS
116
117 Nothing here yet.
118
119 =head1 AUTHOR
120
121 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
122
123 =cut