@@ -30,294 +30,294 @@ |
||
30 | 30 | */ |
31 | 31 | class SosaRecordsService |
32 | 32 | { |
33 | - private ?int $max_system_generations = null; |
|
33 | + private ?int $max_system_generations = null; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Maximum number of generation the system is able to hold. |
|
37 | - * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | - * |
|
39 | - * @return int |
|
40 | - */ |
|
41 | - public function maxSystemGenerations(): int |
|
42 | - { |
|
43 | - if ($this->max_system_generations === null) { |
|
44 | - $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | - } |
|
46 | - return $this->max_system_generations; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Maximum number of generation the system is able to hold. |
|
37 | + * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | + * |
|
39 | + * @return int |
|
40 | + */ |
|
41 | + public function maxSystemGenerations(): int |
|
42 | + { |
|
43 | + if ($this->max_system_generations === null) { |
|
44 | + $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | + } |
|
46 | + return $this->max_system_generations; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Calculate the generation of a sosa |
|
51 | - * Sosa 1 is of generation 1. |
|
52 | - * |
|
53 | - * @param int $sosa |
|
54 | - * @return int |
|
55 | - */ |
|
56 | - public function generation(int $sosa): int |
|
57 | - { |
|
58 | - return BigInteger::of($sosa)->getBitLength(); |
|
59 | - } |
|
49 | + /** |
|
50 | + * Calculate the generation of a sosa |
|
51 | + * Sosa 1 is of generation 1. |
|
52 | + * |
|
53 | + * @param int $sosa |
|
54 | + * @return int |
|
55 | + */ |
|
56 | + public function generation(int $sosa): int |
|
57 | + { |
|
58 | + return BigInteger::of($sosa)->getBitLength(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | - * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | - * |
|
65 | - * @param int $sosa |
|
66 | - * @param int $gen |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | - { |
|
71 | - $gen_sosa = $this->generation($sosa); |
|
72 | - return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | - ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | - ->toInt(); |
|
75 | - } |
|
61 | + /** |
|
62 | + * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | + * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | + * |
|
65 | + * @param int $sosa |
|
66 | + * @param int $gen |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | + { |
|
71 | + $gen_sosa = $this->generation($sosa); |
|
72 | + return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | + ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | + ->toInt(); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Check whether an individual is a Sosa ancestor. |
|
79 | - * |
|
80 | - * @param Tree $tree |
|
81 | - * @param UserInterface $user |
|
82 | - * @param Individual $indi |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | - { |
|
87 | - return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | - } |
|
77 | + /** |
|
78 | + * Check whether an individual is a Sosa ancestor. |
|
79 | + * |
|
80 | + * @param Tree $tree |
|
81 | + * @param UserInterface $user |
|
82 | + * @param Individual $indi |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | + { |
|
87 | + return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns all Sosa numbers associated to an Individual |
|
92 | - * |
|
93 | - * @param Tree $tree |
|
94 | - * @param UserInterface $user |
|
95 | - * @param Individual $indi |
|
96 | - * @return Collection<int, int> |
|
97 | - */ |
|
98 | - public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | - { |
|
100 | - return Registry::cache()->array()->remember( |
|
101 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | - function () use ($tree, $user, $indi): Collection { |
|
103 | - return DB::table('maj_sosa') |
|
104 | - ->select(['majs_sosa', 'majs_gen']) |
|
105 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | - ->where('majs_user_id', '=', $user->id()) |
|
107 | - ->where('majs_i_id', '=', $indi->xref()) |
|
108 | - ->orderBy('majs_sosa') |
|
109 | - ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | - } |
|
111 | - ); |
|
112 | - } |
|
90 | + /** |
|
91 | + * Returns all Sosa numbers associated to an Individual |
|
92 | + * |
|
93 | + * @param Tree $tree |
|
94 | + * @param UserInterface $user |
|
95 | + * @param Individual $indi |
|
96 | + * @return Collection<int, int> |
|
97 | + */ |
|
98 | + public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | + { |
|
100 | + return Registry::cache()->array()->remember( |
|
101 | + 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | + function () use ($tree, $user, $indi): Collection { |
|
103 | + return DB::table('maj_sosa') |
|
104 | + ->select(['majs_sosa', 'majs_gen']) |
|
105 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | + ->where('majs_user_id', '=', $user->id()) |
|
107 | + ->where('majs_i_id', '=', $indi->xref()) |
|
108 | + ->orderBy('majs_sosa') |
|
109 | + ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | + } |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Return a list of the Sosa ancestors across all generation |
|
116 | - * |
|
117 | - * @param Tree $tree |
|
118 | - * @param UserInterface $user |
|
119 | - * @return Collection<\stdClass> |
|
120 | - */ |
|
121 | - public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | - { |
|
123 | - return DB::table('maj_sosa') |
|
124 | - ->select(['majs_sosa', 'majs_i_id']) |
|
125 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | - ->where('majs_user_id', '=', $user->id()) |
|
127 | - ->orderBy('majs_sosa') |
|
128 | - ->get(); |
|
129 | - } |
|
114 | + /** |
|
115 | + * Return a list of the Sosa ancestors across all generation |
|
116 | + * |
|
117 | + * @param Tree $tree |
|
118 | + * @param UserInterface $user |
|
119 | + * @return Collection<\stdClass> |
|
120 | + */ |
|
121 | + public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | + { |
|
123 | + return DB::table('maj_sosa') |
|
124 | + ->select(['majs_sosa', 'majs_i_id']) |
|
125 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | + ->where('majs_user_id', '=', $user->id()) |
|
127 | + ->orderBy('majs_sosa') |
|
128 | + ->get(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Return a list of the Sosa ancestors at a given generation |
|
133 | - * |
|
134 | - * @param Tree $tree |
|
135 | - * @param UserInterface $user |
|
136 | - * @param int $gen |
|
137 | - * @return Collection<\stdClass> |
|
138 | - */ |
|
139 | - public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | - { |
|
141 | - return DB::table('maj_sosa') |
|
142 | - ->select(['majs_sosa', 'majs_i_id']) |
|
143 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | - ->where('majs_user_id', '=', $user->id()) |
|
145 | - ->where('majs_gen', '=', $gen) |
|
146 | - ->orderBy('majs_sosa') |
|
147 | - ->get(); |
|
148 | - } |
|
131 | + /** |
|
132 | + * Return a list of the Sosa ancestors at a given generation |
|
133 | + * |
|
134 | + * @param Tree $tree |
|
135 | + * @param UserInterface $user |
|
136 | + * @param int $gen |
|
137 | + * @return Collection<\stdClass> |
|
138 | + */ |
|
139 | + public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | + { |
|
141 | + return DB::table('maj_sosa') |
|
142 | + ->select(['majs_sosa', 'majs_i_id']) |
|
143 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | + ->where('majs_user_id', '=', $user->id()) |
|
145 | + ->where('majs_gen', '=', $gen) |
|
146 | + ->orderBy('majs_sosa') |
|
147 | + ->get(); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Return a list of the Sosa families at a given generation |
|
152 | - * |
|
153 | - * @param Tree $tree |
|
154 | - * @param UserInterface $user |
|
155 | - * @param int $gen |
|
156 | - * @return Collection<\stdClass> |
|
157 | - */ |
|
158 | - public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | - { |
|
160 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | - return DB::table('families') |
|
162 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | - // Link to family husband |
|
164 | - $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | - ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | - ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | - ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | - }) |
|
169 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | - // Link to family husband |
|
171 | - $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | - ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | - ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | - ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | - }) |
|
176 | - ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | - ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | - ->orderBy('sosa_husb.majs_sosa') |
|
180 | - ->get(); |
|
181 | - } |
|
150 | + /** |
|
151 | + * Return a list of the Sosa families at a given generation |
|
152 | + * |
|
153 | + * @param Tree $tree |
|
154 | + * @param UserInterface $user |
|
155 | + * @param int $gen |
|
156 | + * @return Collection<\stdClass> |
|
157 | + */ |
|
158 | + public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | + { |
|
160 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | + return DB::table('families') |
|
162 | + ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | + // Link to family husband |
|
164 | + $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | + ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | + ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | + ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | + }) |
|
169 | + ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | + // Link to family husband |
|
171 | + $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | + ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | + ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | + ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | + }) |
|
176 | + ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | + ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | + ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | + ->orderBy('sosa_husb.majs_sosa') |
|
180 | + ->get(); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Return a list of Sosa ancestors missing at a given generation. |
|
185 | - * It includes the reference of either parent if it is known. |
|
186 | - * |
|
187 | - * @param Tree $tree |
|
188 | - * @param UserInterface $user |
|
189 | - * @param int $gen |
|
190 | - * @return Collection<\stdClass> |
|
191 | - */ |
|
192 | - public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | - { |
|
194 | - if ($gen == 1) { |
|
195 | - return collect(); |
|
196 | - } |
|
183 | + /** |
|
184 | + * Return a list of Sosa ancestors missing at a given generation. |
|
185 | + * It includes the reference of either parent if it is known. |
|
186 | + * |
|
187 | + * @param Tree $tree |
|
188 | + * @param UserInterface $user |
|
189 | + * @param int $gen |
|
190 | + * @return Collection<\stdClass> |
|
191 | + */ |
|
192 | + public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | + { |
|
194 | + if ($gen == 1) { |
|
195 | + return collect(); |
|
196 | + } |
|
197 | 197 | |
198 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | - return DB::table('maj_sosa AS sosa') |
|
200 | - ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | - // Link to sosa's father |
|
204 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | - ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | - ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | - }) |
|
208 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | - // Link to sosa's mother |
|
210 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | - ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | - ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | - }) |
|
214 | - ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | - ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | - ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | - ->where(function (Builder $query): void { |
|
218 | - $query->whereNull('sosa_fat.majs_i_id') |
|
219 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | - }) |
|
221 | - ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | - ->get(); |
|
224 | - } |
|
198 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | + return DB::table('maj_sosa AS sosa') |
|
200 | + ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | + ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | + // Link to sosa's father |
|
204 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | + ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | + ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | + }) |
|
208 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | + // Link to sosa's mother |
|
210 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | + ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | + ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | + }) |
|
214 | + ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | + ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | + ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | + ->where(function (Builder $query): void { |
|
218 | + $query->whereNull('sosa_fat.majs_i_id') |
|
219 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | + }) |
|
221 | + ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | + ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | + ->get(); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Remove all Sosa entries related to the gedcom file and user |
|
228 | - * |
|
229 | - * @param Tree $tree |
|
230 | - * @param UserInterface $user |
|
231 | - */ |
|
232 | - public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | - { |
|
234 | - DB::table('maj_sosa') |
|
235 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | - ->where('majs_user_id', '=', $user->id()) |
|
237 | - ->delete(); |
|
238 | - } |
|
226 | + /** |
|
227 | + * Remove all Sosa entries related to the gedcom file and user |
|
228 | + * |
|
229 | + * @param Tree $tree |
|
230 | + * @param UserInterface $user |
|
231 | + */ |
|
232 | + public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | + { |
|
234 | + DB::table('maj_sosa') |
|
235 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | + ->where('majs_user_id', '=', $user->id()) |
|
237 | + ->delete(); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * |
|
242 | - * @param Tree $tree |
|
243 | - * @param UserInterface $user |
|
244 | - * @param int $sosa |
|
245 | - */ |
|
246 | - public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | - { |
|
248 | - DB::table('maj_sosa') |
|
249 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | - ->where('majs_user_id', '=', $user->id()) |
|
251 | - ->where('majs_sosa', '>=', $sosa) |
|
252 | - ->whereRaw( |
|
253 | - 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | - [$this->generation($sosa), $sosa] |
|
255 | - ) |
|
256 | - ->delete(); |
|
257 | - } |
|
240 | + /** |
|
241 | + * |
|
242 | + * @param Tree $tree |
|
243 | + * @param UserInterface $user |
|
244 | + * @param int $sosa |
|
245 | + */ |
|
246 | + public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | + { |
|
248 | + DB::table('maj_sosa') |
|
249 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | + ->where('majs_user_id', '=', $user->id()) |
|
251 | + ->where('majs_sosa', '>=', $sosa) |
|
252 | + ->whereRaw( |
|
253 | + 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | + [$this->generation($sosa), $sosa] |
|
255 | + ) |
|
256 | + ->delete(); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Insert (or update if already existing) a list of Sosa individuals |
|
261 | - * |
|
262 | - * @param Tree $tree |
|
263 | - * @param UserInterface $user |
|
264 | - * @param array<array<string,mixed>> $sosa_records |
|
265 | - */ |
|
266 | - public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | - { |
|
268 | - $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
259 | + /** |
|
260 | + * Insert (or update if already existing) a list of Sosa individuals |
|
261 | + * |
|
262 | + * @param Tree $tree |
|
263 | + * @param UserInterface $user |
|
264 | + * @param array<array<string,mixed>> $sosa_records |
|
265 | + */ |
|
266 | + public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | + { |
|
268 | + $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
269 | 269 | |
270 | - $bindings_placeholders = $bindings_values = []; |
|
271 | - $has_records = false; |
|
272 | - foreach ($sosa_records as $i => $row) { |
|
273 | - $gen = $this->generation($row['sosa']); |
|
274 | - if ($gen <= $this->maxSystemGenerations()) { |
|
275 | - $has_records = true; |
|
276 | - if ($mass_update) { |
|
277 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | - $bindings_values = array_merge( |
|
281 | - $bindings_values, |
|
282 | - [ |
|
283 | - 'tree_id' . $i => $tree->id(), |
|
284 | - 'user_id' . $i => $user->id(), |
|
285 | - 'sosa' . $i => $row['sosa'], |
|
286 | - 'indi_id' . $i => $row['indi'], |
|
287 | - 'gen' . $i => $gen, |
|
288 | - 'byear' . $i => $row['birth_year'], |
|
289 | - 'byearest' . $i => $row['birth_year_est'], |
|
290 | - 'dyear' . $i => $row['death_year'], |
|
291 | - 'dyearest' . $i => $row['death_year_est'] |
|
292 | - ] |
|
293 | - ); |
|
294 | - } else { |
|
295 | - DB::table('maj_sosa')->updateOrInsert( |
|
296 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
297 | - [ |
|
298 | - 'majs_i_id' => $row['indi'], |
|
299 | - 'majs_gen' => $gen, |
|
300 | - 'majs_birth_year' => $row['birth_year'], |
|
301 | - 'majs_birth_year_est' => $row['birth_year_est'], |
|
302 | - 'majs_death_year' => $row['death_year'], |
|
303 | - 'majs_death_year_est' => $row['death_year_est'] |
|
304 | - ] |
|
305 | - ); |
|
306 | - } |
|
307 | - } |
|
308 | - } |
|
270 | + $bindings_placeholders = $bindings_values = []; |
|
271 | + $has_records = false; |
|
272 | + foreach ($sosa_records as $i => $row) { |
|
273 | + $gen = $this->generation($row['sosa']); |
|
274 | + if ($gen <= $this->maxSystemGenerations()) { |
|
275 | + $has_records = true; |
|
276 | + if ($mass_update) { |
|
277 | + $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | + ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | + ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | + $bindings_values = array_merge( |
|
281 | + $bindings_values, |
|
282 | + [ |
|
283 | + 'tree_id' . $i => $tree->id(), |
|
284 | + 'user_id' . $i => $user->id(), |
|
285 | + 'sosa' . $i => $row['sosa'], |
|
286 | + 'indi_id' . $i => $row['indi'], |
|
287 | + 'gen' . $i => $gen, |
|
288 | + 'byear' . $i => $row['birth_year'], |
|
289 | + 'byearest' . $i => $row['birth_year_est'], |
|
290 | + 'dyear' . $i => $row['death_year'], |
|
291 | + 'dyearest' . $i => $row['death_year_est'] |
|
292 | + ] |
|
293 | + ); |
|
294 | + } else { |
|
295 | + DB::table('maj_sosa')->updateOrInsert( |
|
296 | + [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
297 | + [ |
|
298 | + 'majs_i_id' => $row['indi'], |
|
299 | + 'majs_gen' => $gen, |
|
300 | + 'majs_birth_year' => $row['birth_year'], |
|
301 | + 'majs_birth_year_est' => $row['birth_year_est'], |
|
302 | + 'majs_death_year' => $row['death_year'], |
|
303 | + 'majs_death_year_est' => $row['death_year_est'] |
|
304 | + ] |
|
305 | + ); |
|
306 | + } |
|
307 | + } |
|
308 | + } |
|
309 | 309 | |
310 | - if ($has_records && $mass_update) { |
|
311 | - DB::connection()->statement( |
|
312 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
313 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
314 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
315 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
316 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
317 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
318 | - ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
319 | - $bindings_values |
|
320 | - ); |
|
321 | - } |
|
322 | - } |
|
310 | + if ($has_records && $mass_update) { |
|
311 | + DB::connection()->statement( |
|
312 | + 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
313 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
314 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
315 | + ' VALUES ' . implode(',', $bindings_placeholders) . |
|
316 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
317 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
318 | + ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
319 | + $bindings_values |
|
320 | + ); |
|
321 | + } |
|
322 | + } |
|
323 | 323 | } |
@@ -33,161 +33,161 @@ |
||
33 | 33 | */ |
34 | 34 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
35 | 35 | { |
36 | - use ModuleMyArtJaubTrait; |
|
37 | - use ModuleBlockTrait; |
|
38 | - |
|
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | - */ |
|
43 | - public function title(): string |
|
44 | - { |
|
45 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
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 “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.'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
61 | - */ |
|
62 | - public function loadRoutes(Map $router): void |
|
63 | - { |
|
64 | - $router->attach('', '', static function (Map $router): void { |
|
65 | - |
|
66 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
67 | - $router->tokens(['block_id' => '\d+']); |
|
68 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
69 | - }); |
|
70 | - }); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
76 | - */ |
|
77 | - public function customModuleVersion(): string |
|
78 | - { |
|
79 | - return '2.0.11-v.2'; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * {@inheritDoc} |
|
84 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
85 | - * |
|
86 | - * @param mixed[] $config |
|
87 | - */ |
|
88 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
89 | - { |
|
90 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
91 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | - |
|
93 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
94 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
95 | - |
|
96 | - $content = view($this->name() . '::block-embed', [ |
|
97 | - 'block_id' => $block_id, |
|
98 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
99 | - 'fab_login_block_view' => $fab_login_block_view, |
|
100 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
101 | - 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
102 | - ]); |
|
103 | - |
|
104 | - if ($context !== self::CONTEXT_EMBED) { |
|
105 | - return view('modules/block-template', [ |
|
106 | - 'block' => Str::kebab($this->name()), |
|
107 | - 'id' => $block_id, |
|
108 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
109 | - 'title' => $tree->title(), |
|
110 | - 'content' => $content, |
|
111 | - ]); |
|
112 | - } |
|
113 | - |
|
114 | - return $content; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * {@inheritDoc} |
|
119 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
120 | - */ |
|
121 | - public function isTreeBlock(): bool |
|
122 | - { |
|
123 | - return true; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * {@inheritDoc} |
|
128 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
129 | - */ |
|
130 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
131 | - { |
|
132 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * {@inheritDoc} |
|
137 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
138 | - */ |
|
139 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
140 | - { |
|
141 | - $params = (array) $request->getParsedBody(); |
|
142 | - |
|
143 | - $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
144 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
145 | - if (!$matomo_enabled) { |
|
146 | - return; |
|
147 | - } |
|
148 | - |
|
149 | - if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
150 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
155 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - $this |
|
160 | - ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
161 | - ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
162 | - ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
163 | - |
|
164 | - Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
169 | - * |
|
170 | - * @param int $block_id |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public function isMatomoEnabled(int $block_id): bool |
|
174 | - { |
|
175 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
180 | - * |
|
181 | - * @param int $block_id |
|
182 | - * @return array<string, mixed> |
|
183 | - */ |
|
184 | - public function matomoSettings(int $block_id): array |
|
185 | - { |
|
186 | - return [ |
|
187 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
188 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
189 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
190 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
191 | - ]; |
|
192 | - } |
|
36 | + use ModuleMyArtJaubTrait; |
|
37 | + use ModuleBlockTrait; |
|
38 | + |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | + */ |
|
43 | + public function title(): string |
|
44 | + { |
|
45 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
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 “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.'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
61 | + */ |
|
62 | + public function loadRoutes(Map $router): void |
|
63 | + { |
|
64 | + $router->attach('', '', static function (Map $router): void { |
|
65 | + |
|
66 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
67 | + $router->tokens(['block_id' => '\d+']); |
|
68 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
69 | + }); |
|
70 | + }); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
76 | + */ |
|
77 | + public function customModuleVersion(): string |
|
78 | + { |
|
79 | + return '2.0.11-v.2'; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * {@inheritDoc} |
|
84 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
85 | + * |
|
86 | + * @param mixed[] $config |
|
87 | + */ |
|
88 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
89 | + { |
|
90 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
91 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | + |
|
93 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
94 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
95 | + |
|
96 | + $content = view($this->name() . '::block-embed', [ |
|
97 | + 'block_id' => $block_id, |
|
98 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
99 | + 'fab_login_block_view' => $fab_login_block_view, |
|
100 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
101 | + 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
102 | + ]); |
|
103 | + |
|
104 | + if ($context !== self::CONTEXT_EMBED) { |
|
105 | + return view('modules/block-template', [ |
|
106 | + 'block' => Str::kebab($this->name()), |
|
107 | + 'id' => $block_id, |
|
108 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
109 | + 'title' => $tree->title(), |
|
110 | + 'content' => $content, |
|
111 | + ]); |
|
112 | + } |
|
113 | + |
|
114 | + return $content; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * {@inheritDoc} |
|
119 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
120 | + */ |
|
121 | + public function isTreeBlock(): bool |
|
122 | + { |
|
123 | + return true; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * {@inheritDoc} |
|
128 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
129 | + */ |
|
130 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
131 | + { |
|
132 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * {@inheritDoc} |
|
137 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
138 | + */ |
|
139 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
140 | + { |
|
141 | + $params = (array) $request->getParsedBody(); |
|
142 | + |
|
143 | + $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
144 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
145 | + if (!$matomo_enabled) { |
|
146 | + return; |
|
147 | + } |
|
148 | + |
|
149 | + if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
150 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
155 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + $this |
|
160 | + ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
161 | + ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
162 | + ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
163 | + |
|
164 | + Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
169 | + * |
|
170 | + * @param int $block_id |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public function isMatomoEnabled(int $block_id): bool |
|
174 | + { |
|
175 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
180 | + * |
|
181 | + * @param int $block_id |
|
182 | + * @return array<string, mixed> |
|
183 | + */ |
|
184 | + public function matomoSettings(int $block_id): array |
|
185 | + { |
|
186 | + return [ |
|
187 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
188 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
189 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
190 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
191 | + ]; |
|
192 | + } |
|
193 | 193 | } |
@@ -26,82 +26,82 @@ |
||
26 | 26 | */ |
27 | 27 | trait ModuleMyArtJaubTrait |
28 | 28 | { |
29 | - use ModuleCustomTrait; |
|
30 | - |
|
31 | - /** |
|
32 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
33 | - */ |
|
34 | - public function boot(): void |
|
35 | - { |
|
36 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | - |
|
38 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
43 | - */ |
|
44 | - public function resourcesFolder(): string |
|
45 | - { |
|
46 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
51 | - */ |
|
52 | - public function customModuleAuthorName(): string |
|
53 | - { |
|
54 | - return 'Jonathan Jaubart'; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
59 | - */ |
|
60 | - public function customModuleSupportUrl(): string |
|
61 | - { |
|
62 | - return 'https://github.com/jon48/webtrees-lib'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
67 | - * |
|
68 | - * @return array<string, string> |
|
69 | - */ |
|
70 | - public function customTranslations(string $language): array |
|
71 | - { |
|
72 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
73 | - |
|
74 | - try { |
|
75 | - $translation = new Translation($translation_file); |
|
76 | - return $translation->asArray(); |
|
77 | - } catch (\Exception $e) { |
|
78 | - } |
|
79 | - |
|
80 | - return []; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
85 | - * |
|
86 | - * @param Map<\Aura\Router\Route> $router |
|
87 | - */ |
|
88 | - public function loadRoutes(Map $router): void |
|
89 | - { |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
94 | - */ |
|
95 | - public function moduleCssUrl(): string |
|
96 | - { |
|
97 | - /** @var ModuleThemeInterface $theme */ |
|
98 | - $theme = app(ModuleThemeInterface::class); |
|
99 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
100 | - |
|
101 | - if (file_exists($css_file)) { |
|
102 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
103 | - } else { |
|
104 | - return $this->assetUrl('css/default.min.css'); |
|
105 | - } |
|
106 | - } |
|
29 | + use ModuleCustomTrait; |
|
30 | + |
|
31 | + /** |
|
32 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
33 | + */ |
|
34 | + public function boot(): void |
|
35 | + { |
|
36 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | + |
|
38 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
43 | + */ |
|
44 | + public function resourcesFolder(): string |
|
45 | + { |
|
46 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
51 | + */ |
|
52 | + public function customModuleAuthorName(): string |
|
53 | + { |
|
54 | + return 'Jonathan Jaubart'; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
59 | + */ |
|
60 | + public function customModuleSupportUrl(): string |
|
61 | + { |
|
62 | + return 'https://github.com/jon48/webtrees-lib'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
67 | + * |
|
68 | + * @return array<string, string> |
|
69 | + */ |
|
70 | + public function customTranslations(string $language): array |
|
71 | + { |
|
72 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
73 | + |
|
74 | + try { |
|
75 | + $translation = new Translation($translation_file); |
|
76 | + return $translation->asArray(); |
|
77 | + } catch (\Exception $e) { |
|
78 | + } |
|
79 | + |
|
80 | + return []; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
85 | + * |
|
86 | + * @param Map<\Aura\Router\Route> $router |
|
87 | + */ |
|
88 | + public function loadRoutes(Map $router): void |
|
89 | + { |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
94 | + */ |
|
95 | + public function moduleCssUrl(): string |
|
96 | + { |
|
97 | + /** @var ModuleThemeInterface $theme */ |
|
98 | + $theme = app(ModuleThemeInterface::class); |
|
99 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
100 | + |
|
101 | + if (file_exists($css_file)) { |
|
102 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
103 | + } else { |
|
104 | + return $this->assetUrl('css/default.min.css'); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | } |
@@ -32,129 +32,129 @@ |
||
32 | 32 | */ |
33 | 33 | class CertificateFilesystemService |
34 | 34 | { |
35 | - /** |
|
36 | - * @var array<int,FilesystemOperator> $filesystem |
|
37 | - */ |
|
38 | - private array $filesystem = []; |
|
35 | + /** |
|
36 | + * @var array<int,FilesystemOperator> $filesystem |
|
37 | + */ |
|
38 | + private array $filesystem = []; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get the filesystem containing certificates for a tree. |
|
42 | - * |
|
43 | - * @param Tree $tree |
|
44 | - * @return FilesystemOperator |
|
45 | - */ |
|
46 | - public function filesystem(Tree $tree): FilesystemOperator |
|
47 | - { |
|
48 | - if (!isset($this->filesystem[$tree->id()])) { |
|
49 | - $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
50 | - $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
40 | + /** |
|
41 | + * Get the filesystem containing certificates for a tree. |
|
42 | + * |
|
43 | + * @param Tree $tree |
|
44 | + * @return FilesystemOperator |
|
45 | + */ |
|
46 | + public function filesystem(Tree $tree): FilesystemOperator |
|
47 | + { |
|
48 | + if (!isset($this->filesystem[$tree->id()])) { |
|
49 | + $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
50 | + $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
51 | 51 | |
52 | - $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
53 | - } |
|
54 | - return $this->filesystem[$tree->id()]; |
|
55 | - } |
|
52 | + $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
53 | + } |
|
54 | + return $this->filesystem[$tree->id()]; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Set the filesystem containing certificates for a tree. |
|
59 | - * |
|
60 | - * @param Tree $tree |
|
61 | - * @param FilesystemOperator $filesystem |
|
62 | - */ |
|
63 | - public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
64 | - { |
|
65 | - $this->filesystem[$tree->id()] = $filesystem; |
|
66 | - } |
|
57 | + /** |
|
58 | + * Set the filesystem containing certificates for a tree. |
|
59 | + * |
|
60 | + * @param Tree $tree |
|
61 | + * @param FilesystemOperator $filesystem |
|
62 | + */ |
|
63 | + public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
64 | + { |
|
65 | + $this->filesystem[$tree->id()] = $filesystem; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Create the Certificate object defined by a path on the filesystem. |
|
70 | - * |
|
71 | - * @param Tree $tree |
|
72 | - * @param string $path |
|
73 | - * @return Certificate|NULL |
|
74 | - */ |
|
75 | - public function certificate(Tree $tree, string $path): ?Certificate |
|
76 | - { |
|
77 | - $filesystem = $this->filesystem($tree); |
|
78 | - if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
79 | - return new Certificate($tree, $path); |
|
80 | - } |
|
81 | - return null; |
|
82 | - } |
|
68 | + /** |
|
69 | + * Create the Certificate object defined by a path on the filesystem. |
|
70 | + * |
|
71 | + * @param Tree $tree |
|
72 | + * @param string $path |
|
73 | + * @return Certificate|NULL |
|
74 | + */ |
|
75 | + public function certificate(Tree $tree, string $path): ?Certificate |
|
76 | + { |
|
77 | + $filesystem = $this->filesystem($tree); |
|
78 | + if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
79 | + return new Certificate($tree, $path); |
|
80 | + } |
|
81 | + return null; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get the cities (first-level folder) available in a the filesystem. |
|
86 | - * |
|
87 | - * @param Tree $tree |
|
88 | - * @return string[] |
|
89 | - */ |
|
90 | - public function cities(Tree $tree): array |
|
91 | - { |
|
92 | - $cities = $this->filesystem($tree) |
|
93 | - ->listContents('') |
|
94 | - ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
96 | - ->toArray(); |
|
97 | - usort($cities, I18N::comparator()); |
|
98 | - return $cities; |
|
99 | - } |
|
84 | + /** |
|
85 | + * Get the cities (first-level folder) available in a the filesystem. |
|
86 | + * |
|
87 | + * @param Tree $tree |
|
88 | + * @return string[] |
|
89 | + */ |
|
90 | + public function cities(Tree $tree): array |
|
91 | + { |
|
92 | + $cities = $this->filesystem($tree) |
|
93 | + ->listContents('') |
|
94 | + ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
96 | + ->toArray(); |
|
97 | + usort($cities, I18N::comparator()); |
|
98 | + return $cities; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the certificates available for a city (first-level folder). |
|
103 | - * |
|
104 | - * @param Tree $tree |
|
105 | - * @param string $city |
|
106 | - * @return Collection<Certificate> |
|
107 | - */ |
|
108 | - public function certificatesForCity(Tree $tree, string $city): Collection |
|
109 | - { |
|
110 | - $filesystem = $this->filesystem($tree); |
|
111 | - $certificates_paths = $filesystem->listContents($city) |
|
112 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
113 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
114 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
115 | - ->toArray(); |
|
116 | - usort($certificates_paths, I18N::comparator()); |
|
117 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
118 | - } |
|
101 | + /** |
|
102 | + * Get the certificates available for a city (first-level folder). |
|
103 | + * |
|
104 | + * @param Tree $tree |
|
105 | + * @param string $city |
|
106 | + * @return Collection<Certificate> |
|
107 | + */ |
|
108 | + public function certificatesForCity(Tree $tree, string $city): Collection |
|
109 | + { |
|
110 | + $filesystem = $this->filesystem($tree); |
|
111 | + $certificates_paths = $filesystem->listContents($city) |
|
112 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
113 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
114 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
115 | + ->toArray(); |
|
116 | + usort($certificates_paths, I18N::comparator()); |
|
117 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Get the certificates available for a city (first-level folder), containing a specified text. |
|
122 | - * |
|
123 | - * @param Tree $tree |
|
124 | - * @param string $city |
|
125 | - * @param string $contains |
|
126 | - * @return Collection<Certificate> |
|
127 | - */ |
|
128 | - public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
129 | - { |
|
130 | - $filesystem = $this->filesystem($tree); |
|
131 | - $certificates_paths = $filesystem->listContents($city) |
|
132 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
133 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
134 | - && mb_stripos($attributes->path(), $contains) !== false) |
|
135 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
136 | - ->toArray(); |
|
137 | - usort($certificates_paths, I18N::comparator()); |
|
138 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
139 | - } |
|
120 | + /** |
|
121 | + * Get the certificates available for a city (first-level folder), containing a specified text. |
|
122 | + * |
|
123 | + * @param Tree $tree |
|
124 | + * @param string $city |
|
125 | + * @param string $contains |
|
126 | + * @return Collection<Certificate> |
|
127 | + */ |
|
128 | + public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
129 | + { |
|
130 | + $filesystem = $this->filesystem($tree); |
|
131 | + $certificates_paths = $filesystem->listContents($city) |
|
132 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
133 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
134 | + && mb_stripos($attributes->path(), $contains) !== false) |
|
135 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
136 | + ->toArray(); |
|
137 | + usort($certificates_paths, I18N::comparator()); |
|
138 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Check if a file on the filesystem is supported by the certificate module. |
|
143 | - * |
|
144 | - * @param FilesystemOperator $filesystem |
|
145 | - * @param string $path |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
149 | - { |
|
150 | - try { |
|
151 | - $mime = $filesystem->mimeType($path); |
|
152 | - return Registry::cache()->array()->remember( |
|
153 | - 'maj-certif-supportedfiles-' . $mime, |
|
154 | - fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
155 | - ); |
|
156 | - } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
157 | - } |
|
158 | - return false; |
|
159 | - } |
|
141 | + /** |
|
142 | + * Check if a file on the filesystem is supported by the certificate module. |
|
143 | + * |
|
144 | + * @param FilesystemOperator $filesystem |
|
145 | + * @param string $path |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
149 | + { |
|
150 | + try { |
|
151 | + $mime = $filesystem->mimeType($path); |
|
152 | + return Registry::cache()->array()->remember( |
|
153 | + 'maj-certif-supportedfiles-' . $mime, |
|
154 | + fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
155 | + ); |
|
156 | + } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
157 | + } |
|
158 | + return false; |
|
159 | + } |
|
160 | 160 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | if (!isset($this->filesystem[$tree->id()])) { |
49 | 49 | $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
50 | - $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
50 | + $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
51 | 51 | |
52 | 52 | $this->filesystem[$tree->id()] = new FileSystem($adapter); |
53 | 53 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function cities(Tree $tree): array |
91 | 91 | { |
92 | - $cities = $this->filesystem($tree) |
|
92 | + $cities = $this->filesystem($tree) |
|
93 | 93 | ->listContents('') |
94 | - ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
94 | + ->filter(fn(StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | + ->map(fn(StorageAttributes $attributes): string => $attributes->path()) |
|
96 | 96 | ->toArray(); |
97 | 97 | usort($cities, I18N::comparator()); |
98 | 98 | return $cities; |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | { |
110 | 110 | $filesystem = $this->filesystem($tree); |
111 | 111 | $certificates_paths = $filesystem->listContents($city) |
112 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
112 | + ->filter(fn(StorageAttributes $attributes): bool => |
|
113 | 113 | $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
114 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
114 | + ->map(fn(StorageAttributes $attributes): string => $attributes->path()) |
|
115 | 115 | ->toArray(); |
116 | 116 | usort($certificates_paths, I18N::comparator()); |
117 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
117 | + return collect($certificates_paths)->map(fn(string $path): Certificate => new Certificate($tree, $path)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | { |
130 | 130 | $filesystem = $this->filesystem($tree); |
131 | 131 | $certificates_paths = $filesystem->listContents($city) |
132 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
132 | + ->filter(fn(StorageAttributes $attributes): bool => |
|
133 | 133 | $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
134 | 134 | && mb_stripos($attributes->path(), $contains) !== false) |
135 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
135 | + ->map(fn(StorageAttributes $attributes): string => $attributes->path()) |
|
136 | 136 | ->toArray(); |
137 | 137 | usort($certificates_paths, I18N::comparator()); |
138 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
138 | + return collect($certificates_paths)->map(fn(string $path): Certificate => new Certificate($tree, $path)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | try { |
151 | 151 | $mime = $filesystem->mimeType($path); |
152 | 152 | return Registry::cache()->array()->remember( |
153 | - 'maj-certif-supportedfiles-' . $mime, |
|
154 | - fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
153 | + 'maj-certif-supportedfiles-'.$mime, |
|
154 | + fn(): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
155 | 155 | ); |
156 | 156 | } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
157 | 157 | } |
@@ -29,144 +29,144 @@ |
||
29 | 29 | class CertificateDataService |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Find individuals linked to a certificate. |
|
34 | - * |
|
35 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
36 | - * but does not work with Sqlite if no default escape has been defined} |
|
37 | - * |
|
38 | - * @param Certificate $certificate |
|
39 | - * @return Collection<\Fisharebest\Webtrees\Individual> |
|
40 | - */ |
|
41 | - public function linkedIndividuals(Certificate $certificate): Collection |
|
42 | - { |
|
43 | - $tree = $certificate->tree(); |
|
44 | - return DB::table('individuals') |
|
45 | - ->where('i_file', '=', $tree->id()) |
|
46 | - ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
47 | - ->select(['individuals.*']) |
|
48 | - ->get() |
|
49 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
50 | - ->filter(GedcomRecord::accessFilter()); |
|
51 | - } |
|
32 | + /** |
|
33 | + * Find individuals linked to a certificate. |
|
34 | + * |
|
35 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
36 | + * but does not work with Sqlite if no default escape has been defined} |
|
37 | + * |
|
38 | + * @param Certificate $certificate |
|
39 | + * @return Collection<\Fisharebest\Webtrees\Individual> |
|
40 | + */ |
|
41 | + public function linkedIndividuals(Certificate $certificate): Collection |
|
42 | + { |
|
43 | + $tree = $certificate->tree(); |
|
44 | + return DB::table('individuals') |
|
45 | + ->where('i_file', '=', $tree->id()) |
|
46 | + ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
47 | + ->select(['individuals.*']) |
|
48 | + ->get() |
|
49 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
50 | + ->filter(GedcomRecord::accessFilter()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Find families linked to a certificate. |
|
55 | - * |
|
56 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
57 | - * but does not work with Sqlite if no default escape has been defined} |
|
58 | - * |
|
59 | - * @param Certificate $certificate |
|
60 | - * @return Collection<\Fisharebest\Webtrees\Family> |
|
61 | - */ |
|
62 | - public function linkedFamilies(Certificate $certificate): Collection |
|
63 | - { |
|
64 | - $tree = $certificate->tree(); |
|
65 | - return DB::table('families') |
|
66 | - ->where('f_file', '=', $tree->id()) |
|
67 | - ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
68 | - ->select(['families.*']) |
|
69 | - ->get() |
|
70 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
71 | - ->filter(GedcomRecord::accessFilter()); |
|
72 | - } |
|
53 | + /** |
|
54 | + * Find families linked to a certificate. |
|
55 | + * |
|
56 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
57 | + * but does not work with Sqlite if no default escape has been defined} |
|
58 | + * |
|
59 | + * @param Certificate $certificate |
|
60 | + * @return Collection<\Fisharebest\Webtrees\Family> |
|
61 | + */ |
|
62 | + public function linkedFamilies(Certificate $certificate): Collection |
|
63 | + { |
|
64 | + $tree = $certificate->tree(); |
|
65 | + return DB::table('families') |
|
66 | + ->where('f_file', '=', $tree->id()) |
|
67 | + ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
68 | + ->select(['families.*']) |
|
69 | + ->get() |
|
70 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
71 | + ->filter(GedcomRecord::accessFilter()); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Find media objects linked to a certificate. |
|
76 | - * |
|
77 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
78 | - * but does not work with Sqlite if no default escape has been defined} |
|
79 | - * |
|
80 | - * @param Certificate $certificate |
|
81 | - * @return Collection<\Fisharebest\Webtrees\Media> |
|
82 | - */ |
|
83 | - public function linkedMedias(Certificate $certificate): Collection |
|
84 | - { |
|
85 | - $tree = $certificate->tree(); |
|
86 | - return DB::table('media') |
|
87 | - ->where('m_file', '=', $tree->id()) |
|
88 | - ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
89 | - ->select(['media.*']) |
|
90 | - ->get() |
|
91 | - ->map(Registry::mediaFactory()->mapper($tree)) |
|
92 | - ->filter(GedcomRecord::accessFilter()); |
|
93 | - } |
|
74 | + /** |
|
75 | + * Find media objects linked to a certificate. |
|
76 | + * |
|
77 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
78 | + * but does not work with Sqlite if no default escape has been defined} |
|
79 | + * |
|
80 | + * @param Certificate $certificate |
|
81 | + * @return Collection<\Fisharebest\Webtrees\Media> |
|
82 | + */ |
|
83 | + public function linkedMedias(Certificate $certificate): Collection |
|
84 | + { |
|
85 | + $tree = $certificate->tree(); |
|
86 | + return DB::table('media') |
|
87 | + ->where('m_file', '=', $tree->id()) |
|
88 | + ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
89 | + ->select(['media.*']) |
|
90 | + ->get() |
|
91 | + ->map(Registry::mediaFactory()->mapper($tree)) |
|
92 | + ->filter(GedcomRecord::accessFilter()); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Find notes linked to a certificate. |
|
97 | - * |
|
98 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
99 | - * but does not work with Sqlite if no default escape has been defined} |
|
100 | - * |
|
101 | - * @param Certificate $certificate |
|
102 | - * @return Collection<\Fisharebest\Webtrees\Note> |
|
103 | - */ |
|
104 | - public function linkedNotes(Certificate $certificate): Collection |
|
105 | - { |
|
106 | - $tree = $certificate->tree(); |
|
107 | - return DB::table('other') |
|
108 | - ->where('o_file', '=', $tree->id()) |
|
109 | - ->where('o_type', '=', 'NOTE') |
|
110 | - ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
111 | - ->select(['other.*']) |
|
112 | - ->get() |
|
113 | - ->map(Registry::noteFactory()->mapper($tree)) |
|
114 | - ->filter(GedcomRecord::accessFilter()); |
|
115 | - } |
|
95 | + /** |
|
96 | + * Find notes linked to a certificate. |
|
97 | + * |
|
98 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
99 | + * but does not work with Sqlite if no default escape has been defined} |
|
100 | + * |
|
101 | + * @param Certificate $certificate |
|
102 | + * @return Collection<\Fisharebest\Webtrees\Note> |
|
103 | + */ |
|
104 | + public function linkedNotes(Certificate $certificate): Collection |
|
105 | + { |
|
106 | + $tree = $certificate->tree(); |
|
107 | + return DB::table('other') |
|
108 | + ->where('o_file', '=', $tree->id()) |
|
109 | + ->where('o_type', '=', 'NOTE') |
|
110 | + ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
111 | + ->select(['other.*']) |
|
112 | + ->get() |
|
113 | + ->map(Registry::noteFactory()->mapper($tree)) |
|
114 | + ->filter(GedcomRecord::accessFilter()); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Return an escaped string to be used in SQL LIKE comparisons. |
|
119 | - * This would not work well for Sqlite, if the escape character is not defined. |
|
120 | - * |
|
121 | - * @param Certificate $certificate |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - protected function escapedSqlPath(Certificate $certificate): string |
|
125 | - { |
|
126 | - return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
127 | - } |
|
117 | + /** |
|
118 | + * Return an escaped string to be used in SQL LIKE comparisons. |
|
119 | + * This would not work well for Sqlite, if the escape character is not defined. |
|
120 | + * |
|
121 | + * @param Certificate $certificate |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + protected function escapedSqlPath(Certificate $certificate): string |
|
125 | + { |
|
126 | + return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Find a source linked to a citation where a certificate file is referenced. |
|
131 | - * |
|
132 | - * @param Certificate $certificate |
|
133 | - * @return Source|NULL |
|
134 | - */ |
|
135 | - public function oneLinkedSource(Certificate $certificate): ?Source |
|
136 | - { |
|
137 | - $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
138 | - $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
129 | + /** |
|
130 | + * Find a source linked to a citation where a certificate file is referenced. |
|
131 | + * |
|
132 | + * @param Certificate $certificate |
|
133 | + * @return Source|NULL |
|
134 | + */ |
|
135 | + public function oneLinkedSource(Certificate $certificate): ?Source |
|
136 | + { |
|
137 | + $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
138 | + $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
139 | 139 | |
140 | - foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
141 | - foreach ($linked_records as $gedcom_record) { |
|
142 | - foreach ($gedcom_record->facts() as $fact) { |
|
143 | - if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
144 | - foreach ($matches as $match) { |
|
145 | - $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
146 | - if ($source !== null && $source->canShowName()) { |
|
147 | - return $source; |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
140 | + foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
141 | + foreach ($linked_records as $gedcom_record) { |
|
142 | + foreach ($gedcom_record->facts() as $fact) { |
|
143 | + if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
144 | + foreach ($matches as $match) { |
|
145 | + $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
146 | + if ($source !== null && $source->canShowName()) { |
|
147 | + return $source; |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - return null; |
|
156 | - } |
|
155 | + return null; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Yield lists of gedcom records linked to a certificate. |
|
160 | - * |
|
161 | - * @param Certificate $certificate |
|
162 | - * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
163 | - * @psalm-suppress InvalidReturnType |
|
164 | - */ |
|
165 | - protected function linkedRecordsLists(Certificate $certificate): Generator |
|
166 | - { |
|
167 | - yield $this->linkedIndividuals($certificate); |
|
168 | - yield $this->linkedFamilies($certificate); |
|
169 | - yield $this->linkedMedias($certificate); |
|
170 | - yield $this->linkedNotes($certificate); |
|
171 | - } |
|
158 | + /** |
|
159 | + * Yield lists of gedcom records linked to a certificate. |
|
160 | + * |
|
161 | + * @param Certificate $certificate |
|
162 | + * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
163 | + * @psalm-suppress InvalidReturnType |
|
164 | + */ |
|
165 | + protected function linkedRecordsLists(Certificate $certificate): Generator |
|
166 | + { |
|
167 | + yield $this->linkedIndividuals($certificate); |
|
168 | + yield $this->linkedFamilies($certificate); |
|
169 | + yield $this->linkedMedias($certificate); |
|
170 | + yield $this->linkedNotes($certificate); |
|
171 | + } |
|
172 | 172 | } |
@@ -25,193 +25,193 @@ |
||
25 | 25 | */ |
26 | 26 | class Certificate |
27 | 27 | { |
28 | - /** |
|
29 | - * Pattern to extract information from a file name. |
|
30 | - * Specific to the author's workflow. |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | - |
|
35 | - private Tree $tree; |
|
36 | - private string $path; |
|
37 | - private ?string $city = null; |
|
38 | - private ?string $basename = null; |
|
39 | - private ?string $filename = null; |
|
40 | - private ?string $extension = null; |
|
41 | - private ?string $type = null; |
|
42 | - private ?string $description = null; |
|
43 | - private ?Date $date = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * Contructor for Certificate |
|
47 | - * |
|
48 | - * @param Tree $tree |
|
49 | - * @param string $path |
|
50 | - */ |
|
51 | - public function __construct(Tree $tree, string $path) |
|
52 | - { |
|
53 | - $this->tree = $tree; |
|
54 | - $this->path = $path; |
|
55 | - $this->extractDataFromPath($path); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | - * Logic specific to the author. |
|
61 | - * |
|
62 | - * @param string $path |
|
63 | - */ |
|
64 | - protected function extractDataFromPath(string $path): void |
|
65 | - { |
|
66 | - $path_parts = pathinfo($path); |
|
67 | - $this->city = $path_parts['dirname']; |
|
68 | - $this->basename = $path_parts['basename']; |
|
69 | - $this->filename = $path_parts['filename']; |
|
70 | - $this->extension = strtolower($path_parts['extension'] ?? ''); |
|
71 | - |
|
72 | - if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | - $this->type = $match['type']; |
|
74 | - $this->description = $match['descr']; |
|
75 | - |
|
76 | - $day = $match['day'] ?? ''; |
|
77 | - $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | - $year = $match['year'] ?? ''; |
|
80 | - |
|
81 | - $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | - } else { |
|
83 | - $this->description = $this->filename; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get the family tree of the certificate |
|
89 | - * |
|
90 | - * @return Tree |
|
91 | - */ |
|
92 | - public function tree(): Tree |
|
93 | - { |
|
94 | - return $this->tree; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get the path of the certificate in the file system. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function path(): string |
|
103 | - { |
|
104 | - return $this->path; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * The the path of the certificate, in a Gedcom canonical form. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function gedcomPath(): string |
|
113 | - { |
|
114 | - return str_replace('\\', '/', $this->path); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get the certificate name. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function name(): string |
|
123 | - { |
|
124 | - return $this->filename ?? ''; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get the certificate file name. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function filename(): string |
|
133 | - { |
|
134 | - return $this->basename ?? ''; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get the certificate's city (the first level folder). |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function city(): string |
|
143 | - { |
|
144 | - return $this->city ?? ''; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the certificate's date. Extracted from the file name. |
|
149 | - * |
|
150 | - * @return Date |
|
151 | - */ |
|
152 | - public function date(): Date |
|
153 | - { |
|
154 | - return $this->date ?? new Date(''); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Get the certificate's type. Extracted from the file name. |
|
159 | - * |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function type(): string |
|
163 | - { |
|
164 | - return $this->type ?? ''; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the certificate's description. Extracted from the file name. |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function description(): string |
|
172 | - { |
|
173 | - return $this->description ?? ''; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Get the certificate's description to be used for sorting. |
|
178 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function sortDescription(): string |
|
183 | - { |
|
184 | - $sort_prefix = ''; |
|
185 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | - return $match[1]; |
|
188 | - }, $matches)) . '_'; |
|
189 | - } |
|
190 | - return $sort_prefix . $this->description(); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get the certificate's MIME type. |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function mimeType(): string |
|
199 | - { |
|
200 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the base parameters to be used in url referencing the certificate. |
|
205 | - * |
|
206 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | - * @return array{tree: string, cid: mixed} |
|
208 | - */ |
|
209 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | - { |
|
211 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | - return [ |
|
213 | - 'tree' => $this->tree->name(), |
|
214 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | - ]; |
|
216 | - } |
|
28 | + /** |
|
29 | + * Pattern to extract information from a file name. |
|
30 | + * Specific to the author's workflow. |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | + |
|
35 | + private Tree $tree; |
|
36 | + private string $path; |
|
37 | + private ?string $city = null; |
|
38 | + private ?string $basename = null; |
|
39 | + private ?string $filename = null; |
|
40 | + private ?string $extension = null; |
|
41 | + private ?string $type = null; |
|
42 | + private ?string $description = null; |
|
43 | + private ?Date $date = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * Contructor for Certificate |
|
47 | + * |
|
48 | + * @param Tree $tree |
|
49 | + * @param string $path |
|
50 | + */ |
|
51 | + public function __construct(Tree $tree, string $path) |
|
52 | + { |
|
53 | + $this->tree = $tree; |
|
54 | + $this->path = $path; |
|
55 | + $this->extractDataFromPath($path); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | + * Logic specific to the author. |
|
61 | + * |
|
62 | + * @param string $path |
|
63 | + */ |
|
64 | + protected function extractDataFromPath(string $path): void |
|
65 | + { |
|
66 | + $path_parts = pathinfo($path); |
|
67 | + $this->city = $path_parts['dirname']; |
|
68 | + $this->basename = $path_parts['basename']; |
|
69 | + $this->filename = $path_parts['filename']; |
|
70 | + $this->extension = strtolower($path_parts['extension'] ?? ''); |
|
71 | + |
|
72 | + if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | + $this->type = $match['type']; |
|
74 | + $this->description = $match['descr']; |
|
75 | + |
|
76 | + $day = $match['day'] ?? ''; |
|
77 | + $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | + $year = $match['year'] ?? ''; |
|
80 | + |
|
81 | + $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | + } else { |
|
83 | + $this->description = $this->filename; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get the family tree of the certificate |
|
89 | + * |
|
90 | + * @return Tree |
|
91 | + */ |
|
92 | + public function tree(): Tree |
|
93 | + { |
|
94 | + return $this->tree; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get the path of the certificate in the file system. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function path(): string |
|
103 | + { |
|
104 | + return $this->path; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * The the path of the certificate, in a Gedcom canonical form. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function gedcomPath(): string |
|
113 | + { |
|
114 | + return str_replace('\\', '/', $this->path); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get the certificate name. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function name(): string |
|
123 | + { |
|
124 | + return $this->filename ?? ''; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get the certificate file name. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function filename(): string |
|
133 | + { |
|
134 | + return $this->basename ?? ''; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get the certificate's city (the first level folder). |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function city(): string |
|
143 | + { |
|
144 | + return $this->city ?? ''; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the certificate's date. Extracted from the file name. |
|
149 | + * |
|
150 | + * @return Date |
|
151 | + */ |
|
152 | + public function date(): Date |
|
153 | + { |
|
154 | + return $this->date ?? new Date(''); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Get the certificate's type. Extracted from the file name. |
|
159 | + * |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function type(): string |
|
163 | + { |
|
164 | + return $this->type ?? ''; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the certificate's description. Extracted from the file name. |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function description(): string |
|
172 | + { |
|
173 | + return $this->description ?? ''; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Get the certificate's description to be used for sorting. |
|
178 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function sortDescription(): string |
|
183 | + { |
|
184 | + $sort_prefix = ''; |
|
185 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | + return $match[1]; |
|
188 | + }, $matches)) . '_'; |
|
189 | + } |
|
190 | + return $sort_prefix . $this->description(); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get the certificate's MIME type. |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function mimeType(): string |
|
199 | + { |
|
200 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the base parameters to be used in url referencing the certificate. |
|
205 | + * |
|
206 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | + * @return array{tree: string, cid: mixed} |
|
208 | + */ |
|
209 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | + { |
|
211 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | + return [ |
|
213 | + 'tree' => $this->tree->name(), |
|
214 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | + ]; |
|
216 | + } |
|
217 | 217 | } |
@@ -21,19 +21,19 @@ |
||
21 | 21 | */ |
22 | 22 | interface ModuleMyArtJaubInterface extends ModuleCustomInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Add module routes to webtrees route loader |
|
26 | - * |
|
27 | - * @param Map<\Aura\Router\Route> $router |
|
28 | - */ |
|
29 | - public function loadRoutes(Map $router): void; |
|
24 | + /** |
|
25 | + * Add module routes to webtrees route loader |
|
26 | + * |
|
27 | + * @param Map<\Aura\Router\Route> $router |
|
28 | + */ |
|
29 | + public function loadRoutes(Map $router): void; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Returns the URL of the module specific stylesheets. |
|
33 | - * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
34 | - * and fallback to default.min.css if none are found |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function moduleCssUrl(): string; |
|
31 | + /** |
|
32 | + * Returns the URL of the module specific stylesheets. |
|
33 | + * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
34 | + * and fallback to default.min.css if none are found |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function moduleCssUrl(): string; |
|
39 | 39 | } |
@@ -30,126 +30,126 @@ |
||
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 string[] $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 | - if ($source_status->isFullySourced()) { |
|
115 | - return $source_status; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $source_status; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Return the status of source citations for an individual's birth events. |
|
124 | - * |
|
125 | - * @param Individual $individual |
|
126 | - * @return FactSourceStatus |
|
127 | - */ |
|
128 | - public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
129 | - { |
|
130 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Return the status of source citations for an individual's death events. |
|
135 | - * |
|
136 | - * @param Individual $individual |
|
137 | - * @return FactSourceStatus |
|
138 | - */ |
|
139 | - public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
140 | - { |
|
141 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Return the status of source citations for a family's marriage events. |
|
146 | - * |
|
147 | - * @param Family $family |
|
148 | - * @return FactSourceStatus |
|
149 | - */ |
|
150 | - public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
151 | - { |
|
152 | - $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']); |
|
153 | - return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
154 | - } |
|
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 string[] $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 | + if ($source_status->isFullySourced()) { |
|
115 | + return $source_status; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $source_status; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Return the status of source citations for an individual's birth events. |
|
124 | + * |
|
125 | + * @param Individual $individual |
|
126 | + * @return FactSourceStatus |
|
127 | + */ |
|
128 | + public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
129 | + { |
|
130 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Return the status of source citations for an individual's death events. |
|
135 | + * |
|
136 | + * @param Individual $individual |
|
137 | + * @return FactSourceStatus |
|
138 | + */ |
|
139 | + public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
140 | + { |
|
141 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Return the status of source citations for a family's marriage events. |
|
146 | + * |
|
147 | + * @param Family $family |
|
148 | + * @return FactSourceStatus |
|
149 | + */ |
|
150 | + public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
151 | + { |
|
152 | + $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']); |
|
153 | + return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
154 | + } |
|
155 | 155 | } |
@@ -39,213 +39,213 @@ |
||
39 | 39 | */ |
40 | 40 | class Migration2 implements MigrationInterface |
41 | 41 | { |
42 | - /** |
|
43 | - * Mapping from old map definitions to new ones |
|
44 | - * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | - */ |
|
46 | - private const MAPS_XML_MAPPING = [ |
|
47 | - 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | - 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | - 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | - 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | - 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | - 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | - 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | - 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | - 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | - 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | - 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | - 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | - 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | - 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | - 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | - 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | - 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | - 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | - 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | - 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | - 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | - 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | - 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | - 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | - ]; |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | - */ |
|
77 | - public function upgrade(): void |
|
78 | - { |
|
79 | - if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - /** @var TreeService $tree_service */ |
|
84 | - $tree_service = app(TreeService::class); |
|
85 | - /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | - $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
87 | - |
|
88 | - $existing_views = DB::table('maj_geodispersion') |
|
89 | - ->select() |
|
90 | - ->get(); |
|
91 | - |
|
92 | - foreach ($existing_views as $old_view) { |
|
93 | - try { |
|
94 | - $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | - } catch (RuntimeException $ex) { |
|
96 | - continue; |
|
97 | - } |
|
98 | - |
|
99 | - if ($old_view->majgd_map === null) { |
|
100 | - $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | - } else { |
|
102 | - DB::connection()->beginTransaction(); |
|
103 | - if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | - DB::connection()->commit(); |
|
105 | - } else { |
|
106 | - DB::connection()->rollBack(); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - DB::schema()->drop('maj_geodispersion'); |
|
112 | - |
|
113 | - FlashMessages::addMessage(I18N::translate( |
|
114 | - 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
115 | - )); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Create a Table geographical analysis view from a migrated item. |
|
120 | - * |
|
121 | - * @param stdClass $old_view |
|
122 | - * @param Tree $tree |
|
123 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - private function migrateGeoAnalysisTable( |
|
127 | - stdClass $old_view, |
|
128 | - Tree $tree, |
|
129 | - GeoAnalysisViewDataService $geoview_data_service |
|
130 | - ): bool { |
|
131 | - $new_view = new GeoAnalysisTable( |
|
132 | - 0, |
|
133 | - $tree, |
|
134 | - $old_view->majgd_status === 'enabled', |
|
135 | - $old_view->majgd_descr, |
|
136 | - app(SosaByGenerationGeoAnalysis::class), |
|
137 | - (int) $old_view->majgd_sublevel, |
|
138 | - (int) $old_view->majgd_detailsgen |
|
139 | - ); |
|
140 | - |
|
141 | - return $geoview_data_service->insertGetId($new_view) > 0; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Create a Map geographical analysis view from a migrated item. |
|
146 | - * |
|
147 | - * @param stdClass $old_view |
|
148 | - * @param Tree $tree |
|
149 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - private function migrateGeoAnalysisMap( |
|
153 | - stdClass $old_view, |
|
154 | - Tree $tree, |
|
155 | - GeoAnalysisViewDataService $geoview_data_service |
|
156 | - ): bool { |
|
157 | - /** @var MapDefinitionsService $map_definition_service */ |
|
158 | - $map_definition_service = app(MapDefinitionsService::class); |
|
159 | - /** @var MapAdapterDataService $mapadapter_data_service */ |
|
160 | - $mapadapter_data_service = app(MapAdapterDataService::class); |
|
161 | - |
|
162 | - $new_view = new GeoAnalysisMap( |
|
163 | - 0, |
|
164 | - $tree, |
|
165 | - $old_view->majgd_status === 'enabled', |
|
166 | - $old_view->majgd_descr, |
|
167 | - app(SosaByGenerationGeoAnalysis::class), |
|
168 | - (int) $old_view->majgd_sublevel, |
|
169 | - (int) $old_view->majgd_detailsgen |
|
170 | - ); |
|
171 | - |
|
172 | - $view_id = $geoview_data_service->insertGetId($new_view); |
|
173 | - if ($view_id === 0) { |
|
174 | - return false; |
|
175 | - } |
|
176 | - $new_view = $new_view->withId($view_id); |
|
177 | - |
|
178 | - $colors = $new_view->colors(); |
|
179 | - foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
180 | - $map = $map_definition_service->find($new_map_id); |
|
181 | - if ($map === null) { |
|
182 | - return false; |
|
183 | - } |
|
184 | - $colors = $this->colorsFromMap($new_map_id); |
|
185 | - |
|
186 | - /** @var SimplePlaceMapper $mapper */ |
|
187 | - $mapper = app(SimplePlaceMapper::class); |
|
188 | - $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
189 | - $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
190 | - |
|
191 | - $mapadapter_data_service->insertGetId($map_adapter); |
|
192 | - } |
|
193 | - |
|
194 | - return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get all new map definitions IDs representing an old map definition |
|
199 | - * |
|
200 | - * @param string $map_xml |
|
201 | - * @return string[] |
|
202 | - */ |
|
203 | - private function mapIdsFromOld(string $map_xml): array |
|
204 | - { |
|
205 | - $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
206 | - return is_array($mapping) ? $mapping : [ $mapping ]; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Get the mapping property to be used for the migrated map adapter |
|
211 | - * |
|
212 | - * @param string $map_id |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - private function mappingPropertyForMap(string $map_id): string |
|
216 | - { |
|
217 | - switch ($map_id) { |
|
218 | - case 'fr-metropole-regions-1970': |
|
219 | - case 'fr-metropole-regions-2016': |
|
220 | - return 'region_insee_libelle'; |
|
221 | - case 'fr-metropole-departements': |
|
222 | - return 'dpt_insee_libelle'; |
|
223 | - case 'fr-dpt-48-codespostaux': |
|
224 | - return 'code_postal'; |
|
225 | - default: |
|
226 | - return 'commune_insee_libelle'; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get the color configuration to be used for the migrated map view |
|
232 | - * |
|
233 | - * @param string $map_id |
|
234 | - * @return MapColorsConfig |
|
235 | - */ |
|
236 | - private function colorsFromMap(string $map_id): MapColorsConfig |
|
237 | - { |
|
238 | - $default = Hex::fromString('#f5f5f5'); |
|
239 | - $stroke = Hex::fromString('#d5d5d5'); |
|
240 | - $hover = Hex::fromString('#ff6600'); |
|
241 | - |
|
242 | - switch ($map_id) { |
|
243 | - case 'fr-metropole-departements': |
|
244 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
245 | - case 'fr-dpt-48-codespostaux': |
|
246 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
247 | - default: |
|
248 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
249 | - } |
|
250 | - } |
|
42 | + /** |
|
43 | + * Mapping from old map definitions to new ones |
|
44 | + * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | + */ |
|
46 | + private const MAPS_XML_MAPPING = [ |
|
47 | + 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | + 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | + 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | + 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | + 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | + 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | + 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | + 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | + 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | + 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | + 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | + 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | + 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | + 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | + 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | + 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | + 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | + 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | + 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | + 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | + 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | + 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | + 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | + 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | + ]; |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | + */ |
|
77 | + public function upgrade(): void |
|
78 | + { |
|
79 | + if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + /** @var TreeService $tree_service */ |
|
84 | + $tree_service = app(TreeService::class); |
|
85 | + /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | + $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
87 | + |
|
88 | + $existing_views = DB::table('maj_geodispersion') |
|
89 | + ->select() |
|
90 | + ->get(); |
|
91 | + |
|
92 | + foreach ($existing_views as $old_view) { |
|
93 | + try { |
|
94 | + $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | + } catch (RuntimeException $ex) { |
|
96 | + continue; |
|
97 | + } |
|
98 | + |
|
99 | + if ($old_view->majgd_map === null) { |
|
100 | + $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | + } else { |
|
102 | + DB::connection()->beginTransaction(); |
|
103 | + if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | + DB::connection()->commit(); |
|
105 | + } else { |
|
106 | + DB::connection()->rollBack(); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + DB::schema()->drop('maj_geodispersion'); |
|
112 | + |
|
113 | + FlashMessages::addMessage(I18N::translate( |
|
114 | + 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
115 | + )); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Create a Table geographical analysis view from a migrated item. |
|
120 | + * |
|
121 | + * @param stdClass $old_view |
|
122 | + * @param Tree $tree |
|
123 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + private function migrateGeoAnalysisTable( |
|
127 | + stdClass $old_view, |
|
128 | + Tree $tree, |
|
129 | + GeoAnalysisViewDataService $geoview_data_service |
|
130 | + ): bool { |
|
131 | + $new_view = new GeoAnalysisTable( |
|
132 | + 0, |
|
133 | + $tree, |
|
134 | + $old_view->majgd_status === 'enabled', |
|
135 | + $old_view->majgd_descr, |
|
136 | + app(SosaByGenerationGeoAnalysis::class), |
|
137 | + (int) $old_view->majgd_sublevel, |
|
138 | + (int) $old_view->majgd_detailsgen |
|
139 | + ); |
|
140 | + |
|
141 | + return $geoview_data_service->insertGetId($new_view) > 0; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Create a Map geographical analysis view from a migrated item. |
|
146 | + * |
|
147 | + * @param stdClass $old_view |
|
148 | + * @param Tree $tree |
|
149 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + private function migrateGeoAnalysisMap( |
|
153 | + stdClass $old_view, |
|
154 | + Tree $tree, |
|
155 | + GeoAnalysisViewDataService $geoview_data_service |
|
156 | + ): bool { |
|
157 | + /** @var MapDefinitionsService $map_definition_service */ |
|
158 | + $map_definition_service = app(MapDefinitionsService::class); |
|
159 | + /** @var MapAdapterDataService $mapadapter_data_service */ |
|
160 | + $mapadapter_data_service = app(MapAdapterDataService::class); |
|
161 | + |
|
162 | + $new_view = new GeoAnalysisMap( |
|
163 | + 0, |
|
164 | + $tree, |
|
165 | + $old_view->majgd_status === 'enabled', |
|
166 | + $old_view->majgd_descr, |
|
167 | + app(SosaByGenerationGeoAnalysis::class), |
|
168 | + (int) $old_view->majgd_sublevel, |
|
169 | + (int) $old_view->majgd_detailsgen |
|
170 | + ); |
|
171 | + |
|
172 | + $view_id = $geoview_data_service->insertGetId($new_view); |
|
173 | + if ($view_id === 0) { |
|
174 | + return false; |
|
175 | + } |
|
176 | + $new_view = $new_view->withId($view_id); |
|
177 | + |
|
178 | + $colors = $new_view->colors(); |
|
179 | + foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
180 | + $map = $map_definition_service->find($new_map_id); |
|
181 | + if ($map === null) { |
|
182 | + return false; |
|
183 | + } |
|
184 | + $colors = $this->colorsFromMap($new_map_id); |
|
185 | + |
|
186 | + /** @var SimplePlaceMapper $mapper */ |
|
187 | + $mapper = app(SimplePlaceMapper::class); |
|
188 | + $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
189 | + $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
190 | + |
|
191 | + $mapadapter_data_service->insertGetId($map_adapter); |
|
192 | + } |
|
193 | + |
|
194 | + return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get all new map definitions IDs representing an old map definition |
|
199 | + * |
|
200 | + * @param string $map_xml |
|
201 | + * @return string[] |
|
202 | + */ |
|
203 | + private function mapIdsFromOld(string $map_xml): array |
|
204 | + { |
|
205 | + $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
206 | + return is_array($mapping) ? $mapping : [ $mapping ]; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Get the mapping property to be used for the migrated map adapter |
|
211 | + * |
|
212 | + * @param string $map_id |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + private function mappingPropertyForMap(string $map_id): string |
|
216 | + { |
|
217 | + switch ($map_id) { |
|
218 | + case 'fr-metropole-regions-1970': |
|
219 | + case 'fr-metropole-regions-2016': |
|
220 | + return 'region_insee_libelle'; |
|
221 | + case 'fr-metropole-departements': |
|
222 | + return 'dpt_insee_libelle'; |
|
223 | + case 'fr-dpt-48-codespostaux': |
|
224 | + return 'code_postal'; |
|
225 | + default: |
|
226 | + return 'commune_insee_libelle'; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get the color configuration to be used for the migrated map view |
|
232 | + * |
|
233 | + * @param string $map_id |
|
234 | + * @return MapColorsConfig |
|
235 | + */ |
|
236 | + private function colorsFromMap(string $map_id): MapColorsConfig |
|
237 | + { |
|
238 | + $default = Hex::fromString('#f5f5f5'); |
|
239 | + $stroke = Hex::fromString('#d5d5d5'); |
|
240 | + $hover = Hex::fromString('#ff6600'); |
|
241 | + |
|
242 | + switch ($map_id) { |
|
243 | + case 'fr-metropole-departements': |
|
244 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
245 | + case 'fr-dpt-48-codespostaux': |
|
246 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
247 | + default: |
|
248 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
249 | + } |
|
250 | + } |
|
251 | 251 | } |