@@ -51,17 +51,20 @@ public function buildAncestorTree(Person $person, int $generations): array
5151 $ family = $ person ->childInFamily ;
5252
5353 if ($ family ) {
54- if ($ family ->husband ) {
54+ $ husband = $ family ->husband ()->first ();
55+ $ wife = $ family ->wife ()->first ();
56+
57+ if ($ husband ) {
5558 $ ancestors ['father ' ] = [
56- 'person ' => $ this ->formatPersonNode ($ family -> husband ),
57- 'ancestors ' => $ this ->buildAncestorTree ($ family -> husband , $ generations - 1 ),
59+ 'person ' => $ this ->formatPersonNode ($ husband ),
60+ 'ancestors ' => $ this ->buildAncestorTree ($ husband , $ generations - 1 ),
5861 ];
5962 }
6063
61- if ($ family -> wife ) {
64+ if ($ wife ) {
6265 $ ancestors ['mother ' ] = [
63- 'person ' => $ this ->formatPersonNode ($ family -> wife ),
64- 'ancestors ' => $ this ->buildAncestorTree ($ family -> wife , $ generations - 1 ),
66+ 'person ' => $ this ->formatPersonNode ($ wife ),
67+ 'ancestors ' => $ this ->buildAncestorTree ($ wife , $ generations - 1 ),
6568 ];
6669 }
6770 }
@@ -93,10 +96,12 @@ public function buildDescendantTree(Person $person, int $generations): array
9396 ];
9497
9598 // Add spouse information
96- if ($ person ->sex === 'M ' && $ family ->wife ) {
97- $ familyNode ['spouse ' ] = $ this ->formatPersonNode ($ family ->wife );
98- } elseif ($ person ->sex === 'F ' && $ family ->husband ) {
99- $ familyNode ['spouse ' ] = $ this ->formatPersonNode ($ family ->husband );
99+ $ wife = $ family ->wife ()->first ();
100+ $ husband = $ family ->husband ()->first ();
101+ if ($ person ->sex === 'M ' && $ wife ) {
102+ $ familyNode ['spouse ' ] = $ this ->formatPersonNode ($ wife );
103+ } elseif ($ person ->sex === 'F ' && $ husband ) {
104+ $ familyNode ['spouse ' ] = $ this ->formatPersonNode ($ husband );
100105 }
101106
102107 // Add children
@@ -145,18 +150,20 @@ protected function buildPedigreeData(Person $person, int $maxGenerations, int $c
145150 $ family = $ person ->childInFamily ;
146151 if ($ family ) {
147152 $ data ['parents ' ] = [];
153+ $ husband = $ family ->husband ()->first ();
154+ $ wife = $ family ->wife ()->first ();
148155
149- if ($ family -> husband ) {
156+ if ($ husband ) {
150157 $ data ['parents ' ]['father ' ] = $ this ->buildPedigreeData (
151- $ family -> husband ,
158+ $ husband ,
152159 $ maxGenerations ,
153160 $ currentGeneration + 1
154161 );
155162 }
156163
157- if ($ family -> wife ) {
164+ if ($ wife ) {
158165 $ data ['parents ' ]['mother ' ] = $ this ->buildPedigreeData (
159- $ family -> wife ,
166+ $ wife ,
160167 $ maxGenerations ,
161168 $ currentGeneration + 1
162169 );
@@ -206,10 +213,12 @@ protected function buildDescendantData(Person $person, int $maxGenerations, int
206213 ];
207214
208215 // Add spouse
209- if ($ person ->sex === 'M ' && $ family ->wife ) {
210- $ familyData ['spouse ' ] = $ this ->formatPersonNode ($ family ->wife );
211- } elseif ($ person ->sex === 'F ' && $ family ->husband ) {
212- $ familyData ['spouse ' ] = $ this ->formatPersonNode ($ family ->husband );
216+ $ wife = $ family ->wife ()->first ();
217+ $ husband = $ family ->husband ()->first ();
218+ if ($ person ->sex === 'M ' && $ wife ) {
219+ $ familyData ['spouse ' ] = $ this ->formatPersonNode ($ wife );
220+ } elseif ($ person ->sex === 'F ' && $ husband ) {
221+ $ familyData ['spouse ' ] = $ this ->formatPersonNode ($ husband );
213222 }
214223
215224 // Add children
@@ -332,14 +341,17 @@ protected function collectAncestors(Person $person, Collection $ancestors, int $
332341
333342 $ family = $ person ->childInFamily ;
334343 if ($ family ) {
335- if ($ family ->husband && !$ ancestors ->contains ('id ' , $ family ->husband ->id )) {
336- $ ancestors ->push ($ family ->husband );
337- $ this ->collectAncestors ($ family ->husband , $ ancestors , $ remainingGenerations - 1 );
344+ $ husband = $ family ->husband ()->first ();
345+ $ wife = $ family ->wife ()->first ();
346+
347+ if ($ husband && !$ ancestors ->contains ('id ' , $ husband ->id )) {
348+ $ ancestors ->push ($ husband );
349+ $ this ->collectAncestors ($ husband , $ ancestors , $ remainingGenerations - 1 );
338350 }
339351
340- if ($ family -> wife && !$ ancestors ->contains ('id ' , $ family -> wife ->id )) {
341- $ ancestors ->push ($ family -> wife );
342- $ this ->collectAncestors ($ family -> wife , $ ancestors , $ remainingGenerations - 1 );
352+ if ($ wife && !$ ancestors ->contains ('id ' , $ wife ->id )) {
353+ $ ancestors ->push ($ wife );
354+ $ this ->collectAncestors ($ wife , $ ancestors , $ remainingGenerations - 1 );
343355 }
344356 }
345357 }
0 commit comments