117c50b57SGreg Roach<?php 23976b470SGreg Roach 317c50b57SGreg Roach/** 417c50b57SGreg Roach * webtrees: online genealogy 5*8d406599SGreg Roach * Copyright (C) 2020 webtrees development team 617c50b57SGreg Roach * This program is free software: you can redistribute it and/or modify 717c50b57SGreg Roach * it under the terms of the GNU General Public License as published by 817c50b57SGreg Roach * the Free Software Foundation, either version 3 of the License, or 917c50b57SGreg Roach * (at your option) any later version. 1017c50b57SGreg Roach * This program is distributed in the hope that it will be useful, 1117c50b57SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1217c50b57SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1317c50b57SGreg Roach * GNU General Public License for more details. 1417c50b57SGreg Roach * You should have received a copy of the GNU General Public License 1517c50b57SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1617c50b57SGreg Roach */ 17fcfa147eSGreg Roach 1817c50b57SGreg Roachdeclare(strict_types=1); 1917c50b57SGreg Roach 2017c50b57SGreg Roachnamespace Fisharebest\Webtrees\Module; 2117c50b57SGreg Roach 2217c50b57SGreg Roachuse Fisharebest\Webtrees\Date; 2317c50b57SGreg Roachuse Fisharebest\Webtrees\Fact; 2417c50b57SGreg Roachuse Fisharebest\Webtrees\I18N; 2517c50b57SGreg Roachuse Fisharebest\Webtrees\Individual; 2617c50b57SGreg Roachuse Illuminate\Support\Collection; 2717c50b57SGreg Roach 2817c50b57SGreg Roach/** 2917c50b57SGreg Roach * Trait ModuleHistoricEventsTrait - Show historic events on an individual‘s page 3017c50b57SGreg Roach */ 3117c50b57SGreg Roachtrait ModuleHistoricEventsTrait 3217c50b57SGreg Roach{ 3317c50b57SGreg Roach /** 3417c50b57SGreg Roach * A sentence describing what this module does. 3517c50b57SGreg Roach * 3617c50b57SGreg Roach * @return string 3717c50b57SGreg Roach */ 3817c50b57SGreg Roach public function description(): string 3917c50b57SGreg Roach { 40b5e8e56bSGreg Roach return I18N::translate('Add historic events to an individual’s page.'); 4117c50b57SGreg Roach } 4217c50b57SGreg Roach 4317c50b57SGreg Roach /** 4417c50b57SGreg Roach * All events provided by this module. 4517c50b57SGreg Roach * 46*8d406599SGreg Roach * @return Collection<string> 4717c50b57SGreg Roach */ 48*8d406599SGreg Roach public function historicEventsAll(): Collection 4917c50b57SGreg Roach { 50*8d406599SGreg Roach return new Collection([ 5117c50b57SGreg Roach "1 EVEN foo\n2 TYPE bar\n2 DATE FROM 6 FEB 1952" 52*8d406599SGreg Roach ]); 5317c50b57SGreg Roach } 5417c50b57SGreg Roach 5517c50b57SGreg Roach /** 5617c50b57SGreg Roach * Which events should we show for an individual? 5717c50b57SGreg Roach * 5817c50b57SGreg Roach * @param Individual $individual 5917c50b57SGreg Roach * 60b5c8fd7eSGreg Roach * @return Collection<Fact> 6117c50b57SGreg Roach */ 6217c50b57SGreg Roach public function historicEventsForIndividual(Individual $individual): Collection 6317c50b57SGreg Roach { 6417c50b57SGreg Roach $min_date = $individual->getEstimatedBirthDate(); 6517c50b57SGreg Roach $max_date = $individual->getEstimatedDeathDate(); 6617c50b57SGreg Roach 6717c50b57SGreg Roach return (new Collection($this->historicEventsAll())) 680b5fd0a6SGreg Roach ->map(static function (string $gedcom) use ($individual): Fact { 6917c50b57SGreg Roach return new Fact($gedcom, $individual, 'histo'); 7017c50b57SGreg Roach }) 710b5fd0a6SGreg Roach ->filter(static function (Fact $fact) use ($min_date, $max_date): bool { 7217c50b57SGreg Roach return Date::compare($fact->date(), $min_date) >= 0 && Date::compare($fact->date(), $max_date) <= 0; 7317c50b57SGreg Roach }); 7417c50b57SGreg Roach } 7517c50b57SGreg Roach} 76