Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision aa925eed

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID aa925eed40c22fe731ac70b496812f7e5a38e240
  • Vorgänger 7d993563
  • Nachfolger a0516348

CreatePDF-Helfer: Funktion zum Auffinden des zu verwendenden Templates

Unterschiede anzeigen:

SL/Helper/CreatePDF.pm
2 2

  
3 3
use strict;
4 4

  
5
use Carp;
5 6
use Cwd;
6 7
use English qw(-no_match_vars);
7 8
use File::Slurp ();
8 9
use File::Temp ();
10
use List::MoreUtils qw(uniq);
11
use List::Util qw(first);
9 12
use String::ShellQuote ();
10 13

  
11 14
use SL::Form;
12 15
use SL::Common;
16
use SL::DB::Language;
17
use SL::DB::Printer;
13 18
use SL::MoreCommon;
14 19
use SL::Template;
15 20
use SL::Template::LaTeX;
16 21

  
17 22
use Exporter 'import';
18
our @EXPORT_OK = qw(create_pdf merge_pdfs);
23
our @EXPORT_OK = qw(create_pdf merge_pdfs find_template);
19 24
our %EXPORT_TAGS = (
20 25
  all => \@EXPORT_OK,
21 26
);
......
98 103
  return scalar File::Slurp::read_file($temp_name);
99 104
}
100 105

  
106
sub find_template {
107
  my ($class, %params) = @_;
108

  
109
  $params{name} or croak "Missing parameter 'name'";
110

  
111
  my $path                 = $::instance_conf->get_templates;
112
  my $extension            = $params{extension} || "tex";
113
  my ($printer, $language) = ('', '');
114

  
115
  if ($params{printer} || $params{printer_id}) {
116
    if ($params{printer} && !ref $params{printer}) {
117
      $printer = '_' . $params{printer};
118
    } else {
119
      $printer = $params{printer} || SL::DB::Printer->new(id => $params{printer_id})->load;
120
      $printer = $printer->template_code ? '_' . $printer->template_code : '';
121
    }
122
  }
123

  
124
  if ($params{language} || $params{language_id}) {
125
    if ($params{language} && !ref $params{language}) {
126
      $language = '_' . $params{language};
127
    } else {
128
      $language = $params{language} || SL::DB::Language->new(id => $params{language_id})->load;
129
      $language = $language->template_code ? '_' . $language->template_code : '';
130
    }
131
  }
132

  
133
  my @template_files = (
134
    $params{name} . "${language}${printer}",
135
    $params{name} . "${language}",
136
    $params{name},
137
    "default",
138
  );
139

  
140
  if ($params{email}) {
141
    unshift @template_files, (
142
      $params{name} . "_email${language}${printer}",
143
      $params{name} . "_email${language}",
144
    );
145
  }
146

  
147
  @template_files = map { "${_}.${extension}" } uniq grep { $_ } @template_files;
148

  
149
  my $template = first { -f ($path . "/$_") } @template_files;
150

  
151
  return wantarray ? ($template, @template_files) : $template;
152
}
153

  
101 154
1;

Auch abrufbar als: Unified diff