|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage Certificates |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart |
|
10
|
|
|
* @license https://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\Certificates; |
|
16
|
|
|
|
|
17
|
|
|
use Aura\Router\Map; |
|
18
|
|
|
use Fisharebest\Webtrees\Auth; |
|
19
|
|
|
use Fisharebest\Webtrees\I18N; |
|
20
|
|
|
use Fisharebest\Webtrees\Registry; |
|
21
|
|
|
use Fisharebest\Webtrees\Tree; |
|
22
|
|
|
use Fisharebest\Webtrees\Http\Middleware\AuthManager; |
|
23
|
|
|
use Fisharebest\Webtrees\Module\AbstractModule; |
|
24
|
|
|
use Fisharebest\Webtrees\Module\ModuleConfigInterface; |
|
25
|
|
|
use Fisharebest\Webtrees\Module\ModuleConfigTrait; |
|
26
|
|
|
use Fisharebest\Webtrees\Module\ModuleGlobalInterface; |
|
27
|
|
|
use Fisharebest\Webtrees\Module\ModuleGlobalTrait; |
|
28
|
|
|
use Fisharebest\Webtrees\Module\ModuleListInterface; |
|
29
|
|
|
use Fisharebest\Webtrees\Module\ModuleListTrait; |
|
30
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface; |
|
31
|
|
|
use MyArtJaub\Webtrees\Http\Middleware\AuthTreePreference; |
|
32
|
|
|
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface; |
|
33
|
|
|
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubTrait; |
|
34
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Elements\SourceCertificate; |
|
35
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Hooks\SourceCertificateIconHook; |
|
36
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\AdminConfigAction; |
|
37
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\AdminConfigPage; |
|
38
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\AutoCompleteFile; |
|
39
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\CertificateImage; |
|
40
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\CertificatePage; |
|
41
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\CertificatesList; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Certificates Module. |
|
45
|
|
|
*/ |
|
46
|
|
|
class CertificatesModule extends AbstractModule implements |
|
47
|
|
|
ModuleMyArtJaubInterface, |
|
48
|
|
|
ModuleConfigInterface, |
|
49
|
|
|
ModuleGlobalInterface, |
|
50
|
|
|
ModuleListInterface, |
|
51
|
|
|
ModuleHookSubscriberInterface |
|
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($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
|
|
|
} |
|
224
|
|
|
|