Skip to content

Commit

Permalink
Add parent age to node data
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Nov 30, 2023
1 parent 79bd6a3 commit 67d8925
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Binary file added resources/images/sex-female.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/sex-male.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/sex-unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/Facade/DataFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace MagicSunday\Webtrees\PedigreeChart\Facade;

use Fisharebest\Webtrees\Age;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
Expand Down Expand Up @@ -134,6 +135,26 @@ private function buildTreeStructure(?Individual $individual, int $generation = 1
$node->addParent($motherNode);
}

if (
$family->husband()
&& $individual->getBirthDate()->isOK()
&& $family->husband()->getBirthDate()->isOK()
) {
$age = new Age($family->husband()->getBirthDate(), $individual->getBirthDate());

$node->getData()->setFatherAge(I18N::number($age->ageYears()));
}

if (
$family->wife()
&& $individual->getBirthDate()->isOK()
&& $family->wife()->getBirthDate()->isOK()
) {
$age = new Age($family->wife()->getBirthDate(), $individual->getBirthDate());

$node->getData()->setMotherAge(I18N::number($age->ageYears()));
}

return $node;
}

Expand Down
38 changes: 38 additions & 0 deletions src/Model/NodeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ class NodeData implements JsonSerializable
*/
protected string $timespan = '';

/**
* The age of the father at birth of a child.
*
* @var string
*/
protected string $fatherAge = '';

/**
* The age of the mother at birth of a child.
*
* @var string
*/
protected string $motherAge = '';

/**
* The underlying individual instance. Only used internally.
*
Expand Down Expand Up @@ -352,6 +366,28 @@ public function setTimespan(string $timespan): NodeData
return $this;
}

/**
* @param string $fatherAge
*
* @return NodeData
*/
public function setFatherAge(string $fatherAge): NodeData
{
$this->fatherAge = $fatherAge;
return $this;
}

/**
* @param string $motherAge
*
* @return NodeData
*/
public function setMotherAge(string $motherAge): NodeData
{
$this->motherAge = $motherAge;
return $this;
}

/**
* @return null|Individual
*/
Expand Down Expand Up @@ -396,6 +432,8 @@ public function jsonSerialize(): array
'birth' => $this->birth,
'death' => $this->death,
'timespan' => $this->timespan,
'fatherAge' => $this->fatherAge,
'motherAge' => $this->motherAge,
];
}
}

0 comments on commit 67d8925

Please sign in to comment.