1*17c50b57SGreg Roach<?php 2*17c50b57SGreg Roach/** 3*17c50b57SGreg Roach * webtrees: online genealogy 4*17c50b57SGreg Roach * Copyright (C) 2019 webtrees development team 5*17c50b57SGreg Roach * This program is free software: you can redistribute it and/or modify 6*17c50b57SGreg Roach * it under the terms of the GNU General Public License as published by 7*17c50b57SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8*17c50b57SGreg Roach * (at your option) any later version. 9*17c50b57SGreg Roach * This program is distributed in the hope that it will be useful, 10*17c50b57SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*17c50b57SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*17c50b57SGreg Roach * GNU General Public License for more details. 13*17c50b57SGreg Roach * You should have received a copy of the GNU General Public License 14*17c50b57SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15*17c50b57SGreg Roach */ 16*17c50b57SGreg Roachdeclare(strict_types=1); 17*17c50b57SGreg Roach 18*17c50b57SGreg Roachnamespace Fisharebest\Webtrees\Module; 19*17c50b57SGreg Roach 20*17c50b57SGreg Roachuse Fisharebest\Webtrees\Date; 21*17c50b57SGreg Roachuse Fisharebest\Webtrees\Fact; 22*17c50b57SGreg Roachuse Fisharebest\Webtrees\I18N; 23*17c50b57SGreg Roachuse Fisharebest\Webtrees\Individual; 24*17c50b57SGreg Roachuse Illuminate\Support\Collection; 25*17c50b57SGreg Roach 26*17c50b57SGreg Roach/** 27*17c50b57SGreg Roach * Trait ModuleHistoricEventsTrait - Show historic events on an individual‘s page 28*17c50b57SGreg Roach */ 29*17c50b57SGreg Roachtrait ModuleHistoricEventsTrait 30*17c50b57SGreg Roach{ 31*17c50b57SGreg Roach /** 32*17c50b57SGreg Roach * A sentence describing what this module does. 33*17c50b57SGreg Roach * 34*17c50b57SGreg Roach * @return string 35*17c50b57SGreg Roach */ 36*17c50b57SGreg Roach public function description(): string 37*17c50b57SGreg Roach { 38*17c50b57SGreg Roach return I18N::translate('Add historic events to an individual‘s page.'); 39*17c50b57SGreg Roach } 40*17c50b57SGreg Roach 41*17c50b57SGreg Roach /** 42*17c50b57SGreg Roach * All events provided by this module. 43*17c50b57SGreg Roach * 44*17c50b57SGreg Roach * @param Individual $individual 45*17c50b57SGreg Roach * 46*17c50b57SGreg Roach * @return string[] 47*17c50b57SGreg Roach */ 48*17c50b57SGreg Roach public function historicEventsAll(): array 49*17c50b57SGreg Roach { 50*17c50b57SGreg Roach return [ 51*17c50b57SGreg Roach "1 EVEN foo\n2 TYPE bar\n2 DATE FROM 6 FEB 1952" 52*17c50b57SGreg Roach ]; 53*17c50b57SGreg Roach } 54*17c50b57SGreg Roach 55*17c50b57SGreg Roach /** 56*17c50b57SGreg Roach * Which events should we show for an individual? 57*17c50b57SGreg Roach * 58*17c50b57SGreg Roach * @param Individual $individual 59*17c50b57SGreg Roach * 60*17c50b57SGreg Roach * @return Collection 61*17c50b57SGreg Roach */ 62*17c50b57SGreg Roach public function historicEventsForIndividual(Individual $individual): Collection 63*17c50b57SGreg Roach { 64*17c50b57SGreg Roach $min_date = $individual->getEstimatedBirthDate(); 65*17c50b57SGreg Roach $max_date = $individual->getEstimatedDeathDate(); 66*17c50b57SGreg Roach 67*17c50b57SGreg Roach return (new Collection($this->historicEventsAll())) 68*17c50b57SGreg Roach ->map(function (string $gedcom) use ($individual): Fact { 69*17c50b57SGreg Roach return new Fact($gedcom, $individual, 'histo'); 70*17c50b57SGreg Roach }) 71*17c50b57SGreg Roach ->filter(function (Fact $fact) use ($min_date, $max_date): bool { 72*17c50b57SGreg Roach return Date::compare($fact->date(), $min_date) >= 0 && Date::compare($fact->date(), $max_date) <= 0; 73*17c50b57SGreg Roach }); 74*17c50b57SGreg Roach } 75*17c50b57SGreg Roach} 76