1168ff6f3Sric2016<?php 2168ff6f3Sric2016/** 3168ff6f3Sric2016 * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 5168ff6f3Sric2016 * This program is free software: you can redistribute it and/or modify 6168ff6f3Sric2016 * it under the terms of the GNU General Public License as published by 7168ff6f3Sric2016 * the Free Software Foundation, either version 3 of the License, or 8168ff6f3Sric2016 * (at your option) any later version. 9168ff6f3Sric2016 * This program is distributed in the hope that it will be useful, 10168ff6f3Sric2016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11168ff6f3Sric2016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12168ff6f3Sric2016 * GNU General Public License for more details. 13168ff6f3Sric2016 * You should have received a copy of the GNU General Public License 14168ff6f3Sric2016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15168ff6f3Sric2016 */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 18168ff6f3Sric2016namespace Fisharebest\Webtrees\Module; 19168ff6f3Sric2016 20e2b8114dSGreg Roachuse Fisharebest\ExtCalendar\GregorianCalendar; 219867b2f0SGreg Roachuse Fisharebest\Webtrees\Auth; 22e2b8114dSGreg Roachuse Fisharebest\Webtrees\ColorGenerator; 23e2b8114dSGreg Roachuse Fisharebest\Webtrees\Date; 24168ff6f3Sric2016use Fisharebest\Webtrees\I18N; 25168ff6f3Sric2016use Fisharebest\Webtrees\Individual; 26e2b8114dSGreg Roachuse Fisharebest\Webtrees\Place; 27e2b8114dSGreg Roachuse Fisharebest\Webtrees\Tree; 28e2b8114dSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 29e2b8114dSGreg Roachuse Illuminate\Database\Query\JoinClause; 306ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 316ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 32e2b8114dSGreg Roachuse stdClass; 33168ff6f3Sric2016 34168ff6f3Sric2016/** 35168ff6f3Sric2016 * Class LifespansChartModule 36168ff6f3Sric2016 */ 3737eb8894SGreg Roachclass LifespansChartModule extends AbstractModule implements ModuleChartInterface 38c1010edaSGreg Roach{ 3949a243cbSGreg Roach use ModuleChartTrait; 4049a243cbSGreg Roach 41e2b8114dSGreg Roach // Parameters for generating colors 42e2b8114dSGreg Roach protected const RANGE = 120; // degrees 43e2b8114dSGreg Roach protected const SATURATION = 100; // percent 44e2b8114dSGreg Roach protected const LIGHTNESS = 30; // percent 45e2b8114dSGreg Roach protected const ALPHA = 0.25; 46e2b8114dSGreg Roach 47168ff6f3Sric2016 /** 480cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 49168ff6f3Sric2016 * 50168ff6f3Sric2016 * @return string 51168ff6f3Sric2016 */ 5249a243cbSGreg Roach public function title(): string 53c1010edaSGreg Roach { 54bbb76c12SGreg Roach /* I18N: Name of a module/chart */ 55bbb76c12SGreg Roach return I18N::translate('Lifespans'); 56168ff6f3Sric2016 } 57168ff6f3Sric2016 58168ff6f3Sric2016 /** 59168ff6f3Sric2016 * A sentence describing what this module does. 60168ff6f3Sric2016 * 61168ff6f3Sric2016 * @return string 62168ff6f3Sric2016 */ 6349a243cbSGreg Roach public function description(): string 64c1010edaSGreg Roach { 65bbb76c12SGreg Roach /* I18N: Description of the “LifespansChart” module */ 66bbb76c12SGreg Roach return I18N::translate('A chart of individuals’ lifespans.'); 67168ff6f3Sric2016 } 68168ff6f3Sric2016 69168ff6f3Sric2016 /** 70377a2979SGreg Roach * CSS class for the URL. 71377a2979SGreg Roach * 72377a2979SGreg Roach * @return string 73377a2979SGreg Roach */ 74377a2979SGreg Roach public function chartMenuClass(): string 75377a2979SGreg Roach { 76377a2979SGreg Roach return 'menu-chart-lifespan'; 77377a2979SGreg Roach } 78377a2979SGreg Roach 79377a2979SGreg Roach /** 80e6562982SGreg Roach * The URL for this chart. 81168ff6f3Sric2016 * 8260bc3e3fSGreg Roach * @param Individual $individual 83e6562982SGreg Roach * @param string[] $parameters 8460bc3e3fSGreg Roach * 85e6562982SGreg Roach * @return string 86168ff6f3Sric2016 */ 87e6562982SGreg Roach public function chartUrl(Individual $individual, array $parameters = []): string 88c1010edaSGreg Roach { 89e2b8114dSGreg Roach return route('module', [ 90e2b8114dSGreg Roach 'module' => $this->name(), 91e2b8114dSGreg Roach 'action' => 'Chart', 92c0935879SGreg Roach 'xrefs[]' => $individual->xref(), 93f4afa648SGreg Roach 'ged' => $individual->tree()->name(), 94e6562982SGreg Roach ] + $parameters); 95168ff6f3Sric2016 } 96e2b8114dSGreg Roach 97e2b8114dSGreg Roach /** 98e2b8114dSGreg Roach * A form to request the chart parameters. 99e2b8114dSGreg Roach * 1006ccdf4f0SGreg Roach * @param ServerRequestInterface $request 101e2b8114dSGreg Roach * 1026ccdf4f0SGreg Roach * @return ResponseInterface 103e2b8114dSGreg Roach */ 104*57ab2231SGreg Roach public function getChartAction(ServerRequestInterface $request): ResponseInterface 105e2b8114dSGreg Roach { 106*57ab2231SGreg Roach $tree = $request->getAttribute('tree'); 107*57ab2231SGreg Roach $user = $request->getAttribute('user'); 108*57ab2231SGreg Roach 1099867b2f0SGreg Roach Auth::checkComponentAccess($this, 'chart', $tree, $user); 1109867b2f0SGreg Roach 1110b93976aSGreg Roach $ajax = $request->getQueryParams()['ajax'] ?? ''; 1120b93976aSGreg Roach $xrefs = (array) ($request->getQueryParams()['xrefs'] ?? []); 1130b93976aSGreg Roach $addxref = $request->getQueryParams()['addxref'] ?? ''; 1140b93976aSGreg Roach $addfam = (bool) ($request->getQueryParams()['addfam'] ?? false); 1150b93976aSGreg Roach $placename = $request->getQueryParams()['placename'] ?? ''; 1160b93976aSGreg Roach $start = $request->getQueryParams()['start'] ?? ''; 1170b93976aSGreg Roach $end = $request->getQueryParams()['end'] ?? ''; 118e2b8114dSGreg Roach 119e2b8114dSGreg Roach $place = new Place($placename, $tree); 120e2b8114dSGreg Roach $start_date = new Date($start); 121e2b8114dSGreg Roach $end_date = new Date($end); 122e2b8114dSGreg Roach 123e2b8114dSGreg Roach $xrefs = array_unique($xrefs); 124e2b8114dSGreg Roach 125e2b8114dSGreg Roach // Add an individual, and family members 126e2b8114dSGreg Roach $individual = Individual::getInstance($addxref, $tree); 127e2b8114dSGreg Roach if ($individual !== null) { 128e2b8114dSGreg Roach $xrefs[] = $addxref; 129e2b8114dSGreg Roach if ($addfam) { 130e2b8114dSGreg Roach $xrefs = array_merge($xrefs, $this->closeFamily($individual)); 131e2b8114dSGreg Roach } 132e2b8114dSGreg Roach } 133e2b8114dSGreg Roach 134e2b8114dSGreg Roach // Select by date and/or place. 135e2b8114dSGreg Roach if ($start_date->isOK() && $end_date->isOK() && $placename !== '') { 136e2b8114dSGreg Roach $date_xrefs = $this->findIndividualsByDate($start_date, $end_date, $tree); 137e2b8114dSGreg Roach $place_xrefs = $this->findIndividualsByPlace($place, $tree); 138e2b8114dSGreg Roach $xrefs = array_intersect($date_xrefs, $place_xrefs); 139e2b8114dSGreg Roach } elseif ($start_date->isOK() && $end_date->isOK()) { 140e2b8114dSGreg Roach $xrefs = $this->findIndividualsByDate($start_date, $end_date, $tree); 141e2b8114dSGreg Roach } elseif ($placename !== '') { 142e2b8114dSGreg Roach $xrefs = $this->findIndividualsByPlace($place, $tree); 143e2b8114dSGreg Roach } 144e2b8114dSGreg Roach 145e2b8114dSGreg Roach // Filter duplicates and private individuals. 146e2b8114dSGreg Roach $xrefs = array_unique($xrefs); 1470b5fd0a6SGreg Roach $xrefs = array_filter($xrefs, static function (string $xref) use ($tree): bool { 148e2b8114dSGreg Roach $individual = Individual::getInstance($xref, $tree); 149e2b8114dSGreg Roach 150e2b8114dSGreg Roach return $individual !== null && $individual->canShow(); 151e2b8114dSGreg Roach }); 152e2b8114dSGreg Roach 1530b93976aSGreg Roach if ($ajax === '1') { 154e2b8114dSGreg Roach $subtitle = $this->subtitle(count($xrefs), $start_date, $end_date, $placename); 155e2b8114dSGreg Roach 156e2b8114dSGreg Roach return $this->chart($tree, $xrefs, $subtitle); 157e2b8114dSGreg Roach } 158e2b8114dSGreg Roach 159e2b8114dSGreg Roach $ajax_url = route('module', [ 1609b5537c3SGreg Roach 'ajax' => true, 161e2b8114dSGreg Roach 'module' => $this->name(), 162e2b8114dSGreg Roach 'action' => 'Chart', 163e2b8114dSGreg Roach 'ged' => $tree->name(), 164e2b8114dSGreg Roach 'xrefs' => $xrefs, 165e2b8114dSGreg Roach ]); 166e2b8114dSGreg Roach 167e2b8114dSGreg Roach $reset_url = route('module', [ 168e2b8114dSGreg Roach 'module' => $this->name(), 169e2b8114dSGreg Roach 'action' => 'Chart', 170e2b8114dSGreg Roach 'ged' => $tree->name(), 171e2b8114dSGreg Roach ]); 172e2b8114dSGreg Roach 1739b5537c3SGreg Roach return $this->viewResponse('modules/lifespans-chart/page', [ 174e2b8114dSGreg Roach 'ajax_url' => $ajax_url, 175e2b8114dSGreg Roach 'module_name' => $this->name(), 176e2b8114dSGreg Roach 'reset_url' => $reset_url, 177e2b8114dSGreg Roach 'title' => $this->title(), 178e2b8114dSGreg Roach 'xrefs' => $xrefs, 179e2b8114dSGreg Roach ]); 180e2b8114dSGreg Roach } 181e2b8114dSGreg Roach 182e2b8114dSGreg Roach /** 183e2b8114dSGreg Roach * @param Tree $tree 184e2b8114dSGreg Roach * @param array $xrefs 185e2b8114dSGreg Roach * @param string $subtitle 186e2b8114dSGreg Roach * 1876ccdf4f0SGreg Roach * @return ResponseInterface 188e2b8114dSGreg Roach */ 1896ccdf4f0SGreg Roach protected function chart(Tree $tree, array $xrefs, string $subtitle): ResponseInterface 190e2b8114dSGreg Roach { 191e2b8114dSGreg Roach /** @var Individual[] $individuals */ 1920b93976aSGreg Roach $individuals = array_map(static function (string $xref) use ($tree): ?Individual { 193e2b8114dSGreg Roach return Individual::getInstance($xref, $tree); 194e2b8114dSGreg Roach }, $xrefs); 195e2b8114dSGreg Roach 1960b93976aSGreg Roach $individuals = array_filter($individuals, static function (?Individual $individual): bool { 1970b93976aSGreg Roach return $individual instanceof Individual && $individual->canShow(); 198e2b8114dSGreg Roach }); 199e2b8114dSGreg Roach 200e2b8114dSGreg Roach // Sort the array in order of birth year 2010c1a5edcSGreg Roach usort($individuals, Individual::birthDateComparator()); 202e2b8114dSGreg Roach 203e2b8114dSGreg Roach // Round to whole decades 204e2b8114dSGreg Roach $start_year = (int) floor($this->minYear($individuals) / 10) * 10; 205e2b8114dSGreg Roach $end_year = (int) ceil($this->maxYear($individuals) / 10) * 10; 206e2b8114dSGreg Roach 207e2b8114dSGreg Roach $lifespans = $this->layoutIndividuals($individuals); 208e2b8114dSGreg Roach 2090b5fd0a6SGreg Roach $max_rows = array_reduce($lifespans, static function ($carry, stdClass $item) { 210e2b8114dSGreg Roach return max($carry, $item->row); 211e2b8114dSGreg Roach }, 0); 212e2b8114dSGreg Roach 213e2b8114dSGreg Roach $html = view('modules/lifespans-chart/chart', [ 214e2b8114dSGreg Roach 'dir' => I18N::direction(), 215e2b8114dSGreg Roach 'end_year' => $end_year, 216e2b8114dSGreg Roach 'lifespans' => $lifespans, 217e2b8114dSGreg Roach 'max_rows' => $max_rows, 218e2b8114dSGreg Roach 'start_year' => $start_year, 219e2b8114dSGreg Roach 'subtitle' => $subtitle, 220e2b8114dSGreg Roach ]); 221e2b8114dSGreg Roach 2226ccdf4f0SGreg Roach return response($html); 223e2b8114dSGreg Roach } 224e2b8114dSGreg Roach 225e2b8114dSGreg Roach /** 226e2b8114dSGreg Roach * @param Individual[] $individuals 227e2b8114dSGreg Roach * 228e2b8114dSGreg Roach * @return stdClass[] 229e2b8114dSGreg Roach */ 230e2b8114dSGreg Roach private function layoutIndividuals(array $individuals): array 231e2b8114dSGreg Roach { 232e2b8114dSGreg Roach $colors = [ 233e2b8114dSGreg Roach 'M' => new ColorGenerator(240, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE * -1), 234e2b8114dSGreg Roach 'F' => new ColorGenerator(000, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE), 235e2b8114dSGreg Roach 'U' => new ColorGenerator(120, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE), 236e2b8114dSGreg Roach ]; 237e2b8114dSGreg Roach 238e2b8114dSGreg Roach $current_year = (int) date('Y'); 239e2b8114dSGreg Roach 240e2b8114dSGreg Roach // Latest year used in each row 241e2b8114dSGreg Roach $rows = []; 242e2b8114dSGreg Roach 243e2b8114dSGreg Roach $lifespans = []; 244e2b8114dSGreg Roach 245e2b8114dSGreg Roach foreach ($individuals as $individual) { 246e2b8114dSGreg Roach $birth_jd = $individual->getEstimatedBirthDate()->minimumJulianDay(); 247e2b8114dSGreg Roach $birth_year = $this->jdToYear($birth_jd); 248e2b8114dSGreg Roach $death_jd = $individual->getEstimatedDeathDate()->maximumJulianDay(); 249e2b8114dSGreg Roach $death_year = $this->jdToYear($death_jd); 250e2b8114dSGreg Roach 2510c1a5edcSGreg Roach // Died before they were born? Swapping the dates allows them to be shown. 2520c1a5edcSGreg Roach if ($death_year < $birth_year) { 2530c1a5edcSGreg Roach $death_year = $birth_year; 2540c1a5edcSGreg Roach } 2550c1a5edcSGreg Roach 256e2b8114dSGreg Roach // Don't show death dates in the future. 257e2b8114dSGreg Roach $death_year = min($death_year, $current_year); 258e2b8114dSGreg Roach 259e2b8114dSGreg Roach // Add this individual to the next row in the chart... 260e2b8114dSGreg Roach $next_row = count($rows); 261e2b8114dSGreg Roach // ...unless we can find an existing row where it fits. 262e2b8114dSGreg Roach foreach ($rows as $row => $year) { 263e2b8114dSGreg Roach if ($year < $birth_year) { 264e2b8114dSGreg Roach $next_row = $row; 265e2b8114dSGreg Roach break; 266e2b8114dSGreg Roach } 267e2b8114dSGreg Roach } 268e2b8114dSGreg Roach 269e2b8114dSGreg Roach // Fill the row up to the year (leaving a small gap) 270e2b8114dSGreg Roach $rows[$next_row] = $death_year; 271e2b8114dSGreg Roach 272e2b8114dSGreg Roach $lifespans[] = (object) [ 27339ca88baSGreg Roach 'background' => $colors[$individual->sex()]->getNextColor(), 274e2b8114dSGreg Roach 'birth_year' => $birth_year, 275e2b8114dSGreg Roach 'death_year' => $death_year, 276e2b8114dSGreg Roach 'id' => 'individual-' . md5($individual->xref()), 277e2b8114dSGreg Roach 'individual' => $individual, 278e2b8114dSGreg Roach 'row' => $next_row, 279e2b8114dSGreg Roach ]; 280e2b8114dSGreg Roach } 281e2b8114dSGreg Roach 282e2b8114dSGreg Roach return $lifespans; 283e2b8114dSGreg Roach } 284e2b8114dSGreg Roach 285e2b8114dSGreg Roach /** 286e2b8114dSGreg Roach * Find the latest event year for individuals 287e2b8114dSGreg Roach * 288e2b8114dSGreg Roach * @param array $individuals 289e2b8114dSGreg Roach * 290e2b8114dSGreg Roach * @return int 291e2b8114dSGreg Roach */ 292e2b8114dSGreg Roach protected function maxYear(array $individuals): int 293e2b8114dSGreg Roach { 2940b5fd0a6SGreg Roach $jd = array_reduce($individuals, static function ($carry, Individual $item) { 295e2b8114dSGreg Roach return max($carry, $item->getEstimatedDeathDate()->maximumJulianDay()); 296e2b8114dSGreg Roach }, 0); 297e2b8114dSGreg Roach 298e2b8114dSGreg Roach $year = $this->jdToYear($jd); 299e2b8114dSGreg Roach 300e2b8114dSGreg Roach // Don't show future dates 301e2b8114dSGreg Roach return min($year, (int) date('Y')); 302e2b8114dSGreg Roach } 303e2b8114dSGreg Roach 304e2b8114dSGreg Roach /** 305e2b8114dSGreg Roach * Find the earliest event year for individuals 306e2b8114dSGreg Roach * 307e2b8114dSGreg Roach * @param array $individuals 308e2b8114dSGreg Roach * 309e2b8114dSGreg Roach * @return int 310e2b8114dSGreg Roach */ 311e2b8114dSGreg Roach protected function minYear(array $individuals): int 312e2b8114dSGreg Roach { 3130b5fd0a6SGreg Roach $jd = array_reduce($individuals, static function ($carry, Individual $item) { 314e2b8114dSGreg Roach return min($carry, $item->getEstimatedBirthDate()->minimumJulianDay()); 315e2b8114dSGreg Roach }, PHP_INT_MAX); 316e2b8114dSGreg Roach 317e2b8114dSGreg Roach return $this->jdToYear($jd); 318e2b8114dSGreg Roach } 319e2b8114dSGreg Roach 320e2b8114dSGreg Roach /** 321e2b8114dSGreg Roach * Convert a julian day to a gregorian year 322e2b8114dSGreg Roach * 323e2b8114dSGreg Roach * @param int $jd 324e2b8114dSGreg Roach * 325e2b8114dSGreg Roach * @return int 326e2b8114dSGreg Roach */ 327e2b8114dSGreg Roach protected function jdToYear(int $jd): int 328e2b8114dSGreg Roach { 329e2b8114dSGreg Roach if ($jd === 0) { 330e2b8114dSGreg Roach return 0; 331e2b8114dSGreg Roach } 332e2b8114dSGreg Roach 333e2b8114dSGreg Roach $gregorian = new GregorianCalendar(); 334e2b8114dSGreg Roach [$y] = $gregorian->jdToYmd($jd); 335e2b8114dSGreg Roach 336e2b8114dSGreg Roach return $y; 337e2b8114dSGreg Roach } 338e2b8114dSGreg Roach 339e2b8114dSGreg Roach /** 340e2b8114dSGreg Roach * @param Date $start 341e2b8114dSGreg Roach * @param Date $end 342e2b8114dSGreg Roach * @param Tree $tree 343e2b8114dSGreg Roach * 344e2b8114dSGreg Roach * @return string[] 345e2b8114dSGreg Roach */ 346e2b8114dSGreg Roach protected function findIndividualsByDate(Date $start, Date $end, Tree $tree): array 347e2b8114dSGreg Roach { 348e2b8114dSGreg Roach return DB::table('individuals') 3490b5fd0a6SGreg Roach ->join('dates', static function (JoinClause $join): void { 350e2b8114dSGreg Roach $join 351e2b8114dSGreg Roach ->on('d_file', '=', 'i_file') 352e2b8114dSGreg Roach ->on('d_gid', '=', 'i_id'); 353e2b8114dSGreg Roach }) 354e2b8114dSGreg Roach ->where('i_file', '=', $tree->id()) 355e2b8114dSGreg Roach ->where('d_julianday1', '<=', $end->maximumJulianDay()) 356e2b8114dSGreg Roach ->where('d_julianday2', '>=', $start->minimumJulianDay()) 357e2b8114dSGreg Roach ->whereNotIn('d_fact', ['BAPL', 'ENDL', 'SLGC', 'SLGS', '_TODO', 'CHAN']) 358e2b8114dSGreg Roach ->pluck('i_id') 359e2b8114dSGreg Roach ->all(); 360e2b8114dSGreg Roach } 361e2b8114dSGreg Roach 362e2b8114dSGreg Roach /** 363e2b8114dSGreg Roach * @param Place $place 364e2b8114dSGreg Roach * @param Tree $tree 365e2b8114dSGreg Roach * 366e2b8114dSGreg Roach * @return string[] 367e2b8114dSGreg Roach */ 368e2b8114dSGreg Roach protected function findIndividualsByPlace(Place $place, Tree $tree): array 369e2b8114dSGreg Roach { 370e2b8114dSGreg Roach return DB::table('individuals') 3710b5fd0a6SGreg Roach ->join('placelinks', static function (JoinClause $join): void { 372e2b8114dSGreg Roach $join 373e2b8114dSGreg Roach ->on('pl_file', '=', 'i_file') 374e2b8114dSGreg Roach ->on('pl_gid', '=', 'i_id'); 375e2b8114dSGreg Roach }) 376e2b8114dSGreg Roach ->where('i_file', '=', $tree->id()) 377392561bbSGreg Roach ->where('pl_p_id', '=', $place->id()) 378e2b8114dSGreg Roach ->pluck('i_id') 379e2b8114dSGreg Roach ->all(); 380e2b8114dSGreg Roach } 381e2b8114dSGreg Roach 382e2b8114dSGreg Roach /** 383e2b8114dSGreg Roach * Find the close family members of an individual. 384e2b8114dSGreg Roach * 385e2b8114dSGreg Roach * @param Individual $individual 386e2b8114dSGreg Roach * 387e2b8114dSGreg Roach * @return string[] 388e2b8114dSGreg Roach */ 389e2b8114dSGreg Roach protected function closeFamily(Individual $individual): array 390e2b8114dSGreg Roach { 391e2b8114dSGreg Roach $xrefs = []; 392e2b8114dSGreg Roach 39339ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 39439ca88baSGreg Roach foreach ($family->children() as $child) { 395e2b8114dSGreg Roach $xrefs[] = $child->xref(); 396e2b8114dSGreg Roach } 397e2b8114dSGreg Roach 39839ca88baSGreg Roach foreach ($family->spouses() as $spouse) { 399e2b8114dSGreg Roach $xrefs[] = $spouse->xref(); 400e2b8114dSGreg Roach } 401e2b8114dSGreg Roach } 402e2b8114dSGreg Roach 40339ca88baSGreg Roach foreach ($individual->childFamilies() as $family) { 40439ca88baSGreg Roach foreach ($family->children() as $child) { 405e2b8114dSGreg Roach $xrefs[] = $child->xref(); 406e2b8114dSGreg Roach } 407e2b8114dSGreg Roach 40839ca88baSGreg Roach foreach ($family->spouses() as $spouse) { 409e2b8114dSGreg Roach $xrefs[] = $spouse->xref(); 410e2b8114dSGreg Roach } 411e2b8114dSGreg Roach } 412e2b8114dSGreg Roach 413e2b8114dSGreg Roach return $xrefs; 414e2b8114dSGreg Roach } 415e2b8114dSGreg Roach 416e2b8114dSGreg Roach /** 417e2b8114dSGreg Roach * Generate a subtitle, based on filter parameters 418e2b8114dSGreg Roach * 419e2b8114dSGreg Roach * @param int $count 420e2b8114dSGreg Roach * @param Date $start 421e2b8114dSGreg Roach * @param Date $end 422e2b8114dSGreg Roach * @param string $placename 423e2b8114dSGreg Roach * 424e2b8114dSGreg Roach * @return string 425e2b8114dSGreg Roach */ 426e2b8114dSGreg Roach protected function subtitle(int $count, Date $start, Date $end, string $placename): string 427e2b8114dSGreg Roach { 428e2b8114dSGreg Roach if ($start->isOK() && $end->isOK() && $placename !== '') { 429e2b8114dSGreg Roach return I18N::plural( 430e2b8114dSGreg Roach '%s individual with events in %s between %s and %s', 431e2b8114dSGreg Roach '%s individuals with events in %s between %s and %s', 432e2b8114dSGreg Roach $count, 433e2b8114dSGreg Roach I18N::number($count), 434e2b8114dSGreg Roach $placename, 435e2b8114dSGreg Roach $start->display(false, '%Y'), 436e2b8114dSGreg Roach $end->display(false, '%Y') 437e2b8114dSGreg Roach ); 438e2b8114dSGreg Roach } 439e2b8114dSGreg Roach 440e2b8114dSGreg Roach if ($placename !== '') { 441e2b8114dSGreg Roach return I18N::plural( 442e2b8114dSGreg Roach '%s individual with events in %s', 443e2b8114dSGreg Roach '%s individuals with events in %s', 444e2b8114dSGreg Roach $count, 445e2b8114dSGreg Roach I18N::number($count), 446e2b8114dSGreg Roach $placename 447e2b8114dSGreg Roach ); 448e2b8114dSGreg Roach } 449e2b8114dSGreg Roach 450e2b8114dSGreg Roach if ($start->isOK() && $end->isOK()) { 451e2b8114dSGreg Roach return I18N::plural( 452e2b8114dSGreg Roach '%s individual with events between %s and %s', 453e2b8114dSGreg Roach '%s individuals with events between %s and %s', 454e2b8114dSGreg Roach $count, 455e2b8114dSGreg Roach I18N::number($count), 456e2b8114dSGreg Roach $start->display(false, '%Y'), 457e2b8114dSGreg Roach $end->display(false, '%Y') 458e2b8114dSGreg Roach ); 459e2b8114dSGreg Roach } 460e2b8114dSGreg Roach 461e2b8114dSGreg Roach return I18N::plural('%s individual', '%s individuals', $count, I18N::number($count)); 462e2b8114dSGreg Roach } 463168ff6f3Sric2016} 464