diff --git a/app/Place.php b/app/Place.php index 6a73120b578..1c1458e6c80 100644 --- a/app/Place.php +++ b/app/Place.php @@ -165,6 +165,19 @@ public function firstParts(int $n): Collection return $this->parts->slice(0, $n); } + /** + * Extract the last parts of a place name, omitting top levels if possible. + * + * @param int $num : of parts to include - has highest priority + * @param int $omit : where to start counting backwards 1=top level, 2=next etc. + * + * @return Collection + */ + public function backParts(int $num, $omit): Collection + { + return $this->parts->slice(-($omit - 1) - $num, $num); + } + /** * Extract the country (last parts) of a place name. * @@ -280,10 +293,11 @@ public function fullName(bool $link = false): string public function shortName(bool $link = false): string { $SHOW_PEDIGREE_PLACES = (int) $this->tree->getPreference('SHOW_PEDIGREE_PLACES'); + $SHOW_PEDIGREE_PLACES_SUFFIX = (int) $this->tree->getPreference('SHOW_PEDIGREE_PLACES_SUFFIX'); // Abbreviate the place name, for lists - if ($this->tree->getPreference('SHOW_PEDIGREE_PLACES_SUFFIX')) { - $parts = $this->lastParts($SHOW_PEDIGREE_PLACES); + if ($SHOW_PEDIGREE_PLACES_SUFFIX) { + $parts = $this->backParts($SHOW_PEDIGREE_PLACES, $SHOW_PEDIGREE_PLACES_SUFFIX); } else { $parts = $this->firstParts($SHOW_PEDIGREE_PLACES); } diff --git a/resources/views/admin/trees-preferences.phtml b/resources/views/admin/trees-preferences.phtml index 0fe268137b1..6eeb503211e 100644 --- a/resources/views/admin/trees-preferences.phtml +++ b/resources/views/admin/trees-preferences.phtml @@ -594,7 +594,13 @@ use Illuminate\Support\Collection;
'SHOW_PEDIGREE_PLACES_SUFFIX', 'selected' => $tree->getPreference('SHOW_PEDIGREE_PLACES_SUFFIX'), 'options' => ['0' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'first'), '1' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'last')]]), + view('components/select', ['name' => 'SHOW_PEDIGREE_PLACES_SUFFIX', 'selected' => $tree->getPreference('SHOW_PEDIGREE_PLACES_SUFFIX'), + 'options' => ['0' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'first'), + '1' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'last'), + '2' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'last, omitting top level'), + '3' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'last, omitting top 2 levels'), + '4' => I18N::translateContext('Show the [first/last] [N] parts of a place name.', 'last, omitting top 3 levels'), + ]]), view('components/select-number', ['name' => 'SHOW_PEDIGREE_PLACES', 'selected' => $tree->getPreference('SHOW_PEDIGREE_PLACES'), 'options' => range(1, 9)]) ) ?>