summaryrefslogtreecommitdiff
path: root/app/Controller/CompactController.php
blob: a73b4c491f8f36beb250eb8b454e4b635a7aeef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Fisharebest\Webtrees\Controller;

use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\I18N;

/**
 * Controller for the compact chart
 */
class CompactController extends ChartController {
	/** @var bool Data for the view .*/
	public $show_thumbs = false;

	/** int[] Data for the controller. */
	private $treeid = array();

	/**
	 * Startup activity
	 */
	public function __construct() {
		parent::__construct();

		// Extract the request parameters
		$this->show_thumbs = Filter::getBool('show_thumbs');

		if ($this->root && $this->root->canShowName()) {
			$this->setPageTitle(
				/* I18N: %s is an individual’s name */
			I18N::translate('Compact tree of %s', $this->root->getFullName())
		);
		} else {
			$this->setPageTitle(I18N::translate('Compact tree'));
		}
		$this->treeid = $this->sosaAncestors(5);
	}

	/**
	 * Get an individual by their SOSA number.
	 *
	 * @param int $n
	 *
	 * @return string
	 */
	public function sosaIndividual($n) {
		$indi = $this->treeid[$n];

		if ($indi && $indi->canShowName()) {
			$name    = $indi->getFullName();
			$addname = $indi->getAddName();

			if ($this->show_thumbs && $indi->getTree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) {
				$html = $indi->displayImage();
			} else {
				$html = '';
			}

			$html .= '<a class="name1" href="' . $indi->getHtmlUrl() . '">';
			$html .= $name;
			if ($addname) {
				$html .= '<br>' . $addname;
			}
			$html .= '</a>';
			$html .= '<br>';
			if ($indi->canShow()) {
				$html .= '<div class="details1">' . $indi->getLifeSpan() . '</div>';
			}
		} else {
			// Empty box
			$html = '&nbsp;';
		}

		// -- box color
		$isF = '';
		if ($n == 1) {
			if ($indi && $indi->getSex() == 'F') {
				$isF = 'F';
			}
		} elseif ($n % 2) {
			$isF = 'F';
		}

		// -- box size
		if ($n == 1) {
			return '<td class="person_box' . $isF . ' person_box_template" style="text-align:center; vertical-align:top;">' . $html . '</td>';
		} else {
			return '<td class="person_box' . $isF . ' person_box_template" style="text-align:center; vertical-align:top;" width="15%">' . $html . '</td>';
		}
	}

	/**
	 * Get an arrow, pointing to other generations.
	 *
	 * @param int    $n
	 * @param string $arrow_dir
	 *
	 * @return string
	 */
	public function sosaArrow($n, $arrow_dir) {
		$indi = $this->treeid[$n];

		$arrow_dir = substr($arrow_dir, 0, 1);
		if (I18N::direction() === 'rtl') {
			if ($arrow_dir === 'l') {
				$arrow_dir = 'r';
			} elseif ($arrow_dir === 'r') {
				$arrow_dir = 'l';
			}
		}

		if ($indi) {
			$title = I18N::translate('Compact tree of %s', $indi->getFullName());
			$text  = '<a class="icon-' . $arrow_dir . 'arrow" title="' . strip_tags($title) . '" href="?rootid=' . $indi->getXref();
			if ($this->show_thumbs) {
				$text .= "&amp;show_thumbs=" . $this->show_thumbs;
			}
			$text .= "\"></a>";
		} else {
			$text = '<i class="icon-' . $arrow_dir . 'arrow"></i>';
		}

		return $text;
	}
}