xref: /webtrees/app/Report/ReportBaseElement.php (revision 589feda391b943b928aea0b4107591eb0e7bbf89)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8a25f0a04SGreg Roach * (at your option) any later version.
9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a25f0a04SGreg Roach * GNU General Public License for more details.
13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15a25f0a04SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
19a25f0a04SGreg Roach
20a25f0a04SGreg Roach/**
21a25f0a04SGreg Roach * Class ReportBaseElement
22a25f0a04SGreg Roach */
23c1010edaSGreg Roachclass ReportBaseElement
24c1010edaSGreg Roach{
2576692c8bSGreg Roach    /** @var string Text */
2676692c8bSGreg Roach    public $text = '';
27a25f0a04SGreg Roach
28a25f0a04SGreg Roach    /**
29a25f0a04SGreg Roach     * Element renderer
30a25f0a04SGreg Roach     *
31729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
32c7ff4153SGreg Roach     *
33c7ff4153SGreg Roach     * @return void
34a25f0a04SGreg Roach     */
35c1010edaSGreg Roach    public function render($renderer)
36c1010edaSGreg Roach    {
37a25f0a04SGreg Roach        //-- to be implemented in inherited classes
38a25f0a04SGreg Roach    }
39a25f0a04SGreg Roach
40a25f0a04SGreg Roach    /**
4176692c8bSGreg Roach     * Get the height.
4276692c8bSGreg Roach     *
43729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
44a25f0a04SGreg Roach     *
45a25f0a04SGreg Roach     * @return float
46a25f0a04SGreg Roach     */
478f53f488SRico Sonntag    public function getHeight($renderer): float
48c1010edaSGreg Roach    {
49a25f0a04SGreg Roach        return 0.0;
50a25f0a04SGreg Roach    }
51a25f0a04SGreg Roach
52a25f0a04SGreg Roach    /**
5376692c8bSGreg Roach     * Get the width.
5476692c8bSGreg Roach     *
55729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
56a25f0a04SGreg Roach     *
578ba2e626SGreg Roach     * @return float|array
58a25f0a04SGreg Roach     */
598ba2e626SGreg Roach    public function getWidth($renderer)
60c1010edaSGreg Roach    {
61a25f0a04SGreg Roach        return 0.0;
62a25f0a04SGreg Roach    }
63a25f0a04SGreg Roach
64a25f0a04SGreg Roach    /**
6576692c8bSGreg Roach     * Add text.
6676692c8bSGreg Roach     *
67a25f0a04SGreg Roach     * @param string $t
68a25f0a04SGreg Roach     *
696c1eebecSGreg Roach     * @return void
70a25f0a04SGreg Roach     */
716c1eebecSGreg Roach    public function addText(string $t)
72c1010edaSGreg Roach    {
73a25f0a04SGreg Roach        $t          = trim($t, "\r\n\t");
74c1010edaSGreg Roach        $t          = str_replace([
75c1010edaSGreg Roach            '<br>',
76c1010edaSGreg Roach            '&nbsp;',
77c1010edaSGreg Roach        ], [
78c1010edaSGreg Roach            "\n",
79c1010edaSGreg Roach            ' ',
80c1010edaSGreg Roach        ], $t);
81a25f0a04SGreg Roach        $t          = strip_tags($t);
82a25f0a04SGreg Roach        $t          = htmlspecialchars_decode($t);
83a25f0a04SGreg Roach        $this->text .= $t;
84a25f0a04SGreg Roach    }
85a25f0a04SGreg Roach
86a25f0a04SGreg Roach    /**
8776692c8bSGreg Roach     * Add an end-of-line.
8876692c8bSGreg Roach     *
89*589feda3SGreg Roach     * @return void
90a25f0a04SGreg Roach     */
91*589feda3SGreg Roach    public function addNewline()
92c1010edaSGreg Roach    {
93a25f0a04SGreg Roach        $this->text .= "\n";
94a25f0a04SGreg Roach    }
95a25f0a04SGreg Roach
96a25f0a04SGreg Roach    /**
9776692c8bSGreg Roach     * Get the current text.
9876692c8bSGreg Roach     *
99a25f0a04SGreg Roach     * @return string
100a25f0a04SGreg Roach     */
1018f53f488SRico Sonntag    public function getValue(): string
102c1010edaSGreg Roach    {
103a25f0a04SGreg Roach        return $this->text;
104a25f0a04SGreg Roach    }
105a25f0a04SGreg Roach
106a25f0a04SGreg Roach    /**
10776692c8bSGreg Roach     * Set the width to wrap text.
10876692c8bSGreg Roach     *
109a25f0a04SGreg Roach     * @param $wrapwidth
110a25f0a04SGreg Roach     * @param $cellwidth
111a25f0a04SGreg Roach     *
112*589feda3SGreg Roach     * @return float
113a25f0a04SGreg Roach     */
114*589feda3SGreg Roach    public function setWrapWidth($wrapwidth, $cellwidth): float
115c1010edaSGreg Roach    {
116a25f0a04SGreg Roach        return 0;
117a25f0a04SGreg Roach    }
118a25f0a04SGreg Roach
119a25f0a04SGreg Roach    /**
12076692c8bSGreg Roach     * Render the footnotes.
12176692c8bSGreg Roach     *
122a25f0a04SGreg Roach     * @param $renderer
12318d7a90dSGreg Roach     *
12418d7a90dSGreg Roach     * @return void
125a25f0a04SGreg Roach     */
126c1010edaSGreg Roach    public function renderFootnote($renderer)
127c1010edaSGreg Roach    {
128a25f0a04SGreg Roach    }
129a25f0a04SGreg Roach
130a25f0a04SGreg Roach    /**
13176692c8bSGreg Roach     * Set the text.
13276692c8bSGreg Roach     *
133a25f0a04SGreg Roach     * @param $text
13418d7a90dSGreg Roach     *
13518d7a90dSGreg Roach     * @return void
136a25f0a04SGreg Roach     */
137c1010edaSGreg Roach    public function setText($text)
138c1010edaSGreg Roach    {
139a25f0a04SGreg Roach        $this->text = $text;
140a25f0a04SGreg Roach    }
141a25f0a04SGreg Roach}
142