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 http://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\Elements; |
16
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\Tree; |
18
|
|
|
use Fisharebest\Webtrees\Elements\AbstractElement; |
19
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\CertificatesModule; |
20
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Services\CertificateFilesystemService; |
21
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Services\UrlObfuscatorService; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Gedcom element for certificate associated to a source. |
25
|
|
|
* Structure: |
26
|
|
|
* n SOUR @XREF@ |
27
|
|
|
* n+1 _ACT certificate_file_path |
28
|
|
|
*/ |
29
|
|
|
class SourceCertificate extends AbstractElement |
30
|
|
|
{ |
31
|
|
|
protected CertificatesModule $module; |
32
|
|
|
protected CertificateFilesystemService $certif_filesystem; |
33
|
|
|
protected UrlObfuscatorService $url_obfuscator_service; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor for SourceCertificate element |
37
|
|
|
* |
38
|
|
|
* @param string $label |
39
|
|
|
* @param CertificatesModule $module |
40
|
|
|
* @param CertificateFilesystemService $certif_filesystem |
41
|
|
|
* @param UrlObfuscatorService $url_obfuscator_service |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
string $label, |
45
|
|
|
CertificatesModule $module, |
46
|
|
|
CertificateFilesystemService $certif_filesystem = null, |
47
|
|
|
UrlObfuscatorService $url_obfuscator_service = null |
48
|
|
|
) { |
49
|
|
|
parent::__construct($label, null); |
50
|
|
|
$this->module = $module; |
51
|
|
|
$this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
52
|
|
|
$this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
* @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
58
|
|
|
*/ |
59
|
|
|
public function canonical(string $value): string |
60
|
|
|
{ |
61
|
|
|
return strtr($value, '\\', '/'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
* @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
67
|
|
|
*/ |
68
|
|
|
public function edit(string $id, string $name, string $value, Tree $tree): string |
69
|
|
|
{ |
70
|
|
|
list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
71
|
|
|
|
72
|
|
|
$cities = array_map(function (string $item): array { |
73
|
|
|
return [$this->url_obfuscator_service->obfuscate($item), $item]; |
74
|
|
|
}, $this->certif_filesystem->cities($tree)); |
75
|
|
|
|
76
|
|
|
return view($this->module->name() . '::components/edit-certificate', [ |
77
|
|
|
'module_name' => $this->module->name(), |
78
|
|
|
'tree' => $tree, |
79
|
|
|
'id' => $id, |
80
|
|
|
'name' => $name, |
81
|
|
|
'cities' => $cities, |
82
|
|
|
'value' => $this->canonical($value), |
83
|
|
|
'value_city' => $city, |
84
|
|
|
'value_file' => $file, |
85
|
|
|
'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|