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; 21e2b8114dSGreg Roachuse Fisharebest\Webtrees\ColorGenerator; 22e2b8114dSGreg Roachuse Fisharebest\Webtrees\Date; 23168ff6f3Sric2016use Fisharebest\Webtrees\I18N; 24168ff6f3Sric2016use Fisharebest\Webtrees\Individual; 25e2b8114dSGreg Roachuse Fisharebest\Webtrees\Place; 26e2b8114dSGreg Roachuse Fisharebest\Webtrees\Tree; 27e2b8114dSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 28e2b8114dSGreg Roachuse Illuminate\Database\Query\JoinClause; 29e2b8114dSGreg Roachuse stdClass; 30e2b8114dSGreg Roachuse Symfony\Component\HttpFoundation\Request; 31e2b8114dSGreg Roachuse Symfony\Component\HttpFoundation\Response; 32168ff6f3Sric2016 33168ff6f3Sric2016/** 34168ff6f3Sric2016 * Class LifespansChartModule 35168ff6f3Sric2016 */ 36*37eb8894SGreg Roachclass LifespansChartModule extends AbstractModule implements ModuleChartInterface 37c1010edaSGreg Roach{ 3849a243cbSGreg Roach use ModuleChartTrait; 3949a243cbSGreg Roach 40e2b8114dSGreg Roach // Parameters for generating colors 41e2b8114dSGreg Roach protected const RANGE = 120; // degrees 42e2b8114dSGreg Roach protected const SATURATION = 100; // percent 43e2b8114dSGreg Roach protected const LIGHTNESS = 30; // percent 44e2b8114dSGreg Roach protected const ALPHA = 0.25; 45e2b8114dSGreg Roach 46168ff6f3Sric2016 /** 47168ff6f3Sric2016 * How should this module be labelled on tabs, menus, etc.? 48168ff6f3Sric2016 * 49168ff6f3Sric2016 * @return string 50168ff6f3Sric2016 */ 5149a243cbSGreg Roach public function title(): string 52c1010edaSGreg Roach { 53bbb76c12SGreg Roach /* I18N: Name of a module/chart */ 54bbb76c12SGreg Roach return I18N::translate('Lifespans'); 55168ff6f3Sric2016 } 56168ff6f3Sric2016 57168ff6f3Sric2016 /** 58168ff6f3Sric2016 * A sentence describing what this module does. 59168ff6f3Sric2016 * 60168ff6f3Sric2016 * @return string 61168ff6f3Sric2016 */ 6249a243cbSGreg Roach public function description(): string 63c1010edaSGreg Roach { 64bbb76c12SGreg Roach /* I18N: Description of the “LifespansChart” module */ 65bbb76c12SGreg Roach return I18N::translate('A chart of individuals’ lifespans.'); 66168ff6f3Sric2016 } 67168ff6f3Sric2016 68168ff6f3Sric2016 /** 69377a2979SGreg Roach * CSS class for the URL. 70377a2979SGreg Roach * 71377a2979SGreg Roach * @return string 72377a2979SGreg Roach */ 73377a2979SGreg Roach public function chartMenuClass(): string 74377a2979SGreg Roach { 75377a2979SGreg Roach return 'menu-chart-lifespan'; 76377a2979SGreg Roach } 77377a2979SGreg Roach 78377a2979SGreg Roach /** 79e6562982SGreg Roach * The URL for this chart. 80168ff6f3Sric2016 * 8160bc3e3fSGreg Roach * @param Individual $individual 82e6562982SGreg Roach * @param string[] $parameters 8360bc3e3fSGreg Roach * 84e6562982SGreg Roach * @return string 85168ff6f3Sric2016 */ 86e6562982SGreg Roach public function chartUrl(Individual $individual, array $parameters = []): string 87c1010edaSGreg Roach { 88e2b8114dSGreg Roach return route('module', [ 89e2b8114dSGreg Roach 'module' => $this->name(), 90e2b8114dSGreg Roach 'action' => 'Chart', 91c0935879SGreg Roach 'xrefs[]' => $individual->xref(), 92f4afa648SGreg Roach 'ged' => $individual->tree()->name(), 93e6562982SGreg Roach ] + $parameters); 94168ff6f3Sric2016 } 95e2b8114dSGreg Roach 96e2b8114dSGreg Roach /** 97e2b8114dSGreg Roach * A form to request the chart parameters. 98e2b8114dSGreg Roach * 99e2b8114dSGreg Roach * @param Request $request 100e2b8114dSGreg Roach * @param Tree $tree 101e2b8114dSGreg Roach * 102e2b8114dSGreg Roach * @return Response 103e2b8114dSGreg Roach */ 104e2b8114dSGreg Roach public function getChartAction(Request $request, Tree $tree): Response 105e2b8114dSGreg Roach { 1069b5537c3SGreg Roach $ajax = (bool) $request->get('ajax'); 107e2b8114dSGreg Roach $xrefs = (array) $request->get('xrefs', []); 108e2b8114dSGreg Roach $addxref = $request->get('addxref', ''); 109e2b8114dSGreg Roach $addfam = (bool) $request->get('addfam', false); 110e2b8114dSGreg Roach $placename = $request->get('placename', ''); 111e2b8114dSGreg Roach $start = $request->get('start', ''); 112e2b8114dSGreg Roach $end = $request->get('end', ''); 113e2b8114dSGreg Roach 114e2b8114dSGreg Roach $place = new Place($placename, $tree); 115e2b8114dSGreg Roach $start_date = new Date($start); 116e2b8114dSGreg Roach $end_date = new Date($end); 117e2b8114dSGreg Roach 118e2b8114dSGreg Roach $xrefs = array_unique($xrefs); 119e2b8114dSGreg Roach 120e2b8114dSGreg Roach // Add an individual, and family members 121e2b8114dSGreg Roach $individual = Individual::getInstance($addxref, $tree); 122e2b8114dSGreg Roach if ($individual !== null) { 123e2b8114dSGreg Roach $xrefs[] = $addxref; 124e2b8114dSGreg Roach if ($addfam) { 125e2b8114dSGreg Roach $xrefs = array_merge($xrefs, $this->closeFamily($individual)); 126e2b8114dSGreg Roach } 127e2b8114dSGreg Roach } 128e2b8114dSGreg Roach 129e2b8114dSGreg Roach // Select by date and/or place. 130e2b8114dSGreg Roach if ($start_date->isOK() && $end_date->isOK() && $placename !== '') { 131e2b8114dSGreg Roach $date_xrefs = $this->findIndividualsByDate($start_date, $end_date, $tree); 132e2b8114dSGreg Roach $place_xrefs = $this->findIndividualsByPlace($place, $tree); 133e2b8114dSGreg Roach $xrefs = array_intersect($date_xrefs, $place_xrefs); 134e2b8114dSGreg Roach } elseif ($start_date->isOK() && $end_date->isOK()) { 135e2b8114dSGreg Roach $xrefs = $this->findIndividualsByDate($start_date, $end_date, $tree); 136e2b8114dSGreg Roach } elseif ($placename !== '') { 137e2b8114dSGreg Roach $xrefs = $this->findIndividualsByPlace($place, $tree); 138e2b8114dSGreg Roach } 139e2b8114dSGreg Roach 140e2b8114dSGreg Roach // Filter duplicates and private individuals. 141e2b8114dSGreg Roach $xrefs = array_unique($xrefs); 142e2b8114dSGreg Roach $xrefs = array_filter($xrefs, function (string $xref) use ($tree): bool { 143e2b8114dSGreg Roach $individual = Individual::getInstance($xref, $tree); 144e2b8114dSGreg Roach 145e2b8114dSGreg Roach return $individual !== null && $individual->canShow(); 146e2b8114dSGreg Roach }); 147e2b8114dSGreg Roach 1489b5537c3SGreg Roach if ($ajax) { 149e2b8114dSGreg Roach $subtitle = $this->subtitle(count($xrefs), $start_date, $end_date, $placename); 150e2b8114dSGreg Roach 151e2b8114dSGreg Roach return $this->chart($tree, $xrefs, $subtitle); 152e2b8114dSGreg Roach } 153e2b8114dSGreg Roach 154e2b8114dSGreg Roach $ajax_url = route('module', [ 1559b5537c3SGreg Roach 'ajax' => true, 156e2b8114dSGreg Roach 'module' => $this->name(), 157e2b8114dSGreg Roach 'action' => 'Chart', 158e2b8114dSGreg Roach 'ged' => $tree->name(), 159e2b8114dSGreg Roach 'xrefs' => $xrefs, 160e2b8114dSGreg Roach ]); 161e2b8114dSGreg Roach 162e2b8114dSGreg Roach $reset_url = route('module', [ 163e2b8114dSGreg Roach 'module' => $this->name(), 164e2b8114dSGreg Roach 'action' => 'Chart', 165e2b8114dSGreg Roach 'ged' => $tree->name(), 166e2b8114dSGreg Roach ]); 167e2b8114dSGreg Roach 1689b5537c3SGreg Roach return $this->viewResponse('modules/lifespans-chart/page', [ 169e2b8114dSGreg Roach 'ajax_url' => $ajax_url, 170e2b8114dSGreg Roach 'module_name' => $this->name(), 171e2b8114dSGreg Roach 'reset_url' => $reset_url, 172e2b8114dSGreg Roach 'title' => $this->title(), 173e2b8114dSGreg Roach 'xrefs' => $xrefs, 174e2b8114dSGreg Roach ]); 175e2b8114dSGreg Roach } 176e2b8114dSGreg Roach 177e2b8114dSGreg Roach /** 178e2b8114dSGreg Roach * @param Tree $tree 179e2b8114dSGreg Roach * @param array $xrefs 180e2b8114dSGreg Roach * @param string $subtitle 181e2b8114dSGreg Roach * 182e2b8114dSGreg Roach * @return Response 183e2b8114dSGreg Roach */ 184e2b8114dSGreg Roach protected function chart(Tree $tree, array $xrefs, string $subtitle): Response 185e2b8114dSGreg Roach { 186e2b8114dSGreg Roach /** @var Individual[] $individuals */ 187e2b8114dSGreg Roach $individuals = array_map(function (string $xref) use ($tree) { 188e2b8114dSGreg Roach return Individual::getInstance($xref, $tree); 189e2b8114dSGreg Roach }, $xrefs); 190e2b8114dSGreg Roach 191e2b8114dSGreg Roach $individuals = array_filter($individuals, function (Individual $individual = null): bool { 192e2b8114dSGreg Roach return $individual !== null && $individual->canShow(); 193e2b8114dSGreg Roach }); 194e2b8114dSGreg Roach 195e2b8114dSGreg Roach // Sort the array in order of birth year 196e2b8114dSGreg Roach usort($individuals, function (Individual $a, Individual $b) { 197e2b8114dSGreg Roach return Date::compare($a->getEstimatedBirthDate(), $b->getEstimatedBirthDate()); 198e2b8114dSGreg Roach }); 199e2b8114dSGreg Roach 200e2b8114dSGreg Roach // Round to whole decades 201e2b8114dSGreg Roach $start_year = (int) floor($this->minYear($individuals) / 10) * 10; 202e2b8114dSGreg Roach $end_year = (int) ceil($this->maxYear($individuals) / 10) * 10; 203e2b8114dSGreg Roach 204e2b8114dSGreg Roach $lifespans = $this->layoutIndividuals($individuals); 205e2b8114dSGreg Roach 206e2b8114dSGreg Roach $max_rows = array_reduce($lifespans, function ($carry, stdClass $item) { 207e2b8114dSGreg Roach return max($carry, $item->row); 208e2b8114dSGreg Roach }, 0); 209e2b8114dSGreg Roach 210e2b8114dSGreg Roach $html = view('modules/lifespans-chart/chart', [ 211e2b8114dSGreg Roach 'dir' => I18N::direction(), 212e2b8114dSGreg Roach 'end_year' => $end_year, 213e2b8114dSGreg Roach 'lifespans' => $lifespans, 214e2b8114dSGreg Roach 'max_rows' => $max_rows, 215e2b8114dSGreg Roach 'start_year' => $start_year, 216e2b8114dSGreg Roach 'subtitle' => $subtitle, 217e2b8114dSGreg Roach ]); 218e2b8114dSGreg Roach 219e2b8114dSGreg Roach return new Response($html); 220e2b8114dSGreg Roach } 221e2b8114dSGreg Roach 222e2b8114dSGreg Roach /** 223e2b8114dSGreg Roach * 224e2b8114dSGreg Roach * 225e2b8114dSGreg Roach * @param Individual[] $individuals 226e2b8114dSGreg Roach * 227e2b8114dSGreg Roach * @return stdClass[] 228e2b8114dSGreg Roach */ 229e2b8114dSGreg Roach private function layoutIndividuals(array $individuals): array 230e2b8114dSGreg Roach { 231e2b8114dSGreg Roach $colors = [ 232e2b8114dSGreg Roach 'M' => new ColorGenerator(240, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE * -1), 233e2b8114dSGreg Roach 'F' => new ColorGenerator(000, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE), 234e2b8114dSGreg Roach 'U' => new ColorGenerator(120, self::SATURATION, self::LIGHTNESS, self::ALPHA, self::RANGE), 235e2b8114dSGreg Roach ]; 236e2b8114dSGreg Roach 237e2b8114dSGreg Roach $current_year = (int) date('Y'); 238e2b8114dSGreg Roach 239e2b8114dSGreg Roach // Latest year used in each row 240e2b8114dSGreg Roach $rows = []; 241e2b8114dSGreg Roach 242e2b8114dSGreg Roach $lifespans = []; 243e2b8114dSGreg Roach 244e2b8114dSGreg Roach foreach ($individuals as $individual) { 245e2b8114dSGreg Roach $birth_jd = $individual->getEstimatedBirthDate()->minimumJulianDay(); 246e2b8114dSGreg Roach $birth_year = $this->jdToYear($birth_jd); 247e2b8114dSGreg Roach $death_jd = $individual->getEstimatedDeathDate()->maximumJulianDay(); 248e2b8114dSGreg Roach $death_year = $this->jdToYear($death_jd); 249e2b8114dSGreg Roach 250e2b8114dSGreg Roach // Don't show death dates in the future. 251e2b8114dSGreg Roach $death_year = min($death_year, $current_year); 252e2b8114dSGreg Roach 253e2b8114dSGreg Roach // Add this individual to the next row in the chart... 254e2b8114dSGreg Roach $next_row = count($rows); 255e2b8114dSGreg Roach // ...unless we can find an existing row where it fits. 256e2b8114dSGreg Roach foreach ($rows as $row => $year) { 257e2b8114dSGreg Roach if ($year < $birth_year) { 258e2b8114dSGreg Roach $next_row = $row; 259e2b8114dSGreg Roach break; 260e2b8114dSGreg Roach } 261e2b8114dSGreg Roach } 262e2b8114dSGreg Roach 263e2b8114dSGreg Roach // Fill the row up to the year (leaving a small gap) 264e2b8114dSGreg Roach $rows[$next_row] = $death_year; 265e2b8114dSGreg Roach 266e2b8114dSGreg Roach $lifespans[] = (object) [ 267e2b8114dSGreg Roach 'background' => $colors[$individual->getSex()]->getNextColor(), 268e2b8114dSGreg Roach 'birth_year' => $birth_year, 269e2b8114dSGreg Roach 'death_year' => $death_year, 270e2b8114dSGreg Roach 'id' => 'individual-' . md5($individual->xref()), 271e2b8114dSGreg Roach 'individual' => $individual, 272e2b8114dSGreg Roach 'row' => $next_row, 273e2b8114dSGreg Roach ]; 274e2b8114dSGreg Roach } 275e2b8114dSGreg Roach 276e2b8114dSGreg Roach return $lifespans; 277e2b8114dSGreg Roach } 278e2b8114dSGreg Roach 279e2b8114dSGreg Roach /** 280e2b8114dSGreg Roach * Find the latest event year for individuals 281e2b8114dSGreg Roach * 282e2b8114dSGreg Roach * @param array $individuals 283e2b8114dSGreg Roach * 284e2b8114dSGreg Roach * @return int 285e2b8114dSGreg Roach */ 286e2b8114dSGreg Roach protected function maxYear(array $individuals): int 287e2b8114dSGreg Roach { 288e2b8114dSGreg Roach $jd = array_reduce($individuals, function ($carry, Individual $item) { 289e2b8114dSGreg Roach return max($carry, $item->getEstimatedDeathDate()->maximumJulianDay()); 290e2b8114dSGreg Roach }, 0); 291e2b8114dSGreg Roach 292e2b8114dSGreg Roach $year = $this->jdToYear($jd); 293e2b8114dSGreg Roach 294e2b8114dSGreg Roach // Don't show future dates 295e2b8114dSGreg Roach return min($year, (int) date('Y')); 296e2b8114dSGreg Roach } 297e2b8114dSGreg Roach 298e2b8114dSGreg Roach /** 299e2b8114dSGreg Roach * Find the earliest event year for individuals 300e2b8114dSGreg Roach * 301e2b8114dSGreg Roach * @param array $individuals 302e2b8114dSGreg Roach * 303e2b8114dSGreg Roach * @return int 304e2b8114dSGreg Roach */ 305e2b8114dSGreg Roach protected function minYear(array $individuals): int 306e2b8114dSGreg Roach { 307e2b8114dSGreg Roach $jd = array_reduce($individuals, function ($carry, Individual $item) { 308e2b8114dSGreg Roach return min($carry, $item->getEstimatedBirthDate()->minimumJulianDay()); 309e2b8114dSGreg Roach }, PHP_INT_MAX); 310e2b8114dSGreg Roach 311e2b8114dSGreg Roach return $this->jdToYear($jd); 312e2b8114dSGreg Roach } 313e2b8114dSGreg Roach 314e2b8114dSGreg Roach /** 315e2b8114dSGreg Roach * Convert a julian day to a gregorian year 316e2b8114dSGreg Roach * 317e2b8114dSGreg Roach * @param int $jd 318e2b8114dSGreg Roach * 319e2b8114dSGreg Roach * @return int 320e2b8114dSGreg Roach */ 321e2b8114dSGreg Roach protected function jdToYear(int $jd): int 322e2b8114dSGreg Roach { 323e2b8114dSGreg Roach if ($jd === 0) { 324e2b8114dSGreg Roach return 0; 325e2b8114dSGreg Roach } 326e2b8114dSGreg Roach 327e2b8114dSGreg Roach $gregorian = new GregorianCalendar(); 328e2b8114dSGreg Roach [$y] = $gregorian->jdToYmd($jd); 329e2b8114dSGreg Roach 330e2b8114dSGreg Roach return $y; 331e2b8114dSGreg Roach } 332e2b8114dSGreg Roach 333e2b8114dSGreg Roach /** 334e2b8114dSGreg Roach * @param Date $start 335e2b8114dSGreg Roach * @param Date $end 336e2b8114dSGreg Roach * @param Tree $tree 337e2b8114dSGreg Roach * 338e2b8114dSGreg Roach * @return string[] 339e2b8114dSGreg Roach */ 340e2b8114dSGreg Roach protected function findIndividualsByDate(Date $start, Date $end, Tree $tree): array 341e2b8114dSGreg Roach { 342e2b8114dSGreg Roach return DB::table('individuals') 343e2b8114dSGreg Roach ->join('dates', function (JoinClause $join): void { 344e2b8114dSGreg Roach $join 345e2b8114dSGreg Roach ->on('d_file', '=', 'i_file') 346e2b8114dSGreg Roach ->on('d_gid', '=', 'i_id'); 347e2b8114dSGreg Roach }) 348e2b8114dSGreg Roach ->where('i_file', '=', $tree->id()) 349e2b8114dSGreg Roach ->where('d_julianday1', '<=', $end->maximumJulianDay()) 350e2b8114dSGreg Roach ->where('d_julianday2', '>=', $start->minimumJulianDay()) 351e2b8114dSGreg Roach ->whereNotIn('d_fact', ['BAPL', 'ENDL', 'SLGC', 'SLGS', '_TODO', 'CHAN']) 352e2b8114dSGreg Roach ->pluck('i_id') 353e2b8114dSGreg Roach ->all(); 354e2b8114dSGreg Roach } 355e2b8114dSGreg Roach 356e2b8114dSGreg Roach /** 357e2b8114dSGreg Roach * @param Place $place 358e2b8114dSGreg Roach * @param Tree $tree 359e2b8114dSGreg Roach * 360e2b8114dSGreg Roach * @return string[] 361e2b8114dSGreg Roach */ 362e2b8114dSGreg Roach protected function findIndividualsByPlace(Place $place, Tree $tree): array 363e2b8114dSGreg Roach { 364e2b8114dSGreg Roach return DB::table('individuals') 365e2b8114dSGreg Roach ->join('placelinks', function (JoinClause $join): void { 366e2b8114dSGreg Roach $join 367e2b8114dSGreg Roach ->on('pl_file', '=', 'i_file') 368e2b8114dSGreg Roach ->on('pl_gid', '=', 'i_id'); 369e2b8114dSGreg Roach }) 370e2b8114dSGreg Roach ->where('i_file', '=', $tree->id()) 371e2b8114dSGreg Roach ->where('pl_p_id', '=', $place->getPlaceId()) 372e2b8114dSGreg Roach ->pluck('i_id') 373e2b8114dSGreg Roach ->all(); 374e2b8114dSGreg Roach } 375e2b8114dSGreg Roach 376e2b8114dSGreg Roach /** 377e2b8114dSGreg Roach * Find the close family members of an individual. 378e2b8114dSGreg Roach * 379e2b8114dSGreg Roach * @param Individual $individual 380e2b8114dSGreg Roach * 381e2b8114dSGreg Roach * @return string[] 382e2b8114dSGreg Roach */ 383e2b8114dSGreg Roach protected function closeFamily(Individual $individual): array 384e2b8114dSGreg Roach { 385e2b8114dSGreg Roach $xrefs = []; 386e2b8114dSGreg Roach 387e2b8114dSGreg Roach foreach ($individual->getSpouseFamilies() as $family) { 388e2b8114dSGreg Roach foreach ($family->getChildren() as $child) { 389e2b8114dSGreg Roach $xrefs[] = $child->xref(); 390e2b8114dSGreg Roach } 391e2b8114dSGreg Roach 392e2b8114dSGreg Roach foreach ($family->getSpouses() as $spouse) { 393e2b8114dSGreg Roach $xrefs[] = $spouse->xref(); 394e2b8114dSGreg Roach } 395e2b8114dSGreg Roach } 396e2b8114dSGreg Roach 397e2b8114dSGreg Roach foreach ($individual->getChildFamilies() as $family) { 398e2b8114dSGreg Roach foreach ($family->getChildren() as $child) { 399e2b8114dSGreg Roach $xrefs[] = $child->xref(); 400e2b8114dSGreg Roach } 401e2b8114dSGreg Roach 402e2b8114dSGreg Roach foreach ($family->getSpouses() as $spouse) { 403e2b8114dSGreg Roach $xrefs[] = $spouse->xref(); 404e2b8114dSGreg Roach } 405e2b8114dSGreg Roach } 406e2b8114dSGreg Roach 407e2b8114dSGreg Roach return $xrefs; 408e2b8114dSGreg Roach } 409e2b8114dSGreg Roach 410e2b8114dSGreg Roach /** 411e2b8114dSGreg Roach * Generate a subtitle, based on filter parameters 412e2b8114dSGreg Roach * 413e2b8114dSGreg Roach * @param int $count 414e2b8114dSGreg Roach * @param Date $start 415e2b8114dSGreg Roach * @param Date $end 416e2b8114dSGreg Roach * @param string $placename 417e2b8114dSGreg Roach * 418e2b8114dSGreg Roach * @return string 419e2b8114dSGreg Roach */ 420e2b8114dSGreg Roach protected function subtitle(int $count, Date $start, Date $end, string $placename): string 421e2b8114dSGreg Roach { 422e2b8114dSGreg Roach if ($start->isOK() && $end->isOK() && $placename !== '') { 423e2b8114dSGreg Roach return I18N::plural( 424e2b8114dSGreg Roach '%s individual with events in %s between %s and %s', 425e2b8114dSGreg Roach '%s individuals with events in %s between %s and %s', 426e2b8114dSGreg Roach $count, 427e2b8114dSGreg Roach I18N::number($count), 428e2b8114dSGreg Roach $placename, 429e2b8114dSGreg Roach $start->display(false, '%Y'), 430e2b8114dSGreg Roach $end->display(false, '%Y') 431e2b8114dSGreg Roach ); 432e2b8114dSGreg Roach } 433e2b8114dSGreg Roach 434e2b8114dSGreg Roach if ($placename !== '') { 435e2b8114dSGreg Roach return I18N::plural( 436e2b8114dSGreg Roach '%s individual with events in %s', 437e2b8114dSGreg Roach '%s individuals with events in %s', 438e2b8114dSGreg Roach $count, 439e2b8114dSGreg Roach I18N::number($count), 440e2b8114dSGreg Roach $placename 441e2b8114dSGreg Roach ); 442e2b8114dSGreg Roach } 443e2b8114dSGreg Roach 444e2b8114dSGreg Roach if ($start->isOK() && $end->isOK()) { 445e2b8114dSGreg Roach return I18N::plural( 446e2b8114dSGreg Roach '%s individual with events between %s and %s', 447e2b8114dSGreg Roach '%s individuals with events between %s and %s', 448e2b8114dSGreg Roach $count, 449e2b8114dSGreg Roach I18N::number($count), 450e2b8114dSGreg Roach $start->display(false, '%Y'), 451e2b8114dSGreg Roach $end->display(false, '%Y') 452e2b8114dSGreg Roach ); 453e2b8114dSGreg Roach } 454e2b8114dSGreg Roach 455e2b8114dSGreg Roach return I18N::plural('%s individual', '%s individuals', $count, I18N::number($count)); 456e2b8114dSGreg Roach } 457168ff6f3Sric2016} 458