xref: /webtrees/app/Report/ReportBaseFootnote.php (revision 6c1eebec4aa5bd884cd4af58f83736c7af4d7509)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Report;
17
18/**
19 * Class ReportBaseFootnote
20 */
21class ReportBaseFootnote extends ReportBaseElement
22{
23    /**
24     * The name of the style for this element
25     *
26     * @var string
27     */
28    public $styleName = '';
29
30    /**
31     * Numbers for the links
32     *
33     * @var int
34     */
35    public $num;
36
37    /**
38     * The text that will be printed with the number
39     *
40     * @var string
41     */
42    public $numText = '';
43
44    /**
45     * Remaining width of a cell
46     *
47     * @var float User unit (points)
48     */
49    public $wrapWidthRemaining;
50
51    /**
52     * Original width of a cell
53     *
54     * @var float User unit (points)
55     */
56    public $wrapWidthCell;
57
58    /** @var string A link */
59    public $addlink;
60
61    /**
62     * Createa an element.
63     *
64     * @param string $style
65     */
66    public function __construct($style = '')
67    {
68        $this->text = '';
69        if (!empty($style)) {
70            $this->styleName = $style;
71        } else {
72            $this->styleName = 'footnote';
73        }
74    }
75
76    /**
77     * Add text.
78     *
79     * @param $t
80     *
81     * @return void
82     */
83    public function addText(string $t)
84    {
85        $t          = trim($t, "\r\n\t");
86        $t          = str_replace([
87            '<br>',
88            '&nbsp;',
89        ], [
90            "\n",
91            ' ',
92        ], $t);
93        $t          = strip_tags($t);
94        $t          = htmlspecialchars_decode($t);
95        $this->text .= $t;
96    }
97
98    /**
99     * Set the width to wrap text.
100     *
101     * @param $wrapwidth
102     * @param $cellwidth
103     *
104     * @return int
105     */
106    public function setWrapWidth($wrapwidth, $cellwidth): int
107    {
108        $this->wrapWidthCell = $cellwidth;
109        if (strpos($this->numText, "\n") !== false) {
110            $this->wrapWidthRemaining = $cellwidth;
111        } else {
112            $this->wrapWidthRemaining = $wrapwidth;
113        }
114
115        return $this->wrapWidthRemaining;
116    }
117
118    /**
119     * Set the number.
120     *
121     * @param $n
122     *
123     * @return int
124     */
125    public function setNum($n): int
126    {
127        $this->num     = $n;
128        $this->numText = "$n ";
129
130        return 0;
131    }
132
133    /**
134     * Add a link.
135     *
136     * @param $a
137     *
138     * @return int
139     */
140    public function setAddlink($a): int
141    {
142        $this->addlink = $a;
143
144        return 0;
145    }
146}
147