diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-02-16 14:57:27 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-02-16 16:19:49 +0000 |
| commit | 820b62df142779302ed642942aa3676dd58f5906 (patch) | |
| tree | 7a9186bc7db6c15106a054e5e1afc4875d73787c /app | |
| parent | 39ca88ba08cefcfcaf891abfcf748f9c808eb326 (diff) | |
| download | webtrees-820b62df142779302ed642942aa3676dd58f5906.tar.gz webtrees-820b62df142779302ed642942aa3676dd58f5906.tar.bz2 webtrees-820b62df142779302ed642942aa3676dd58f5906.zip | |
Use Collection class
Diffstat (limited to 'app')
24 files changed, 103 insertions, 121 deletions
diff --git a/app/Family.php b/app/Family.php index f80e43f3ad..dfb11d5a84 100644 --- a/app/Family.php +++ b/app/Family.php @@ -19,6 +19,7 @@ namespace Fisharebest\Webtrees; use Closure; use Illuminate\Database\Capsule\Manager as DB; +use Illuminate\Support\Collection; use stdClass; /** @@ -243,14 +244,16 @@ class Family extends GedcomRecord * * @param int|null $access_level * - * @return Individual[] + * @return Collection|Individual[] */ - public function spouses($access_level = null): array + public function spouses($access_level = null): Collection { - return array_filter([ + $spouses = new Collection([ $this->husband($access_level), $this->wife($access_level), ]); + + return $spouses->filter(); } /** @@ -258,9 +261,9 @@ class Family extends GedcomRecord * * @param int|null $access_level * - * @return Individual[] + * @return Collection|Individual[] */ - public function children($access_level = null): array + public function children($access_level = null): Collection { if ($access_level === null) { $access_level = Auth::accessLevel($this->tree); @@ -268,11 +271,13 @@ class Family extends GedcomRecord $SHOW_PRIVATE_RELATIONSHIPS = (bool) $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'); - $children = []; + $children = new Collection(); + foreach ($this->facts(['CHIL'], false, $access_level, $SHOW_PRIVATE_RELATIONSHIPS) as $fact) { $child = $fact->target(); + if ($child instanceof Individual && ($SHOW_PRIVATE_RELATIONSHIPS || $child->canShowName($access_level))) { - $children[] = $child; + $children->push($child); } } @@ -286,7 +291,8 @@ class Family extends GedcomRecord */ public function numberOfChildren(): int { - $nchi = count($this->children()); + $nchi = $this->children()->count(); + foreach ($this->facts(['NCHI']) as $fact) { $nchi = max($nchi, (int) $fact->value()); } @@ -299,9 +305,9 @@ class Family extends GedcomRecord * * @return Fact|null */ - public function getMarriage() + public function getMarriage(): ?Fact { - return $this->firstFact('MARR'); + return $this->facts(['MARR'])->first(); } /** @@ -309,7 +315,7 @@ class Family extends GedcomRecord * * @return Date */ - public function getMarriageDate() + public function getMarriageDate(): Date { $marriage = $this->getMarriage(); if ($marriage) { diff --git a/app/Functions/FunctionsCharts.php b/app/Functions/FunctionsCharts.php index cf969a65da..c5a6ba8521 100644 --- a/app/Functions/FunctionsCharts.php +++ b/app/Functions/FunctionsCharts.php @@ -309,12 +309,10 @@ class FunctionsCharts string $label = '', bool $show_cousins = false ) { - $bheight = app()->make(ModuleThemeInterface::class)->parameter('chart-box-y'); - + $bheight = app()->make(ModuleThemeInterface::class)->parameter('chart-box-y'); $pbheight = $bheight + 14; - $children = $family->children(); - $numchil = count($children); + $numchil = $children->count(); echo '<table border="0" cellpadding="0" cellspacing="0"><tr>'; if ($sosa > 0) { @@ -354,7 +352,8 @@ class FunctionsCharts echo '</tr>'; $nchi = 1; - if ($children) { + + if ($children->isNotEmpty()) { foreach ($children as $child) { echo '<tr>'; if ($sosa != 0) { @@ -385,8 +384,7 @@ class FunctionsCharts echo '</tr><tr><td></td>'; echo '<td style="text-align:end; vertical-align: top;">'; //find out how many cousins there are to establish vertical line on second families - $fchildren = $famids[$f]->children(); - $kids = count($fchildren); + $kids = $famids[$f]->children()->count(); if ($show_cousins) { if ($kids > 0) { @@ -407,8 +405,8 @@ class FunctionsCharts echo '<td class="details1" style="text-align:center;">'; $spouse = $famids[$f]->spouse($child); - $marr = $famids[$f]->firstFact('MARR'); - $div = $famids[$f]->firstFact('DIV'); + $marr = $famids[$f]->facts(['MARR'])->first(); + $div = $famids[$f]->facts(['DIV'])->first(); if ($marr) { // marriage date echo $marr->date()->minimumDate()->format('%Y'); @@ -510,15 +508,15 @@ class FunctionsCharts { $bheight = app()->make(ModuleThemeInterface::class)->parameter('chart-box-y'); $fchildren = $family->children(); - $kids = count($fchildren); + $kids = $fchildren->count(); echo '<td>'; - if ($kids) { + if ($fchildren->isNotEmpty()) { echo '<table cellspacing="0" cellpadding="0" border="0" ><tr>'; - if ($kids > 1) { + if ($fchildren->count() > 1) { echo '<td rowspan="', $kids, '"><img width="3px" height="', (($bheight) * ($kids - 1)), 'px" src="', e(asset('css/images/vline.png')), '"></td>'; } - $ctkids = count($fchildren); + $ctkids = $fchildren->count(); $i = 1; foreach ($fchildren as $fchil) { if ($i == 1) { diff --git a/app/Functions/FunctionsEdit.php b/app/Functions/FunctionsEdit.php index d5132fed6f..a06ba2efbd 100644 --- a/app/Functions/FunctionsEdit.php +++ b/app/Functions/FunctionsEdit.php @@ -564,7 +564,7 @@ class FunctionsEdit if ($fact === 'HUSB' || $fact === 'WIFE') { $family = Family::getInstance($xref, $tree); if ($family) { - $spouse_link = $family->firstFact($fact); + $spouse_link = $family->facts([$fact])->first(); if ($spouse_link) { $spouse = $spouse_link->target(); if ($spouse instanceof Individual) { diff --git a/app/Functions/FunctionsExport.php b/app/Functions/FunctionsExport.php index f16a85ca1c..c49ba96742 100644 --- a/app/Functions/FunctionsExport.php +++ b/app/Functions/FunctionsExport.php @@ -101,11 +101,11 @@ class FunctionsExport // Preserve some values from the original header $record = GedcomRecord::getInstance('HEAD', $tree); - $fact = $record->firstFact('COPR'); + $fact = $record->facts(['COPR'])->first(); if ($fact instanceof Fact) { $COPR = "\n1 COPR " .$fact->value(); } - $fact = $record->firstFact('LANG'); + $fact = $record->facts(['LANG'])->first(); if ($fact instanceof Fact) { $LANG = "\n1 LANG " .$fact->value(); } diff --git a/app/Functions/FunctionsPrint.php b/app/Functions/FunctionsPrint.php index 5ff06a1e13..ecf14bf930 100644 --- a/app/Functions/FunctionsPrint.php +++ b/app/Functions/FunctionsPrint.php @@ -274,7 +274,7 @@ class FunctionsPrint // Can't use getDeathDate(), as this also gives BURI/CREM events, which // wouldn't give the correct "days after death" result for people with // no DEAT. - $death_event = $record->firstFact('DEAT'); + $death_event = $record->facts(['DEAT'])->first(); if ($death_event) { $death_date = $death_event->date(); } else { diff --git a/app/Functions/FunctionsPrintFacts.php b/app/Functions/FunctionsPrintFacts.php index 540f522618..2d7ce2e7f1 100644 --- a/app/Functions/FunctionsPrintFacts.php +++ b/app/Functions/FunctionsPrintFacts.php @@ -606,7 +606,7 @@ class FunctionsPrintFacts } $data .= ' class="source_citations">'; // PUBL - $publ = $source->firstFact('PUBL'); + $publ = $source->facts(['PUBL'])->first(); if ($publ) { $data .= GedcomTag::getLabelValue('PUBL', $publ->value()); } @@ -790,7 +790,7 @@ class FunctionsPrintFacts if ($source) { echo '<a href="', e($source->url()), '">', $source->fullName(), '</a>'; // PUBL - $publ = $source->firstFact('PUBL'); + $publ = $source->facts(['PUBL'])->first(); if ($publ) { echo GedcomTag::getLabelValue('PUBL', $publ->value()); } diff --git a/app/GedcomRecord.php b/app/GedcomRecord.php index ffae9af09f..3eabde397e 100644 --- a/app/GedcomRecord.php +++ b/app/GedcomRecord.php @@ -1066,24 +1066,6 @@ class GedcomRecord } /** - * Get the first (i.e. prefered) Fact for the given fact type - * - * @param string $tag - * - * @return Fact|null - */ - public function firstFact(string $tag) - { - foreach ($this->facts() as $fact) { - if ($fact->getTag() === $tag) { - return $fact; - } - } - - return null; - } - - /** * The facts and events for this record. * * @param string[] $filter @@ -1125,7 +1107,7 @@ class GedcomRecord */ public function lastChangeTimestamp(bool $sorting = false) { - $chan = $this->firstFact('CHAN'); + $chan = $this->facts(['CHAN'])->first(); if ($chan) { // The record does have a CHAN event @@ -1159,7 +1141,7 @@ class GedcomRecord */ public function lastChangeUser() { - $chan = $this->firstFact('CHAN'); + $chan = $this->facts(['CHAN'])->first(); if ($chan === null) { return I18N::translate('Unknown'); diff --git a/app/Http/Controllers/Admin/FixLevel0MediaController.php b/app/Http/Controllers/Admin/FixLevel0MediaController.php index 220a870b54..af5a342607 100644 --- a/app/Http/Controllers/Admin/FixLevel0MediaController.php +++ b/app/Http/Controllers/Admin/FixLevel0MediaController.php @@ -151,20 +151,20 @@ class FixLevel0MediaController extends AbstractAdminController $facts = []; } - $facts = array_map(function (Fact $fact) use ($individual, $media): string { + $facts = $facts->map(function (Fact $fact) use ($individual, $media): string { return view('admin/fix-level-0-media-action', [ 'fact' => $fact, 'individual' => $individual, 'media' => $media, ]); - }, $facts); + }); return [ $tree->name(), $media->displayImage(100, 100, 'fit', ['class' => 'img-thumbnail']), '<a href="' . e($media->url()) . '">' . $media->fullName() . '</a>', '<a href="' . e($individual->url()) . '">' . $individual->fullName() . '</a>', - implode(' ', $facts), + $facts->implode(' '), ]; }); } diff --git a/app/Http/Controllers/BranchesController.php b/app/Http/Controllers/BranchesController.php index dbde24195d..e539a12c13 100644 --- a/app/Http/Controllers/BranchesController.php +++ b/app/Http/Controllers/BranchesController.php @@ -324,7 +324,7 @@ class BranchesController extends AbstractBaseController $marriage_year = $family->getMarriageYear(); if ($marriage_year) { $fam_html .= ' <a href="' . e($family->url()) . '" title="' . strip_tags($family->getMarriageDate()->display()) . '"><i class="icon-rings"></i>' . $marriage_year . '</a>'; - } elseif ($family->firstFact('MARR')) { + } elseif ($family->facts(['MARR'])->first()) { $fam_html .= ' <a href="' . e($family->url()) . '" title="' . I18N::translate('Marriage') . '"><i class="icon-rings"></i></a>'; } else { $fam_html .= ' <a href="' . e($family->url()) . '" title="' . I18N::translate('Not married') . '"><i class="icon-rings"></i></a>'; diff --git a/app/Http/Controllers/EditFamilyController.php b/app/Http/Controllers/EditFamilyController.php index 964840d465..1f430f39ee 100644 --- a/app/Http/Controllers/EditFamilyController.php +++ b/app/Http/Controllers/EditFamilyController.php @@ -19,6 +19,7 @@ namespace Fisharebest\Webtrees\Http\Controllers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Date; +use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\GedcomCode\GedcomCodePedi; use Fisharebest\Webtrees\I18N; @@ -263,7 +264,7 @@ class EditFamilyController extends AbstractEditController $spouse = $tree->createIndividual($gedrec); // Update the existing family - add marriage, etc - if ($family->firstFact('HUSB')) { + if ($family->facts(['HUSB'])->first() instanceof Fact) { $family->createFact('1 WIFE @' . $spouse->xref() . '@', true); } else { $family->createFact('1 HUSB @' . $spouse->xref() . '@', true); @@ -405,7 +406,7 @@ class EditFamilyController extends AbstractEditController } foreach ($new_children as $new_child) { - if ($new_child && !in_array($new_child, $old_children)) { + if ($new_child && !$old_children->contains($new_child)) { // Add new FAMC link $new_child->createFact('1 FAMC @' . $family->xref() . '@', true); // Add new CHIL link diff --git a/app/Individual.php b/app/Individual.php index 277e47812f..d6ec8ab3bf 100644 --- a/app/Individual.php +++ b/app/Individual.php @@ -961,9 +961,9 @@ class Individual extends GedcomRecord /** * Get a list of step-parent families. * - * @return Family[] + * @return Collection|Family[] */ - public function childStepFamilies(): array + public function childStepFamilies(): Collection { $step_families = []; $families = $this->childFamilies(); @@ -986,20 +986,22 @@ class Individual extends GedcomRecord } } - return $step_families; + return new Collection($step_families); } /** * Get a list of step-parent families. * - * @return Family[] + * @return Collection|Family[] */ - public function spouseStepFamilies(): array + public function spouseStepFamilies(): Collection { $step_families = []; $families = $this->spouseFamilies(); + foreach ($families as $family) { $spouse = $family->spouse($this); + if ($spouse) { foreach ($family->spouse($this)->spouseFamilies() as $step_family) { if (!$families->containsStrict($step_family)) { @@ -1009,7 +1011,7 @@ class Individual extends GedcomRecord } } - return $step_families; + return new Collection($step_families); } /** @@ -1019,7 +1021,7 @@ class Individual extends GedcomRecord * * @return string */ - public function getChildFamilyLabel(Family $family) + public function getChildFamilyLabel(Family $family): string { if (preg_match('/\n1 FAMC @' . $family->xref() . '@(?:\n[2-9].*)*\n2 PEDI (.+)/', $this->gedcom(), $match)) { // A specified pedigree diff --git a/app/Media.php b/app/Media.php index 8c7b5e9e56..b4b901d05a 100644 --- a/app/Media.php +++ b/app/Media.php @@ -146,7 +146,8 @@ class Media extends GedcomRecord */ public function getNote() { - $fact = $this->firstFact('NOTE'); + $fact = $this->facts(['NOTE'])->first(); + if ($fact instanceof Fact) { // Link to note object $note = $fact->target(); diff --git a/app/Module/BatchUpdate/BatchUpdateMissingDeathPlugin.php b/app/Module/BatchUpdate/BatchUpdateMissingDeathPlugin.php index 671d3b29bb..0dc7d2e45b 100644 --- a/app/Module/BatchUpdate/BatchUpdateMissingDeathPlugin.php +++ b/app/Module/BatchUpdate/BatchUpdateMissingDeathPlugin.php @@ -55,7 +55,7 @@ class BatchUpdateMissingDeathPlugin extends BatchUpdateBasePlugin */ public function doesRecordNeedUpdate(GedcomRecord $record): bool { - return $record instanceof Individual && $record->firstFact('DEAT') === null && $record->isDead(); + return $record instanceof Individual && $record->facts(['DEAT'])->isEmpty() && $record->isDead(); } /** diff --git a/app/Module/DescendancyChartModule.php b/app/Module/DescendancyChartModule.php index 29c5192db6..75c43bea4c 100644 --- a/app/Module/DescendancyChartModule.php +++ b/app/Module/DescendancyChartModule.php @@ -350,13 +350,13 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf // children $children = $family->children(); echo '<tr><td colspan="3" class="details1" > '; - if (!empty($children)) { - echo GedcomTag::getLabel('NCHI') . ': ' . count($children); + if ($children->isNotEmpty()) { + echo GedcomTag::getLabel('NCHI') . ': ' . $children->count(); } else { // Distinguish between no children (NCHI 0) and no recorded // children (no CHIL records) if (strpos($family->gedcom(), '\n1 NCHI 0') !== false) { - echo GedcomTag::getLabel('NCHI') . ': ' . count($children); + echo GedcomTag::getLabel('NCHI') . ': ' . $children->count(); } else { echo I18N::translate('No children'); } diff --git a/app/Module/DescendancyModule.php b/app/Module/DescendancyModule.php index fe73dc1d24..c11f6f8859 100644 --- a/app/Module/DescendancyModule.php +++ b/app/Module/DescendancyModule.php @@ -237,7 +237,8 @@ class DescendancyModule extends AbstractModule implements ModuleSidebarInterface $out = ''; if ($family->canShow()) { $children = $family->children(); - if ($children) { + + if ($children->isNotEmpty()) { foreach ($children as $child) { $out .= $this->getPersonLi($child, $generations - 1); } diff --git a/app/Module/HourglassChartModule.php b/app/Module/HourglassChartModule.php index 5a34a1ce97..7ab237c9eb 100644 --- a/app/Module/HourglassChartModule.php +++ b/app/Module/HourglassChartModule.php @@ -372,13 +372,13 @@ class HourglassChartModule extends AbstractModule implements ModuleChartInterfac } // filter out root person from children array so only siblings remain - $siblings = array_filter($family->children(), function (Individual $x) use ($individual): bool { + $siblings = $family->children()->filter(function (Individual $x) use ($individual): bool { return $x !== $individual; }); - $count_siblings = count($siblings); - if ($count_siblings > 0) { + + if ($siblings->count() > 0) { echo '<span class="name1">'; - echo $count_siblings > 1 ? I18N::translate('Siblings') : I18N::translate('Sibling'); + echo $siblings->count() > 1 ? I18N::translate('Siblings') : I18N::translate('Sibling'); echo '</span>'; foreach ($siblings as $child) { echo '<a href="' . e(route('hourglass', [ diff --git a/app/Module/InteractiveTree/TreeView.php b/app/Module/InteractiveTree/TreeView.php index 04804c58a2..6411504846 100644 --- a/app/Module/InteractiveTree/TreeView.php +++ b/app/Module/InteractiveTree/TreeView.php @@ -186,7 +186,7 @@ class TreeView foreach ($familyList as $f) { $children = $f->children(); - if ($children) { + if ($children->isNotEmpty()) { $f2load[] = $f->xref(); foreach ($children as $child) { // Eliminate duplicates - e.g. when adopted by a step-parent diff --git a/app/Module/ModuleThemeTrait.php b/app/Module/ModuleThemeTrait.php index fb20594a51..3e7a9c4ee8 100644 --- a/app/Module/ModuleThemeTrait.php +++ b/app/Module/ModuleThemeTrait.php @@ -172,8 +172,8 @@ trait ModuleThemeTrait // Show BIRT or equivalent event foreach (Gedcom::BIRTH_EVENTS as $birttag) { if (!in_array($birttag, $opt_tags)) { - $event = $individual->firstFact($birttag); - if ($event) { + $event = $individual->facts([$birttag])->first(); + if ($event instanceof Fact) { $html .= $event->summary(); break; } @@ -182,8 +182,8 @@ trait ModuleThemeTrait // Show optional events (before death) foreach ($opt_tags as $key => $tag) { if (!in_array($tag, Gedcom::DEATH_EVENTS)) { - $event = $individual->firstFact($tag); - if ($event !== null) { + $event = $individual->facts([$tag])->first(); + if ($event instanceof Fact) { $html .= $event->summary(); unset($opt_tags[$key]); } @@ -191,8 +191,8 @@ trait ModuleThemeTrait } // Show DEAT or equivalent event foreach (Gedcom::DEATH_EVENTS as $deattag) { - $event = $individual->firstFact($deattag); - if ($event) { + $event = $individual->facts([$deattag])->first(); + if ($event instanceof Fact) { $html .= $event->summary(); if (in_array($deattag, $opt_tags)) { unset($opt_tags[array_search($deattag, $opt_tags)]); @@ -202,8 +202,8 @@ trait ModuleThemeTrait } // Show remaining optional events (after death) foreach ($opt_tags as $tag) { - $event = $individual->firstFact($tag); - if ($event) { + $event = $individual->facts([$tag])->first(); + if ($event instanceof Fact) { $html .= $event->summary(); } } diff --git a/app/Module/PedigreeMapModule.php b/app/Module/PedigreeMapModule.php index e4516aea59..91de38d673 100644 --- a/app/Module/PedigreeMapModule.php +++ b/app/Module/PedigreeMapModule.php @@ -286,7 +286,7 @@ class PedigreeMapModule extends AbstractModule implements ModuleChartInterface $facts = []; foreach ($ancestors as $sosa => $person) { if ($person->canShow()) { - $birth = $person->firstFact('BIRT'); + $birth = $person->facts(['BIRT'])->first(); if ($birth instanceof Fact && $birth->place()->gedcomName() !== '') { $facts[$sosa] = $birth; } diff --git a/app/Module/PlacesModule.php b/app/Module/PlacesModule.php index 63b1010eab..232eb38828 100644 --- a/app/Module/PlacesModule.php +++ b/app/Module/PlacesModule.php @@ -216,7 +216,7 @@ class PlacesModule extends AbstractModule implements ModuleTabInterface $facts = $facts->merge($family->facts()); // Add birth of children from this family to the facts array foreach ($family->children() as $child) { - $childsBirth = $child->firstFact('BIRT'); + $childsBirth = $child->facts(['BIRT'])->first(); if ($childsBirth && $childsBirth->place()->gedcomName() !== '') { $facts->push($childsBirth); } diff --git a/app/Report/ReportParserGenerate.php b/app/Report/ReportParserGenerate.php index 51a00a49ee..3c07d9d864 100644 --- a/app/Report/ReportParserGenerate.php +++ b/app/Report/ReportParserGenerate.php @@ -1296,8 +1296,7 @@ class ReportParserGenerate extends ReportParserBase $record = GedcomRecord::getInstance($id, $this->tree); if (empty($attrs['diff']) && !empty($id)) { - throw new \Exception('eek'); - Functions::sortFacts($facts); + $facts = $record->facts([], true); $this->repeats = []; $nonfacts = explode(',', $tag); foreach ($facts as $fact) { @@ -2405,37 +2404,23 @@ class ReportParserGenerate extends ReportParserBase switch ($group) { case 'child-family': foreach ($person->childFamilies() as $family) { - $husband = $family->husband(); - $wife = $family->wife(); - if (!empty($husband)) { - $this->list[$husband->xref()] = $husband; + foreach ($family->spouses() as $spouse) { + $this->list[$spouse->xref()] = $spouse; } - if (!empty($wife)) { - $this->list[$wife->xref()] = $wife; - } - $children = $family->children(); - foreach ($children as $child) { - if (!empty($child)) { - $this->list[$child->xref()] = $child; - } + + foreach ($family->children() as $child) { + $this->list[$child->xref()] = $child; } } break; case 'spouse-family': foreach ($person->spouseFamilies() as $family) { - $husband = $family->husband(); - $wife = $family->wife(); - if (!empty($husband)) { - $this->list[$husband->xref()] = $husband; + foreach ($family->spouses() as $spouse) { + $this->list[$spouse->xref()] = $spouse; } - if (!empty($wife)) { - $this->list[$wife->xref()] = $wife; - } - $children = $family->children(); - foreach ($children as $child) { - if (!empty($child)) { - $this->list[$child->xref()] = $child; - } + + foreach ($family->children() as $child) { + $this->list[$child->xref()] = $child; } } break; @@ -2749,10 +2734,13 @@ class ReportParserGenerate extends ReportParserBase } } } + $children = $family->children(); + foreach ($children as $child) { if ($child) { $list[$child->xref()] = $child; + if (isset($list[$pid]->generation)) { $list[$child->xref()]->generation = $list[$pid]->generation + 1; } else { @@ -2778,7 +2766,7 @@ class ReportParserGenerate extends ReportParserBase * * @return void */ - private function addAncestors(&$list, $pid, $children = false, $generations = -1) + private function addAncestors(array &$list, string $pid, bool $children = false, int $generations = -1) { $genlist = [$pid]; $list[$pid]->generation = 1; diff --git a/app/Statistics/Repository/EventRepository.php b/app/Statistics/Repository/EventRepository.php index fca9856992..6a79b56797 100644 --- a/app/Statistics/Repository/EventRepository.php +++ b/app/Statistics/Repository/EventRepository.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Statistics\Repository; use Fisharebest\Webtrees\Date; +use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Functions\FunctionsPrint; use Fisharebest\Webtrees\Gedcom; use Fisharebest\Webtrees\GedcomRecord; @@ -401,10 +402,10 @@ class EventRepository implements EventRepositoryInterface $fact = null; if ($record) { - $fact = $record->firstFact($row->fact); + $fact = $record->facts([$row->fact])->first(); } - if ($fact) { + if ($fact instanceof Fact) { return FunctionsPrint::formatFactPlace($fact, true, true, true); } } diff --git a/app/Statistics/Repository/FamilyDatesRepository.php b/app/Statistics/Repository/FamilyDatesRepository.php index 7beac8f5ef..e1cfd1b084 100644 --- a/app/Statistics/Repository/FamilyDatesRepository.php +++ b/app/Statistics/Repository/FamilyDatesRepository.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Statistics\Repository; use Fisharebest\Webtrees\Date; +use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Functions\FunctionsPrint; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\I18N; @@ -367,10 +368,10 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface $fact = null; if ($record) { - $fact = $record->firstFact($row->fact); + $fact = $record->facts([$row->fact])->first(); } - if ($fact) { + if ($fact instanceof Fact) { return FunctionsPrint::formatFactPlace($fact, true, true, true); } } diff --git a/app/Statistics/Repository/GedcomRepository.php b/app/Statistics/Repository/GedcomRepository.php index 869bd27f2b..eb9047c939 100644 --- a/app/Statistics/Repository/GedcomRepository.php +++ b/app/Statistics/Repository/GedcomRepository.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Statistics\Repository; use Fisharebest\Webtrees\Date; +use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\Statistics\Repository\Interfaces\GedcomRepositoryInterface; use Fisharebest\Webtrees\Tree; @@ -57,10 +58,10 @@ class GedcomRepository implements GedcomRepositoryInterface $head = GedcomRecord::getInstance('HEAD', $this->tree); - if ($head !== null) { - $sour = $head->firstFact('SOUR'); + if ($head instanceof GedcomRecord) { + $sour = $head->facts(['SOUR'])->first(); - if ($sour !== null) { + if ($sour instanceof Fact) { $source = $sour->value(); $title = $sour->attribute('NAME'); $version = $sour->attribute('VERS'); @@ -139,10 +140,10 @@ class GedcomRepository implements GedcomRepositoryInterface { $head = GedcomRecord::getInstance('HEAD', $this->tree); - if ($head !== null) { - $fact = $head->firstFact('DATE'); + if ($head instanceof GedcomRecord) { + $fact = $head->facts(['DATE'])->first(); - if ($fact) { + if ($fact instanceof Fact) { return (new Date($fact->value()))->display(); } } |
