1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
5
|
|
|
* |
6
|
|
|
* @package MyArtJaub\Webtrees |
7
|
|
|
* @subpackage GeoDispersion |
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2021-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\GeoDispersion\GeoAnalyses; |
16
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\I18N; |
18
|
|
|
use Fisharebest\Webtrees\Tree; |
19
|
|
|
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisPlace; |
20
|
|
|
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisResults; |
21
|
|
|
use MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface; |
22
|
|
|
use MyArtJaub\Webtrees\Module\GeoDispersion\Services\GeoAnalysisDataService; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Analyse the geographical dispersion of all individuals and families' events, detailed by type of event. |
26
|
|
|
*/ |
27
|
|
|
class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface |
28
|
|
|
{ |
29
|
|
|
private GeoAnalysisDataService $geoanalysis_data_service; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor for AllEventsByTypeGeoAnalysis |
33
|
|
|
* |
34
|
|
|
* @param GeoAnalysisDataService $geoanalysis_data_service |
35
|
|
|
*/ |
36
|
|
|
public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
37
|
|
|
{ |
38
|
|
|
$this->geoanalysis_data_service = $geoanalysis_data_service; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
44
|
|
|
*/ |
45
|
|
|
public function title(): string |
46
|
|
|
{ |
47
|
|
|
return I18N::translate('All events places by event type'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
53
|
|
|
*/ |
54
|
|
|
public function itemsDescription(): callable |
55
|
|
|
{ |
56
|
|
|
return fn(int $count): string => I18N::plural('event', 'events', $count); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
* @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
62
|
|
|
*/ |
63
|
|
|
public function results(Tree $tree, int $depth): GeoAnalysisResults |
64
|
|
|
{ |
65
|
|
|
$results = new GeoAnalysisResults(); |
66
|
|
|
|
67
|
|
|
foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
68
|
|
|
foreach ($record->facts([]) as $fact) { |
69
|
|
|
$place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
70
|
|
|
if ($place->isUnknown()) { |
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
$results->addPlace($place); |
74
|
|
|
$results->addPlaceInCategory($fact->label(), 0, $place); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $results; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|