Skip to content

Commit

Permalink
GH-38: Display marriage name depending on spouse
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Aug 23, 2023
1 parent 80c3a1c commit 842508e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private function buildJsonTree(?Individual $individual, int $generation = 1): ar
$parents = [];

$parents[$individual->xref()] = [
'data' => $this->getIndividualData($individual, $generation),
'data' => $this->getIndividualData($individual, null, $generation),
];

if ($families->count() > 0) {
Expand Down
34 changes: 21 additions & 13 deletions src/Traits/IndividualTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,46 @@ trait IndividualTrait
/**
* Returns the primary name used in the chart.
*
* @param Individual $individual The current individual
* @param bool $useMarriedName TRUE to return the married name instead of the primary one
* @param Individual $individual The current individual
* @param null|Individual $spouse
* @param bool $useMarriedName TRUE to return the married name instead of the primary one
*
* @return array
*/
private function getPrimaryName(Individual $individual, bool $useMarriedName = false): array
private function getPrimaryName(Individual $individual, Individual $spouse = null, bool $useMarriedName = false): array
{
$allNames = $individual->getAllNames();

if ($useMarriedName !== false) {
foreach ($allNames as $name) {
if ($name['type'] === '_MARNM') {
return $name;
$individualNames = $individual->getAllNames();

if (($useMarriedName !== false) && ($spouse !== null)) {
foreach ($individualNames as $individualName) {
foreach ($spouse->getAllNames() as $spouseName) {
if (
($individualName['type'] === '_MARNM')
&& ($individualName['surn'] === $spouseName['surn'])
) {
return $individualName;
}
}
}
}

return $allNames[$individual->getPrimaryName()];
return $individualNames[$individual->getPrimaryName()];
}

/**
* Get the individual data required for display the chart.
*
* @param Individual $individual The current individual
* @param int $generation The generation the person belongs to
* @param Individual $individual The current individual
* @param null|Individual $spouse The current spouse of the individual
* @param int $generation The generation the person belongs to
*
* @return array<string, array<string>|bool|int|string>
*/
private function getIndividualData(Individual $individual, int $generation): array
private function getIndividualData(Individual $individual, Individual $spouse = null, int $generation): array
{
$primaryName = $this->getPrimaryName(
$individual,
$spouse,
$this->configuration->getShowMarriedNames()
);

Expand Down

0 comments on commit 842508e

Please sign in to comment.