@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -21,23 +21,23 @@ discard block |
||
21 | 21 | */ |
22 | 22 | interface RecordNameTextExtenderInterface extends HookInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Insert some content before the record name text. |
|
26 | - * |
|
27 | - * @param GedcomRecord $record Gedcom record |
|
28 | - * @param bool $use_long Use the long text extender format |
|
29 | - * @param string $size Prepend size |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string; |
|
24 | + /** |
|
25 | + * Insert some content before the record name text. |
|
26 | + * |
|
27 | + * @param GedcomRecord $record Gedcom record |
|
28 | + * @param bool $use_long Use the long text extender format |
|
29 | + * @param string $size Prepend size |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Insert some content after the record name text. |
|
36 | - * |
|
37 | - * @param GedcomRecord $record Gedcom record |
|
38 | - * @param bool $use_long Use the long text extender format |
|
39 | - * @param string $size Append size |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string; |
|
34 | + /** |
|
35 | + * Insert some content after the record name text. |
|
36 | + * |
|
37 | + * @param GedcomRecord $record Gedcom record |
|
38 | + * @param bool $use_long Use the long text extender format |
|
39 | + * @param string $size Append size |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string; |
|
43 | 43 | } |
@@ -21,11 +21,11 @@ |
||
21 | 21 | */ |
22 | 22 | interface ModuleTasksProviderInterface extends ModuleInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * List tasks provided by the module as an associative array. |
|
26 | - * They keys are used as task IDs for storage and reference. |
|
27 | - * |
|
28 | - * @return array<string, string> List of tasks |
|
29 | - */ |
|
30 | - public function listTasks(): array; |
|
24 | + /** |
|
25 | + * List tasks provided by the module as an associative array. |
|
26 | + * They keys are used as task IDs for storage and reference. |
|
27 | + * |
|
28 | + * @return array<string, string> List of tasks |
|
29 | + */ |
|
30 | + public function listTasks(): array; |
|
31 | 31 | } |
@@ -21,10 +21,10 @@ |
||
21 | 21 | */ |
22 | 22 | interface ModuleMapDefinitionProviderInterface extends ModuleInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * List map definitions provided by the module as an array. |
|
26 | - * |
|
27 | - * @return array<int, MapDefinitionInterface> List of map definitions |
|
28 | - */ |
|
29 | - public function listMapDefinition(): array; |
|
24 | + /** |
|
25 | + * List map definitions provided by the module as an array. |
|
26 | + * |
|
27 | + * @return array<int, MapDefinitionInterface> List of map definitions |
|
28 | + */ |
|
29 | + public function listMapDefinition(): array; |
|
30 | 30 | } |
@@ -21,10 +21,10 @@ |
||
21 | 21 | */ |
22 | 22 | interface ModuleGeoAnalysisProviderInterface extends ModuleInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * List geographical analyses provided by the module as an array. |
|
26 | - * |
|
27 | - * @return string[] List of geographical analyses |
|
28 | - */ |
|
29 | - public function listGeoAnalyses(): array; |
|
24 | + /** |
|
25 | + * List geographical analyses provided by the module as an array. |
|
26 | + * |
|
27 | + * @return string[] List of geographical analyses |
|
28 | + */ |
|
29 | + public function listGeoAnalyses(): array; |
|
30 | 30 | } |
@@ -21,10 +21,10 @@ |
||
21 | 21 | */ |
22 | 22 | interface ModulePlaceMapperProviderInterface extends ModuleInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * List place mappers provided by the module as an array. |
|
26 | - * |
|
27 | - * @return string[] List of place mappers |
|
28 | - */ |
|
29 | - public function listPlaceMappers(): array; |
|
24 | + /** |
|
25 | + * List place mappers provided by the module as an array. |
|
26 | + * |
|
27 | + * @return string[] List of place mappers |
|
28 | + */ |
|
29 | + public function listPlaceMappers(): array; |
|
30 | 30 | } |
@@ -31,71 +31,71 @@ |
||
31 | 31 | */ |
32 | 32 | class AdminConfigAction implements RequestHandlerInterface |
33 | 33 | { |
34 | - private ?CertificatesModule $module; |
|
34 | + private ?CertificatesModule $module; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for Admin Config Action request handler |
|
38 | - * |
|
39 | - * @param ModuleService $module_service |
|
40 | - */ |
|
41 | - public function __construct(ModuleService $module_service) |
|
42 | - { |
|
43 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for Admin Config Action request handler |
|
38 | + * |
|
39 | + * @param ModuleService $module_service |
|
40 | + */ |
|
41 | + public function __construct(ModuleService $module_service) |
|
42 | + { |
|
43 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | - */ |
|
50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | - { |
|
52 | - $tree = Validator::attributes($request)->tree(); |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | + */ |
|
50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | + { |
|
52 | + $tree = Validator::attributes($request)->tree(); |
|
53 | 53 | |
54 | - if ($this->module === null) { |
|
55 | - FlashMessages::addMessage( |
|
56 | - I18N::translate('The attached module could not be found.'), |
|
57 | - 'danger' |
|
58 | - ); |
|
59 | - return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]); |
|
60 | - } |
|
54 | + if ($this->module === null) { |
|
55 | + FlashMessages::addMessage( |
|
56 | + I18N::translate('The attached module could not be found.'), |
|
57 | + 'danger' |
|
58 | + ); |
|
59 | + return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]); |
|
60 | + } |
|
61 | 61 | |
62 | - $tree->setPreference( |
|
63 | - 'MAJ_CERTIF_SHOW_CERT', |
|
64 | - (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_CERT', Auth::PRIV_HIDE) |
|
65 | - ); |
|
66 | - $tree->setPreference( |
|
67 | - 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
68 | - (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_NO_WATERMARK', Auth::PRIV_HIDE) |
|
69 | - ); |
|
70 | - $tree->setPreference( |
|
71 | - 'MAJ_CERTIF_WM_DEFAULT', |
|
72 | - Validator::parsedBody($request)->string('MAJ_CERTIF_WM_DEFAULT', '') |
|
73 | - ); |
|
62 | + $tree->setPreference( |
|
63 | + 'MAJ_CERTIF_SHOW_CERT', |
|
64 | + (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_CERT', Auth::PRIV_HIDE) |
|
65 | + ); |
|
66 | + $tree->setPreference( |
|
67 | + 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
68 | + (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_NO_WATERMARK', Auth::PRIV_HIDE) |
|
69 | + ); |
|
70 | + $tree->setPreference( |
|
71 | + 'MAJ_CERTIF_WM_DEFAULT', |
|
72 | + Validator::parsedBody($request)->string('MAJ_CERTIF_WM_DEFAULT', '') |
|
73 | + ); |
|
74 | 74 | |
75 | - $tree->setPreference( |
|
76 | - 'MAJ_CERTIF_WM_FONT_MAXSIZE', |
|
77 | - (string) ( |
|
78 | - Validator::parsedBody($request)->isBetween(0, PHP_INT_MAX)->integer('MAJ_CERTIF_WM_FONT_MAXSIZE', 18) |
|
79 | - ) |
|
80 | - ); |
|
75 | + $tree->setPreference( |
|
76 | + 'MAJ_CERTIF_WM_FONT_MAXSIZE', |
|
77 | + (string) ( |
|
78 | + Validator::parsedBody($request)->isBetween(0, PHP_INT_MAX)->integer('MAJ_CERTIF_WM_FONT_MAXSIZE', 18) |
|
79 | + ) |
|
80 | + ); |
|
81 | 81 | |
82 | - // Only accept valid color for MAJ_WM_FONT_COLOR |
|
83 | - $watermark_color = Validator::parsedBody($request)->string('MAJ_CERTIF_WM_FONT_COLOR', ''); |
|
84 | - if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
85 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
86 | - } |
|
82 | + // Only accept valid color for MAJ_WM_FONT_COLOR |
|
83 | + $watermark_color = Validator::parsedBody($request)->string('MAJ_CERTIF_WM_FONT_COLOR', ''); |
|
84 | + if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
85 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
86 | + } |
|
87 | 87 | |
88 | - // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
89 | - $cert_root_dir = Validator::parsedBody($request)->string('MAJ_CERTIF_ROOTDIR', ''); |
|
90 | - $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir) ?? ''; |
|
91 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
92 | - $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
88 | + // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
89 | + $cert_root_dir = Validator::parsedBody($request)->string('MAJ_CERTIF_ROOTDIR', ''); |
|
90 | + $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir) ?? ''; |
|
91 | + $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
92 | + $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
93 | 93 | |
94 | - FlashMessages::addMessage( |
|
95 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
96 | - 'success' |
|
97 | - ); |
|
94 | + FlashMessages::addMessage( |
|
95 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
96 | + 'success' |
|
97 | + ); |
|
98 | 98 | |
99 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
100 | - } |
|
99 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
100 | + } |
|
101 | 101 | } |
@@ -25,191 +25,191 @@ |
||
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($this->gedcomPath()); |
|
67 | - $this->city = $path_parts['dirname'] ?? ''; |
|
68 | - $this->basename = $path_parts['basename']; |
|
69 | - $this->filename = $path_parts['filename']; |
|
70 | - $this->extension = strtoupper($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 | - $month_date = DateTime::createFromFormat('m', $match['month']); |
|
77 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
78 | - |
|
79 | - $this->date = new Date(sprintf('%s %s %s', $match['day'], $month, $match['year'])); |
|
80 | - } else { |
|
81 | - $this->description = $this->filename; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Get the family tree of the certificate |
|
87 | - * |
|
88 | - * @return Tree |
|
89 | - */ |
|
90 | - public function tree(): Tree |
|
91 | - { |
|
92 | - return $this->tree; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the path of the certificate in the file system. |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function path(): string |
|
101 | - { |
|
102 | - return $this->path; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * The the path of the certificate, in a Gedcom canonical form. |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function gedcomPath(): string |
|
111 | - { |
|
112 | - return str_replace('\\', '/', $this->path); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the certificate name. |
|
117 | - * |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function name(): string |
|
121 | - { |
|
122 | - return $this->filename ?? ''; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get the certificate file name. |
|
127 | - * |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function filename(): string |
|
131 | - { |
|
132 | - return $this->basename ?? ''; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Get the certificate's city (the first level folder). |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function city(): string |
|
141 | - { |
|
142 | - return $this->city ?? ''; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get the certificate's date. Extracted from the file name. |
|
147 | - * |
|
148 | - * @return Date |
|
149 | - */ |
|
150 | - public function date(): Date |
|
151 | - { |
|
152 | - return $this->date ?? new Date(''); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Get the certificate's type. Extracted from the file name. |
|
157 | - * |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function type(): string |
|
161 | - { |
|
162 | - return $this->type ?? ''; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the certificate's description. Extracted from the file name. |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function description(): string |
|
170 | - { |
|
171 | - return $this->description ?? ''; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Get the certificate's description to be used for sorting. |
|
176 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function sortDescription(): string |
|
181 | - { |
|
182 | - $sort_prefix = ''; |
|
183 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
184 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
185 | - return $match[1]; |
|
186 | - }, $matches)) . '_'; |
|
187 | - } |
|
188 | - return $sort_prefix . $this->description(); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the certificate's MIME type. |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function mimeType(): string |
|
197 | - { |
|
198 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Get the base parameters to be used in url referencing the certificate. |
|
203 | - * |
|
204 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
205 | - * @return array{tree: string, cid: mixed} |
|
206 | - */ |
|
207 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
208 | - { |
|
209 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
210 | - return [ |
|
211 | - 'tree' => $this->tree->name(), |
|
212 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
213 | - ]; |
|
214 | - } |
|
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($this->gedcomPath()); |
|
67 | + $this->city = $path_parts['dirname'] ?? ''; |
|
68 | + $this->basename = $path_parts['basename']; |
|
69 | + $this->filename = $path_parts['filename']; |
|
70 | + $this->extension = strtoupper($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 | + $month_date = DateTime::createFromFormat('m', $match['month']); |
|
77 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
78 | + |
|
79 | + $this->date = new Date(sprintf('%s %s %s', $match['day'], $month, $match['year'])); |
|
80 | + } else { |
|
81 | + $this->description = $this->filename; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Get the family tree of the certificate |
|
87 | + * |
|
88 | + * @return Tree |
|
89 | + */ |
|
90 | + public function tree(): Tree |
|
91 | + { |
|
92 | + return $this->tree; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the path of the certificate in the file system. |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function path(): string |
|
101 | + { |
|
102 | + return $this->path; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * The the path of the certificate, in a Gedcom canonical form. |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function gedcomPath(): string |
|
111 | + { |
|
112 | + return str_replace('\\', '/', $this->path); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the certificate name. |
|
117 | + * |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function name(): string |
|
121 | + { |
|
122 | + return $this->filename ?? ''; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get the certificate file name. |
|
127 | + * |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function filename(): string |
|
131 | + { |
|
132 | + return $this->basename ?? ''; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Get the certificate's city (the first level folder). |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function city(): string |
|
141 | + { |
|
142 | + return $this->city ?? ''; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get the certificate's date. Extracted from the file name. |
|
147 | + * |
|
148 | + * @return Date |
|
149 | + */ |
|
150 | + public function date(): Date |
|
151 | + { |
|
152 | + return $this->date ?? new Date(''); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Get the certificate's type. Extracted from the file name. |
|
157 | + * |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function type(): string |
|
161 | + { |
|
162 | + return $this->type ?? ''; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the certificate's description. Extracted from the file name. |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function description(): string |
|
170 | + { |
|
171 | + return $this->description ?? ''; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Get the certificate's description to be used for sorting. |
|
176 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function sortDescription(): string |
|
181 | + { |
|
182 | + $sort_prefix = ''; |
|
183 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
184 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
185 | + return $match[1]; |
|
186 | + }, $matches)) . '_'; |
|
187 | + } |
|
188 | + return $sort_prefix . $this->description(); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the certificate's MIME type. |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function mimeType(): string |
|
197 | + { |
|
198 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Get the base parameters to be used in url referencing the certificate. |
|
203 | + * |
|
204 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
205 | + * @return array{tree: string, cid: mixed} |
|
206 | + */ |
|
207 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
208 | + { |
|
209 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
210 | + return [ |
|
211 | + 'tree' => $this->tree->name(), |
|
212 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
213 | + ]; |
|
214 | + } |
|
215 | 215 | } |
@@ -44,180 +44,180 @@ |
||
44 | 44 | * Certificates Module. |
45 | 45 | */ |
46 | 46 | class CertificatesModule extends AbstractModule implements |
47 | - ModuleMyArtJaubInterface, |
|
48 | - ModuleConfigInterface, |
|
49 | - ModuleGlobalInterface, |
|
50 | - ModuleListInterface, |
|
51 | - ModuleHookSubscriberInterface |
|
47 | + ModuleMyArtJaubInterface, |
|
48 | + ModuleConfigInterface, |
|
49 | + ModuleGlobalInterface, |
|
50 | + ModuleListInterface, |
|
51 | + ModuleHookSubscriberInterface |
|
52 | 52 | { |
53 | - use ModuleMyArtJaubTrait { |
|
54 | - ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | - } |
|
56 | - use ModuleConfigTrait; |
|
57 | - use ModuleGlobalTrait; |
|
58 | - use ModuleListTrait; |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | - */ |
|
64 | - public function title(): string |
|
65 | - { |
|
66 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | - */ |
|
73 | - public function description(): string |
|
74 | - { |
|
75 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * {@inheritDoc} |
|
81 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | - */ |
|
83 | - public function boot(): void |
|
84 | - { |
|
85 | - $this->traitMajBoot(); |
|
86 | - |
|
87 | - Registry::elementFactory()->registerTags([ |
|
88 | - 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | - 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | - 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | - 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | - 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | - 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | - 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | - 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | - ]); |
|
97 | - |
|
98 | - Registry::elementFactory()->registerSubTags([ |
|
99 | - 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | - 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | - 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | - 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | - 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | - 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | - 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | - 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | - ]); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | - */ |
|
114 | - public function loadRoutes(Map $router): void |
|
115 | - { |
|
116 | - $router->attach('', '', static function (Map $router): void { |
|
117 | - |
|
118 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | - |
|
120 | - $router->attach('', '/admin', static function (Map $router): void { |
|
121 | - |
|
122 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | - ->extras([ |
|
125 | - 'middleware' => [ |
|
126 | - AuthManager::class, |
|
127 | - ], |
|
128 | - ]); |
|
129 | - }); |
|
130 | - |
|
131 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | - ->extras([ |
|
133 | - 'middleware' => [AuthTreePreference::class], |
|
134 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | - ]); |
|
136 | - |
|
137 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | - ->extras([ |
|
139 | - 'middleware' => [AuthTreePreference::class], |
|
140 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | - ]); |
|
142 | - |
|
143 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | - |
|
145 | - $router->extras([ |
|
146 | - 'middleware' => [AuthTreePreference::class], |
|
147 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | - ]); |
|
149 | - |
|
150 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | - }); |
|
153 | - }); |
|
154 | - }); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * {@inheritDoc} |
|
159 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | - */ |
|
161 | - public function customModuleVersion(): string |
|
162 | - { |
|
163 | - return '2.1.3-v.1'; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * {@inheritDoc} |
|
168 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | - */ |
|
170 | - public function getConfigLink(): string |
|
171 | - { |
|
172 | - return route(AdminConfigPage::class); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * {@inheritDoc} |
|
177 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | - */ |
|
179 | - public function headContent(): string |
|
180 | - { |
|
181 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * {@inheritDoc} |
|
186 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | - * |
|
188 | - * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | - */ |
|
190 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | - { |
|
192 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * {@inheritDoc} |
|
197 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | - */ |
|
199 | - public function listMenuClass(): string |
|
200 | - { |
|
201 | - return 'menu-maj-certificates'; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * {@inheritDoc} |
|
206 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | - */ |
|
208 | - public function listIsEmpty(Tree $tree): bool |
|
209 | - { |
|
210 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * {@inheritDoc} |
|
215 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | - */ |
|
217 | - public function listSubscribedHooks(): array |
|
218 | - { |
|
219 | - return [ |
|
220 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | - ]; |
|
222 | - } |
|
53 | + use ModuleMyArtJaubTrait { |
|
54 | + ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | + } |
|
56 | + use ModuleConfigTrait; |
|
57 | + use ModuleGlobalTrait; |
|
58 | + use ModuleListTrait; |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | + */ |
|
64 | + public function title(): string |
|
65 | + { |
|
66 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | + */ |
|
73 | + public function description(): string |
|
74 | + { |
|
75 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * {@inheritDoc} |
|
81 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | + */ |
|
83 | + public function boot(): void |
|
84 | + { |
|
85 | + $this->traitMajBoot(); |
|
86 | + |
|
87 | + Registry::elementFactory()->registerTags([ |
|
88 | + 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | + 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | + 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | + 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | + 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | + 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | + 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | + 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | + ]); |
|
97 | + |
|
98 | + Registry::elementFactory()->registerSubTags([ |
|
99 | + 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | + 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | + 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | + 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | + 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | + 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | + 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | + 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | + ]); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | + */ |
|
114 | + public function loadRoutes(Map $router): void |
|
115 | + { |
|
116 | + $router->attach('', '', static function (Map $router): void { |
|
117 | + |
|
118 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | + |
|
120 | + $router->attach('', '/admin', static function (Map $router): void { |
|
121 | + |
|
122 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | + ->extras([ |
|
125 | + 'middleware' => [ |
|
126 | + AuthManager::class, |
|
127 | + ], |
|
128 | + ]); |
|
129 | + }); |
|
130 | + |
|
131 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | + ->extras([ |
|
133 | + 'middleware' => [AuthTreePreference::class], |
|
134 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | + ]); |
|
136 | + |
|
137 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | + ->extras([ |
|
139 | + 'middleware' => [AuthTreePreference::class], |
|
140 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | + ]); |
|
142 | + |
|
143 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | + |
|
145 | + $router->extras([ |
|
146 | + 'middleware' => [AuthTreePreference::class], |
|
147 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | + ]); |
|
149 | + |
|
150 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | + }); |
|
153 | + }); |
|
154 | + }); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * {@inheritDoc} |
|
159 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | + */ |
|
161 | + public function customModuleVersion(): string |
|
162 | + { |
|
163 | + return '2.1.3-v.1'; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * {@inheritDoc} |
|
168 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | + */ |
|
170 | + public function getConfigLink(): string |
|
171 | + { |
|
172 | + return route(AdminConfigPage::class); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * {@inheritDoc} |
|
177 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | + */ |
|
179 | + public function headContent(): string |
|
180 | + { |
|
181 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * {@inheritDoc} |
|
186 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | + * |
|
188 | + * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | + */ |
|
190 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | + { |
|
192 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * {@inheritDoc} |
|
197 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | + */ |
|
199 | + public function listMenuClass(): string |
|
200 | + { |
|
201 | + return 'menu-maj-certificates'; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * {@inheritDoc} |
|
206 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | + */ |
|
208 | + public function listIsEmpty(Tree $tree): bool |
|
209 | + { |
|
210 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * {@inheritDoc} |
|
215 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | + */ |
|
217 | + public function listSubscribedHooks(): array |
|
218 | + { |
|
219 | + return [ |
|
220 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | + ]; |
|
222 | + } |
|
223 | 223 | } |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function loadRoutes(Map $router): void |
115 | 115 | { |
116 | - $router->attach('', '', static function (Map $router): void { |
|
116 | + $router->attach('', '', static function(Map $router): void { |
|
117 | 117 | |
118 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
118 | + $router->attach('', '/module-maj/certificates', static function(Map $router): void { |
|
119 | 119 | |
120 | - $router->attach('', '/admin', static function (Map $router): void { |
|
120 | + $router->attach('', '/admin', static function(Map $router): void { |
|
121 | 121 | |
122 | 122 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
123 | 123 | $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
141 | 141 | ]); |
142 | 142 | |
143 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
143 | + $router->attach('', '/certificate/{tree}/{cid}', static function(Map $router): void { |
|
144 | 144 | |
145 | 145 | $router->extras([ |
146 | 146 | 'middleware' => [AuthTreePreference::class], |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function headContent(): string |
180 | 180 | { |
181 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
181 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function listUrl(Tree $tree, array $parameters = []): string |
191 | 191 | { |
192 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
192 | + return route(CertificatesList::class, ['tree' => $tree->name()] + $parameters); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function listIsEmpty(Tree $tree): bool |
209 | 209 | { |
210 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
210 | + return Auth::accessLevel($tree) > (int)$tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string)Auth::PRIV_HIDE); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -25,68 +25,68 @@ |
||
25 | 25 | */ |
26 | 26 | class TitlesCardHook implements NameAccordionExtenderInterface |
27 | 27 | { |
28 | - private ModuleInterface $module; |
|
28 | + private ModuleInterface $module; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for TitlesCardHook |
|
32 | - * |
|
33 | - * @param ModuleInterface $module |
|
34 | - */ |
|
35 | - public function __construct(ModuleInterface $module) |
|
36 | - { |
|
37 | - $this->module = $module; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for TitlesCardHook |
|
32 | + * |
|
33 | + * @param ModuleInterface $module |
|
34 | + */ |
|
35 | + public function __construct(ModuleInterface $module) |
|
36 | + { |
|
37 | + $this->module = $module; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritDoc} |
|
42 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
43 | - */ |
|
44 | - public function module(): ModuleInterface |
|
45 | - { |
|
46 | - return $this->module; |
|
47 | - } |
|
40 | + /** |
|
41 | + * {@inheritDoc} |
|
42 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
43 | + */ |
|
44 | + public function module(): ModuleInterface |
|
45 | + { |
|
46 | + return $this->module; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
52 | - */ |
|
53 | - public function accordionCard(Individual $individual): string |
|
54 | - { |
|
55 | - $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
56 | - if ($title_separator === '') { |
|
57 | - return ''; |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
52 | + */ |
|
53 | + public function accordionCard(Individual $individual): string |
|
54 | + { |
|
55 | + $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
56 | + if ($title_separator === '') { |
|
57 | + return ''; |
|
58 | + } |
|
59 | 59 | |
60 | - $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
60 | + $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
61 | 61 | |
62 | - return count($titles) === 0 ? '' : |
|
63 | - view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
64 | - } |
|
62 | + return count($titles) === 0 ? '' : |
|
63 | + view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Extract the individual titles from the TITL tags. |
|
68 | - * Split the title based on a pattern to identify the title and the land it refers to. |
|
69 | - * |
|
70 | - * @param Individual $individual |
|
71 | - * @param non-empty-string $pattern |
|
72 | - * @return array<string, string[]> |
|
73 | - */ |
|
74 | - protected function individualTitles(Individual $individual, string $pattern): array |
|
75 | - { |
|
76 | - $titles_list = []; |
|
77 | - /** @var \Illuminate\Support\Collection<string> $titles */ |
|
78 | - $titles = $individual->facts(['TITL']) |
|
79 | - ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
80 | - ->map(fn(Fact $fact) => $fact->value()); |
|
66 | + /** |
|
67 | + * Extract the individual titles from the TITL tags. |
|
68 | + * Split the title based on a pattern to identify the title and the land it refers to. |
|
69 | + * |
|
70 | + * @param Individual $individual |
|
71 | + * @param non-empty-string $pattern |
|
72 | + * @return array<string, string[]> |
|
73 | + */ |
|
74 | + protected function individualTitles(Individual $individual, string $pattern): array |
|
75 | + { |
|
76 | + $titles_list = []; |
|
77 | + /** @var \Illuminate\Support\Collection<string> $titles */ |
|
78 | + $titles = $individual->facts(['TITL']) |
|
79 | + ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
80 | + ->map(fn(Fact $fact) => $fact->value()); |
|
81 | 81 | |
82 | - foreach ($titles as $title) { |
|
83 | - if (preg_match($pattern, $title, $match) === 1) { |
|
84 | - /** @var array<int, string> $match */ |
|
85 | - $titles_list[$match[1]][] = trim($match[2]); |
|
86 | - } else { |
|
87 | - $titles_list[$title][] = ''; |
|
88 | - } |
|
89 | - } |
|
90 | - return $titles_list; |
|
91 | - } |
|
82 | + foreach ($titles as $title) { |
|
83 | + if (preg_match($pattern, $title, $match) === 1) { |
|
84 | + /** @var array<int, string> $match */ |
|
85 | + $titles_list[$match[1]][] = trim($match[2]); |
|
86 | + } else { |
|
87 | + $titles_list[$title][] = ''; |
|
88 | + } |
|
89 | + } |
|
90 | + return $titles_list; |
|
91 | + } |
|
92 | 92 | } |