kivitendo/SL/Helper/File.pm @ 4a663bf8
0bfbcce6 | Martin Helmling | package SL::Helper::File;
|
||
use strict;
|
||||
use Exporter 'import';
|
||||
c9b4e6bc | Martin Helmling | our @EXPORT_OK = qw(store_pdf append_general_pdf_attachments doc_storage_enabled);
|
||
0bfbcce6 | Martin Helmling | our %EXPORT_TAGS = (all => \@EXPORT_OK,);
|
||
use SL::File;
|
||||
c9b4e6bc | Martin Helmling | sub doc_storage_enabled {
|
||
return 0 unless $::instance_conf->get_doc_storage;
|
||||
return 1 if $::instance_conf->get_doc_storage_for_documents eq 'Filesystem' && $::instance_conf->get_doc_files;
|
||||
return 1 if $::instance_conf->get_doc_storage_for_documents eq 'Webdav' && $::instance_conf->get_doc_webdav;
|
||||
return 0;
|
||||
}
|
||||
0bfbcce6 | Martin Helmling | sub store_pdf {
|
||
my ($self, $form) = @_;
|
||||
c9b4e6bc | Martin Helmling | return unless $self->doc_storage_enabled;
|
||
0bfbcce6 | Martin Helmling | my $type = $form->{type};
|
||
97422880 | Martin Helmling | $type = $form->{formname} if $form->{formname} && !$form->{type};
|
||
$type = $form->{attachment_type} if $form->{attachment_type};
|
||||
0bfbcce6 | Martin Helmling | my $id = $form->{id};
|
||
$id = $form->{attachment_id} if $form->{attachment_id} && !$form->{id};
|
||||
return if !$id || !$type;
|
||||
262811c8 | Bernd Bleßmann | |||
0bfbcce6 | Martin Helmling | SL::File->save(
|
||
0631649c | Bernd Bleßmann | object_id => $id,
|
||
object_type => $type,
|
||||
mime_type => 'application/pdf',
|
||||
source => 'created',
|
||||
file_type => 'document',
|
||||
file_name => $form->{attachment_filename},
|
||||
file_path => $form->{tmpfile},
|
||||
print_variant => $form->{formname},
|
||||
0bfbcce6 | Martin Helmling | );
|
||
}
|
||||
# This method also needed by $form to append all general pdf attachments
|
||||
#
|
||||
sub append_general_pdf_attachments {
|
||||
my ($self, %params) = @_;
|
||||
return 0 unless $::instance_conf->get_doc_storage;
|
||||
return 0 if !$params{filepath} || !$params{type};
|
||||
my @files = SL::File->get_all(
|
||||
object_id => 0,
|
||||
object_type => $params{type},
|
||||
mime_type => 'application/pdf'
|
||||
);
|
||||
return 0 if $#files < 0;
|
||||
my @pdf_file_names = ($params{filepath});
|
||||
foreach my $file (@files) {
|
||||
my $path = $file->get_file;
|
||||
push @pdf_file_names, $path if $path;
|
||||
}
|
||||
#TODO immer noch das alte Problem:
|
||||
#je nachdem von woher der Aufruf kommt ist man in ./users oder .
|
||||
my $savedir = POSIX::getcwd();
|
||||
chdir("$self->{cwd}");
|
||||
$self->merge_pdfs(
|
||||
file_names => \@pdf_file_names,
|
||||
out_path => $params{filepath}
|
||||
);
|
||||
chdir("$savedir");
|
||||
return 0;
|
||||
}
|
||||
1;
|
||||
__END__
|
||||
=encoding utf-8
|
||||
=head1 NAME
|
||||
SL::Helper::File - Helper for $::Form to store generated PDF-Documents
|
||||
=head1 SYNOPSIS
|
||||
# This Helper is used by SL::Form to store new generated PDF-Files and append general attachments to this documents.
|
||||
#
|
||||
# in SL::Form.pm:
|
||||
$self->store_pdf($self);
|
||||
54ce5144 | Martin Helmling | $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type}) if ( $ext_for_format eq 'pdf' );
|
||
#It is also used in MassPrint Helper
|
||||
97422880 | Martin Helmling | #
|
||
0bfbcce6 | Martin Helmling | |||
=head1 DESCRIPTION
|
||||
The files with file_type "generated" are stored.
|
||||
See also L<SL::File>.
|
||||
=head1 METHODS
|
||||
=head2 C<store_pdf>
|
||||
Copy generated PDF-File to File destination.
|
||||
This method is need from SL::Form after LaTeX-PDF Generation
|
||||
=over 4
|
||||
=item C<form.id>
|
||||
ID of ERP-Document
|
||||
=item C<form.type>
|
||||
type of ERP-document
|
||||
=item C<form.formname>
|
||||
if no type is set this is used as type
|
||||
=item C<form.attachment_id>
|
||||
if no id is set this is used as id
|
||||
=item C<form.tmpfile>
|
||||
The path of the generated PDF-file
|
||||
=item C<form.attachment_filename>
|
||||
The generated filename which is used as new filename (without timestamp)
|
||||
=back
|
||||
=head2 C<append_general_pdf_attachments PARAMS>
|
||||
This method also needed by SL::Form to append all general pdf attachments
|
||||
needed C<PARAMS>:
|
||||
=over 4
|
||||
=item C<type>
|
||||
type of ERP-document
|
||||
=item C<outname>
|
||||
Name of file to which the general attachments must be added
|
||||
=back
|
||||
=head1 AUTHOR
|
||||
Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
|
||||
=cut
|