1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees: online genealogy |
4
|
|
|
* Copyright (C) 2017 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
|
|
|
*/ |
16
|
|
|
namespace Fisharebest\Webtrees\Controller; |
17
|
|
|
|
18
|
|
|
use Fisharebest\Webtrees\Date; |
19
|
|
|
use Fisharebest\Webtrees\Date\GregorianDate; |
20
|
|
|
use Fisharebest\Webtrees\Fact; |
21
|
|
|
use Fisharebest\Webtrees\Family; |
22
|
|
|
use Fisharebest\Webtrees\Filter; |
23
|
|
|
use Fisharebest\Webtrees\Functions\FunctionsDate; |
24
|
|
|
use Fisharebest\Webtrees\Functions\FunctionsPrint; |
25
|
|
|
use Fisharebest\Webtrees\Html; |
26
|
|
|
use Fisharebest\Webtrees\I18N; |
27
|
|
|
use Fisharebest\Webtrees\Individual; |
28
|
|
|
use Fisharebest\Webtrees\Theme; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Controller for the timeline chart |
32
|
|
|
*/ |
33
|
|
|
class TimelineController extends PageController { |
34
|
|
|
/** @var int Height of the age box */ |
35
|
|
|
public $bheight = 30; |
36
|
|
|
|
37
|
|
|
/** @var Fact[] The facts to display on the chart */ |
38
|
|
|
public $indifacts = []; // array to store the fact records in for sorting and displaying |
39
|
|
|
|
40
|
|
|
/** @var int[] Numeric birth years of each individual */ |
41
|
|
|
public $birthyears = []; |
42
|
|
|
|
43
|
|
|
/** @var int[] Numeric birth months of each individual */ |
44
|
|
|
public $birthmonths = []; |
45
|
|
|
|
46
|
|
|
/** @var int[] Numeric birth days of each individual */ |
47
|
|
|
public $birthdays = []; |
48
|
|
|
|
49
|
|
|
/** @var int Lowest year to display */ |
50
|
|
|
public $baseyear = 0; |
51
|
|
|
|
52
|
|
|
/** @var int Highest year to display */ |
53
|
|
|
public $topyear = 0; |
54
|
|
|
|
55
|
|
|
/** @var Individual[] List of individuals to display */ |
56
|
|
|
public $people = []; |
57
|
|
|
|
58
|
|
|
/** @var string URL-encoded list of XREFs */ |
59
|
|
|
public $pidlinks = ''; |
60
|
|
|
|
61
|
|
|
/** @var int Vertical scale */ |
62
|
|
|
public $scale = 2; |
63
|
|
|
|
64
|
|
|
/** @var string[] GEDCOM elements that may have DATE data, but should not be displayed */ |
65
|
|
|
private $nonfacts = ['BAPL', 'ENDL', 'SLGC', 'SLGS', '_TODO', 'CHAN']; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Startup activity |
69
|
|
|
*/ |
70
|
|
|
public function __construct() { |
71
|
|
|
parent::__construct(); |
72
|
|
|
|
73
|
|
|
$this->setPageTitle(I18N::translate('Timeline')); |
74
|
|
|
|
75
|
|
|
$this->baseyear = (int) date('Y'); |
76
|
|
|
|
77
|
|
|
$remove = Filter::get('remove', WT_REGEX_XREF); |
78
|
|
|
$newpid = Filter::get('newpid', WT_REGEX_XREF); |
79
|
|
|
$pids = Filter::getArray('pids', WT_REGEX_XREF); |
80
|
|
|
$pids[] = $newpid; |
81
|
|
|
|
82
|
|
|
foreach (array_unique(array_filter($pids)) as $pid) { |
83
|
|
|
if ($pid !== $remove) { |
84
|
|
|
$person = Individual::getInstance($pid, $this->tree()); |
85
|
|
|
if ($person && $person->canShow()) { |
86
|
|
|
$this->people[] = $person; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
$this->pidlinks = ''; |
91
|
|
|
|
92
|
|
|
foreach ($this->people as $indi) { |
93
|
|
|
// setup string of valid pids for links |
94
|
|
|
$this->pidlinks .= 'pids%5B%5D=' . $indi->getXref() . '&'; |
95
|
|
|
$bdate = $indi->getBirthDate(); |
|
|
|
|
96
|
|
|
if ($bdate->isOK()) { |
97
|
|
|
$date = new GregorianDate($bdate->minimumJulianDay()); |
98
|
|
|
$this->birthyears [$indi->getXref()] = $date->y; |
99
|
|
|
$this->birthmonths[$indi->getXref()] = max(1, $date->m); |
100
|
|
|
$this->birthdays [$indi->getXref()] = max(1, $date->d); |
101
|
|
|
} |
102
|
|
|
// find all the fact information |
103
|
|
|
$facts = $indi->getFacts(); |
104
|
|
|
foreach ($indi->getSpouseFamilies() as $family) { |
|
|
|
|
105
|
|
|
foreach ($family->getFacts() as $fact) { |
106
|
|
|
$facts[] = $fact; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
foreach ($facts as $event) { |
110
|
|
|
// get the fact type |
111
|
|
|
$fact = $event->getTag(); |
112
|
|
|
if (!in_array($fact, $this->nonfacts)) { |
113
|
|
|
// check for a date |
114
|
|
|
$date = $event->getDate(); |
115
|
|
|
if ($date->isOK()) { |
116
|
|
|
$date = new GregorianDate($date->minimumJulianDay()); |
117
|
|
|
$this->baseyear = min($this->baseyear, $date->y); |
118
|
|
|
$this->topyear = max($this->topyear, $date->y); |
119
|
|
|
|
120
|
|
|
if (!$indi->isDead()) { |
|
|
|
|
121
|
|
|
$this->topyear = max($this->topyear, (int) date('Y')); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// do not add the same fact twice (prevents marriages from being added multiple times) |
125
|
|
|
if (!in_array($event, $this->indifacts, true)) { |
126
|
|
|
$this->indifacts[] = $event; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
$scale = Filter::getInteger('scale', 0, 200); |
133
|
|
|
if ($scale === 0) { |
134
|
|
|
$this->scale = (int) (($this->topyear - $this->baseyear) / 20 * count($this->indifacts) / 4); |
135
|
|
|
if ($this->scale < 6) { |
136
|
|
|
$this->scale = 6; |
137
|
|
|
} |
138
|
|
|
} else { |
139
|
|
|
$this->scale = $scale; |
140
|
|
|
} |
141
|
|
|
if ($this->scale < 2) { |
142
|
|
|
$this->scale = 2; |
143
|
|
|
} |
144
|
|
|
$this->baseyear -= 5; |
145
|
|
|
$this->topyear += 5; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Print a fact for an individual. |
150
|
|
|
* |
151
|
|
|
* @param Fact $event |
152
|
|
|
*/ |
153
|
|
|
public function printTimeFact(Fact $event) { |
154
|
|
|
global $factcount, $placements; |
155
|
|
|
|
156
|
|
|
$desc = $event->getValue(); |
157
|
|
|
// check if this is a family fact |
158
|
|
|
$gdate = $event->getDate(); |
159
|
|
|
$date = $gdate->minimumDate(); |
160
|
|
|
$date = $date->convertToCalendar('gregorian'); |
161
|
|
|
$year = $date->y; |
162
|
|
|
$month = max(1, $date->m); |
163
|
|
|
$day = max(1, $date->d); |
164
|
|
|
$xoffset = 0 + 22; |
165
|
|
|
$yoffset = 0 + (($year - $this->baseyear) * $this->scale) - ($this->scale); |
166
|
|
|
$yoffset = $yoffset + (($month / 12) * $this->scale); |
167
|
|
|
$yoffset = $yoffset + (($day / 30) * ($this->scale / 12)); |
168
|
|
|
$yoffset = (int) ($yoffset); |
169
|
|
|
$place = (int) ($yoffset / $this->bheight); |
170
|
|
|
$i = 1; |
171
|
|
|
$j = 0; |
172
|
|
|
$tyoffset = 0; |
173
|
|
|
while (isset($placements[$place])) { |
174
|
|
|
if ($i === $j) { |
175
|
|
|
$tyoffset = $this->bheight * $i; |
176
|
|
|
$i++; |
177
|
|
|
} else { |
178
|
|
|
$tyoffset = -1 * $this->bheight * $j; |
179
|
|
|
$j++; |
180
|
|
|
} |
181
|
|
|
$place = (int) (($yoffset + $tyoffset) / ($this->bheight)); |
182
|
|
|
} |
183
|
|
|
$yoffset += $tyoffset; |
184
|
|
|
$xoffset += abs($tyoffset); |
185
|
|
|
$placements[$place] = $yoffset; |
186
|
|
|
|
187
|
|
|
echo "<div id=\"fact$factcount\" style=\"position:absolute; " . (I18N::direction() === 'ltr' ? 'left: ' . ($xoffset) : 'right: ' . ($xoffset)) . 'px; top:' . ($yoffset) . 'px; font-size: 8pt; height: ' . ($this->bheight) . "px;\" onmousedown=\"factMouseDown(this, '" . $factcount . "', " . ($yoffset - $tyoffset) . ');">'; |
188
|
|
|
echo '<table cellspacing="0" cellpadding="0" border="0" style="cursor: hand;"><tr><td>'; |
189
|
|
|
echo '<img src="' . Theme::theme()->parameter('image-hline') . '" name="boxline' . $factcount . '" id="boxline' . $factcount . '" height="3" width="10" style="padding-'; |
190
|
|
|
if (I18N::direction() === 'ltr') { |
191
|
|
|
echo 'left: 3px;">'; |
192
|
|
|
} else { |
193
|
|
|
echo 'right: 3px;">'; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$col = array_search($event->getParent(), $this->people); |
197
|
|
|
if ($col === false) { |
198
|
|
|
// Marriage event - use the color of the husband |
199
|
|
|
$col = array_search($event->getParent()->getHusband(), $this->people); |
|
|
|
|
200
|
|
|
} |
201
|
|
|
if ($col === false) { |
202
|
|
|
// Marriage event - use the color of the wife |
203
|
|
|
$col = array_search($event->getParent()->getWife(), $this->people); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
$col = $col % 6; |
206
|
|
|
echo '</td><td class="person' . $col . '">'; |
207
|
|
|
if (count($this->people) > 6) { |
208
|
|
|
// We only have six colours, so show naes if more than this number |
209
|
|
|
echo $event->getParent()->getFullName() . ' — '; |
210
|
|
|
} |
211
|
|
|
$record = $event->getParent(); |
212
|
|
|
echo $event->getLabel(); |
213
|
|
|
echo ' — '; |
214
|
|
|
if ($record instanceof Individual) { |
215
|
|
|
echo FunctionsPrint::formatFactDate($event, $record, false, false); |
216
|
|
|
} elseif ($record instanceof Family) { |
217
|
|
|
echo $gdate->display(); |
218
|
|
View Code Duplication |
if ($record->getHusband() && $record->getHusband()->getBirthDate()->isOK()) { |
219
|
|
|
$ageh = FunctionsDate::getAgeAtEvent(Date::getAgeGedcom($record->getHusband()->getBirthDate(), $gdate)); |
220
|
|
|
} else { |
221
|
|
|
$ageh = null; |
222
|
|
|
} |
223
|
|
View Code Duplication |
if ($record->getWife() && $record->getWife()->getBirthDate()->isOK()) { |
224
|
|
|
$agew = FunctionsDate::getAgeAtEvent(Date::getAgeGedcom($record->getWife()->getBirthDate(), $gdate)); |
225
|
|
|
} else { |
226
|
|
|
$agew = null; |
227
|
|
|
} |
228
|
|
|
if ($ageh && $agew) { |
|
|
|
|
229
|
|
|
echo '<span class="age"> ', I18N::translate('Husband’s age'), ' ', $ageh, ' ', I18N::translate('Wife’s age'), ' ', $agew, '</span>'; |
230
|
|
|
} elseif ($ageh) { |
|
|
|
|
231
|
|
|
echo '<span class="age"> ', I18N::translate('Age'), ' ', $ageh, '</span>'; |
232
|
|
|
} elseif ($agew) { |
|
|
|
|
233
|
|
|
echo '<span class="age"> ', I18N::translate('Age'), ' ', $ageh, '</span>'; |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
echo ' ' . Html::escape($desc); |
237
|
|
|
if (!$event->getPlace()->isEmpty()) { |
238
|
|
|
echo ' — ' . $event->getPlace()->getShortName(); |
239
|
|
|
} |
240
|
|
|
// Print spouses names for family events |
241
|
|
|
if ($event->getParent() instanceof Family) { |
242
|
|
|
echo ' — <a href="', $event->getParent()->getHtmlUrl(), '">', $event->getParent()->getFullName(), '</a>'; |
243
|
|
|
} |
244
|
|
|
echo '</td></tr></table>'; |
245
|
|
|
echo '</div>'; |
246
|
|
View Code Duplication |
if (I18N::direction() === 'ltr') { |
247
|
|
|
$img = 'image-dline2'; |
248
|
|
|
$ypos = '0%'; |
249
|
|
|
} else { |
250
|
|
|
$img = 'image-dline'; |
251
|
|
|
$ypos = '100%'; |
252
|
|
|
} |
253
|
|
|
$dyoffset = ($yoffset - $tyoffset) + $this->bheight / 3; |
254
|
|
|
if ($tyoffset < 0) { |
255
|
|
|
$dyoffset = $yoffset + $this->bheight / 3; |
256
|
|
View Code Duplication |
if (I18N::direction() === 'ltr') { |
257
|
|
|
$img = 'image-dline'; |
258
|
|
|
$ypos = '100%'; |
259
|
|
|
} else { |
260
|
|
|
$img = 'image-dline2'; |
261
|
|
|
$ypos = '0%'; |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
// Print the diagonal line |
265
|
|
|
echo '<div id="dbox' . $factcount . '" style="position:absolute; ' . (I18N::direction() === 'ltr' ? 'left: ' . (0 + 25) : 'right: ' . (0 + 25)) . 'px; top:' . ($dyoffset) . 'px; font-size: 8pt; height: ' . abs($tyoffset) . 'px; width: ' . abs($tyoffset) . 'px;'; |
266
|
|
|
echo ' background-image: url(\'' . Theme::theme()->parameter($img) . '\');'; |
267
|
|
|
echo ' background-position: 0% ' . $ypos . ';">'; |
268
|
|
|
echo '</div>'; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Get significant information from this page, to allow other pages such as |
273
|
|
|
* charts and reports to initialise with the same records |
274
|
|
|
* |
275
|
|
|
* @return Individual |
276
|
|
|
*/ |
277
|
|
|
public function getSignificantIndividual() { |
278
|
|
|
if ($this->people) { |
|
|
|
|
279
|
|
|
return $this->people[0]; |
280
|
|
|
} else { |
281
|
|
|
return parent::getSignificantIndividual(); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|