xref: /webtrees/app/Report/ReportBaseFootnote.php (revision e7f56f2af615447ab1a7646851f88b465ace9e04)
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 */
16*e7f56f2aSGreg Roachdeclare(strict_types=1);
17*e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
19a25f0a04SGreg Roach
20a25f0a04SGreg Roach/**
21a25f0a04SGreg Roach * Class ReportBaseFootnote
22a25f0a04SGreg Roach */
23c1010edaSGreg Roachclass ReportBaseFootnote extends ReportBaseElement
24c1010edaSGreg Roach{
25a25f0a04SGreg Roach    /**
26a25f0a04SGreg Roach     * The name of the style for this element
27a25f0a04SGreg Roach     *
28a25f0a04SGreg Roach     * @var string
29a25f0a04SGreg Roach     */
307a6ee1acSGreg Roach    public $styleName = '';
31a25f0a04SGreg Roach
32a25f0a04SGreg Roach    /**
33a25f0a04SGreg Roach     * Numbers for the links
34a25f0a04SGreg Roach     *
35a25f0a04SGreg Roach     * @var int
36a25f0a04SGreg Roach     */
37a25f0a04SGreg Roach    public $num;
38a25f0a04SGreg Roach
39a25f0a04SGreg Roach    /**
40a25f0a04SGreg Roach     * The text that will be printed with the number
41a25f0a04SGreg Roach     *
42a25f0a04SGreg Roach     * @var string
43a25f0a04SGreg Roach     */
447a6ee1acSGreg Roach    public $numText = '';
45a25f0a04SGreg Roach
46a25f0a04SGreg Roach    /**
47a25f0a04SGreg Roach     * Remaining width of a cell
48a25f0a04SGreg Roach     *
49a25f0a04SGreg Roach     * @var float User unit (points)
50a25f0a04SGreg Roach     */
51a25f0a04SGreg Roach    public $wrapWidthRemaining;
52a25f0a04SGreg Roach
53a25f0a04SGreg Roach    /**
54a25f0a04SGreg Roach     * Original width of a cell
55a25f0a04SGreg Roach     *
56a25f0a04SGreg Roach     * @var float User unit (points)
57a25f0a04SGreg Roach     */
58a25f0a04SGreg Roach    public $wrapWidthCell;
59a25f0a04SGreg Roach
6076692c8bSGreg Roach    /** @var string A link */
61a25f0a04SGreg Roach    public $addlink;
62a25f0a04SGreg Roach
63a25f0a04SGreg Roach    /**
6476692c8bSGreg Roach     * Createa an element.
6576692c8bSGreg Roach     *
66a25f0a04SGreg Roach     * @param string $style
67a25f0a04SGreg Roach     */
68c1010edaSGreg Roach    public function __construct($style = '')
69c1010edaSGreg Roach    {
707a6ee1acSGreg Roach        $this->text = '';
71a25f0a04SGreg Roach        if (!empty($style)) {
72a25f0a04SGreg Roach            $this->styleName = $style;
73a25f0a04SGreg Roach        } else {
747a6ee1acSGreg Roach            $this->styleName = 'footnote';
75a25f0a04SGreg Roach        }
76a25f0a04SGreg Roach    }
77a25f0a04SGreg Roach
78a25f0a04SGreg Roach    /**
7976692c8bSGreg Roach     * Add text.
8076692c8bSGreg Roach     *
81a25f0a04SGreg Roach     * @param $t
82a25f0a04SGreg Roach     *
836c1eebecSGreg Roach     * @return void
84a25f0a04SGreg Roach     */
856c1eebecSGreg Roach    public function addText(string $t)
86c1010edaSGreg Roach    {
87a25f0a04SGreg Roach        $t          = trim($t, "\r\n\t");
88c1010edaSGreg Roach        $t          = str_replace([
89c1010edaSGreg Roach            '<br>',
90c1010edaSGreg Roach            '&nbsp;',
91c1010edaSGreg Roach        ], [
92c1010edaSGreg Roach            "\n",
93c1010edaSGreg Roach            ' ',
94c1010edaSGreg Roach        ], $t);
95a25f0a04SGreg Roach        $t          = strip_tags($t);
96a25f0a04SGreg Roach        $t          = htmlspecialchars_decode($t);
97a25f0a04SGreg Roach        $this->text .= $t;
98a25f0a04SGreg Roach    }
99a25f0a04SGreg Roach
100a25f0a04SGreg Roach    /**
10176692c8bSGreg Roach     * Set the width to wrap text.
10276692c8bSGreg Roach     *
103a25f0a04SGreg Roach     * @param $wrapwidth
104a25f0a04SGreg Roach     * @param $cellwidth
105a25f0a04SGreg Roach     *
1068ba2e626SGreg Roach     * @return int
107a25f0a04SGreg Roach     */
1088ba2e626SGreg Roach    public function setWrapWidth($wrapwidth, $cellwidth): int
109c1010edaSGreg Roach    {
110a25f0a04SGreg Roach        $this->wrapWidthCell = $cellwidth;
111a25f0a04SGreg Roach        if (strpos($this->numText, "\n") !== false) {
112a25f0a04SGreg Roach            $this->wrapWidthRemaining = $cellwidth;
113a25f0a04SGreg Roach        } else {
114a25f0a04SGreg Roach            $this->wrapWidthRemaining = $wrapwidth;
115a25f0a04SGreg Roach        }
116a25f0a04SGreg Roach
117a25f0a04SGreg Roach        return $this->wrapWidthRemaining;
118a25f0a04SGreg Roach    }
119a25f0a04SGreg Roach
120a25f0a04SGreg Roach    /**
12176692c8bSGreg Roach     * Set the number.
12276692c8bSGreg Roach     *
123a25f0a04SGreg Roach     * @param $n
124a25f0a04SGreg Roach     *
125cbc1590aSGreg Roach     * @return int
126a25f0a04SGreg Roach     */
1278f53f488SRico Sonntag    public function setNum($n): int
128c1010edaSGreg Roach    {
129a25f0a04SGreg Roach        $this->num     = $n;
130a25f0a04SGreg Roach        $this->numText = "$n ";
131a25f0a04SGreg Roach
132a25f0a04SGreg Roach        return 0;
133a25f0a04SGreg Roach    }
134a25f0a04SGreg Roach
135a25f0a04SGreg Roach    /**
13676692c8bSGreg Roach     * Add a link.
13776692c8bSGreg Roach     *
138a25f0a04SGreg Roach     * @param $a
139a25f0a04SGreg Roach     *
140cbc1590aSGreg Roach     * @return int
141a25f0a04SGreg Roach     */
1428f53f488SRico Sonntag    public function setAddlink($a): int
143c1010edaSGreg Roach    {
144a25f0a04SGreg Roach        $this->addlink = $a;
145a25f0a04SGreg Roach
146a25f0a04SGreg Roach        return 0;
147a25f0a04SGreg Roach    }
148a25f0a04SGreg Roach}
149