Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Module/PatronymicLineage/Model/LineageRootNode.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -24,68 +24,68 @@
 block discarded – undo
24 24
 class LineageRootNode extends LineageNode
25 25
 {
26 26
     
27
-    /**
28
-     * @var Collection $places Places for the lineage node
29
-     */
30
-    private $places;
27
+	/**
28
+	 * @var Collection $places Places for the lineage node
29
+	 */
30
+	private $places;
31 31
    
32
-    /**
33
-     * @var int $nb_children Number of node childs
34
-     */
35
-    private $nb_children;
32
+	/**
33
+	 * @var int $nb_children Number of node childs
34
+	 */
35
+	private $nb_children;
36 36
   
37
-    /**
38
-     * Constructor for LineageRootNode
39
-     *
40
-     * @param Individual|null $node_indi
41
-     */
42
-    public function __construct(?Individual $node_indi = null)
43
-    {
44
-        parent::__construct($node_indi, $this);
45
-        $this->places = new Collection();
46
-        $this->nb_children = 0;
47
-    }
37
+	/**
38
+	 * Constructor for LineageRootNode
39
+	 *
40
+	 * @param Individual|null $node_indi
41
+	 */
42
+	public function __construct(?Individual $node_indi = null)
43
+	{
44
+		parent::__construct($node_indi, $this);
45
+		$this->places = new Collection();
46
+		$this->nb_children = 0;
47
+	}
48 48
    
49
-    /**
50
-     * Adds a place to the list of lineage's place
51
-     *
52
-     * @param Place $place
53
-     */
54
-    public function addPlace(Place $place): void
55
-    {
56
-        $place_name = $place->gedcomName();
57
-        if (mb_strlen($place_name) > 0) {
58
-            $this->places->put($place_name, $this->places->get($place_name, 0) + 1);
59
-        }
60
-    }
49
+	/**
50
+	 * Adds a place to the list of lineage's place
51
+	 *
52
+	 * @param Place $place
53
+	 */
54
+	public function addPlace(Place $place): void
55
+	{
56
+		$place_name = $place->gedcomName();
57
+		if (mb_strlen($place_name) > 0) {
58
+			$this->places->put($place_name, $this->places->get($place_name, 0) + 1);
59
+		}
60
+	}
61 61
     
62
-    /**
63
-     * Returns the number of child nodes.
64
-     * This number is more to be used as indication rather than an accurate one.
65
-     *
66
-     * @return int
67
-     */
68
-    public function numberChildNodes(): int
69
-    {
70
-        return $this->nb_children;
71
-    }
62
+	/**
63
+	 * Returns the number of child nodes.
64
+	 * This number is more to be used as indication rather than an accurate one.
65
+	 *
66
+	 * @return int
67
+	 */
68
+	public function numberChildNodes(): int
69
+	{
70
+		return $this->nb_children;
71
+	}
72 72
    
73
-    /**
74
-     * Increments the number of child nodes by one
75
-     *
76
-     */
77
-    public function incrementChildNodes(): void
78
-    {
79
-        $this->nb_children++;
80
-    }
73
+	/**
74
+	 * Increments the number of child nodes by one
75
+	 *
76
+	 */
77
+	public function incrementChildNodes(): void
78
+	{
79
+		$this->nb_children++;
80
+	}
81 81
    
82
-    /**
83
-     * Returns the list of place for the lineage
84
-     *
85
-     * @return Collection
86
-     */
87
-    public function places(): Collection
88
-    {
89
-        return $this->places;
90
-    }
82
+	/**
83
+	 * Returns the list of place for the lineage
84
+	 *
85
+	 * @return Collection
86
+	 */
87
+	public function places(): Collection
88
+	{
89
+		return $this->places;
90
+	}
91 91
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function addFamily(Family $fams): object
69 69
     {
70 70
         if (!$this->linked_fams->has($fams->xref())) {
71
-            $this->linked_fams->put($fams->xref(), (object) [
71
+            $this->linked_fams->put($fams->xref(), (object)[
72 72
                 'family'   =>  $fams,
73 73
                 'children' =>  new Collection()
74 74
             ]);
@@ -135,6 +135,6 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function hasFollowUpSurname(): bool
137 137
     {
138
-        return mb_strlen($this->followUpSurname()) > 0 ;
138
+        return mb_strlen($this->followUpSurname()) > 0;
139 139
     }
140 140
 }
Please login to merge, or discard this patch.
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -25,117 +25,117 @@
 block discarded – undo
25 25
 class LineageNode
26 26
 {
27 27
 
28
-    /**
29
-     * @var Collection $linked_fams Spouse families linked to the node
30
-     */
31
-    private $linked_fams;
32
-
33
-    /**
34
-     * @var ?Individual $node_indi Reference individual for the node
35
-     */
36
-    private $node_indi;
37
-
38
-    /**
39
-     * @var LineageRootNode $root_node Root node of the lineage
40
-     */
41
-    private $root_node;
42
-
43
-    /**
44
-     * @var ?string $alt_surname Linked surname, used to link to another lineage
45
-     */
46
-    private $alt_surname;
47
-
48
-    /**
49
-     * Constructor for Lineage node
50
-     *
51
-     * @param Individual $node_indi Main individual
52
-     * @param LineageRootNode $root_node Node of the lineage root
53
-     * @param null|string $alt_surname Follow-up surname
54
-     */
55
-    public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
56
-    {
57
-        $this->node_indi = $node_indi;
58
-        $this->root_node = $root_node;
59
-        $this->alt_surname = $alt_surname;
60
-        $this->linked_fams = new Collection();
61
-    }
62
-
63
-    /**
64
-     * Add a spouse family to the node
65
-     *
66
-     * @param Family $fams
67
-     * @return stdClass
68
-     */
69
-    public function addFamily(Family $fams): object
70
-    {
71
-        if (!$this->linked_fams->has($fams->xref())) {
72
-            $this->linked_fams->put($fams->xref(), (object) [
73
-                'family'   =>  $fams,
74
-                'children' =>  new Collection()
75
-            ]);
76
-        }
77
-        return $this->linked_fams->get($fams->xref());
78
-    }
79
-
80
-    /**
81
-     * Add a child LineageNode to the node
82
-     *
83
-     * @param Family $fams
84
-     * @param LineageNode $child
85
-     */
86
-    public function addChild(Family $fams, LineageNode $child = null): void
87
-    {
88
-        $this->addFamily($fams)->children->push($child);
89
-        $this->root_node->incrementChildNodes();
90
-    }
91
-
92
-    /**
93
-     * Returns the node individual
94
-     *
95
-     * @return Individual|NULL
96
-     */
97
-    public function individual(): ?Individual
98
-    {
99
-        return $this->node_indi;
100
-    }
101
-
102
-    /**
103
-     * Returns the lineage root node individual
104
-     *
105
-     * @return LineageRootNode
106
-     */
107
-    public function rootNode(): LineageRootNode
108
-    {
109
-        return $this->root_node;
110
-    }
111
-
112
-    /**
113
-     * Returns the spouse families linked to the node
114
-     *
115
-     * @return Collection
116
-     */
117
-    public function families(): Collection
118
-    {
119
-        return $this->linked_fams;
120
-    }
121
-
122
-    /**
123
-     * Returns the follow-up surname
124
-     *
125
-     * @return string
126
-     */
127
-    public function followUpSurname(): string
128
-    {
129
-        return $this->alt_surname ?? '';
130
-    }
131
-
132
-    /**
133
-     * Indicates whether the node has a follow up surname
134
-     *
135
-     * @return boolean
136
-     */
137
-    public function hasFollowUpSurname(): bool
138
-    {
139
-        return mb_strlen($this->followUpSurname()) > 0 ;
140
-    }
28
+	/**
29
+	 * @var Collection $linked_fams Spouse families linked to the node
30
+	 */
31
+	private $linked_fams;
32
+
33
+	/**
34
+	 * @var ?Individual $node_indi Reference individual for the node
35
+	 */
36
+	private $node_indi;
37
+
38
+	/**
39
+	 * @var LineageRootNode $root_node Root node of the lineage
40
+	 */
41
+	private $root_node;
42
+
43
+	/**
44
+	 * @var ?string $alt_surname Linked surname, used to link to another lineage
45
+	 */
46
+	private $alt_surname;
47
+
48
+	/**
49
+	 * Constructor for Lineage node
50
+	 *
51
+	 * @param Individual $node_indi Main individual
52
+	 * @param LineageRootNode $root_node Node of the lineage root
53
+	 * @param null|string $alt_surname Follow-up surname
54
+	 */
55
+	public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
56
+	{
57
+		$this->node_indi = $node_indi;
58
+		$this->root_node = $root_node;
59
+		$this->alt_surname = $alt_surname;
60
+		$this->linked_fams = new Collection();
61
+	}
62
+
63
+	/**
64
+	 * Add a spouse family to the node
65
+	 *
66
+	 * @param Family $fams
67
+	 * @return stdClass
68
+	 */
69
+	public function addFamily(Family $fams): object
70
+	{
71
+		if (!$this->linked_fams->has($fams->xref())) {
72
+			$this->linked_fams->put($fams->xref(), (object) [
73
+				'family'   =>  $fams,
74
+				'children' =>  new Collection()
75
+			]);
76
+		}
77
+		return $this->linked_fams->get($fams->xref());
78
+	}
79
+
80
+	/**
81
+	 * Add a child LineageNode to the node
82
+	 *
83
+	 * @param Family $fams
84
+	 * @param LineageNode $child
85
+	 */
86
+	public function addChild(Family $fams, LineageNode $child = null): void
87
+	{
88
+		$this->addFamily($fams)->children->push($child);
89
+		$this->root_node->incrementChildNodes();
90
+	}
91
+
92
+	/**
93
+	 * Returns the node individual
94
+	 *
95
+	 * @return Individual|NULL
96
+	 */
97
+	public function individual(): ?Individual
98
+	{
99
+		return $this->node_indi;
100
+	}
101
+
102
+	/**
103
+	 * Returns the lineage root node individual
104
+	 *
105
+	 * @return LineageRootNode
106
+	 */
107
+	public function rootNode(): LineageRootNode
108
+	{
109
+		return $this->root_node;
110
+	}
111
+
112
+	/**
113
+	 * Returns the spouse families linked to the node
114
+	 *
115
+	 * @return Collection
116
+	 */
117
+	public function families(): Collection
118
+	{
119
+		return $this->linked_fams;
120
+	}
121
+
122
+	/**
123
+	 * Returns the follow-up surname
124
+	 *
125
+	 * @return string
126
+	 */
127
+	public function followUpSurname(): string
128
+	{
129
+		return $this->alt_surname ?? '';
130
+	}
131
+
132
+	/**
133
+	 * Indicates whether the node has a follow up surname
134
+	 *
135
+	 * @return boolean
136
+	 */
137
+	public function hasFollowUpSurname(): bool
138
+	{
139
+		return mb_strlen($this->followUpSurname()) > 0 ;
140
+	}
141 141
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
             }
108 108
         }
109 109
       
110
-        return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) {
110
+        return $root_lineages->sort(function(LineageRootNode $a, LineageRootNode $b) {
111 111
 
112 112
             if ($a->numberChildNodes() == $b->numberChildNodes()) {
113 113
                 return 0;
Please login to merge, or discard this patch.
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -29,221 +29,221 @@
 block discarded – undo
29 29
 class LineageBuilder
30 30
 {
31 31
 
32
-    /**
33
-     * @var string $surname Reference surname
34
-     */
35
-    private $surname;
36
-
37
-    /**
38
-     * @var Tree $tree Reference tree
39
-     */
40
-    private $tree;
41
-
42
-    /**
43
-     * @var IndividualListModule|null $indilist_module
44
-     */
45
-    private $indilist_module;
46
-
47
-    /**
48
-     * @var Collection $used_indis Individuals already processed
49
-     */
50
-    private $used_indis;
51
-
52
-    /**
53
-     * Constructor for Lineage Builder
54
-     *
55
-     * @param string $surname Reference surname
56
-     * @param Tree $tree Gedcom tree
57
-     */
58
-    public function __construct($surname, Tree $tree, IndividualListModule $indilist_module)
59
-    {
60
-        $this->surname = $surname;
61
-        $this->tree = $tree;
62
-        $this->indilist_module = $indilist_module;
63
-        $this->used_indis = new Collection();
64
-    }
65
-
66
-    /**
67
-     * Build all patronymic lineages for the reference surname.
68
-     *
69
-     * @return Collection|NULL List of root patronymic lineages
70
-     */
71
-    public function buildLineages(): ?Collection
72
-    {
73
-        if ($this->indilist_module === null) {
74
-            return null;
75
-        }
76
-
77
-        $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale());
78
-        //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality
79
-        if (count($indis) == 0) {
80
-            return null;
81
-        }
82
-
83
-        $root_lineages = new Collection();
84
-
85
-        foreach ($indis as $indi) {
86
-            /** @var Individual $indi */
87
-            if ($this->used_indis->get($indi->xref(), false) === false) {
88
-                $indi_first = $this->getLineageRootIndividual($indi);
89
-                if ($indi_first !== null) {
90
-                    // The root lineage needs to be recreated from the Factory, to retrieve the proper object
91
-                    $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree);
92
-                }
93
-                if ($indi_first === null) {
94
-                    continue;
95
-                }
96
-                $this->used_indis->put($indi_first->xref(), true);
97
-                if ($indi_first->canShow()) {
98
-                    //Check if the root individual has brothers and sisters, without parents
99
-                    $indi_first_child_family = $indi_first->childFamilies()->first();
100
-                    if ($indi_first_child_family !== null) {
101
-                        $root_node = new LineageRootNode(null);
102
-                        $root_node->addFamily($indi_first_child_family);
103
-                    } else {
104
-                        $root_node = new LineageRootNode($indi_first);
105
-                    }
106
-                    $root_node = $this->buildLineage($root_node);
107
-                    $root_lineages->add($root_node);
108
-                }
109
-            }
110
-        }
111
-
112
-        return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) {
113
-
114
-            if ($a->numberChildNodes() == $b->numberChildNodes()) {
115
-                return 0;
116
-            }
117
-            return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1;
118
-        });
119
-    }
120
-
121
-    /**
122
-     * Retrieve the root individual, from any individual, by recursion.
123
-     * The Root individual is the individual without a father, or without a mother holding the same name.
124
-     *
125
-     * @param Individual $indi
126
-     * @return Individual|NULL Root individual
127
-     */
128
-    private function getLineageRootIndividual(Individual $indi): ?Individual
129
-    {
130
-        $child_families = $indi->childFamilies();
131
-        if ($this->used_indis->get($indi->xref(), false) !== false) {
132
-            return null;
133
-        }
134
-
135
-        foreach ($child_families as $child_family) {
136
-            /** @var Family $child_family */
137
-            $child_family->husband();
138
-            if (($husb = $child_family->husband()) !== null) {
139
-                if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') {
140
-                    return $indi;
141
-                }
142
-                return $this->getLineageRootIndividual($husb);
143
-            } elseif (($wife = $child_family->wife()) !== null) {
144
-                if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
145
-                    $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname'];
146
-                    $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname'];
147
-                    if (
148
-                        $indi->canShowName()
149
-                        && $wife->canShowName()
150
-                        && I18N::comparator()($indi_surname, $wife_surname) == 0
151
-                    ) {
152
-                            return $this->getLineageRootIndividual($wife);
153
-                    }
154
-                }
155
-                return $indi;
156
-            }
157
-        }
158
-        return $indi;
159
-    }
160
-
161
-    /**
162
-     * Computes descendent Lineage from a node.
163
-     * Uses recursion to build the lineage tree
164
-     *
165
-     * @param LineageNode $node
166
-     * @return LineageNode Computed lineage
167
-     */
168
-    private function buildLineage(LineageNode $node): LineageNode
169
-    {
170
-        $indi_surname = '';
171
-
172
-        $indi_node = $node->individual();
173
-        if ($indi_node !== null) {
174
-            if ($node->families()->count() == 0) {
175
-                foreach ($indi_node->spouseFamilies() as $spouse_family) {
176
-                    $node->addFamily($spouse_family);
177
-                }
178
-            }
179
-
180
-            $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? '';
181
-            $node->rootNode()->addPlace($indi_node->getBirthPlace());
182
-
183
-            //Tag the individual as used
184
-            $this->used_indis->put($indi_node->xref(), true);
185
-        }
186
-
187
-        foreach ($node->families() as $family_node) {
188
-            /** @var Family $spouse_family */
189
-            $spouse_family = $family_node->family;
190
-            $spouse_surname = '';
191
-            $spouse = null;
192
-            if (
193
-                $indi_node !== null &&
194
-                ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName()
195
-            ) {
196
-                $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? '';
197
-            }
198
-
199
-            $nb_children = $nb_natural = 0;
200
-
201
-            foreach ($spouse_family->children() as $child) {
202
-                if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
203
-                    $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? '';
204
-
205
-                    $nb_children++;
206
-                    if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother
207
-                        //Print only lineages of children with the same surname as their mother
208
-                        //(supposing they are natural children)
209
-                        /** @psalm-suppress RedundantCondition */
210
-                        if (
211
-                            $spouse === null ||
212
-                            ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0)
213
-                        ) {
214
-                            if (I18N::comparator()($child_surname, $indi_surname) == 0) {
215
-                                $nb_natural++;
216
-                                $node_child = new LineageNode($child, $node->rootNode());
217
-                                $node_child = $this->buildLineage($node_child);
218
-                                $node->addChild($spouse_family, $node_child);
219
-                            }
220
-                        }
221
-                    } else { //If the root individual is the father
222
-                        $nb_natural++;
223
-                        //Print if the children does not bear the same name as his mother
224
-                        //(and different from his father)
225
-                        if (
226
-                            mb_strlen($child_surname) == 0 ||
227
-                            mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
228
-                            I18N::comparator()($child_surname, $indi_surname) == 0 ||
229
-                            I18N::comparator()($child_surname, $spouse_surname) != 0
230
-                        ) {
231
-                            $node_child = new LineageNode($child, $node->rootNode());
232
-                            $node_child = $this->buildLineage($node_child);
233
-                        } else {
234
-                            $node_child = new LineageNode($child, $node->rootNode(), $child_surname);
235
-                        }
236
-                        $node->addChild($spouse_family, $node_child);
237
-                    }
238
-                }
239
-            }
240
-
241
-            //Do not print other children
242
-            if (($nb_children - $nb_natural) > 0) {
243
-                $node->addChild($spouse_family, null);
244
-            }
245
-        }
246
-
247
-        return $node;
248
-    }
32
+	/**
33
+	 * @var string $surname Reference surname
34
+	 */
35
+	private $surname;
36
+
37
+	/**
38
+	 * @var Tree $tree Reference tree
39
+	 */
40
+	private $tree;
41
+
42
+	/**
43
+	 * @var IndividualListModule|null $indilist_module
44
+	 */
45
+	private $indilist_module;
46
+
47
+	/**
48
+	 * @var Collection $used_indis Individuals already processed
49
+	 */
50
+	private $used_indis;
51
+
52
+	/**
53
+	 * Constructor for Lineage Builder
54
+	 *
55
+	 * @param string $surname Reference surname
56
+	 * @param Tree $tree Gedcom tree
57
+	 */
58
+	public function __construct($surname, Tree $tree, IndividualListModule $indilist_module)
59
+	{
60
+		$this->surname = $surname;
61
+		$this->tree = $tree;
62
+		$this->indilist_module = $indilist_module;
63
+		$this->used_indis = new Collection();
64
+	}
65
+
66
+	/**
67
+	 * Build all patronymic lineages for the reference surname.
68
+	 *
69
+	 * @return Collection|NULL List of root patronymic lineages
70
+	 */
71
+	public function buildLineages(): ?Collection
72
+	{
73
+		if ($this->indilist_module === null) {
74
+			return null;
75
+		}
76
+
77
+		$indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale());
78
+		//Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality
79
+		if (count($indis) == 0) {
80
+			return null;
81
+		}
82
+
83
+		$root_lineages = new Collection();
84
+
85
+		foreach ($indis as $indi) {
86
+			/** @var Individual $indi */
87
+			if ($this->used_indis->get($indi->xref(), false) === false) {
88
+				$indi_first = $this->getLineageRootIndividual($indi);
89
+				if ($indi_first !== null) {
90
+					// The root lineage needs to be recreated from the Factory, to retrieve the proper object
91
+					$indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree);
92
+				}
93
+				if ($indi_first === null) {
94
+					continue;
95
+				}
96
+				$this->used_indis->put($indi_first->xref(), true);
97
+				if ($indi_first->canShow()) {
98
+					//Check if the root individual has brothers and sisters, without parents
99
+					$indi_first_child_family = $indi_first->childFamilies()->first();
100
+					if ($indi_first_child_family !== null) {
101
+						$root_node = new LineageRootNode(null);
102
+						$root_node->addFamily($indi_first_child_family);
103
+					} else {
104
+						$root_node = new LineageRootNode($indi_first);
105
+					}
106
+					$root_node = $this->buildLineage($root_node);
107
+					$root_lineages->add($root_node);
108
+				}
109
+			}
110
+		}
111
+
112
+		return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) {
113
+
114
+			if ($a->numberChildNodes() == $b->numberChildNodes()) {
115
+				return 0;
116
+			}
117
+			return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1;
118
+		});
119
+	}
120
+
121
+	/**
122
+	 * Retrieve the root individual, from any individual, by recursion.
123
+	 * The Root individual is the individual without a father, or without a mother holding the same name.
124
+	 *
125
+	 * @param Individual $indi
126
+	 * @return Individual|NULL Root individual
127
+	 */
128
+	private function getLineageRootIndividual(Individual $indi): ?Individual
129
+	{
130
+		$child_families = $indi->childFamilies();
131
+		if ($this->used_indis->get($indi->xref(), false) !== false) {
132
+			return null;
133
+		}
134
+
135
+		foreach ($child_families as $child_family) {
136
+			/** @var Family $child_family */
137
+			$child_family->husband();
138
+			if (($husb = $child_family->husband()) !== null) {
139
+				if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') {
140
+					return $indi;
141
+				}
142
+				return $this->getLineageRootIndividual($husb);
143
+			} elseif (($wife = $child_family->wife()) !== null) {
144
+				if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
145
+					$indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname'];
146
+					$wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname'];
147
+					if (
148
+						$indi->canShowName()
149
+						&& $wife->canShowName()
150
+						&& I18N::comparator()($indi_surname, $wife_surname) == 0
151
+					) {
152
+							return $this->getLineageRootIndividual($wife);
153
+					}
154
+				}
155
+				return $indi;
156
+			}
157
+		}
158
+		return $indi;
159
+	}
160
+
161
+	/**
162
+	 * Computes descendent Lineage from a node.
163
+	 * Uses recursion to build the lineage tree
164
+	 *
165
+	 * @param LineageNode $node
166
+	 * @return LineageNode Computed lineage
167
+	 */
168
+	private function buildLineage(LineageNode $node): LineageNode
169
+	{
170
+		$indi_surname = '';
171
+
172
+		$indi_node = $node->individual();
173
+		if ($indi_node !== null) {
174
+			if ($node->families()->count() == 0) {
175
+				foreach ($indi_node->spouseFamilies() as $spouse_family) {
176
+					$node->addFamily($spouse_family);
177
+				}
178
+			}
179
+
180
+			$indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? '';
181
+			$node->rootNode()->addPlace($indi_node->getBirthPlace());
182
+
183
+			//Tag the individual as used
184
+			$this->used_indis->put($indi_node->xref(), true);
185
+		}
186
+
187
+		foreach ($node->families() as $family_node) {
188
+			/** @var Family $spouse_family */
189
+			$spouse_family = $family_node->family;
190
+			$spouse_surname = '';
191
+			$spouse = null;
192
+			if (
193
+				$indi_node !== null &&
194
+				($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName()
195
+			) {
196
+				$spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? '';
197
+			}
198
+
199
+			$nb_children = $nb_natural = 0;
200
+
201
+			foreach ($spouse_family->children() as $child) {
202
+				if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
203
+					$child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? '';
204
+
205
+					$nb_children++;
206
+					if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother
207
+						//Print only lineages of children with the same surname as their mother
208
+						//(supposing they are natural children)
209
+						/** @psalm-suppress RedundantCondition */
210
+						if (
211
+							$spouse === null ||
212
+							($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0)
213
+						) {
214
+							if (I18N::comparator()($child_surname, $indi_surname) == 0) {
215
+								$nb_natural++;
216
+								$node_child = new LineageNode($child, $node->rootNode());
217
+								$node_child = $this->buildLineage($node_child);
218
+								$node->addChild($spouse_family, $node_child);
219
+							}
220
+						}
221
+					} else { //If the root individual is the father
222
+						$nb_natural++;
223
+						//Print if the children does not bear the same name as his mother
224
+						//(and different from his father)
225
+						if (
226
+							mb_strlen($child_surname) == 0 ||
227
+							mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
228
+							I18N::comparator()($child_surname, $indi_surname) == 0 ||
229
+							I18N::comparator()($child_surname, $spouse_surname) != 0
230
+						) {
231
+							$node_child = new LineageNode($child, $node->rootNode());
232
+							$node_child = $this->buildLineage($node_child);
233
+						} else {
234
+							$node_child = new LineageNode($child, $node->rootNode(), $child_surname);
235
+						}
236
+						$node->addChild($spouse_family, $node_child);
237
+					}
238
+				}
239
+			}
240
+
241
+			//Do not print other children
242
+			if (($nb_children - $nb_natural) > 0) {
243
+				$node->addChild($spouse_family, null);
244
+			}
245
+		}
246
+
247
+		return $node;
248
+	}
249 249
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Http/RequestHandlers/TokenGenerate.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
         
57 57
         $token = Functions::generateRandomToken();
58 58
         $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token);
59
-        Log::addConfigurationLog($this->module->title() . ' : New token generated.');
59
+        Log::addConfigurationLog($this->module->title().' : New token generated.');
60 60
         
61 61
         return response(['token' => $token]);
62 62
     }
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -29,35 +29,35 @@
 block discarded – undo
29 29
  */
30 30
 class TokenGenerate implements RequestHandlerInterface
31 31
 {
32
-    /**
33
-     * @var AdminTasksModule|null $module
34
-     */
35
-    private $module;
36
-
37
-    /**
38
-     * Constructor for TokenGenerate request handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
-    }
46
-
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        if ($this->module === null) {
54
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
-        }
56
-
57
-        $token = Functions::generateRandomToken();
58
-        $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token);
59
-        Log::addConfigurationLog($this->module->title() . ' : New token generated.');
60
-
61
-        return response(['token' => $token]);
62
-    }
32
+	/**
33
+	 * @var AdminTasksModule|null $module
34
+	 */
35
+	private $module;
36
+
37
+	/**
38
+	 * Constructor for TokenGenerate request handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
+	}
46
+
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		if ($this->module === null) {
54
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
+		}
56
+
57
+		$token = Functions::generateRandomToken();
58
+		$this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token);
59
+		Log::addConfigurationLog($this->module->title() . ' : New token generated.');
60
+
61
+		return response(['token' => $token]);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Http/RequestHandlers/AdminConfigPage.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
             $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
74 74
         }
75 75
         
76
-        return $this->viewResponse($this->module->name() . '::admin/config', [
76
+        return $this->viewResponse($this->module->name().'::admin/config', [
77 77
             'title'             =>  $this->module->title(),
78 78
             'trigger_token'     =>  $token,
79 79
             'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -30,48 +30,48 @@
 block discarded – undo
30 30
  */
31 31
 class AdminConfigPage implements RequestHandlerInterface
32 32
 {
33
-    use ViewResponseTrait;
33
+	use ViewResponseTrait;
34 34
 
35
-    /**
36
-     * @var AdminTasksModule|null $module
37
-     */
38
-    private $module;
35
+	/**
36
+	 * @var AdminTasksModule|null $module
37
+	 */
38
+	private $module;
39 39
 
40
-    /**
41
-     * Constructor for Admin Config request handler
42
-     *
43
-     * @param ModuleService $module_service
44
-     */
45
-    public function __construct(ModuleService $module_service)
46
-    {
47
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
-    }
40
+	/**
41
+	 * Constructor for Admin Config request handler
42
+	 *
43
+	 * @param ModuleService $module_service
44
+	 */
45
+	public function __construct(ModuleService $module_service)
46
+	{
47
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
-     */
54
-    public function handle(ServerRequestInterface $request): ResponseInterface
55
-    {
56
-        $this->layout = 'layouts/administration';
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
+	 */
54
+	public function handle(ServerRequestInterface $request): ResponseInterface
55
+	{
56
+		$this->layout = 'layouts/administration';
57 57
 
58
-        if ($this->module === null) {
59
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
-        }
58
+		if ($this->module === null) {
59
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
+		}
61 61
 
62
-        $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
63
-        if ($token === '') {
64
-            $token = Functions::generateRandomToken();
65
-            $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
66
-        }
62
+		$token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
63
+		if ($token === '') {
64
+			$token = Functions::generateRandomToken();
65
+			$this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
66
+		}
67 67
 
68
-        return $this->viewResponse($this->module->name() . '::admin/config', [
69
-            'title'             =>  $this->module->title(),
70
-            'trigger_token'     =>  $token,
71
-            'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
72
-            'new_token_route'   =>  route(TokenGenerate::class),
73
-            'tasks_data_route'  =>  route(TasksList::class),
74
-            'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
75
-        ]);
76
-    }
68
+		return $this->viewResponse($this->module->name() . '::admin/config', [
69
+			'title'             =>  $this->module->title(),
70
+			'trigger_token'     =>  $token,
71
+			'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
72
+			'new_token_route'   =>  route(TokenGenerate::class),
73
+			'tasks_data_route'  =>  route(TasksList::class),
74
+			'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
75
+		]);
76
+	}
77 77
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Schema/Migration0.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@
 block discarded – undo
22 22
 class Migration0 implements MigrationInterface
23 23
 {
24 24
     
25
-    /**
26
-     * {@inheritDoc}
27
-     * @see MigrationInterface::upgrade()
28
-     */
29
-    public function upgrade(): void
30
-    {
31
-        // These migrations have been merged into migration 1.
32
-    }
25
+	/**
26
+	 * {@inheritDoc}
27
+	 * @see MigrationInterface::upgrade()
28
+	 */
29
+	public function upgrade(): void
30
+	{
31
+		// These migrations have been merged into migration 1.
32
+	}
33 33
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Contracts/ConfigurableTaskInterface.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,20 +22,20 @@
 block discarded – undo
22 22
 interface ConfigurableTaskInterface
23 23
 {
24 24
     
25
-    /**
26
-     * Returns the HTML code to display the specific task configuration.
27
-     *
28
-     * @param ServerRequestInterface $request
29
-     * @return string HTML code
30
-     */
31
-    public function configView(ServerRequestInterface $request): string;
25
+	/**
26
+	 * Returns the HTML code to display the specific task configuration.
27
+	 *
28
+	 * @param ServerRequestInterface $request
29
+	 * @return string HTML code
30
+	 */
31
+	public function configView(ServerRequestInterface $request): string;
32 32
  
33
-    /**
34
-     * Update the specific configuration of the task.
35
-     *
36
-     * @param ServerRequestInterface $request
37
-     * @param TaskSchedule $task_schedule
38
-     * @return bool Result of the update
39
-     */
40
-    public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool;
33
+	/**
34
+	 * Update the specific configuration of the task.
35
+	 *
36
+	 * @param ServerRequestInterface $request
37
+	 * @param TaskSchedule $task_schedule
38
+	 * @return bool Result of the update
39
+	 */
40
+	public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool;
41 41
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Contracts/TaskInterface.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,25 +19,25 @@
 block discarded – undo
19 19
  */
20 20
 interface TaskInterface
21 21
 {
22
-    /**
23
-     * Display name of the task
24
-     *
25
-     * @return string
26
-     */
27
-    public function name(): string;
22
+	/**
23
+	 * Display name of the task
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public function name(): string;
28 28
     
29
-    /**
30
-     * Return the default frequency for the execution of the task, in minutes.
31
-     *
32
-     * @return int Frequency for the execution of the task
33
-     */
34
-    public function defaultFrequency(): int;
29
+	/**
30
+	 * Return the default frequency for the execution of the task, in minutes.
31
+	 *
32
+	 * @return int Frequency for the execution of the task
33
+	 */
34
+	public function defaultFrequency(): int;
35 35
     
36
-    /**
37
-     * Run the task's actions, and return whether the execution has been successful.
38
-     *
39
-     * @param TaskSchedule $task_schedule
40
-     * @return bool Has the execution been a success
41
-     */
42
-    public function run(TaskSchedule $task_schedule): bool;
36
+	/**
37
+	 * Run the task's actions, and return whether the execution has been successful.
38
+	 *
39
+	 * @param TaskSchedule $task_schedule
40
+	 * @return bool Has the execution been a success
41
+	 */
42
+	public function run(TaskSchedule $task_schedule): bool;
43 43
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Contracts/ModuleTasksProviderInterface.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
 interface ModuleTasksProviderInterface
21 21
 {
22 22
     
23
-    /**
24
-     * List tasks provided by the module as an associative array.
25
-     * They keys are used as task IDs for storage and reference.
26
-     *
27
-     * @return array<string, string> List of tasks
28
-     */
29
-    public function listTasks(): array;
23
+	/**
24
+	 * List tasks provided by the module as an associative array.
25
+	 * They keys are used as task IDs for storage and reference.
26
+	 *
27
+	 * @return array<string, string> List of tasks
28
+	 */
29
+	public function listTasks(): array;
30 30
 }
Please login to merge, or discard this patch.