From 820b62df142779302ed642942aa3676dd58f5906 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Sat, 16 Feb 2019 14:57:27 +0000 Subject: Use Collection class --- app/Functions/FunctionsCharts.php | 24 +++++++++++------------- app/Functions/FunctionsEdit.php | 2 +- app/Functions/FunctionsExport.php | 4 ++-- app/Functions/FunctionsPrint.php | 2 +- app/Functions/FunctionsPrintFacts.php | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'app/Functions') 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 ''; if ($sosa > 0) { @@ -354,7 +352,8 @@ class FunctionsCharts echo ''; $nchi = 1; - if ($children) { + + if ($children->isNotEmpty()) { foreach ($children as $child) { echo ''; if ($sosa != 0) { @@ -385,8 +384,7 @@ class FunctionsCharts echo ''; echo '
'; //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 ''; $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 ''; - if ($kids) { + if ($fchildren->isNotEmpty()) { echo ''; - if ($kids > 1) { + if ($fchildren->count() > 1) { echo ''; } - $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 '', $source->fullName(), ''; // PUBL - $publ = $source->firstFact('PUBL'); + $publ = $source->facts(['PUBL'])->first(); if ($publ) { echo GedcomTag::getLabelValue('PUBL', $publ->value()); } -- cgit v1.3