xref: /webtrees/app/Report/ReportBaseFootnote.php (revision b2ce94c6833c25934b40a7e6bc15985d50b5f42a)
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 int
82     */
83    public function addText($t): int
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        return 0;
98    }
99
100    /**
101     * Set the width to wrap text.
102     *
103     * @param $wrapwidth
104     * @param $cellwidth
105     *
106     * @return int
107     */
108    public function setWrapWidth($wrapwidth, $cellwidth): int
109    {
110        $this->wrapWidthCell = $cellwidth;
111        if (strpos($this->numText, "\n") !== false) {
112            $this->wrapWidthRemaining = $cellwidth;
113        } else {
114            $this->wrapWidthRemaining = $wrapwidth;
115        }
116
117        return $this->wrapWidthRemaining;
118    }
119
120    /**
121     * Set the number.
122     *
123     * @param $n
124     *
125     * @return int
126     */
127    public function setNum($n): int
128    {
129        $this->num     = $n;
130        $this->numText = "$n ";
131
132        return 0;
133    }
134
135    /**
136     * Add a link.
137     *
138     * @param $a
139     *
140     * @return int
141     */
142    public function setAddlink($a): int
143    {
144        $this->addlink = $a;
145
146        return 0;
147    }
148}
149