|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage PatronymicLineage |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart |
|
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\PatronymicLineage\Model; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\Individual; |
|
18
|
|
|
use Fisharebest\Webtrees\Place; |
|
19
|
|
|
use Illuminate\Support\Collection; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Derived class from the LineageNode, indicating a Root Lineage node |
|
23
|
|
|
*/ |
|
24
|
|
|
class LineageRootNode extends LineageNode |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Collection<string, int> $places Places for the lineage node |
|
28
|
|
|
*/ |
|
29
|
|
|
private $places; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int $nb_children Number of node childs |
|
33
|
|
|
*/ |
|
34
|
|
|
private $nb_children; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor for LineageRootNode |
|
38
|
|
|
* |
|
39
|
|
|
* @param Individual|null $node_indi |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(?Individual $node_indi = null) |
|
42
|
|
|
{ |
|
43
|
|
|
parent::__construct($node_indi, $this); |
|
44
|
|
|
$this->places = new Collection(); |
|
45
|
|
|
$this->nb_children = 0; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Adds a place to the list of lineage's place |
|
50
|
|
|
* |
|
51
|
|
|
* @param Place $place |
|
52
|
|
|
*/ |
|
53
|
|
|
public function addPlace(Place $place): void |
|
54
|
|
|
{ |
|
55
|
|
|
$place_name = $place->gedcomName(); |
|
56
|
|
|
if (mb_strlen($place_name) > 0) { |
|
57
|
|
|
$this->places->put($place_name, $this->places->get($place_name, 0) + 1); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns the number of child nodes. |
|
63
|
|
|
* This number is more to be used as indication rather than an accurate one. |
|
64
|
|
|
* |
|
65
|
|
|
* @return int |
|
66
|
|
|
*/ |
|
67
|
|
|
public function numberChildNodes(): int |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->nb_children; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Increments the number of child nodes by one |
|
74
|
|
|
* |
|
75
|
|
|
*/ |
|
76
|
|
|
public function incrementChildNodes(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->nb_children++; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns the list of place for the lineage |
|
83
|
|
|
* |
|
84
|
|
|
* @return Collection<string, int> |
|
85
|
|
|
*/ |
|
86
|
|
|
public function places(): Collection |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->places; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|