|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage IsSourced |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2011-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\IsSourced\Hooks; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\Family; |
|
18
|
|
|
use Fisharebest\Webtrees\I18N; |
|
19
|
|
|
use Fisharebest\Webtrees\Individual; |
|
20
|
|
|
use Fisharebest\Webtrees\Registry; |
|
21
|
|
|
use Fisharebest\Webtrees\Module\ModuleInterface; |
|
22
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface; |
|
23
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface; |
|
24
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface; |
|
25
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface; |
|
26
|
|
|
use MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface; |
|
27
|
|
|
use MyArtJaub\Webtrees\Module\IsSourced\Services\SourceStatusService; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Hook for adding columns with source statuses in datatables. |
|
31
|
|
|
*/ |
|
32
|
|
|
class IsSourcedStatusColumnsHook implements |
|
33
|
|
|
FamilyDatatablesExtenderInterface, |
|
34
|
|
|
IndividualDatatablesExtenderInterface, |
|
35
|
|
|
SosaFamilyDatatablesExtenderInterface, |
|
36
|
|
|
SosaIndividualDatatablesExtenderInterface, |
|
37
|
|
|
SosaMissingDatatablesExtenderInterface |
|
38
|
|
|
{ |
|
39
|
|
|
private ModuleInterface $module; |
|
40
|
|
|
private SourceStatusService $source_status_service; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Constructor for IsSourcedStatusColumnsHook |
|
44
|
|
|
* |
|
45
|
|
|
* @param ModuleInterface $module |
|
46
|
|
|
* @param SourceStatusService $source_status_service |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->module = $module; |
|
51
|
|
|
$this->source_status_service = $source_status_service; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritDoc} |
|
56
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
57
|
|
|
*/ |
|
58
|
|
|
public function module(): ModuleInterface |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->module; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface::individualColumns() |
|
66
|
|
|
*/ |
|
67
|
|
|
public function individualColumns(iterable $records): array |
|
68
|
|
|
{ |
|
69
|
|
|
$records = collect($records); |
|
70
|
|
|
return [ |
|
71
|
|
|
'issourced' => [ |
|
72
|
|
|
'birth' => [ |
|
73
|
|
|
'position' => 7, |
|
74
|
|
|
'column_def' => [ 'class' => 'text-center' ], |
|
75
|
|
|
'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
76
|
|
|
'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
77
|
|
|
]), |
|
78
|
|
|
'records' => $records->map(function (Individual $individual): array { |
|
79
|
|
|
$source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
80
|
|
|
return [ |
|
81
|
|
|
'order' => $source_status->order(), |
|
82
|
|
|
'text' => view($this->module()->name() . '::icons/source-status', [ |
|
83
|
|
|
'module_name' => $this->module()->name(), |
|
84
|
|
|
'source_status' => $source_status, |
|
85
|
|
|
'context' => 'INDI:BIRT', |
|
86
|
|
|
'size_style' => '' ]) |
|
87
|
|
|
]; |
|
88
|
|
|
})->toArray() |
|
89
|
|
|
], |
|
90
|
|
|
'death' => [ |
|
91
|
|
|
'position' => 12, |
|
92
|
|
|
'column_def' => [ 'class' => 'text-center' ], |
|
93
|
|
|
'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
94
|
|
|
'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:DEAT')->label()) |
|
95
|
|
|
]), |
|
96
|
|
|
'records' => $records->map(function (Individual $individual): array { |
|
97
|
|
|
$source_status = $this->source_status_service->sourceStatusForDeath($individual); |
|
98
|
|
|
return $individual->isDead() ? [ |
|
99
|
|
|
'order' => $source_status->order(), |
|
100
|
|
|
'text' => view($this->module()->name() . '::icons/source-status', [ |
|
101
|
|
|
'module_name' => $this->module()->name(), |
|
102
|
|
|
'source_status' => $source_status, |
|
103
|
|
|
'context' => 'INDI:DEAT', |
|
104
|
|
|
'size_style' => '' ]) |
|
105
|
|
|
] : ['order' => 0, 'text' => '']; |
|
106
|
|
|
})->toArray() |
|
107
|
|
|
] |
|
108
|
|
|
] |
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritDoc} |
|
114
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface::familyColumns() |
|
115
|
|
|
*/ |
|
116
|
|
|
public function familyColumns(iterable $records): array |
|
117
|
|
|
{ |
|
118
|
|
|
$records = collect($records); |
|
119
|
|
|
return [ |
|
120
|
|
|
'issourced' => [ |
|
121
|
|
|
'marr' => [ |
|
122
|
|
|
'position' => 10, |
|
123
|
|
|
'column_def' => [ 'class' => 'text-center' ], |
|
124
|
|
|
'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
125
|
|
|
'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('FAM:MARR')->label()) |
|
126
|
|
|
]), |
|
127
|
|
|
'records' => $records->map(function (Family $family): array { |
|
128
|
|
|
$source_status = $this->source_status_service->sourceStatusForMarriage($family); |
|
129
|
|
|
return $family->getMarriage() !== null ? [ |
|
130
|
|
|
'order' => $source_status->order(), |
|
131
|
|
|
'text' => view($this->module()->name() . '::icons/source-status', [ |
|
132
|
|
|
'module_name' => $this->module()->name(), |
|
133
|
|
|
'source_status' => $source_status, |
|
134
|
|
|
'context' => 'FAM:MARR', |
|
135
|
|
|
'size_style' => '' ]) |
|
136
|
|
|
] : ['order' => 0, 'text' => '']; |
|
137
|
|
|
})->toArray() |
|
138
|
|
|
] |
|
139
|
|
|
] |
|
140
|
|
|
]; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritDoc} |
|
145
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface::sosaIndividualColumns() |
|
146
|
|
|
*/ |
|
147
|
|
|
public function sosaIndividualColumns(iterable $records): array |
|
148
|
|
|
{ |
|
149
|
|
|
$columns = $this->individualColumns($records); |
|
150
|
|
|
$columns['issourced']['birth']['position'] = 5; |
|
151
|
|
|
$columns['issourced']['death']['position'] = 8; |
|
152
|
|
|
return $columns; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* {@inheritDoc} |
|
157
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface::sosaFamilyColumns() |
|
158
|
|
|
*/ |
|
159
|
|
|
public function sosaFamilyColumns(iterable $records): array |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->familyColumns($records); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* {@inheritDoc} |
|
166
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns() |
|
167
|
|
|
*/ |
|
168
|
|
|
public function sosaMissingColumns(iterable $records): array |
|
169
|
|
|
{ |
|
170
|
|
|
$records = collect($records); |
|
171
|
|
|
return [ |
|
172
|
|
|
'issourced' => [ |
|
173
|
|
|
'indi' => [ |
|
174
|
|
|
'position' => 3, |
|
175
|
|
|
'column_def' => [ 'class' => 'text-center' ], |
|
176
|
|
|
'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
177
|
|
|
'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI')->label()) |
|
178
|
|
|
]), |
|
179
|
|
|
'records' => $records->map(function (Individual $individual): array { |
|
180
|
|
|
$source_status = $this->source_status_service->sourceStatusForRecord($individual); |
|
181
|
|
|
return [ |
|
182
|
|
|
'order' => $source_status->order(), |
|
183
|
|
|
'text' => view($this->module()->name() . '::icons/source-status', [ |
|
184
|
|
|
'module_name' => $this->module()->name(), |
|
185
|
|
|
'source_status' => $source_status, |
|
186
|
|
|
'context' => 'INDI', |
|
187
|
|
|
'size_style' => '' ]) |
|
188
|
|
|
]; |
|
189
|
|
|
})->toArray() |
|
190
|
|
|
], |
|
191
|
|
|
'birth' => [ |
|
192
|
|
|
'position' => 7, |
|
193
|
|
|
'column_def' => [ 'class' => 'text-center' ], |
|
194
|
|
|
'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
195
|
|
|
'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
196
|
|
|
]), |
|
197
|
|
|
'records' => $records->map(function (Individual $individual): array { |
|
198
|
|
|
$source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
199
|
|
|
return [ |
|
200
|
|
|
'order' => $source_status->order(), |
|
201
|
|
|
'text' => view($this->module()->name() . '::icons/source-status', [ |
|
202
|
|
|
'module_name' => $this->module()->name(), |
|
203
|
|
|
'source_status' => $source_status, |
|
204
|
|
|
'context' => 'INDI:BIRT', |
|
205
|
|
|
'size_style' => '' ]) |
|
206
|
|
|
]; |
|
207
|
|
|
})->toArray() |
|
208
|
|
|
] |
|
209
|
|
|
] |
|
210
|
|
|
]; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|