Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Http/Middleware/AuthTreePreference.php 1 patch
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.
src/Webtrees/Individual.php 1 patch
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.
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 1 patch
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.
src/Webtrees/Module/PatronymicLineage/Http/RequestHandlers/SurnamesList.php 1 patch
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.
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 1 patch
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.
src/Webtrees/Module/IsSourced/Data/SourceStatus.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -22,137 +22,137 @@
 block discarded – undo
22 22
  */
23 23
 class SourceStatus
24 24
 {
25
-    /**
26
-     * @var boolean $source_exist
27
-     */
28
-    private $source_exist = false;
29
-
30
-    /**
31
-     * @var boolean $has_document
32
-     */
33
-    private $has_document = false;
34
-
35
-    /**
36
-     * Return whether the SourceStatus object contains relevant data.
37
-     *
38
-     * @return bool
39
-     */
40
-    public function isSet(): bool
41
-    {
42
-        return true;
43
-    }
44
-
45
-    /**
46
-     * Returns whether the record contains a source.
47
-     *
48
-     * @return bool
49
-     */
50
-    public function hasSource(): bool
51
-    {
52
-        return $this->source_exist;
53
-    }
54
-
55
-    /**
56
-     *  Set whether the record contains a source.
57
-     *
58
-     * @param bool $source_exist
59
-     * @return self
60
-     */
61
-    public function setHasSource(bool $source_exist): self
62
-    {
63
-        $this->source_exist = $source_exist;
64
-        return $this;
65
-    }
66
-
67
-    /**
68
-     * Combine whether the record contains a source with the previous status.
69
-     *
70
-     * @param bool $source_exist
71
-     * @return self
72
-     */
73
-    public function addHasSource(bool $source_exist): self
74
-    {
75
-        $this->source_exist = $this->source_exist || $source_exist;
76
-        return $this;
77
-    }
78
-
79
-    /**
80
-     * Return whether the source citation is supported by a document.
81
-     * Uses the _ACT tag from the MyArtJaub Certificates module.
82
-     *
83
-     * @return bool
84
-     */
85
-    public function hasSupportingDocument(): bool
86
-    {
87
-        return $this->hasSource() && $this->has_document;
88
-    }
89
-
90
-    /**
91
-     * Set whether the source citation is supported by a document.
92
-     *
93
-     * @param bool $has_document
94
-     * @return self
95
-     */
96
-    public function setHasSupportingDocument(bool $has_document): self
97
-    {
98
-        $this->has_document = $has_document;
99
-        return $this;
100
-    }
101
-
102
-    /**
103
-     * Combine whether the source citation is supported by a document with the previous status.
104
-     *
105
-     * @param bool $has_document
106
-     * @return self
107
-     */
108
-    public function addHasSupportingDocument(bool $has_document): self
109
-    {
110
-        $this->has_document = $this->has_document || $has_document;
111
-        return $this;
112
-    }
113
-
114
-    /**
115
-     * Check whether all possible criteria for defining a sourced element have been met.
116
-     *
117
-     * @return bool
118
-     */
119
-    public function isFullySourced(): bool
120
-    {
121
-        return $this->hasSupportingDocument();
122
-    }
123
-
124
-    /**
125
-     * Get the label to display to describe the source status.
126
-     *
127
-     * @param string $context
128
-     * @return string
129
-     */
130
-    public function label(string $context): string
131
-    {
132
-        $context_label = Registry::elementFactory()->make($context)->label();
133
-
134
-        if (!$this->hasSource()) {
135
-            return I18N::translate('%s not sourced', $context_label);
136
-        }
137
-
138
-        if ($this->hasSupportingDocument()) {
139
-            return I18N::translate('%s sourced with a certificate', $context_label);
140
-        }
141
-
142
-        return I18N::translate('%s sourced', $context_label);
143
-    }
144
-
145
-    /**
146
-     * Return an element combining properties of the current object with another SourceStatus.
147
-     * Do not use the initial object anymore, it may not appropriately describe the status anymore.
148
-     *
149
-     * @param SourceStatus $other
150
-     * @return self
151
-     */
152
-    public function combineWith(SourceStatus $other): self
153
-    {
154
-        $this->addHasSource($other->hasSource());
155
-        $this->addHasSupportingDocument($other->hasSource());
156
-        return $this;
157
-    }
25
+	/**
26
+	 * @var boolean $source_exist
27
+	 */
28
+	private $source_exist = false;
29
+
30
+	/**
31
+	 * @var boolean $has_document
32
+	 */
33
+	private $has_document = false;
34
+
35
+	/**
36
+	 * Return whether the SourceStatus object contains relevant data.
37
+	 *
38
+	 * @return bool
39
+	 */
40
+	public function isSet(): bool
41
+	{
42
+		return true;
43
+	}
44
+
45
+	/**
46
+	 * Returns whether the record contains a source.
47
+	 *
48
+	 * @return bool
49
+	 */
50
+	public function hasSource(): bool
51
+	{
52
+		return $this->source_exist;
53
+	}
54
+
55
+	/**
56
+	 *  Set whether the record contains a source.
57
+	 *
58
+	 * @param bool $source_exist
59
+	 * @return self
60
+	 */
61
+	public function setHasSource(bool $source_exist): self
62
+	{
63
+		$this->source_exist = $source_exist;
64
+		return $this;
65
+	}
66
+
67
+	/**
68
+	 * Combine whether the record contains a source with the previous status.
69
+	 *
70
+	 * @param bool $source_exist
71
+	 * @return self
72
+	 */
73
+	public function addHasSource(bool $source_exist): self
74
+	{
75
+		$this->source_exist = $this->source_exist || $source_exist;
76
+		return $this;
77
+	}
78
+
79
+	/**
80
+	 * Return whether the source citation is supported by a document.
81
+	 * Uses the _ACT tag from the MyArtJaub Certificates module.
82
+	 *
83
+	 * @return bool
84
+	 */
85
+	public function hasSupportingDocument(): bool
86
+	{
87
+		return $this->hasSource() && $this->has_document;
88
+	}
89
+
90
+	/**
91
+	 * Set whether the source citation is supported by a document.
92
+	 *
93
+	 * @param bool $has_document
94
+	 * @return self
95
+	 */
96
+	public function setHasSupportingDocument(bool $has_document): self
97
+	{
98
+		$this->has_document = $has_document;
99
+		return $this;
100
+	}
101
+
102
+	/**
103
+	 * Combine whether the source citation is supported by a document with the previous status.
104
+	 *
105
+	 * @param bool $has_document
106
+	 * @return self
107
+	 */
108
+	public function addHasSupportingDocument(bool $has_document): self
109
+	{
110
+		$this->has_document = $this->has_document || $has_document;
111
+		return $this;
112
+	}
113
+
114
+	/**
115
+	 * Check whether all possible criteria for defining a sourced element have been met.
116
+	 *
117
+	 * @return bool
118
+	 */
119
+	public function isFullySourced(): bool
120
+	{
121
+		return $this->hasSupportingDocument();
122
+	}
123
+
124
+	/**
125
+	 * Get the label to display to describe the source status.
126
+	 *
127
+	 * @param string $context
128
+	 * @return string
129
+	 */
130
+	public function label(string $context): string
131
+	{
132
+		$context_label = Registry::elementFactory()->make($context)->label();
133
+
134
+		if (!$this->hasSource()) {
135
+			return I18N::translate('%s not sourced', $context_label);
136
+		}
137
+
138
+		if ($this->hasSupportingDocument()) {
139
+			return I18N::translate('%s sourced with a certificate', $context_label);
140
+		}
141
+
142
+		return I18N::translate('%s sourced', $context_label);
143
+	}
144
+
145
+	/**
146
+	 * Return an element combining properties of the current object with another SourceStatus.
147
+	 * Do not use the initial object anymore, it may not appropriately describe the status anymore.
148
+	 *
149
+	 * @param SourceStatus $other
150
+	 * @return self
151
+	 */
152
+	public function combineWith(SourceStatus $other): self
153
+	{
154
+		$this->addHasSource($other->hasSource());
155
+		$this->addHasSupportingDocument($other->hasSource());
156
+		return $this;
157
+	}
158 158
 }
Please login to merge, or discard this patch.