initial commit
[namibia] / module / Utility / src / Utility / Export / PdfTemplate.php
1 <?php
2 namespace Utility\Export;
3
4
5
6 class PdfTemplate
7 {
8
9         /**
10          * Filename to use for output
11          * @var string
12          */
13         protected $_fileName = null;
14
15
16
17         /**
18          * Constructor.
19          * @param \Utility\Service\PdfTemplate $template
20          */
21         public function __construct(\Utility\Service\PdfTemplate $template)
22         {
23                 $this->_fileName = str_replace(' ', '-', $template->getTitle()) . '.pdf';
24                 $this->_htmlData = $template->getHtml();
25         }
26
27         /**
28          * Output result.
29          * @todo  add email, filesystem and ftp as potential targets.
30          * @param null|string $target
31          */
32         public function output($target = null)
33         {
34                 set_time_limit(90);
35
36                 $html2pdf = new \HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(5, 5, 5, 5));
37                 $html2pdf->writeHTML($this->_htmlData);
38                 if (is_null($target))
39                 {
40                         #-> Direct output.
41                         $html2pdf->Output($this->_fileName, 'D');
42                         exit(0);
43                 }
44                 elseif (strpos($target, '@'))
45                 {
46                         #-> Send to email.
47                 }
48                 elseif (empty($target))
49                 {
50                         #-> Return document.
51                         return $html2pdf->Output($this->_fileName, 'S');
52                 }
53                 else
54                 {
55                         #-> Write to file.
56                         $html2pdf->Output($target . $this->_fileName, 'F');
57                 }
58         }
59
60
61 }