AllEventsByCenturyGeoAnalysis   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A results() 0 24 5
A itemsDescription() 0 3 1
A title() 0 3 1
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\Auth;
18
use Fisharebest\Webtrees\I18N;
19
use Fisharebest\Webtrees\Tree;
20
use Fisharebest\Webtrees\Statistics\Service\CenturyService;
21
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisPlace;
22
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisResults;
23
use MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface;
24
use MyArtJaub\Webtrees\Module\GeoDispersion\Services\GeoAnalysisDataService;
25
26
/**
27
 * Analyse the geographical dispersion of all individuals and families' events, detailed by century.
28
 */
29
class AllEventsByCenturyGeoAnalysis implements GeoAnalysisInterface
30
{
31
    private GeoAnalysisDataService $geoanalysis_data_service;
32
    private CenturyService $century_service;
33
34
    /**
35
     * Constructor for AllEventsByCenturyGeoAnalysis
36
     *
37
     * @param GeoAnalysisDataService $geoanalysis_data_service
38
     * @param CenturyService $century_service
39
     */
40
    public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service)
41
    {
42
        $this->geoanalysis_data_service = $geoanalysis_data_service;
43
        $this->century_service = $century_service;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
49
     */
50
    public function title(): string
51
    {
52
        return I18N::translate('All events places by century');
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
58
     */
59
    public function itemsDescription(): callable
60
    {
61
        return fn(int $count): string => I18N::plural('event', 'events', $count);
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
67
     */
68
    public function results(Tree $tree, int $depth): GeoAnalysisResults
69
    {
70
        $results = new GeoAnalysisResults();
71
72
        foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) {
73
            foreach ($record->facts([]) as $fact) {
74
                $place = new GeoAnalysisPlace($tree, $fact->place(), $depth);
75
                if ($place->isUnknown()) {
76
                    continue;
77
                }
78
                $results->addPlace($place);
79
                $date = $fact->date();
80
                if ($date->isOK()) {
81
                    $century = intdiv($date->gregorianYear(), 100);
82
                    $results->addPlaceInCategory(
83
                        I18N::translate('%s century', $this->century_service->centuryName($century)),
84
                        $century,
85
                        $place
86
                    );
87
                }
88
            }
89
        }
90
91
        return $results;
92
    }
93
}
94