|
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\Model; |
|
16
|
|
|
|
|
17
|
|
|
use Illuminate\Support\Collection; |
|
18
|
|
|
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisPlace; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Data structure for populating map features with their mapped places and count. |
|
22
|
|
|
*/ |
|
23
|
|
|
class MapFeatureAnalysisData |
|
24
|
|
|
{ |
|
25
|
|
|
private int $count; |
|
26
|
|
|
private bool $in_map; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var Collection<GeoAnalysisPlace> $places |
|
29
|
|
|
*/ |
|
30
|
|
|
private Collection $places; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Constructor for MapFeatureAnalysisData |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->count = 0; |
|
38
|
|
|
$this->places = new Collection(); |
|
39
|
|
|
$this->in_map = false; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the list of places mapped to the feature |
|
44
|
|
|
* |
|
45
|
|
|
* @return Collection<GeoAnalysisPlace> |
|
46
|
|
|
*/ |
|
47
|
|
|
public function places(): Collection |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->places; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the count of analysis items occurring in the feature |
|
54
|
|
|
* |
|
55
|
|
|
* @return int |
|
56
|
|
|
*/ |
|
57
|
|
|
public function count(): int |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->count; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Check whether the feature exist in the target map |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function existsInMap(): bool |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->in_map; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Confirm that the feature exist in the target map |
|
74
|
|
|
* |
|
75
|
|
|
* @return $this |
|
76
|
|
|
*/ |
|
77
|
|
|
public function tagAsExisting(): self |
|
78
|
|
|
{ |
|
79
|
|
|
$this->in_map = true; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Add a GeoAnalysisPlace to the feature |
|
85
|
|
|
* |
|
86
|
|
|
* @param GeoAnalysisPlace $place |
|
87
|
|
|
* @param int $count |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
public function add(GeoAnalysisPlace $place, int $count): self |
|
91
|
|
|
{ |
|
92
|
|
|
if (!$place->isExcluded()) { |
|
93
|
|
|
$this->places->add($place); |
|
94
|
|
|
$this->count += $count; |
|
95
|
|
|
} |
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|