Passed
Branch feature/2.0 (d2af8f)
by Jonathan
13:07
created
src/Webtrees/Functions/Functions.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param string $text Text to display
34 34
 	 */
35
-	static public function promptAlert($text){
35
+	static public function promptAlert($text) {
36 36
 		echo '<script>';
37
-		echo 'alert("',fw\Filter::escapeHtml($text),'")';
37
+		echo 'alert("', fw\Filter::escapeHtml($text), '")';
38 38
 		echo '</script>';
39 39
 	}
40 40
 	
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @return float Result of the safe division
48 48
 	 */
49 49
 	public static function safeDivision($num, $denom, $default = 0) {
50
-		if($denom && $denom!=0){
50
+		if ($denom && $denom != 0) {
51 51
 			return $num / $denom;
52 52
 		}
53 53
 		return $default;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @param float $default Default value if denominator null or 0
62 62
 	 * @return float Percentage
63 63
 	 */
64
-	public static function getPercentage($num, $denom, $default = 0){
64
+	public static function getPercentage($num, $denom, $default = 0) {
65 65
 		return 100 * self::safeDivision($num, $denom, $default);
66 66
 	}
67 67
 	
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 * @param int $target	The final max width/height
73 73
 	 * @return array array of ($width, $height). One of them must be $target
74 74
 	 */
75
-	static public function getResizedImageSize($file, $target=25){
76
-		list($width, $height, , ) = getimagesize($file);
75
+	static public function getResizedImageSize($file, $target = 25) {
76
+		list($width, $height,,) = getimagesize($file);
77 77
 		$max = max($width, $height);
78 78
 		$rapp = $target / $max;
79 79
 		$width = intval($rapp * $width);
@@ -103,21 +103,21 @@  discard block
 block discarded – undo
103 103
 	 * @param int $length Length of the token, default to 32
104 104
 	 * @return string Random token
105 105
 	 */
106
-	public static function generateRandomToken($length=32) {
106
+	public static function generateRandomToken($length = 32) {
107 107
 		$chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
108 108
 		$len_chars = count($chars);
109 109
 		$token = '';
110 110
 		
111 111
 		for ($i = 0; $i < $length; $i++)
112
-			$token .= $chars[ mt_rand(0, $len_chars - 1) ];
112
+			$token .= $chars[mt_rand(0, $len_chars - 1)];
113 113
 		
114 114
 		# Number of 32 char chunks
115
-		$chunks = ceil( strlen($token) / 32 );
115
+		$chunks = ceil(strlen($token) / 32);
116 116
 		$md5token = '';
117 117
 		
118 118
 		# Run each chunk through md5
119
-		for ( $i=1; $i<=$chunks; $i++ )
120
-			$md5token .= md5( substr($token, $i * 32 - 32, 32) );
119
+		for ($i = 1; $i <= $chunks; $i++)
120
+			$md5token .= md5(substr($token, $i * 32 - 32, 32));
121 121
 		
122 122
 			# Trim the token
123 123
 		return substr($md5token, 0, $length);		
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	protected static function getBase64EncryptionKey() {	    
132 132
 	    $key = 'STANDARDKEYIFNOSERVER';
133
-	    if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE')))
133
+	    if (!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE')))
134 134
 	        $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
135 135
 	    
136 136
 	    return $key;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @param string $data Text to encrypt
144 144
 	 * @return string Encrypted and encoded text
145 145
 	 */
146
-	public static function encryptToSafeBase64($data){		
146
+	public static function encryptToSafeBase64($data) {		
147 147
 		$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);	
148 148
 		$id = sodium_crypto_secretbox($data, $nonce, self::getBase64EncryptionKey());
149 149
 		$encrypted = base64_encode($nonce.$id);
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
 	 * @param string $encrypted Text to decrypt
164 164
 	 * @return string Decrypted text
165 165
 	 */
166
-	public static function decryptFromSafeBase64($encrypted){
166
+	public static function decryptFromSafeBase64($encrypted) {
167 167
 		$encrypted = str_replace('-', '+', $encrypted);
168 168
 		$encrypted = str_replace('_', '/', $encrypted);
169 169
 		$encrypted = str_replace('*', '=', $encrypted);
170 170
 		$encrypted = base64_decode($encrypted);
171
-		if($encrypted === false)
171
+		if ($encrypted === false)
172 172
 			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
173 173
 		
174 174
 		if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES))
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         
180 180
         $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey());
181 181
 		
182
-        if($decrypted === false) {
182
+        if ($decrypted === false) {
183 183
             throw new \InvalidArgumentException('The message has been tampered with in transit.');
184 184
         }
185 185
         
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	 * @param string $string Filesystem encoded string to encode
195 195
 	 * @return string UTF-8 encoded string
196 196
 	 */
197
-	public static function encodeFileSystemToUtf8($string){
197
+	public static function encodeFileSystemToUtf8($string) {
198 198
 		if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') {
199
-		    return iconv('cp1252', 'utf-8//IGNORE',$string);
199
+		    return iconv('cp1252', 'utf-8//IGNORE', $string);
200 200
 		}
201 201
 		return $string;
202 202
 	}
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 	 * @param string $string UTF-8 encoded string to encode
208 208
 	 * @return string Filesystem encoded string
209 209
 	 */
210
-	public static function encodeUtf8ToFileSystem($string){
210
+	public static function encodeUtf8ToFileSystem($string) {
211 211
 		if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') {
212
-			return iconv('utf-8', 'cp1252//IGNORE' ,  $string);
212
+			return iconv('utf-8', 'cp1252//IGNORE', $string);
213 213
 		}
214 214
 		return $string;
215 215
 	}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @return boolean True if path valid
223 223
 	 */
224 224
 	public static function isValidPath($filename, $acceptfolder = FALSE) {		
225
-		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
225
+		if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
226 226
 		return false;
227 227
 	}
228 228
 	
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @return array Array of month short names
235 235
 	 */
236 236
 	public static function getCalendarShortMonths($calendarId = 0) {
237
-		if(!isset(self::$calendarShortMonths[$calendarId])) {
237
+		if (!isset(self::$calendarShortMonths[$calendarId])) {
238 238
 			$calendar_info = cal_info($calendarId);
239 239
 			self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths'];
240 240
 		}		
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -29,220 +29,220 @@
 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 $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::strcasecmp($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
-                        if (
210
-                            $spouse === null ||
211
-                            ($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0)
212
-                        ) {
213
-                            if (I18N::strcasecmp($child_surname, $indi_surname) == 0) {
214
-                                $nb_natural++;
215
-                                $node_child = new LineageNode($child, $node->rootNode());
216
-                                $node_child = $this->buildLineage($node_child);
217
-                                $node->addChild($spouse_family, $node_child);
218
-                            }
219
-                        }
220
-                    } else { //If the root individual is the father
221
-                        $nb_natural++;
222
-                        //Print if the children does not bear the same name as his mother
223
-                        //(and different from his father)
224
-                        if (
225
-                            mb_strlen($child_surname) == 0 ||
226
-                            mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
227
-                            I18N::strcasecmp($child_surname, $indi_surname) == 0 ||
228
-                            I18N::strcasecmp($child_surname, $spouse_surname) != 0
229
-                        ) {
230
-                            $node_child = new LineageNode($child, $node->rootNode());
231
-                            $node_child = $this->buildLineage($node_child);
232
-                        } else {
233
-                            $node_child = new LineageNode($child, $node->rootNode(), $child_surname);
234
-                        }
235
-                        $node->addChild($spouse_family, $node_child);
236
-                    }
237
-                }
238
-            }
239
-
240
-            //Do not print other children
241
-            if (($nb_children - $nb_natural) > 0) {
242
-                $node->addChild($spouse_family, null);
243
-            }
244
-        }
245
-
246
-        return $node;
247
-    }
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 $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::strcasecmp($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
+						if (
210
+							$spouse === null ||
211
+							($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0)
212
+						) {
213
+							if (I18N::strcasecmp($child_surname, $indi_surname) == 0) {
214
+								$nb_natural++;
215
+								$node_child = new LineageNode($child, $node->rootNode());
216
+								$node_child = $this->buildLineage($node_child);
217
+								$node->addChild($spouse_family, $node_child);
218
+							}
219
+						}
220
+					} else { //If the root individual is the father
221
+						$nb_natural++;
222
+						//Print if the children does not bear the same name as his mother
223
+						//(and different from his father)
224
+						if (
225
+							mb_strlen($child_surname) == 0 ||
226
+							mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
227
+							I18N::strcasecmp($child_surname, $indi_surname) == 0 ||
228
+							I18N::strcasecmp($child_surname, $spouse_surname) != 0
229
+						) {
230
+							$node_child = new LineageNode($child, $node->rootNode());
231
+							$node_child = $this->buildLineage($node_child);
232
+						} else {
233
+							$node_child = new LineageNode($child, $node->rootNode(), $child_surname);
234
+						}
235
+						$node->addChild($spouse_family, $node_child);
236
+					}
237
+				}
238
+			}
239
+
240
+			//Do not print other children
241
+			if (($nb_children - $nb_natural) > 0) {
242
+				$node->addChild($spouse_family, null);
243
+			}
244
+		}
245
+
246
+		return $node;
247
+	}
248 248
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -25,117 +25,117 @@
 block discarded – undo
25 25
 class LineageNode
26 26
 {
27 27
 
28
-    /**
29
-     * @var Collection $linked_fams Spouse families linked to the node
30
-     */
31
-    private $linked_fams;
32
-
33
-    /**
34
-     * @var ?Individual $node_indi Reference individual for the node
35
-     */
36
-    private $node_indi;
37
-
38
-    /**
39
-     * @var LineageRootNode $root_node Root node of the lineage
40
-     */
41
-    private $root_node;
42
-
43
-    /**
44
-     * @var ?string $alt_surname Linked surname, used to link to another lineage
45
-     */
46
-    private $alt_surname;
47
-
48
-    /**
49
-     * Constructor for Lineage node
50
-     *
51
-     * @param Individual $node_indi Main individual
52
-     * @param LineageRootNode $root_node Node of the lineage root
53
-     * @param null|string $alt_surname Follow-up surname
54
-     */
55
-    public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
56
-    {
57
-        $this->node_indi = $node_indi;
58
-        $this->root_node = $root_node;
59
-        $this->alt_surname = $alt_surname;
60
-        $this->linked_fams = new Collection();
61
-    }
62
-
63
-    /**
64
-     * Add a spouse family to the node
65
-     *
66
-     * @param Family $fams
67
-     * @return stdClass
68
-     */
69
-    public function addFamily(Family $fams): object
70
-    {
71
-        if (!$this->linked_fams->has($fams->xref())) {
72
-            $this->linked_fams->put($fams->xref(), (object) [
73
-                'family'   =>  $fams,
74
-                'children' =>  new Collection()
75
-            ]);
76
-        }
77
-        return $this->linked_fams->get($fams->xref());
78
-    }
79
-
80
-    /**
81
-     * Add a child LineageNode to the node
82
-     *
83
-     * @param Family $fams
84
-     * @param LineageNode $child
85
-     */
86
-    public function addChild(Family $fams, LineageNode $child = null): void
87
-    {
88
-        $this->addFamily($fams)->children->push($child);
89
-        $this->root_node->incrementChildNodes();
90
-    }
91
-
92
-    /**
93
-     * Returns the node individual
94
-     *
95
-     * @return Individual|NULL
96
-     */
97
-    public function individual(): ?Individual
98
-    {
99
-        return $this->node_indi;
100
-    }
101
-
102
-    /**
103
-     * Returns the lineage root node individual
104
-     *
105
-     * @return LineageRootNode
106
-     */
107
-    public function rootNode(): LineageRootNode
108
-    {
109
-        return $this->root_node;
110
-    }
111
-
112
-    /**
113
-     * Returns the spouse families linked to the node
114
-     *
115
-     * @return Collection
116
-     */
117
-    public function families(): Collection
118
-    {
119
-        return $this->linked_fams;
120
-    }
121
-
122
-    /**
123
-     * Returns the follow-up surname
124
-     *
125
-     * @return string
126
-     */
127
-    public function followUpSurname(): string
128
-    {
129
-        return $this->alt_surname ?? '';
130
-    }
131
-
132
-    /**
133
-     * Indicates whether the node has a follow up surname
134
-     *
135
-     * @return boolean
136
-     */
137
-    public function hasFollowUpSurname(): bool
138
-    {
139
-        return mb_strlen($this->followUpSurname()) > 0 ;
140
-    }
28
+	/**
29
+	 * @var Collection $linked_fams Spouse families linked to the node
30
+	 */
31
+	private $linked_fams;
32
+
33
+	/**
34
+	 * @var ?Individual $node_indi Reference individual for the node
35
+	 */
36
+	private $node_indi;
37
+
38
+	/**
39
+	 * @var LineageRootNode $root_node Root node of the lineage
40
+	 */
41
+	private $root_node;
42
+
43
+	/**
44
+	 * @var ?string $alt_surname Linked surname, used to link to another lineage
45
+	 */
46
+	private $alt_surname;
47
+
48
+	/**
49
+	 * Constructor for Lineage node
50
+	 *
51
+	 * @param Individual $node_indi Main individual
52
+	 * @param LineageRootNode $root_node Node of the lineage root
53
+	 * @param null|string $alt_surname Follow-up surname
54
+	 */
55
+	public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
56
+	{
57
+		$this->node_indi = $node_indi;
58
+		$this->root_node = $root_node;
59
+		$this->alt_surname = $alt_surname;
60
+		$this->linked_fams = new Collection();
61
+	}
62
+
63
+	/**
64
+	 * Add a spouse family to the node
65
+	 *
66
+	 * @param Family $fams
67
+	 * @return stdClass
68
+	 */
69
+	public function addFamily(Family $fams): object
70
+	{
71
+		if (!$this->linked_fams->has($fams->xref())) {
72
+			$this->linked_fams->put($fams->xref(), (object) [
73
+				'family'   =>  $fams,
74
+				'children' =>  new Collection()
75
+			]);
76
+		}
77
+		return $this->linked_fams->get($fams->xref());
78
+	}
79
+
80
+	/**
81
+	 * Add a child LineageNode to the node
82
+	 *
83
+	 * @param Family $fams
84
+	 * @param LineageNode $child
85
+	 */
86
+	public function addChild(Family $fams, LineageNode $child = null): void
87
+	{
88
+		$this->addFamily($fams)->children->push($child);
89
+		$this->root_node->incrementChildNodes();
90
+	}
91
+
92
+	/**
93
+	 * Returns the node individual
94
+	 *
95
+	 * @return Individual|NULL
96
+	 */
97
+	public function individual(): ?Individual
98
+	{
99
+		return $this->node_indi;
100
+	}
101
+
102
+	/**
103
+	 * Returns the lineage root node individual
104
+	 *
105
+	 * @return LineageRootNode
106
+	 */
107
+	public function rootNode(): LineageRootNode
108
+	{
109
+		return $this->root_node;
110
+	}
111
+
112
+	/**
113
+	 * Returns the spouse families linked to the node
114
+	 *
115
+	 * @return Collection
116
+	 */
117
+	public function families(): Collection
118
+	{
119
+		return $this->linked_fams;
120
+	}
121
+
122
+	/**
123
+	 * Returns the follow-up surname
124
+	 *
125
+	 * @return string
126
+	 */
127
+	public function followUpSurname(): string
128
+	{
129
+		return $this->alt_surname ?? '';
130
+	}
131
+
132
+	/**
133
+	 * Indicates whether the node has a follow up surname
134
+	 *
135
+	 * @return boolean
136
+	 */
137
+	public function hasFollowUpSurname(): bool
138
+	{
139
+		return mb_strlen($this->followUpSurname()) > 0 ;
140
+	}
141 141
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/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 $module
38
-     */
39
-    private $module;
40
-
41
-    /**
42
-     * @var IndividualListModule $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 ($count, $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 $module
38
+	 */
39
+	private $module;
40
+
41
+	/**
42
+	 * @var IndividualListModule $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 ($count, $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 ($count, $initial): bool {
78
+            ->reject(function($count, $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 $module
37
-     */
38
-    private $module;
39
-
40
-    /**
41
-     * @var IndividualListModule $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 ($count, $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 $module
37
+	 */
38
+	private $module;
39
+
40
+	/**
41
+	 * @var IndividualListModule $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 ($count, $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 ($count, $initial): bool {
75
+            ->reject(function($count, $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 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -33,95 +33,95 @@
 block discarded – undo
33 33
  */
34 34
 class PatronymicLineageModule extends AbstractModuleMaj implements ModuleListInterface, ModuleGlobalInterface
35 35
 {
36
-    use ModuleListTrait;
37
-    use ModuleGlobalTrait;
38
-
39
-     /**
40
-     * {@inheritDoc}
41
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
-     */
43
-    public function title(): string
44
-    {
45
-        return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
46
-    }
47
-
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
-     */
52
-    public function description(): string
53
-    {
54
-        //phpcs:ignore Generic.Files.LineLength.TooLong
55
-        return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
56
-    }
57
-
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes()
61
-     */
62
-    public function loadRoutes(Map $router): void
63
-    {
64
-        $router->attach('', '', static function (Map $router): void {
65
-
66
-            $router->attach('', '/module-maj/lineages', static function (Map $router): void {
67
-
68
-                $router->attach('', '/Page', static function (Map $router): void {
69
-
70
-                    $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
71
-                    $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
72
-                });
73
-            });
74
-        });
75
-    }
76
-
77
-    /**
78
-     * {@inheritDoc}
79
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
80
-     */
81
-    public function customModuleVersion(): string
82
-    {
83
-        return '2.0.7-v.1';
84
-    }
85
-
86
-    /**
87
-     * {@inheritDoc}
88
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
89
-     */
90
-    public function listUrl(Tree $tree, array $parameters = []): string
91
-    {
92
-        $surname = $parameters['surname'] ?? '';
93
-
94
-        $xref = app(ServerRequestInterface::class)->getAttribute('xref', '');
95
-        if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) {
96
-            $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname'];
97
-        }
98
-
99
-        if ($surname !== '') {
100
-            return route(LineagesPage::class, [
101
-                'tree'      =>  $tree->name(),
102
-                'surname'   =>  $surname
103
-            ] + $parameters);
104
-        }
105
-        return route(SurnamesList::class, [
106
-            'tree'  =>  $tree->name()
107
-        ] + $parameters);
108
-    }
109
-
110
-    /**
111
-     * {@inheritDoc}
112
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
113
-     */
114
-    public function listMenuClass(): string
115
-    {
116
-        return 'menu-maj-patrolineage';
117
-    }
118
-
119
-    /**
120
-     * {@inheritDoc}
121
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
122
-     */
123
-    public function headContent(): string
124
-    {
125
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
126
-    }
36
+	use ModuleListTrait;
37
+	use ModuleGlobalTrait;
38
+
39
+	 /**
40
+	  * {@inheritDoc}
41
+	  * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
+	  */
43
+	public function title(): string
44
+	{
45
+		return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
46
+	}
47
+
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
+	 */
52
+	public function description(): string
53
+	{
54
+		//phpcs:ignore Generic.Files.LineLength.TooLong
55
+		return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
56
+	}
57
+
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes()
61
+	 */
62
+	public function loadRoutes(Map $router): void
63
+	{
64
+		$router->attach('', '', static function (Map $router): void {
65
+
66
+			$router->attach('', '/module-maj/lineages', static function (Map $router): void {
67
+
68
+				$router->attach('', '/Page', static function (Map $router): void {
69
+
70
+					$router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
71
+					$router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
72
+				});
73
+			});
74
+		});
75
+	}
76
+
77
+	/**
78
+	 * {@inheritDoc}
79
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
80
+	 */
81
+	public function customModuleVersion(): string
82
+	{
83
+		return '2.0.7-v.1';
84
+	}
85
+
86
+	/**
87
+	 * {@inheritDoc}
88
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
89
+	 */
90
+	public function listUrl(Tree $tree, array $parameters = []): string
91
+	{
92
+		$surname = $parameters['surname'] ?? '';
93
+
94
+		$xref = app(ServerRequestInterface::class)->getAttribute('xref', '');
95
+		if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) {
96
+			$surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname'];
97
+		}
98
+
99
+		if ($surname !== '') {
100
+			return route(LineagesPage::class, [
101
+				'tree'      =>  $tree->name(),
102
+				'surname'   =>  $surname
103
+			] + $parameters);
104
+		}
105
+		return route(SurnamesList::class, [
106
+			'tree'  =>  $tree->name()
107
+		] + $parameters);
108
+	}
109
+
110
+	/**
111
+	 * {@inheritDoc}
112
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
113
+	 */
114
+	public function listMenuClass(): string
115
+	{
116
+		return 'menu-maj-patrolineage';
117
+	}
118
+
119
+	/**
120
+	 * {@inheritDoc}
121
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
122
+	 */
123
+	public function headContent(): string
124
+	{
125
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function loadRoutes(Map $router): void
63 63
     {
64
-        $router->attach('', '', static function (Map $router): void {
64
+        $router->attach('', '', static function(Map $router): void {
65 65
 
66
-            $router->attach('', '/module-maj/lineages', static function (Map $router): void {
66
+            $router->attach('', '/module-maj/lineages', static function(Map $router): void {
67 67
 
68
-                $router->attach('', '/Page', static function (Map $router): void {
68
+                $router->attach('', '/Page', static function(Map $router): void {
69 69
 
70 70
                     $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
71 71
                     $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
@@ -122,6 +122,6 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function headContent(): string
124 124
     {
125
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
125
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
126 126
     }
127 127
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Http/RequestHandlers/MatomoStats.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -27,50 +27,50 @@
 block discarded – undo
27 27
  */
28 28
 class MatomoStats implements RequestHandlerInterface
29 29
 {
30
-    use ViewResponseTrait;
30
+	use ViewResponseTrait;
31 31
 
32
-    /**
33
-     * @var WelcomeBlockModule
34
-     */
35
-    private $module;
32
+	/**
33
+	 * @var WelcomeBlockModule
34
+	 */
35
+	private $module;
36 36
 
37
-    /**
38
-     * @var MatomoStatsService $matomo_service
39
-     */
40
-    private $matomo_service;
37
+	/**
38
+	 * @var MatomoStatsService $matomo_service
39
+	 */
40
+	private $matomo_service;
41 41
 
42
-    /**
43
-     * Constructor for MatomoStats request handler
44
-     * @param ModuleService $module_service
45
-     * @param MatomoStatsService $matomo_service
46
-     */
47
-    public function __construct(
48
-        ModuleService $module_service,
49
-        MatomoStatsService $matomo_service
50
-    ) {
51
-        $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
52
-        $this->matomo_service = $matomo_service;
53
-    }
42
+	/**
43
+	 * Constructor for MatomoStats request handler
44
+	 * @param ModuleService $module_service
45
+	 * @param MatomoStatsService $matomo_service
46
+	 */
47
+	public function __construct(
48
+		ModuleService $module_service,
49
+		MatomoStatsService $matomo_service
50
+	) {
51
+		$this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
52
+		$this->matomo_service = $matomo_service;
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
58
-     */
59
-    public function handle(ServerRequestInterface $request): ResponseInterface
60
-    {
61
-        $this->layout = 'layouts/ajax';
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
58
+	 */
59
+	public function handle(ServerRequestInterface $request): ResponseInterface
60
+	{
61
+		$this->layout = 'layouts/ajax';
62 62
 
63
-        $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
64
-        $nb_visits_year = $nb_visits_today = null;
63
+		$block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
64
+		$nb_visits_year = $nb_visits_today = null;
65 65
 
66
-        if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
67
-            $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id);
68
-            $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today;
69
-        }
66
+		if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
67
+			$nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id);
68
+			$nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today;
69
+		}
70 70
 
71
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
72
-            'visits_year'   =>  $nb_visits_year,
73
-            'visits_today'  =>  $nb_visits_today
74
-        ]);
75
-    }
71
+		return $this->viewResponse($this->module->name() . '::matomo-stats', [
72
+			'visits_year'   =>  $nb_visits_year,
73
+			'visits_today'  =>  $nb_visits_today
74
+		]);
75
+	}
76 76
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -64,11 +64,11 @@
 block discarded – undo
64 64
         $nb_visits_year = $nb_visits_today = null;
65 65
 
66 66
         if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
67
-            $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id);
68
-            $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today;
67
+            $nb_visits_today = (int)$this->matomo_service->visitsToday($this->module, $block_id);
68
+            $nb_visits_year = (int)$this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today;
69 69
         }
70 70
 
71
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
71
+        return $this->viewResponse($this->module->name().'::matomo-stats', [
72 72
             'visits_year'   =>  $nb_visits_year,
73 73
             'visits_today'  =>  $nb_visits_today
74 74
         ]);
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/WelcomeBlockModule.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -30,157 +30,157 @@
 block discarded – undo
30 30
  */
31 31
 class WelcomeBlockModule extends AbstractModuleMaj implements ModuleBlockInterface
32 32
 {
33
-    use ModuleBlockTrait;
34
-
35
-    /**
36
-     * {@inheritDoc}
37
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
38
-     */
39
-    public function title(): string
40
-    {
41
-        return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
42
-    }
43
-
44
-    /**
45
-     * {@inheritDoc}
46
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
47
-     */
48
-    public function description(): string
49
-    {
50
-        //phpcs:ignore Generic.Files.LineLength.TooLong
51
-        return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
52
-    }
53
-
54
-    /**
55
-     * {@inheritDoc}
56
-     * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes()
57
-     */
58
-    public function loadRoutes(Map $router): void
59
-    {
60
-        $router->attach('', '', static function (Map $router): void {
61
-
62
-            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
63
-
64
-                $router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
65
-            });
66
-        });
67
-    }
68
-
69
-    /**
70
-     * {@inheritDoc}
71
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
72
-     */
73
-    public function customModuleVersion(): string
74
-    {
75
-        return '2.0.6-v.1';
76
-    }
77
-
78
-    /**
79
-     * {@inheritDoc}
80
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
81
-     */
82
-    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
83
-    {
84
-        $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
85
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
86
-
87
-        $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
88
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
89
-
90
-        $content = view($this->name() . '::block-embed', [
91
-            'block_id'                  =>  $block_id,
92
-            'fab_welcome_block_view'    =>  $fab_welcome_block_view,
93
-            'fab_login_block_view'      =>  $fab_login_block_view,
94
-            'matomo_enabled'            =>  $this->isMatomoEnabled($block_id)
95
-        ]);
96
-
97
-        if ($context !== self::CONTEXT_EMBED) {
98
-            return view('modules/block-template', [
99
-                'block'      => Str::kebab($this->name()),
100
-                'id'         => $block_id,
101
-                'config_url' => $this->configUrl($tree, $context, $block_id),
102
-                'title'      => $tree->title(),
103
-                'content'    => $content,
104
-            ]);
105
-        }
106
-
107
-        return $content;
108
-    }
109
-
110
-    /**
111
-     * {@inheritDoc}
112
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
113
-     */
114
-    public function isTreeBlock(): bool
115
-    {
116
-        return true;
117
-    }
118
-
119
-    /**
120
-     * {@inheritDoc}
121
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
122
-     */
123
-    public function editBlockConfiguration(Tree $tree, int $block_id): string
124
-    {
125
-        return view($this->name() . '::config', $this->matomoSettings($block_id));
126
-    }
127
-
128
-    /**
129
-     * {@inheritDoc}
130
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
131
-     */
132
-    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
133
-    {
134
-        $params = (array) $request->getParsedBody();
135
-
136
-        $matomo_enabled = $params['matomo_enabled'] == 'yes';
137
-        $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
138
-        if (!$matomo_enabled) {
139
-            return;
140
-        }
141
-
142
-        if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
143
-            FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
144
-            return;
145
-        }
146
-
147
-        if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
148
-            FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
149
-            return;
150
-        }
151
-
152
-        $this
153
-            ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
154
-            ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
155
-            ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
156
-
157
-        app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id);
158
-    }
159
-
160
-    /**
161
-     * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
162
-     *
163
-     * @param int $block_id
164
-     * @return bool
165
-     */
166
-    public function isMatomoEnabled(int $block_id): bool
167
-    {
168
-        return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
169
-    }
170
-
171
-    /**
172
-     * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
173
-     *
174
-     * @param int $block_id
175
-     * @return array<string, mixed>
176
-     */
177
-    public function matomoSettings(int $block_id): array
178
-    {
179
-        return [
180
-            'matomo_enabled' => $this->isMatomoEnabled($block_id),
181
-            'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
182
-            'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
183
-            'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
184
-        ];
185
-    }
33
+	use ModuleBlockTrait;
34
+
35
+	/**
36
+	 * {@inheritDoc}
37
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
38
+	 */
39
+	public function title(): string
40
+	{
41
+		return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
42
+	}
43
+
44
+	/**
45
+	 * {@inheritDoc}
46
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
47
+	 */
48
+	public function description(): string
49
+	{
50
+		//phpcs:ignore Generic.Files.LineLength.TooLong
51
+		return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
52
+	}
53
+
54
+	/**
55
+	 * {@inheritDoc}
56
+	 * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes()
57
+	 */
58
+	public function loadRoutes(Map $router): void
59
+	{
60
+		$router->attach('', '', static function (Map $router): void {
61
+
62
+			$router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
63
+
64
+				$router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
65
+			});
66
+		});
67
+	}
68
+
69
+	/**
70
+	 * {@inheritDoc}
71
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
72
+	 */
73
+	public function customModuleVersion(): string
74
+	{
75
+		return '2.0.6-v.1';
76
+	}
77
+
78
+	/**
79
+	 * {@inheritDoc}
80
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
81
+	 */
82
+	public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
83
+	{
84
+		$fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
85
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
86
+
87
+		$fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
88
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
89
+
90
+		$content = view($this->name() . '::block-embed', [
91
+			'block_id'                  =>  $block_id,
92
+			'fab_welcome_block_view'    =>  $fab_welcome_block_view,
93
+			'fab_login_block_view'      =>  $fab_login_block_view,
94
+			'matomo_enabled'            =>  $this->isMatomoEnabled($block_id)
95
+		]);
96
+
97
+		if ($context !== self::CONTEXT_EMBED) {
98
+			return view('modules/block-template', [
99
+				'block'      => Str::kebab($this->name()),
100
+				'id'         => $block_id,
101
+				'config_url' => $this->configUrl($tree, $context, $block_id),
102
+				'title'      => $tree->title(),
103
+				'content'    => $content,
104
+			]);
105
+		}
106
+
107
+		return $content;
108
+	}
109
+
110
+	/**
111
+	 * {@inheritDoc}
112
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
113
+	 */
114
+	public function isTreeBlock(): bool
115
+	{
116
+		return true;
117
+	}
118
+
119
+	/**
120
+	 * {@inheritDoc}
121
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
122
+	 */
123
+	public function editBlockConfiguration(Tree $tree, int $block_id): string
124
+	{
125
+		return view($this->name() . '::config', $this->matomoSettings($block_id));
126
+	}
127
+
128
+	/**
129
+	 * {@inheritDoc}
130
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
131
+	 */
132
+	public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
133
+	{
134
+		$params = (array) $request->getParsedBody();
135
+
136
+		$matomo_enabled = $params['matomo_enabled'] == 'yes';
137
+		$this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
138
+		if (!$matomo_enabled) {
139
+			return;
140
+		}
141
+
142
+		if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
143
+			FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
144
+			return;
145
+		}
146
+
147
+		if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
148
+			FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
149
+			return;
150
+		}
151
+
152
+		$this
153
+			->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
154
+			->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
155
+			->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
156
+
157
+		app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id);
158
+	}
159
+
160
+	/**
161
+	 * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
162
+	 *
163
+	 * @param int $block_id
164
+	 * @return bool
165
+	 */
166
+	public function isMatomoEnabled(int $block_id): bool
167
+	{
168
+		return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
169
+	}
170
+
171
+	/**
172
+	 * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
173
+	 *
174
+	 * @param int $block_id
175
+	 * @return array<string, mixed>
176
+	 */
177
+	public function matomoSettings(int $block_id): array
178
+	{
179
+		return [
180
+			'matomo_enabled' => $this->isMatomoEnabled($block_id),
181
+			'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
182
+			'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
183
+			'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
184
+		];
185
+	}
186 186
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function loadRoutes(Map $router): void
59 59
     {
60
-        $router->attach('', '', static function (Map $router): void {
60
+        $router->attach('', '', static function(Map $router): void {
61 61
 
62
-            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
62
+            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function(Map $router): void {
63 63
 
64 64
                 $router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
65 65
             });
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
88 88
             ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
89 89
 
90
-        $content = view($this->name() . '::block-embed', [
90
+        $content = view($this->name().'::block-embed', [
91 91
             'block_id'                  =>  $block_id,
92 92
             'fab_welcome_block_view'    =>  $fab_welcome_block_view,
93 93
             'fab_login_block_view'      =>  $fab_login_block_view,
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function editBlockConfiguration(Tree $tree, int $block_id): string
124 124
     {
125
-        return view($this->name() . '::config', $this->matomoSettings($block_id));
125
+        return view($this->name().'::config', $this->matomoSettings($block_id));
126 126
     }
127 127
 
128 128
     /**
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
133 133
     {
134
-        $params = (array) $request->getParsedBody();
134
+        $params = (array)$request->getParsedBody();
135 135
 
136 136
         $matomo_enabled = $params['matomo_enabled'] == 'yes';
137 137
         $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
             ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
155 155
             ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
156 156
 
157
-        app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id);
157
+        app('cache.files')->forget($this->name().'-matomovisits-yearly-'.$block_id);
158 158
     }
159 159
 
160 160
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
             'matomo_enabled' => $this->isMatomoEnabled($block_id),
181 181
             'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
182 182
             'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
183
-            'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
183
+            'matomo_siteid'  => (int)$this->getBlockSetting($block_id, 'matomo_siteid', '0')
184 184
         ];
185 185
     }
186 186
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Services/MatomoStatsService.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -30,95 +30,95 @@
 block discarded – undo
30 30
 class MatomoStatsService
31 31
 {
32 32
 
33
-    /**
34
-     * Returns the number of visits for the current year (up to the day before).
35
-     * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
36
-     *
37
-     * @param WelcomeBlockModule $module
38
-     * @param int $block_id
39
-     * @return int|NULL
40
-     */
41
-    public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
42
-    {
43
-        $cache = Registry::cache()->file();
33
+	/**
34
+	 * Returns the number of visits for the current year (up to the day before).
35
+	 * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
36
+	 *
37
+	 * @param WelcomeBlockModule $module
38
+	 * @param int $block_id
39
+	 * @return int|NULL
40
+	 */
41
+	public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
42
+	{
43
+		$cache = Registry::cache()->file();
44 44
 
45
-        return $cache->remember(
46
-            $module->name() . '-matomovisits-yearly-' . $block_id,
47
-            function () use ($module, $block_id): ?int {
48
-                $visits_year = $this->visits($module, $block_id, 'year');
49
-                if ($visits_year === null) {
50
-                    return null;
51
-                }
52
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
45
+		return $cache->remember(
46
+			$module->name() . '-matomovisits-yearly-' . $block_id,
47
+			function () use ($module, $block_id): ?int {
48
+				$visits_year = $this->visits($module, $block_id, 'year');
49
+				if ($visits_year === null) {
50
+					return null;
51
+				}
52
+				$visits_today = (int) $this->visits($module, $block_id, 'day');
53 53
 
54
-                return $visits_year - $visits_today;
55
-            },
56
-            Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
57
-        );
58
-    }
54
+				return $visits_year - $visits_today;
55
+			},
56
+			Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
57
+		);
58
+	}
59 59
 
60
-    /**
61
-     * Returns the number of visits for the current day.
62
-     *
63
-     * @param WelcomeBlockModule $module
64
-     * @param int $block_id
65
-     * @return int|NULL
66
-     */
67
-    public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
68
-    {
69
-        return app('cache.array')->remember(
70
-            $module->name() . '-matomovisits-daily-' . $block_id,
71
-            function () use ($module, $block_id): ?int {
72
-                return $this->visits($module, $block_id, 'day');
73
-            }
74
-        );
75
-    }
60
+	/**
61
+	 * Returns the number of visits for the current day.
62
+	 *
63
+	 * @param WelcomeBlockModule $module
64
+	 * @param int $block_id
65
+	 * @return int|NULL
66
+	 */
67
+	public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
68
+	{
69
+		return app('cache.array')->remember(
70
+			$module->name() . '-matomovisits-daily-' . $block_id,
71
+			function () use ($module, $block_id): ?int {
72
+				return $this->visits($module, $block_id, 'day');
73
+			}
74
+		);
75
+	}
76 76
 
77
-    /**
78
-     * Invoke the Matomo API to retrieve the number of visits over a period.
79
-     *
80
-     * @param WelcomeBlockModule $module
81
-     * @param int $block_id
82
-     * @param string $period
83
-     * @return int|NULL
84
-     */
85
-    protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
86
-    {
87
-        $settings = $module->matomoSettings($block_id);
77
+	/**
78
+	 * Invoke the Matomo API to retrieve the number of visits over a period.
79
+	 *
80
+	 * @param WelcomeBlockModule $module
81
+	 * @param int $block_id
82
+	 * @param string $period
83
+	 * @return int|NULL
84
+	 */
85
+	protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
86
+	{
87
+		$settings = $module->matomoSettings($block_id);
88 88
 
89
-        if (
90
-            $settings['matomo_enabled'] === true
91
-            && mb_strlen($settings['matomo_url']) > 0
92
-            && mb_strlen($settings['matomo_token']) > 0
93
-            && $settings['matomo_siteid'] > 0
94
-        ) {
95
-            try {
96
-                $http_client = new Client([
97
-                    RequestOptions::TIMEOUT => 30
98
-                ]);
89
+		if (
90
+			$settings['matomo_enabled'] === true
91
+			&& mb_strlen($settings['matomo_url']) > 0
92
+			&& mb_strlen($settings['matomo_token']) > 0
93
+			&& $settings['matomo_siteid'] > 0
94
+		) {
95
+			try {
96
+				$http_client = new Client([
97
+					RequestOptions::TIMEOUT => 30
98
+				]);
99 99
 
100
-                $response = $http_client->get($settings['matomo_url'], [
101
-                    'query' =>  [
102
-                        'module'    =>  'API',
103
-                        'method'    =>  'VisitsSummary.getVisits',
104
-                        'idSite'    =>  $settings['matomo_siteid'],
105
-                        'period'    =>  $period,
106
-                        'date'      =>  'today',
107
-                        'token_auth' =>  $settings['matomo_token'],
108
-                        'format'    =>  'json'
109
-                    ]
110
-                ]);
100
+				$response = $http_client->get($settings['matomo_url'], [
101
+					'query' =>  [
102
+						'module'    =>  'API',
103
+						'method'    =>  'VisitsSummary.getVisits',
104
+						'idSite'    =>  $settings['matomo_siteid'],
105
+						'period'    =>  $period,
106
+						'date'      =>  'today',
107
+						'token_auth' =>  $settings['matomo_token'],
108
+						'format'    =>  'json'
109
+					]
110
+				]);
111 111
 
112
-                if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
113
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
114
-                    if ($result !== null) {
115
-                        return (int)$result;
116
-                    }
117
-                }
118
-            } catch (RequestException $ex) {
119
-            }
120
-        }
112
+				if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
113
+					$result = json_decode((string) $response->getBody(), true)['value'] ?? null;
114
+					if ($result !== null) {
115
+						return (int)$result;
116
+					}
117
+				}
118
+			} catch (RequestException $ex) {
119
+			}
120
+		}
121 121
 
122
-        return null;
123
-    }
122
+		return null;
123
+	}
124 124
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
         $cache = Registry::cache()->file();
44 44
 
45 45
         return $cache->remember(
46
-            $module->name() . '-matomovisits-yearly-' . $block_id,
47
-            function () use ($module, $block_id): ?int {
46
+            $module->name().'-matomovisits-yearly-'.$block_id,
47
+            function() use ($module, $block_id): ?int {
48 48
                 $visits_year = $this->visits($module, $block_id, 'year');
49 49
                 if ($visits_year === null) {
50 50
                     return null;
51 51
                 }
52
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
52
+                $visits_today = (int)$this->visits($module, $block_id, 'day');
53 53
 
54 54
                 return $visits_year - $visits_today;
55 55
             },
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
     public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
68 68
     {
69 69
         return app('cache.array')->remember(
70
-            $module->name() . '-matomovisits-daily-' . $block_id,
71
-            function () use ($module, $block_id): ?int {
70
+            $module->name().'-matomovisits-daily-'.$block_id,
71
+            function() use ($module, $block_id) : ?int {
72 72
                 return $this->visits($module, $block_id, 'day');
73 73
             }
74 74
         );
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                 ]);
111 111
 
112 112
                 if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
113
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
113
+                    $result = json_decode((string)$response->getBody(), true)['value'] ?? null;
114 114
                     if ($result !== null) {
115 115
                         return (int)$result;
116 116
                     }
Please login to merge, or discard this patch.