Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Contracts/GeoDispersion/MapViewConfigInterface.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,17 +18,17 @@
 block discarded – undo
18 18
  */
19 19
 interface MapViewConfigInterface
20 20
 {
21
-    /**
22
-     * Get the feature property to be used for mapping the map feature with the analysis results
23
-     * 
24
-     * @return string
25
-     */
26
-    function mapMappingProperty(): string;
21
+	/**
22
+	 * Get the feature property to be used for mapping the map feature with the analysis results
23
+	 * 
24
+	 * @return string
25
+	 */
26
+	function mapMappingProperty(): string;
27 27
 
28
-    /**
29
-     * Get the config of the mapper associated with the map view
30
-     * 
31
-     * @return PlaceMapperConfigInterface
32
-     */
33
-    function mapperConfig(): PlaceMapperConfigInterface;
28
+	/**
29
+	 * Get the config of the mapper associated with the map view
30
+	 * 
31
+	 * @return PlaceMapperConfigInterface
32
+	 */
33
+	function mapperConfig(): PlaceMapperConfigInterface;
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
src/Webtrees/Http/Middleware/AuthTreePreference.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@
 block discarded – undo
30 30
  */
31 31
 class AuthTreePreference implements MiddlewareInterface
32 32
 {
33
-    /**
34
-     * {@inheritDoc}
35
-     * @see \Psr\Http\Server\MiddlewareInterface::process()
36
-     */
37
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
38
-    {
39
-        $tree = $request->getAttribute('tree');
40
-        assert($tree instanceof Tree);
41
-        /** @var Tree $tree */
33
+	/**
34
+	 * {@inheritDoc}
35
+	 * @see \Psr\Http\Server\MiddlewareInterface::process()
36
+	 */
37
+	public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
38
+	{
39
+		$tree = $request->getAttribute('tree');
40
+		assert($tree instanceof Tree);
41
+		/** @var Tree $tree */
42 42
 
43
-        $route = $request->getAttribute('route');
44
-        assert($route instanceof \Aura\Router\Route);
45
-        /** @var \Aura\Router\Route $route */
43
+		$route = $request->getAttribute('route');
44
+		assert($route instanceof \Aura\Router\Route);
45
+		/** @var \Aura\Router\Route $route */
46 46
 
47
-        $user = $request->getAttribute('user');
47
+		$user = $request->getAttribute('user');
48 48
 
49
-        $permission_preference = $route->extras['permission_preference'] ?? '';
50
-        $permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference);
49
+		$permission_preference = $route->extras['permission_preference'] ?? '';
50
+		$permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference);
51 51
 
52
-        // Permissions are configured
53
-        if (is_numeric($permission_level)) {
54
-            // Logged in with the correct role?
55
-            if (Auth::accessLevel($tree, $user) <= (int) $permission_level) {
56
-                    return $handler->handle($request);
57
-            }
52
+		// Permissions are configured
53
+		if (is_numeric($permission_level)) {
54
+			// Logged in with the correct role?
55
+			if (Auth::accessLevel($tree, $user) <= (int) $permission_level) {
56
+					return $handler->handle($request);
57
+			}
58 58
 
59
-            // Logged in, but without the correct role?
60
-            if ($user instanceof User) {
61
-                throw new HttpAccessDeniedException();
62
-            }
63
-        }
59
+			// Logged in, but without the correct role?
60
+			if ($user instanceof User) {
61
+				throw new HttpAccessDeniedException();
62
+			}
63
+		}
64 64
 
65
-        // Permissions no configured, or not logged in
66
-        if ($request->getMethod() === RequestMethodInterface::METHOD_POST) {
67
-            throw new HttpAccessDeniedException();
68
-        }
65
+		// Permissions no configured, or not logged in
66
+		if ($request->getMethod() === RequestMethodInterface::METHOD_POST) {
67
+			throw new HttpAccessDeniedException();
68
+		}
69 69
 
70
-        return redirect(route(LoginPage::class, ['tree' => $tree->name(), 'url' => $request->getUri()]));
71
-    }
70
+		return redirect(route(LoginPage::class, ['tree' => $tree->name(), 'url' => $request->getUri()]));
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
         // Permissions are configured
53 53
         if (is_numeric($permission_level)) {
54 54
             // Logged in with the correct role?
55
-            if (Auth::accessLevel($tree, $user) <= (int) $permission_level) {
55
+            if (Auth::accessLevel($tree, $user) <= (int)$permission_level) {
56 56
                     return $handler->handle($request);
57 57
             }
58 58
 
Please login to merge, or discard this patch.
src/Webtrees/Individual.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -105,29 +105,29 @@
 block discarded – undo
105 105
 	 * @return string|array Estimated birth place if found, null otherwise
106 106
 	 */
107 107
 	public function getSignificantPlace(){
108
-	    if($bplace = $this->gedcomrecord->getBirthPlace()){
109
-	        return $bplace;
110
-	    }
108
+		if($bplace = $this->gedcomrecord->getBirthPlace()){
109
+			return $bplace;
110
+		}
111 111
 	
112
-	    foreach ($this->gedcomrecord->getAllEventPlaces('RESI') as $rplace) {
113
-	        if ($rplace) {
114
-	            return $rplace;
115
-	        }
116
-	    }
112
+		foreach ($this->gedcomrecord->getAllEventPlaces('RESI') as $rplace) {
113
+			if ($rplace) {
114
+				return $rplace;
115
+			}
116
+		}
117 117
 	
118
-	    if($dplace = $this->gedcomrecord->getDeathPlace()){
119
-	        return $dplace;
120
-	    }
118
+		if($dplace = $this->gedcomrecord->getDeathPlace()){
119
+			return $dplace;
120
+		}
121 121
 	
122
-	    foreach($this->gedcomrecord->getSpouseFamilies() as $fams) {
123
-	        foreach ($fams->getAllEventPlaces('RESI') as $rplace) {
124
-	            if ($rplace) {
125
-	                return $rplace;
126
-	            }
127
-	        }
128
-	    }
122
+		foreach($this->gedcomrecord->getSpouseFamilies() as $fams) {
123
+			foreach ($fams->getAllEventPlaces('RESI') as $rplace) {
124
+				if ($rplace) {
125
+					return $rplace;
126
+				}
127
+			}
128
+		}
129 129
 	
130
-	    return null;
130
+		return null;
131 131
 	}
132 132
 }
133 133
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 class Individual extends GedcomRecord {
22 22
 
23 23
 	/** @var array|null List of titles the individal holds */	
24
-	protected $titles=null;
24
+	protected $titles = null;
25 25
 	
26 26
 	/** @var string|null Individual's primary surname, without any privacy applied to it */
27 27
 	protected $unprotected_prim_surname = null;
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param null|string $gedcom
36 36
 	 * @return null|Individual
37 37
 	 */
38
-	public static function getIntance($xref, Tree $tree, $gedcom = null){
38
+	public static function getIntance($xref, Tree $tree, $gedcom = null) {
39 39
 		$indi = \Fisharebest\Webtrees\Individual::getInstance($xref, $tree, $gedcom);
40
-		if($indi){
40
+		if ($indi) {
41 41
 			return new Individual($indi);
42 42
 		}
43 43
 		return null;
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
 	 * 
49 49
 	 * @return array Array of titles
50 50
 	 */
51
-	public function getTitles(){
52
-		if(is_null($this->titles) && $module = Module::getModuleByName(Constants::MODULE_MAJ_MISC_NAME)){
51
+	public function getTitles() {
52
+		if (is_null($this->titles) && $module = Module::getModuleByName(Constants::MODULE_MAJ_MISC_NAME)) {
53 53
 			$pattern = '/(.*) (('.$module->getSetting('MAJ_TITLE_PREFIX', '').')(.*))/';
54
-			$this->titles=array();
54
+			$this->titles = array();
55 55
 			$titlefacts = $this->gedcomrecord->getFacts('TITL');
56
-			foreach($titlefacts as $titlefact){
56
+			foreach ($titlefacts as $titlefact) {
57 57
 				$ct2 = preg_match_all($pattern, $titlefact->getValue(), $match2);
58
-				if($ct2>0){
59
-					$this->titles[$match2[1][0]][]= trim($match2[2][0]);
58
+				if ($ct2 > 0) {
59
+					$this->titles[$match2[1][0]][] = trim($match2[2][0]);
60 60
 				}
61
-				else{
62
-					$this->titles[$titlefact->getValue()][]='';
61
+				else {
62
+					$this->titles[$titlefact->getValue()][] = '';
63 63
 				}
64 64
 			}
65 65
 		}
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @return string Primary surname
74 74
 	 */
75 75
 	public function getUnprotectedPrimarySurname() {
76
-		if(!$this->unprotected_prim_surname){
77
-			$tmp=$this->gedcomrecord->getAllNames();
76
+		if (!$this->unprotected_prim_surname) {
77
+			$tmp = $this->gedcomrecord->getAllNames();
78 78
 			$this->unprotected_prim_surname = $tmp[$this->gedcomrecord->getPrimaryName()]['surname'];
79 79
 		}
80 80
 		return $this->unprotected_prim_surname;
@@ -86,12 +86,12 @@  discard block
 block discarded – undo
86 86
 	 * @param boolean $perc Should the coefficient of reliability be returned
87 87
 	 * @return string|array Estimated birth place if found, null otherwise
88 88
 	 */
89
-	public function getEstimatedBirthPlace($perc=false){
90
-		if($bplace = $this->gedcomrecord->getBirthPlace()){
91
-			if($perc){
92
-				return array ($bplace, 1);
89
+	public function getEstimatedBirthPlace($perc = false) {
90
+		if ($bplace = $this->gedcomrecord->getBirthPlace()) {
91
+			if ($perc) {
92
+				return array($bplace, 1);
93 93
 			}
94
-			else{
94
+			else {
95 95
 				return $bplace;
96 96
 			}
97 97
 		}
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * @param boolean $perc Should the coefficient of reliability be returned
105 105
 	 * @return string|array Estimated birth place if found, null otherwise
106 106
 	 */
107
-	public function getSignificantPlace(){
108
-	    if($bplace = $this->gedcomrecord->getBirthPlace()){
107
+	public function getSignificantPlace() {
108
+	    if ($bplace = $this->gedcomrecord->getBirthPlace()) {
109 109
 	        return $bplace;
110 110
 	    }
111 111
 	
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 	        }
116 116
 	    }
117 117
 	
118
-	    if($dplace = $this->gedcomrecord->getDeathPlace()){
118
+	    if ($dplace = $this->gedcomrecord->getDeathPlace()) {
119 119
 	        return $dplace;
120 120
 	    }
121 121
 	
122
-	    foreach($this->gedcomrecord->getSpouseFamilies() as $fams) {
122
+	    foreach ($this->gedcomrecord->getSpouseFamilies() as $fams) {
123 123
 	        foreach ($fams->getAllEventPlaces('RESI') as $rplace) {
124 124
 	            if ($rplace) {
125 125
 	                return $rplace;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,8 +57,7 @@  discard block
 block discarded – undo
57 57
 				$ct2 = preg_match_all($pattern, $titlefact->getValue(), $match2);
58 58
 				if($ct2>0){
59 59
 					$this->titles[$match2[1][0]][]= trim($match2[2][0]);
60
-				}
61
-				else{
60
+				} else{
62 61
 					$this->titles[$titlefact->getValue()][]='';
63 62
 				}
64 63
 			}
@@ -90,8 +89,7 @@  discard block
 block discarded – undo
90 89
 		if($bplace = $this->gedcomrecord->getBirthPlace()){
91 90
 			if($perc){
92 91
 				return array ($bplace, 1);
93
-			}
94
-			else{
92
+			} else{
95 93
 				return $bplace;
96 94
 			}
97 95
 		}
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php 1 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/PatronymicLineage/Http/RequestHandlers/LineagesPage.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -31,69 +31,69 @@
 block discarded – undo
31 31
  */
32 32
 class LineagesPage implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
35
-
36
-    /**
37
-     * @var PatronymicLineageModule|null $module
38
-     */
39
-    private $module;
40
-
41
-    /**
42
-     * @var IndividualListModule|null $indilist_module
43
-     */
44
-    private $indilist_module;
45
-
46
-    /**
47
-     * Constructor for LineagesPage Request handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     */
51
-    public function __construct(ModuleService $module_service)
52
-    {
53
-        $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
54
-        $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
55
-    }
56
-
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
-     */
61
-    public function handle(ServerRequestInterface $request): ResponseInterface
62
-    {
63
-        if ($this->module === null) {
64
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
-        }
66
-
67
-        if ($this->indilist_module === null) {
68
-            throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
69
-        }
70
-
71
-        $tree = $request->getAttribute('tree');
72
-        assert($tree instanceof Tree);
73
-
74
-        $surname = $request->getAttribute('surname');
75
-
76
-        $initial = mb_substr($surname, 0, 1);
77
-        $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
78
-            ->reject(function (int $count, string $initial): bool {
79
-
80
-                return $initial === '@' || $initial === ',';
81
-            });
82
-
83
-        $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname;
84
-
85
-        $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
86
-
87
-        return $this->viewResponse($this->module->name() . '::lineages-page', [
88
-            'title'         =>  $title,
89
-            'module'        =>  $this->module,
90
-            'tree'          =>  $tree,
91
-            'initials_list' =>  $initials_list,
92
-            'initial'       =>  $initial,
93
-            'show_all'      =>  'no',
94
-            'surname'       =>  $surname,
95
-            'lineages'      =>  $lineages,
96
-            'nb_lineages'   =>  $lineages !== null ? $lineages->count() : 0
97
-        ]);
98
-    }
34
+	use ViewResponseTrait;
35
+
36
+	/**
37
+	 * @var PatronymicLineageModule|null $module
38
+	 */
39
+	private $module;
40
+
41
+	/**
42
+	 * @var IndividualListModule|null $indilist_module
43
+	 */
44
+	private $indilist_module;
45
+
46
+	/**
47
+	 * Constructor for LineagesPage Request handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 */
51
+	public function __construct(ModuleService $module_service)
52
+	{
53
+		$this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
54
+		$this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
55
+	}
56
+
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
+	 */
61
+	public function handle(ServerRequestInterface $request): ResponseInterface
62
+	{
63
+		if ($this->module === null) {
64
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
+		}
66
+
67
+		if ($this->indilist_module === null) {
68
+			throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
69
+		}
70
+
71
+		$tree = $request->getAttribute('tree');
72
+		assert($tree instanceof Tree);
73
+
74
+		$surname = $request->getAttribute('surname');
75
+
76
+		$initial = mb_substr($surname, 0, 1);
77
+		$initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
78
+			->reject(function (int $count, string $initial): bool {
79
+
80
+				return $initial === '@' || $initial === ',';
81
+			});
82
+
83
+		$title = I18N::translate('Patronymic Lineages') . ' — ' . $surname;
84
+
85
+		$lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
86
+
87
+		return $this->viewResponse($this->module->name() . '::lineages-page', [
88
+			'title'         =>  $title,
89
+			'module'        =>  $this->module,
90
+			'tree'          =>  $tree,
91
+			'initials_list' =>  $initials_list,
92
+			'initial'       =>  $initial,
93
+			'show_all'      =>  'no',
94
+			'surname'       =>  $surname,
95
+			'lineages'      =>  $lineages,
96
+			'nb_lineages'   =>  $lineages !== null ? $lineages->count() : 0
97
+		]);
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -75,16 +75,16 @@
 block discarded – undo
75 75
 
76 76
         $initial = mb_substr($surname, 0, 1);
77 77
         $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
78
-            ->reject(function (int $count, string $initial): bool {
78
+            ->reject(function(int $count, string $initial): bool {
79 79
 
80 80
                 return $initial === '@' || $initial === ',';
81 81
             });
82 82
 
83
-        $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname;
83
+        $title = I18N::translate('Patronymic Lineages').' — '.$surname;
84 84
 
85 85
         $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
86 86
 
87
-        return $this->viewResponse($this->module->name() . '::lineages-page', [
87
+        return $this->viewResponse($this->module->name().'::lineages-page', [
88 88
             'title'         =>  $title,
89 89
             'module'        =>  $this->module,
90 90
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Http/RequestHandlers/SurnamesList.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -30,74 +30,74 @@
 block discarded – undo
30 30
  */
31 31
 class SurnamesList implements RequestHandlerInterface
32 32
 {
33
-    use ViewResponseTrait;
34
-
35
-    /**
36
-     * @var PatronymicLineageModule|null $module
37
-     */
38
-    private $module;
39
-
40
-    /**
41
-     * @var IndividualListModule|null $indilist_module
42
-     */
43
-    private $indilist_module;
44
-
45
-    /**
46
-     * Constructor for SurnamesList Request Handler
47
-     *
48
-     * @param ModuleService $module_service
49
-     */
50
-    public function __construct(ModuleService $module_service)
51
-    {
52
-        $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
53
-        $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
54
-    }
55
-
56
-    /**
57
-     * {@inheritDoc}
58
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
-     */
60
-    public function handle(ServerRequestInterface $request): ResponseInterface
61
-    {
62
-        if ($this->module === null) {
63
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
-        }
65
-
66
-        if ($this->indilist_module === null) {
67
-            throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
68
-        }
69
-
70
-        $tree = $request->getAttribute('tree');
71
-        assert($tree instanceof Tree);
72
-
73
-        $initial = $request->getAttribute('alpha');
74
-        $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
-            ->reject(function (int $count, string $initial): bool {
76
-
77
-                return $initial === '@' || $initial === ',';
78
-            });
79
-
80
-        $show_all = $request->getQueryParams()['show_all'] ?? 'no';
81
-
82
-        if ($show_all === 'yes') {
83
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
84
-            $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85
-        } elseif ($initial !== null && mb_strlen($initial) == 1) {
86
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
87
-            $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88
-        } else {
89
-            $title =  I18N::translate('Patronymic Lineages');
90
-            $surnames = [];
91
-        }
92
-
93
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
94
-            'title'         =>  $title,
95
-            'module'        =>  $this->module,
96
-            'tree'          =>  $tree,
97
-            'initials_list' =>  $initials_list,
98
-            'initial'       =>  $initial,
99
-            'show_all'      =>  $show_all,
100
-            'surnames'      =>  $surnames
101
-        ]);
102
-    }
33
+	use ViewResponseTrait;
34
+
35
+	/**
36
+	 * @var PatronymicLineageModule|null $module
37
+	 */
38
+	private $module;
39
+
40
+	/**
41
+	 * @var IndividualListModule|null $indilist_module
42
+	 */
43
+	private $indilist_module;
44
+
45
+	/**
46
+	 * Constructor for SurnamesList Request Handler
47
+	 *
48
+	 * @param ModuleService $module_service
49
+	 */
50
+	public function __construct(ModuleService $module_service)
51
+	{
52
+		$this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
53
+		$this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
54
+	}
55
+
56
+	/**
57
+	 * {@inheritDoc}
58
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
+	 */
60
+	public function handle(ServerRequestInterface $request): ResponseInterface
61
+	{
62
+		if ($this->module === null) {
63
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
+		}
65
+
66
+		if ($this->indilist_module === null) {
67
+			throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
68
+		}
69
+
70
+		$tree = $request->getAttribute('tree');
71
+		assert($tree instanceof Tree);
72
+
73
+		$initial = $request->getAttribute('alpha');
74
+		$initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
+			->reject(function (int $count, string $initial): bool {
76
+
77
+				return $initial === '@' || $initial === ',';
78
+			});
79
+
80
+		$show_all = $request->getQueryParams()['show_all'] ?? 'no';
81
+
82
+		if ($show_all === 'yes') {
83
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
84
+			$surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85
+		} elseif ($initial !== null && mb_strlen($initial) == 1) {
86
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
87
+			$surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88
+		} else {
89
+			$title =  I18N::translate('Patronymic Lineages');
90
+			$surnames = [];
91
+		}
92
+
93
+		return $this->viewResponse($this->module->name() . '::surnames-page', [
94
+			'title'         =>  $title,
95
+			'module'        =>  $this->module,
96
+			'tree'          =>  $tree,
97
+			'initials_list' =>  $initials_list,
98
+			'initial'       =>  $initial,
99
+			'show_all'      =>  $show_all,
100
+			'surnames'      =>  $surnames
101
+		]);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
         $initial = $request->getAttribute('alpha');
74 74
         $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
-            ->reject(function (int $count, string $initial): bool {
75
+            ->reject(function(int $count, string $initial): bool {
76 76
 
77 77
                 return $initial === '@' || $initial === ',';
78 78
             });
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
         $show_all = $request->getQueryParams()['show_all'] ?? 'no';
81 81
 
82 82
         if ($show_all === 'yes') {
83
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
83
+            $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All');
84 84
             $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85 85
         } elseif ($initial !== null && mb_strlen($initial) == 1) {
86
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
86
+            $title = I18N::translate('Patronymic Lineages').' — '.$initial;
87 87
             $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88 88
         } else {
89
-            $title =  I18N::translate('Patronymic Lineages');
89
+            $title = I18N::translate('Patronymic Lineages');
90 90
             $surnames = [];
91 91
         }
92 92
 
93
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
93
+        return $this->viewResponse($this->module->name().'::surnames-page', [
94 94
             'title'         =>  $title,
95 95
             'module'        =>  $this->module,
96 96
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/PatronymicLineageModule.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -34,100 +34,100 @@
 block discarded – undo
34 34
  * Display lineages of people with the same surname.
35 35
  */
36 36
 class PatronymicLineageModule extends IndividualListModule implements
37
-    ModuleMyArtJaubInterface,
38
-    ModuleListInterface,
39
-    ModuleGlobalInterface
37
+	ModuleMyArtJaubInterface,
38
+	ModuleListInterface,
39
+	ModuleGlobalInterface
40 40
 {
41
-    use ModuleMyArtJaubTrait;
42
-    use ModuleListTrait;
43
-    use ModuleGlobalTrait;
44
-
45
-     /**
46
-     * {@inheritDoc}
47
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
48
-     */
49
-    public function title(): string
50
-    {
51
-        return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
52
-    }
53
-
54
-    /**
55
-     * {@inheritDoc}
56
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
57
-     */
58
-    public function description(): string
59
-    {
60
-        //phpcs:ignore Generic.Files.LineLength.TooLong
61
-        return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
67
-     */
68
-    public function loadRoutes(Map $router): void
69
-    {
70
-        $router->attach('', '', static function (Map $router): void {
71
-
72
-            $router->attach('', '/module-maj/lineages', static function (Map $router): void {
73
-
74
-                $router->attach('', '/Page', static function (Map $router): void {
75
-
76
-                    $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
77
-                    $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
78
-                });
79
-            });
80
-        });
81
-    }
82
-
83
-    /**
84
-     * {@inheritDoc}
85
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
86
-     */
87
-    public function customModuleVersion(): string
88
-    {
89
-        return '2.0.11-v.1';
90
-    }
91
-
92
-    /**
93
-     * {@inheritDoc}
94
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
95
-     */
96
-    public function listUrl(Tree $tree, array $parameters = []): string
97
-    {
98
-        $surname = $parameters['surname'] ?? '';
99
-
100
-        $xref = app(ServerRequestInterface::class)->getAttribute('xref', '');
101
-        if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) {
102
-            $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname'];
103
-        }
104
-
105
-        if ($surname !== '') {
106
-            return route(LineagesPage::class, [
107
-                'tree'      =>  $tree->name(),
108
-                'surname'   =>  $surname
109
-            ] + $parameters);
110
-        }
111
-        return route(SurnamesList::class, [
112
-            'tree'  =>  $tree->name()
113
-        ] + $parameters);
114
-    }
115
-
116
-    /**
117
-     * {@inheritDoc}
118
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
119
-     */
120
-    public function listMenuClass(): string
121
-    {
122
-        return 'menu-maj-patrolineage';
123
-    }
124
-
125
-    /**
126
-     * {@inheritDoc}
127
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
128
-     */
129
-    public function headContent(): string
130
-    {
131
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
132
-    }
41
+	use ModuleMyArtJaubTrait;
42
+	use ModuleListTrait;
43
+	use ModuleGlobalTrait;
44
+
45
+	 /**
46
+	  * {@inheritDoc}
47
+	  * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
48
+	  */
49
+	public function title(): string
50
+	{
51
+		return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
52
+	}
53
+
54
+	/**
55
+	 * {@inheritDoc}
56
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
57
+	 */
58
+	public function description(): string
59
+	{
60
+		//phpcs:ignore Generic.Files.LineLength.TooLong
61
+		return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
67
+	 */
68
+	public function loadRoutes(Map $router): void
69
+	{
70
+		$router->attach('', '', static function (Map $router): void {
71
+
72
+			$router->attach('', '/module-maj/lineages', static function (Map $router): void {
73
+
74
+				$router->attach('', '/Page', static function (Map $router): void {
75
+
76
+					$router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
77
+					$router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
78
+				});
79
+			});
80
+		});
81
+	}
82
+
83
+	/**
84
+	 * {@inheritDoc}
85
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
86
+	 */
87
+	public function customModuleVersion(): string
88
+	{
89
+		return '2.0.11-v.1';
90
+	}
91
+
92
+	/**
93
+	 * {@inheritDoc}
94
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
95
+	 */
96
+	public function listUrl(Tree $tree, array $parameters = []): string
97
+	{
98
+		$surname = $parameters['surname'] ?? '';
99
+
100
+		$xref = app(ServerRequestInterface::class)->getAttribute('xref', '');
101
+		if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) {
102
+			$surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname'];
103
+		}
104
+
105
+		if ($surname !== '') {
106
+			return route(LineagesPage::class, [
107
+				'tree'      =>  $tree->name(),
108
+				'surname'   =>  $surname
109
+			] + $parameters);
110
+		}
111
+		return route(SurnamesList::class, [
112
+			'tree'  =>  $tree->name()
113
+		] + $parameters);
114
+	}
115
+
116
+	/**
117
+	 * {@inheritDoc}
118
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
119
+	 */
120
+	public function listMenuClass(): string
121
+	{
122
+		return 'menu-maj-patrolineage';
123
+	}
124
+
125
+	/**
126
+	 * {@inheritDoc}
127
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
128
+	 */
129
+	public function headContent(): string
130
+	{
131
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
132
+	}
133 133
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/Services/SourceStatusService.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -30,127 +30,127 @@
 block discarded – undo
30 30
 class SourceStatusService
31 31
 {
32 32
 
33
-    /**
34
-     * Maximum timespan between the date of a source and the date of the event to consider the source precise.
35
-     * Arbitrally set to approximately a year around the event date.
36
-     *
37
-     * @var int DATE_PRECISION_MARGIN
38
-     */
39
-    private const DATE_PRECISION_MARGIN = 180;
40
-
41
-    /**
42
-     * Return the status of source citations for a fact.
43
-     *
44
-     * @param Fact $fact
45
-     * @return FactSourceStatus
46
-     */
47
-    public function sourceStatusForFact(Fact $fact): FactSourceStatus
48
-    {
49
-        $source_status = new FactSourceStatus();
50
-
51
-        $date = $fact->date();
52
-        $source_status
53
-            ->setFactHasDate($date->isOK())
54
-            ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay());
55
-
56
-        foreach ($fact->getCitations() as $citation) {
57
-            $source_status
58
-                ->setHasSource(true)
59
-                ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1);
60
-
61
-            preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER);
62
-            foreach ($date_matches as $date_match) {
63
-                $source_date = new Date($date_match[1]);
64
-                $source_status
65
-                    ->addSourceHasDate($source_date->isOK())
66
-                    ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK()
67
-                        && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN);
68
-            }
69
-
70
-            if ($source_status->isFullySourced()) {
71
-                return $source_status;
72
-            }
73
-        }
74
-
75
-        return $source_status;
76
-    }
77
-
78
-    /**
79
-     * Return the status of sources for a Gedcom record.
80
-     *
81
-     * @param GedcomRecord $record
82
-     * @return SourceStatus
83
-     */
84
-    public function sourceStatusForRecord(GedcomRecord $record): SourceStatus
85
-    {
86
-        $source_status = new SourceStatus();
87
-
88
-        foreach ($record->facts(['SOUR']) as $source) {
89
-            $source_status
90
-                ->setHasSource(true)
91
-                ->addHasSupportingDocument($source->attribute('_ACT') !== '');
92
-
93
-            if ($source_status->isFullySourced()) {
94
-                return $source_status;
95
-            }
96
-        }
97
-
98
-        return $source_status;
99
-    }
100
-
101
-    /**
102
-     * Return the status of source citations for a list of fact types associated with a record.
103
-     *
104
-     * @param GedcomRecord $record
105
-     * @param array $tags
106
-     * @return FactSourceStatus
107
-     */
108
-    public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus
109
-    {
110
-        $source_status = new NullFactSourceStatus();
111
-
112
-        foreach ($record->facts($tags) as $fact) {
113
-            $source_status = $source_status->combineWith($this->sourceStatusForFact($fact));
114
-            assert($source_status instanceof FactSourceStatus);
115
-            if ($source_status->isFullySourced()) {
116
-                return $source_status;
117
-            }
118
-        }
119
-
120
-        return $source_status;
121
-    }
122
-
123
-    /**
124
-     * Return the status of source citations for an individual's birth events.
125
-     *
126
-     * @param Individual $individual
127
-     * @return FactSourceStatus
128
-     */
129
-    public function sourceStatusForBirth(Individual $individual): FactSourceStatus
130
-    {
131
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
132
-    }
133
-
134
-    /**
135
-     * Return the status of source citations for an individual's death events.
136
-     *
137
-     * @param Individual $individual
138
-     * @return FactSourceStatus
139
-     */
140
-    public function sourceStatusForDeath(Individual $individual): FactSourceStatus
141
-    {
142
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
143
-    }
144
-
145
-    /**
146
-     * Return the status of source citations for a family's marriage events.
147
-     *
148
-     * @param Family $family
149
-     * @return FactSourceStatus
150
-     */
151
-    public function sourceStatusForMarriage(Family $family): FactSourceStatus
152
-    {
153
-        $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']);
154
-        return $this->sourceStatusForFactsWithTags($family, $marr_events);
155
-    }
33
+	/**
34
+	 * Maximum timespan between the date of a source and the date of the event to consider the source precise.
35
+	 * Arbitrally set to approximately a year around the event date.
36
+	 *
37
+	 * @var int DATE_PRECISION_MARGIN
38
+	 */
39
+	private const DATE_PRECISION_MARGIN = 180;
40
+
41
+	/**
42
+	 * Return the status of source citations for a fact.
43
+	 *
44
+	 * @param Fact $fact
45
+	 * @return FactSourceStatus
46
+	 */
47
+	public function sourceStatusForFact(Fact $fact): FactSourceStatus
48
+	{
49
+		$source_status = new FactSourceStatus();
50
+
51
+		$date = $fact->date();
52
+		$source_status
53
+			->setFactHasDate($date->isOK())
54
+			->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay());
55
+
56
+		foreach ($fact->getCitations() as $citation) {
57
+			$source_status
58
+				->setHasSource(true)
59
+				->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1);
60
+
61
+			preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER);
62
+			foreach ($date_matches as $date_match) {
63
+				$source_date = new Date($date_match[1]);
64
+				$source_status
65
+					->addSourceHasDate($source_date->isOK())
66
+					->addSourceMatchesFactDate($date->isOK() && $source_date->isOK()
67
+						&& abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN);
68
+			}
69
+
70
+			if ($source_status->isFullySourced()) {
71
+				return $source_status;
72
+			}
73
+		}
74
+
75
+		return $source_status;
76
+	}
77
+
78
+	/**
79
+	 * Return the status of sources for a Gedcom record.
80
+	 *
81
+	 * @param GedcomRecord $record
82
+	 * @return SourceStatus
83
+	 */
84
+	public function sourceStatusForRecord(GedcomRecord $record): SourceStatus
85
+	{
86
+		$source_status = new SourceStatus();
87
+
88
+		foreach ($record->facts(['SOUR']) as $source) {
89
+			$source_status
90
+				->setHasSource(true)
91
+				->addHasSupportingDocument($source->attribute('_ACT') !== '');
92
+
93
+			if ($source_status->isFullySourced()) {
94
+				return $source_status;
95
+			}
96
+		}
97
+
98
+		return $source_status;
99
+	}
100
+
101
+	/**
102
+	 * Return the status of source citations for a list of fact types associated with a record.
103
+	 *
104
+	 * @param GedcomRecord $record
105
+	 * @param array $tags
106
+	 * @return FactSourceStatus
107
+	 */
108
+	public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus
109
+	{
110
+		$source_status = new NullFactSourceStatus();
111
+
112
+		foreach ($record->facts($tags) as $fact) {
113
+			$source_status = $source_status->combineWith($this->sourceStatusForFact($fact));
114
+			assert($source_status instanceof FactSourceStatus);
115
+			if ($source_status->isFullySourced()) {
116
+				return $source_status;
117
+			}
118
+		}
119
+
120
+		return $source_status;
121
+	}
122
+
123
+	/**
124
+	 * Return the status of source citations for an individual's birth events.
125
+	 *
126
+	 * @param Individual $individual
127
+	 * @return FactSourceStatus
128
+	 */
129
+	public function sourceStatusForBirth(Individual $individual): FactSourceStatus
130
+	{
131
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
132
+	}
133
+
134
+	/**
135
+	 * Return the status of source citations for an individual's death events.
136
+	 *
137
+	 * @param Individual $individual
138
+	 * @return FactSourceStatus
139
+	 */
140
+	public function sourceStatusForDeath(Individual $individual): FactSourceStatus
141
+	{
142
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
143
+	}
144
+
145
+	/**
146
+	 * Return the status of source citations for a family's marriage events.
147
+	 *
148
+	 * @param Family $family
149
+	 * @return FactSourceStatus
150
+	 */
151
+	public function sourceStatusForMarriage(Family $family): FactSourceStatus
152
+	{
153
+		$marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']);
154
+		return $this->sourceStatusForFactsWithTags($family, $marr_events);
155
+	}
156 156
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/IsSourcedModule.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -30,92 +30,92 @@
 block discarded – undo
30 30
  * IsSourced Module
31 31
  */
32 32
 class IsSourcedModule extends AbstractModule implements
33
-    ModuleMyArtJaubInterface,
34
-    ModuleGlobalInterface,
35
-    ModuleSidebarInterface
33
+	ModuleMyArtJaubInterface,
34
+	ModuleGlobalInterface,
35
+	ModuleSidebarInterface
36 36
 {
37
-    use ModuleMyArtJaubTrait;
38
-    use ModuleGlobalTrait;
39
-    use ModuleSidebarTrait;
37
+	use ModuleMyArtJaubTrait;
38
+	use ModuleGlobalTrait;
39
+	use ModuleSidebarTrait;
40 40
 
41
-    /**
42
-     * {@inheritDoc}
43
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
44
-     */
45
-    public function title(): string
46
-    {
47
-        return I18N::translate('Sourced events');
48
-    }
41
+	/**
42
+	 * {@inheritDoc}
43
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
44
+	 */
45
+	public function title(): string
46
+	{
47
+		return I18N::translate('Sourced events');
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
53
-     */
54
-    public function description(): string
55
-    {
56
-        return I18N::translate('Indicate if events related to an record are sourced.');
57
-    }
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
53
+	 */
54
+	public function description(): string
55
+	{
56
+		return I18N::translate('Indicate if events related to an record are sourced.');
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
62
-     */
63
-    public function customModuleVersion(): string
64
-    {
65
-        return '2.1.0-v.1';
66
-    }
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
62
+	 */
63
+	public function customModuleVersion(): string
64
+	{
65
+		return '2.1.0-v.1';
66
+	}
67 67
 
68
-    /**
69
-     * {@inheritDoc}
70
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
71
-     */
72
-    public function headContent(): string
73
-    {
74
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
75
-    }
68
+	/**
69
+	 * {@inheritDoc}
70
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
71
+	 */
72
+	public function headContent(): string
73
+	{
74
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
75
+	}
76 76
 
77
-    /**
78
-     * {@inheritDoc}
79
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
80
-     */
81
-    public function bodyContent(): string
82
-    {
83
-        return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
84
-    }
77
+	/**
78
+	 * {@inheritDoc}
79
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
80
+	 */
81
+	public function bodyContent(): string
82
+	{
83
+		return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
84
+	}
85 85
 
86
-    /**
87
-     * {@inheritDoc}
88
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
89
-     */
90
-    public function hasSidebarContent(Individual $individual): bool
91
-    {
92
-        return true;
93
-    }
86
+	/**
87
+	 * {@inheritDoc}
88
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
89
+	 */
90
+	public function hasSidebarContent(Individual $individual): bool
91
+	{
92
+		return true;
93
+	}
94 94
 
95
-    /**
96
-     * {@inheritDoc}
97
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
98
-     */
99
-    public function getSidebarContent(Individual $individual): string
100
-    {
101
-        /** @var SourceStatusService $source_status_service */
102
-        $source_status_service = app(SourceStatusService::class);
95
+	/**
96
+	 * {@inheritDoc}
97
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
98
+	 */
99
+	public function getSidebarContent(Individual $individual): string
100
+	{
101
+		/** @var SourceStatusService $source_status_service */
102
+		$source_status_service = app(SourceStatusService::class);
103 103
 
104
-        $spouse_families_status = $individual->spouseFamilies()->map(
105
-            function (Family $sfamily) use ($source_status_service): array {
106
-                return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107
-            }
108
-        )->filter(function (array $item): bool {
109
-            return $item[1]->isSet();
110
-        });
104
+		$spouse_families_status = $individual->spouseFamilies()->map(
105
+			function (Family $sfamily) use ($source_status_service): array {
106
+				return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107
+			}
108
+		)->filter(function (array $item): bool {
109
+			return $item[1]->isSet();
110
+		});
111 111
 
112
-        return view($this->name() . '::sidebar/content', [
113
-            'module_name'               => $this->name(),
114
-            'individual'                =>  $individual,
115
-            'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
116
-            'source_status_birth'       =>  $source_status_service->sourceStatusForBirth($individual),
117
-            'source_status_marriages'   =>  $spouse_families_status,
118
-            'source_status_death'       =>  $source_status_service->sourceStatusForDeath($individual)
119
-        ]);
120
-    }
112
+		return view($this->name() . '::sidebar/content', [
113
+			'module_name'               => $this->name(),
114
+			'individual'                =>  $individual,
115
+			'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
116
+			'source_status_birth'       =>  $source_status_service->sourceStatusForBirth($individual),
117
+			'source_status_marriages'   =>  $spouse_families_status,
118
+			'source_status_death'       =>  $source_status_service->sourceStatusForDeath($individual)
119
+		]);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function headContent(): string
73 73
     {
74
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
74
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
75 75
     }
76 76
 
77 77
     /**
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function bodyContent(): string
82 82
     {
83
-        return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
83
+        return '<script src="'.$this->assetUrl('js/issourced.min.js').'"></script>';
84 84
     }
85 85
 
86 86
     /**
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
         $source_status_service = app(SourceStatusService::class);
103 103
 
104 104
         $spouse_families_status = $individual->spouseFamilies()->map(
105
-            function (Family $sfamily) use ($source_status_service): array {
106
-                return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
105
+            function(Family $sfamily) use ($source_status_service): array {
106
+                return [$sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107 107
             }
108
-        )->filter(function (array $item): bool {
108
+        )->filter(function(array $item): bool {
109 109
             return $item[1]->isSet();
110 110
         });
111 111
 
112
-        return view($this->name() . '::sidebar/content', [
112
+        return view($this->name().'::sidebar/content', [
113 113
             'module_name'               => $this->name(),
114 114
             'individual'                =>  $individual,
115 115
             'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
Please login to merge, or discard this patch.