Skip to content

Commit

Permalink
Finer control of abbreviate place names
Browse files Browse the repository at this point in the history
Motivation: Including highest level place name when abbrevaiting from 
back is not always desirable. This change will allow you to request the 
highest level to keep while always trying to show SHOW_PEDIGREE_PLACES 
number of levels

Implementation: 

- add function backParts to Places
- keep lastParts as it is used by census handlers
- expand scope of SHOW_PEDIGREE_PLACES_SUFFIX so that 1=keep top level, 
2=only keep to 2nd highest level, etc.

Note: help text probably needs work
  • Loading branch information
tronsmit committed Apr 7, 2021
1 parent fb29270 commit 9a85fa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 16 additions & 2 deletions app/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
*/
public function backParts(int $num, $omit): Collection
{
return $this->parts->slice(-($omit - 1) - $num, $num);
}

/**
* Extract the country (last parts) of a place name.
*
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion resources/views/admin/trees-preferences.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ use Illuminate\Support\Collection;
<div class="col-sm-9">
<?= /* I18N: The placeholders are edit controls. Show the [first/last] [1/2/3/4/5] parts of a place name */ I18N::translate(
'Show the %1$s %2$s parts of a place name.',
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')]]),
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)])
) ?>
<p class="small text-muted">
Expand Down

0 comments on commit 9a85fa0

Please sign in to comment.