1<?php
2/**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10namespace Piwik;
11
12use Exception;
13
14/**
15 * TCPDF class wrapper.
16 *
17 */
18class TCPDF extends \TCPDF
19{
20    protected $footerContent = null;
21    protected $currentPageNo = null;
22
23    /**
24     * Render page footer
25     *
26     * @see TCPDF::Footer()
27     */
28    public function Footer()
29    {
30        //Don't show footer on the frontPage
31        if ($this->currentPageNo > 1) {
32            $this->SetY(-15);
33            $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
34            $this->Cell(0, 10, $this->footerContent . Piwik::translate('ScheduledReports_Pagination', array($this->getAliasNumPage(), $this->getAliasNbPages())), 0, false, 'C', 0, '', 0, false, 'T', 'M');
35        }
36    }
37
38    /**
39     * @see TCPDF::Error()
40     * @param $msg
41     * @throws Exception
42     */
43    public function Error($msg)
44    {
45        $this->_destroy(true);
46        throw new Exception($msg);
47    }
48
49    /**
50     * Set current page number
51     */
52    public function setCurrentPageNo()
53    {
54        if (empty($this->currentPageNo)) {
55            $this->currentPageNo = 1;
56        } else {
57            $this->currentPageNo++;
58        }
59    }
60
61    /**
62     * Add page to document
63     *
64     * @see TCPDF::AddPage()
65     *
66     * @param string $orientation
67     * @param mixed $format
68     * @param bool $keepmargins
69     * @param bool $tocpage
70     */
71    public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
72    {
73        parent::AddPage($orientation);
74        $this->setCurrentPageNo();
75    }
76
77    /**
78     * Set footer content
79     *
80     * @param string $footerContent
81     */
82    public function SetFooterContent($footerContent)
83    {
84        $this->footerContent = $footerContent;
85    }
86}
87