@@ -30,147 +30,147 @@ |
||
30 | 30 | */ |
31 | 31 | class SourceStatusService |
32 | 32 | { |
33 | - /** |
|
34 | - * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
35 | - * Arbitrally set to approximately a year around the event date. |
|
36 | - * |
|
37 | - * @var int DATE_PRECISION_MARGIN |
|
38 | - */ |
|
39 | - private const DATE_PRECISION_MARGIN = 180; |
|
40 | - |
|
41 | - /** |
|
42 | - * Extract gedcom for all source citations of a fact. |
|
43 | - * Logic removed from \Fisharebest\Webtrees\Fact. |
|
44 | - * |
|
45 | - * @param Fact $fact |
|
46 | - * @return string[] |
|
47 | - */ |
|
48 | - private function extractCitations(Fact $fact) |
|
49 | - { |
|
50 | - $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/'; |
|
51 | - preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER); |
|
52 | - $citations = []; |
|
53 | - foreach ($matches as $match) { |
|
54 | - $source = Registry::sourceFactory()->make($match[2], $fact->record()->tree()); |
|
55 | - if ($source !== null && $source->canShow()) { |
|
56 | - $citations[] = $match[1]; |
|
57 | - } |
|
58 | - } |
|
59 | - return $citations; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Return the status of source citations for a fact. |
|
64 | - * |
|
65 | - * @param Fact $fact |
|
66 | - * @return FactSourceStatus |
|
67 | - */ |
|
68 | - public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
69 | - { |
|
70 | - $source_status = new FactSourceStatus(); |
|
71 | - |
|
72 | - $date = $fact->date(); |
|
73 | - $source_status |
|
74 | - ->setFactHasDate($date->isOK()) |
|
75 | - ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
76 | - |
|
77 | - foreach ($this->extractCitations($fact) as $citation) { |
|
78 | - $source_status |
|
79 | - ->setHasSource(true) |
|
80 | - ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
81 | - |
|
82 | - preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
83 | - foreach ($date_matches as $date_match) { |
|
84 | - $source_date = new Date($date_match[1]); |
|
85 | - $source_status |
|
86 | - ->addSourceHasDate($source_date->isOK()) |
|
87 | - ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
88 | - && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
89 | - } |
|
90 | - |
|
91 | - if ($source_status->isFullySourced()) { |
|
92 | - return $source_status; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return $source_status; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Return the status of sources for a Gedcom record. |
|
101 | - * |
|
102 | - * @param GedcomRecord $record |
|
103 | - * @return SourceStatus |
|
104 | - */ |
|
105 | - public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
106 | - { |
|
107 | - $source_status = new SourceStatus(); |
|
108 | - |
|
109 | - foreach ($record->facts(['SOUR']) as $source) { |
|
110 | - $source_status |
|
111 | - ->setHasSource(true) |
|
112 | - ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
113 | - |
|
114 | - if ($source_status->isFullySourced()) { |
|
115 | - return $source_status; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $source_status; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Return the status of source citations for a list of fact types associated with a record. |
|
124 | - * |
|
125 | - * @param GedcomRecord $record |
|
126 | - * @param string[] $tags |
|
127 | - * @return FactSourceStatus |
|
128 | - */ |
|
129 | - public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
130 | - { |
|
131 | - $source_status = new NullFactSourceStatus(); |
|
132 | - |
|
133 | - foreach ($record->facts($tags) as $fact) { |
|
134 | - $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
135 | - if ($source_status->isFullySourced()) { |
|
136 | - return $source_status; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $source_status; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Return the status of source citations for an individual's birth events. |
|
145 | - * |
|
146 | - * @param Individual $individual |
|
147 | - * @return FactSourceStatus |
|
148 | - */ |
|
149 | - public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
150 | - { |
|
151 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Return the status of source citations for an individual's death events. |
|
156 | - * |
|
157 | - * @param Individual $individual |
|
158 | - * @return FactSourceStatus |
|
159 | - */ |
|
160 | - public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
161 | - { |
|
162 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Return the status of source citations for a family's marriage events. |
|
167 | - * |
|
168 | - * @param Family $family |
|
169 | - * @return FactSourceStatus |
|
170 | - */ |
|
171 | - public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
172 | - { |
|
173 | - $marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS']; |
|
174 | - return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
175 | - } |
|
33 | + /** |
|
34 | + * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
35 | + * Arbitrally set to approximately a year around the event date. |
|
36 | + * |
|
37 | + * @var int DATE_PRECISION_MARGIN |
|
38 | + */ |
|
39 | + private const DATE_PRECISION_MARGIN = 180; |
|
40 | + |
|
41 | + /** |
|
42 | + * Extract gedcom for all source citations of a fact. |
|
43 | + * Logic removed from \Fisharebest\Webtrees\Fact. |
|
44 | + * |
|
45 | + * @param Fact $fact |
|
46 | + * @return string[] |
|
47 | + */ |
|
48 | + private function extractCitations(Fact $fact) |
|
49 | + { |
|
50 | + $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/'; |
|
51 | + preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER); |
|
52 | + $citations = []; |
|
53 | + foreach ($matches as $match) { |
|
54 | + $source = Registry::sourceFactory()->make($match[2], $fact->record()->tree()); |
|
55 | + if ($source !== null && $source->canShow()) { |
|
56 | + $citations[] = $match[1]; |
|
57 | + } |
|
58 | + } |
|
59 | + return $citations; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Return the status of source citations for a fact. |
|
64 | + * |
|
65 | + * @param Fact $fact |
|
66 | + * @return FactSourceStatus |
|
67 | + */ |
|
68 | + public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
69 | + { |
|
70 | + $source_status = new FactSourceStatus(); |
|
71 | + |
|
72 | + $date = $fact->date(); |
|
73 | + $source_status |
|
74 | + ->setFactHasDate($date->isOK()) |
|
75 | + ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
76 | + |
|
77 | + foreach ($this->extractCitations($fact) as $citation) { |
|
78 | + $source_status |
|
79 | + ->setHasSource(true) |
|
80 | + ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
81 | + |
|
82 | + preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
83 | + foreach ($date_matches as $date_match) { |
|
84 | + $source_date = new Date($date_match[1]); |
|
85 | + $source_status |
|
86 | + ->addSourceHasDate($source_date->isOK()) |
|
87 | + ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
88 | + && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
89 | + } |
|
90 | + |
|
91 | + if ($source_status->isFullySourced()) { |
|
92 | + return $source_status; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return $source_status; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Return the status of sources for a Gedcom record. |
|
101 | + * |
|
102 | + * @param GedcomRecord $record |
|
103 | + * @return SourceStatus |
|
104 | + */ |
|
105 | + public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
106 | + { |
|
107 | + $source_status = new SourceStatus(); |
|
108 | + |
|
109 | + foreach ($record->facts(['SOUR']) as $source) { |
|
110 | + $source_status |
|
111 | + ->setHasSource(true) |
|
112 | + ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
113 | + |
|
114 | + if ($source_status->isFullySourced()) { |
|
115 | + return $source_status; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $source_status; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Return the status of source citations for a list of fact types associated with a record. |
|
124 | + * |
|
125 | + * @param GedcomRecord $record |
|
126 | + * @param string[] $tags |
|
127 | + * @return FactSourceStatus |
|
128 | + */ |
|
129 | + public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
130 | + { |
|
131 | + $source_status = new NullFactSourceStatus(); |
|
132 | + |
|
133 | + foreach ($record->facts($tags) as $fact) { |
|
134 | + $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
135 | + if ($source_status->isFullySourced()) { |
|
136 | + return $source_status; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $source_status; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Return the status of source citations for an individual's birth events. |
|
145 | + * |
|
146 | + * @param Individual $individual |
|
147 | + * @return FactSourceStatus |
|
148 | + */ |
|
149 | + public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
150 | + { |
|
151 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Return the status of source citations for an individual's death events. |
|
156 | + * |
|
157 | + * @param Individual $individual |
|
158 | + * @return FactSourceStatus |
|
159 | + */ |
|
160 | + public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
161 | + { |
|
162 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Return the status of source citations for a family's marriage events. |
|
167 | + * |
|
168 | + * @param Family $family |
|
169 | + * @return FactSourceStatus |
|
170 | + */ |
|
171 | + public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
172 | + { |
|
173 | + $marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS']; |
|
174 | + return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
175 | + } |
|
176 | 176 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | */ |
48 | 48 | private function extractCitations(Fact $fact) |
49 | 49 | { |
50 | - $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/'; |
|
50 | + $extract_regex = '/\n(2 SOUR @('.Gedcom::REGEX_XREF.')@(?:\n[3-9] .*)*)/'; |
|
51 | 51 | preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER); |
52 | 52 | $citations = []; |
53 | 53 | foreach ($matches as $match) { |
@@ -29,191 +29,191 @@ |
||
29 | 29 | */ |
30 | 30 | class GeoAnalysisMapAdapter |
31 | 31 | { |
32 | - private int $id; |
|
33 | - private int $view_id; |
|
34 | - private MapDefinitionInterface $map; |
|
35 | - private PlaceMapperInterface $place_mapper; |
|
36 | - private MapViewConfigInterface $config; |
|
37 | - |
|
38 | - /** |
|
39 | - * Constructor for GeoAnalysisMapAdapter |
|
40 | - * |
|
41 | - * @param int $id |
|
42 | - * @param MapDefinitionInterface $map |
|
43 | - * @param PlaceMapperInterface $mapper |
|
44 | - * @param MapViewConfigInterface $config |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - int $id, |
|
48 | - int $view_id, |
|
49 | - MapDefinitionInterface $map, |
|
50 | - PlaceMapperInterface $mapper, |
|
51 | - MapViewConfigInterface $config |
|
52 | - ) { |
|
53 | - $this->id = $id; |
|
54 | - $this->view_id = $view_id; |
|
55 | - $this->map = $map; |
|
56 | - $this->place_mapper = $mapper; |
|
57 | - $this->config = $config; |
|
58 | - $this->place_mapper->setConfig($this->config->mapperConfig()); |
|
59 | - $this->place_mapper->setData('map', $map); |
|
60 | - $this->place_mapper->boot(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Create a copy of the GeoAnalysisMapAdapter with new properties. |
|
65 | - * |
|
66 | - * @param MapDefinitionInterface $map |
|
67 | - * @param PlaceMapperInterface $mapper |
|
68 | - * @param string $mapping_property |
|
69 | - * @return static |
|
70 | - */ |
|
71 | - public function with( |
|
72 | - MapDefinitionInterface $map, |
|
73 | - PlaceMapperInterface $mapper, |
|
74 | - string $mapping_property |
|
75 | - ): self { |
|
76 | - $new = clone $this; |
|
77 | - $new->map = $map; |
|
78 | - $new->place_mapper = $mapper; |
|
79 | - $new->config = $this->config->with($mapping_property, $mapper->config()); |
|
80 | - return $new; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the GeoAnalysisMapAdapter ID |
|
85 | - * |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function id(): int |
|
89 | - { |
|
90 | - return $this->id; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Get the ID of the associated GeoAnalysisView |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function geoAnalysisViewId(): int |
|
99 | - { |
|
100 | - return $this->view_id; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get the associated target map |
|
105 | - * |
|
106 | - * @return MapDefinitionInterface |
|
107 | - */ |
|
108 | - public function map(): MapDefinitionInterface |
|
109 | - { |
|
110 | - return $this->map; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the Place Mapper used for the mapping |
|
115 | - * |
|
116 | - * @return PlaceMapperInterface |
|
117 | - */ |
|
118 | - public function placeMapper(): PlaceMapperInterface |
|
119 | - { |
|
120 | - return $this->place_mapper; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Get the configuration of the Map View. |
|
125 | - * |
|
126 | - * @return MapViewConfigInterface |
|
127 | - */ |
|
128 | - public function viewConfig(): MapViewConfigInterface |
|
129 | - { |
|
130 | - return $this->config; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Convert the geographical analysis result to a MapAdapter result for usage in the Map View |
|
135 | - * |
|
136 | - * @param GeoAnalysisResult $result |
|
137 | - * @return MapAdapterResult |
|
138 | - */ |
|
139 | - public function convert(GeoAnalysisResult $result): MapAdapterResult |
|
140 | - { |
|
141 | - $result = $result->copy(); |
|
142 | - |
|
143 | - $features = []; |
|
144 | - list($features_data, $result) = $this->featureAnalysisData($result); |
|
145 | - |
|
146 | - $places_found = $result->countFound(); |
|
147 | - foreach ($this->map->features() as $feature) { |
|
148 | - $feature_id = $this->featureId($feature); |
|
149 | - if ($feature_id !== null && $features_data->has($feature_id)) { |
|
150 | - /** @var MapFeatureAnalysisData $feature_data */ |
|
151 | - $feature_data = $features_data->get($feature_id)->tagAsExisting(); |
|
152 | - $place_count = $feature_data->count(); |
|
153 | - $features[] = $feature |
|
154 | - ->withProperty('count', $place_count) |
|
155 | - ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0) |
|
156 | - ->withProperty( |
|
157 | - 'places', |
|
158 | - $feature_data->places() |
|
159 | - ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first()) |
|
160 | - ->sort(I18N::comparator()) |
|
161 | - ->toArray() |
|
162 | - ); |
|
163 | - } else { |
|
164 | - $features[] = $feature; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - $features_data |
|
169 | - ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap()) |
|
170 | - ->each( |
|
171 | - fn (MapFeatureAnalysisData $data) => |
|
172 | - $data->places()->each( |
|
173 | - function (GeoAnalysisPlace $place) use ($result): void { |
|
174 | - $result->exclude($place); |
|
175 | - } |
|
176 | - ) |
|
177 | - ); |
|
178 | - |
|
179 | - return new MapAdapterResult($result, $features); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Populate the map features with the mapped Places and total count |
|
184 | - * |
|
185 | - * @param GeoAnalysisResult $result |
|
186 | - * @return mixed[] |
|
187 | - */ |
|
188 | - protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
189 | - { |
|
190 | - $features_mapping = new Collection(); |
|
191 | - |
|
192 | - $byplaces = $result->knownPlaces(); |
|
193 | - $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
194 | - $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
195 | - |
|
196 | - if ($id !== null && mb_strlen($id) > 0) { |
|
197 | - $features_mapping->put( |
|
198 | - $id, |
|
199 | - $features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count()) |
|
200 | - ); |
|
201 | - } else { |
|
202 | - $result->exclude($item->place()); |
|
203 | - } |
|
204 | - }); |
|
205 | - |
|
206 | - return [ $features_mapping, $result]; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Get the value of the feature property used for the mapping |
|
211 | - * |
|
212 | - * @param Feature $feature |
|
213 | - * @return string|NULL |
|
214 | - */ |
|
215 | - protected function featureId(Feature $feature): ?string |
|
216 | - { |
|
217 | - return $feature->getProperty($this->config->mapMappingProperty()); |
|
218 | - } |
|
32 | + private int $id; |
|
33 | + private int $view_id; |
|
34 | + private MapDefinitionInterface $map; |
|
35 | + private PlaceMapperInterface $place_mapper; |
|
36 | + private MapViewConfigInterface $config; |
|
37 | + |
|
38 | + /** |
|
39 | + * Constructor for GeoAnalysisMapAdapter |
|
40 | + * |
|
41 | + * @param int $id |
|
42 | + * @param MapDefinitionInterface $map |
|
43 | + * @param PlaceMapperInterface $mapper |
|
44 | + * @param MapViewConfigInterface $config |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + int $id, |
|
48 | + int $view_id, |
|
49 | + MapDefinitionInterface $map, |
|
50 | + PlaceMapperInterface $mapper, |
|
51 | + MapViewConfigInterface $config |
|
52 | + ) { |
|
53 | + $this->id = $id; |
|
54 | + $this->view_id = $view_id; |
|
55 | + $this->map = $map; |
|
56 | + $this->place_mapper = $mapper; |
|
57 | + $this->config = $config; |
|
58 | + $this->place_mapper->setConfig($this->config->mapperConfig()); |
|
59 | + $this->place_mapper->setData('map', $map); |
|
60 | + $this->place_mapper->boot(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Create a copy of the GeoAnalysisMapAdapter with new properties. |
|
65 | + * |
|
66 | + * @param MapDefinitionInterface $map |
|
67 | + * @param PlaceMapperInterface $mapper |
|
68 | + * @param string $mapping_property |
|
69 | + * @return static |
|
70 | + */ |
|
71 | + public function with( |
|
72 | + MapDefinitionInterface $map, |
|
73 | + PlaceMapperInterface $mapper, |
|
74 | + string $mapping_property |
|
75 | + ): self { |
|
76 | + $new = clone $this; |
|
77 | + $new->map = $map; |
|
78 | + $new->place_mapper = $mapper; |
|
79 | + $new->config = $this->config->with($mapping_property, $mapper->config()); |
|
80 | + return $new; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the GeoAnalysisMapAdapter ID |
|
85 | + * |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function id(): int |
|
89 | + { |
|
90 | + return $this->id; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Get the ID of the associated GeoAnalysisView |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function geoAnalysisViewId(): int |
|
99 | + { |
|
100 | + return $this->view_id; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get the associated target map |
|
105 | + * |
|
106 | + * @return MapDefinitionInterface |
|
107 | + */ |
|
108 | + public function map(): MapDefinitionInterface |
|
109 | + { |
|
110 | + return $this->map; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the Place Mapper used for the mapping |
|
115 | + * |
|
116 | + * @return PlaceMapperInterface |
|
117 | + */ |
|
118 | + public function placeMapper(): PlaceMapperInterface |
|
119 | + { |
|
120 | + return $this->place_mapper; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Get the configuration of the Map View. |
|
125 | + * |
|
126 | + * @return MapViewConfigInterface |
|
127 | + */ |
|
128 | + public function viewConfig(): MapViewConfigInterface |
|
129 | + { |
|
130 | + return $this->config; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Convert the geographical analysis result to a MapAdapter result for usage in the Map View |
|
135 | + * |
|
136 | + * @param GeoAnalysisResult $result |
|
137 | + * @return MapAdapterResult |
|
138 | + */ |
|
139 | + public function convert(GeoAnalysisResult $result): MapAdapterResult |
|
140 | + { |
|
141 | + $result = $result->copy(); |
|
142 | + |
|
143 | + $features = []; |
|
144 | + list($features_data, $result) = $this->featureAnalysisData($result); |
|
145 | + |
|
146 | + $places_found = $result->countFound(); |
|
147 | + foreach ($this->map->features() as $feature) { |
|
148 | + $feature_id = $this->featureId($feature); |
|
149 | + if ($feature_id !== null && $features_data->has($feature_id)) { |
|
150 | + /** @var MapFeatureAnalysisData $feature_data */ |
|
151 | + $feature_data = $features_data->get($feature_id)->tagAsExisting(); |
|
152 | + $place_count = $feature_data->count(); |
|
153 | + $features[] = $feature |
|
154 | + ->withProperty('count', $place_count) |
|
155 | + ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0) |
|
156 | + ->withProperty( |
|
157 | + 'places', |
|
158 | + $feature_data->places() |
|
159 | + ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first()) |
|
160 | + ->sort(I18N::comparator()) |
|
161 | + ->toArray() |
|
162 | + ); |
|
163 | + } else { |
|
164 | + $features[] = $feature; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + $features_data |
|
169 | + ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap()) |
|
170 | + ->each( |
|
171 | + fn (MapFeatureAnalysisData $data) => |
|
172 | + $data->places()->each( |
|
173 | + function (GeoAnalysisPlace $place) use ($result): void { |
|
174 | + $result->exclude($place); |
|
175 | + } |
|
176 | + ) |
|
177 | + ); |
|
178 | + |
|
179 | + return new MapAdapterResult($result, $features); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Populate the map features with the mapped Places and total count |
|
184 | + * |
|
185 | + * @param GeoAnalysisResult $result |
|
186 | + * @return mixed[] |
|
187 | + */ |
|
188 | + protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
189 | + { |
|
190 | + $features_mapping = new Collection(); |
|
191 | + |
|
192 | + $byplaces = $result->knownPlaces(); |
|
193 | + $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
194 | + $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
195 | + |
|
196 | + if ($id !== null && mb_strlen($id) > 0) { |
|
197 | + $features_mapping->put( |
|
198 | + $id, |
|
199 | + $features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count()) |
|
200 | + ); |
|
201 | + } else { |
|
202 | + $result->exclude($item->place()); |
|
203 | + } |
|
204 | + }); |
|
205 | + |
|
206 | + return [ $features_mapping, $result]; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Get the value of the feature property used for the mapping |
|
211 | + * |
|
212 | + * @param Feature $feature |
|
213 | + * @return string|NULL |
|
214 | + */ |
|
215 | + protected function featureId(Feature $feature): ?string |
|
216 | + { |
|
217 | + return $feature->getProperty($this->config->mapMappingProperty()); |
|
218 | + } |
|
219 | 219 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | ->withProperty( |
157 | 157 | 'places', |
158 | 158 | $feature_data->places() |
159 | - ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first()) |
|
159 | + ->map(fn(GeoAnalysisPlace $place) : string => $place->place()->firstParts(1)->first()) |
|
160 | 160 | ->sort(I18N::comparator()) |
161 | 161 | ->toArray() |
162 | 162 | ); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | ->each( |
171 | 171 | fn (MapFeatureAnalysisData $data) => |
172 | 172 | $data->places()->each( |
173 | - function (GeoAnalysisPlace $place) use ($result): void { |
|
173 | + function(GeoAnalysisPlace $place) use ($result): void { |
|
174 | 174 | $result->exclude($place); |
175 | 175 | } |
176 | 176 | ) |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $features_mapping = new Collection(); |
191 | 191 | |
192 | 192 | $byplaces = $result->knownPlaces(); |
193 | - $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
193 | + $byplaces->each(function(GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
194 | 194 | $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
195 | 195 | |
196 | 196 | if ($id !== null && mb_strlen($id) > 0) { |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | }); |
205 | 205 | |
206 | - return [ $features_mapping, $result]; |
|
206 | + return [$features_mapping, $result]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | */ |
20 | 20 | interface SosaMissingDatatablesExtenderInterface extends HookInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Get the columns to be added to missing ancestors datatables |
|
24 | - * |
|
25 | - * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
26 | - * @return array<string, array<string, array<string, mixed>>> |
|
27 | - */ |
|
28 | - public function sosaMissingColumns(iterable $records): array; |
|
22 | + /** |
|
23 | + * Get the columns to be added to missing ancestors datatables |
|
24 | + * |
|
25 | + * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
26 | + * @return array<string, array<string, array<string, mixed>>> |
|
27 | + */ |
|
28 | + public function sosaMissingColumns(iterable $records): array; |
|
29 | 29 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | */ |
20 | 20 | interface HookServiceInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Select the hook collector to use for a specific hook interface |
|
24 | - * |
|
25 | - * @template THook of HookInterface |
|
26 | - * @param class-string<THook> $hook_interface |
|
27 | - * @return HookCollectorInterface|NULL |
|
28 | - */ |
|
29 | - public function use(string $hook_interface): ?HookCollectorInterface; |
|
22 | + /** |
|
23 | + * Select the hook collector to use for a specific hook interface |
|
24 | + * |
|
25 | + * @template THook of HookInterface |
|
26 | + * @param class-string<THook> $hook_interface |
|
27 | + * @return HookCollectorInterface|NULL |
|
28 | + */ |
|
29 | + public function use(string $hook_interface): ?HookCollectorInterface; |
|
30 | 30 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | */ |
22 | 22 | interface NameAccordionExtenderInterface extends HookInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Add a new card to the names accordion. |
|
26 | - * |
|
27 | - * @param Individual $individual |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function accordionCard(Individual $individual): string; |
|
24 | + /** |
|
25 | + * Add a new card to the names accordion. |
|
26 | + * |
|
27 | + * @param Individual $individual |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function accordionCard(Individual $individual): string; |
|
31 | 31 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | */ |
20 | 20 | interface SosaFamilyDatatablesExtenderInterface extends HookInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Get the columns to be added to sosa families datatables |
|
24 | - * |
|
25 | - * @param iterable<\Fisharebest\Webtrees\Family> $records |
|
26 | - * @return array<string, array<string, array<string, mixed>>> |
|
27 | - */ |
|
28 | - public function sosaFamilyColumns(iterable $records): array; |
|
22 | + /** |
|
23 | + * Get the columns to be added to sosa families datatables |
|
24 | + * |
|
25 | + * @param iterable<\Fisharebest\Webtrees\Family> $records |
|
26 | + * @return array<string, array<string, array<string, mixed>>> |
|
27 | + */ |
|
28 | + public function sosaFamilyColumns(iterable $records): array; |
|
29 | 29 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | */ |
20 | 20 | interface SosaIndividualDatatablesExtenderInterface extends HookInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Get the columns to be added to ancestors datatables |
|
24 | - * |
|
25 | - * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
26 | - * @return array<string, array<string, array<string, mixed>>> |
|
27 | - */ |
|
28 | - public function sosaIndividualColumns(iterable $records): array; |
|
22 | + /** |
|
23 | + * Get the columns to be added to ancestors datatables |
|
24 | + * |
|
25 | + * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
26 | + * @return array<string, array<string, array<string, mixed>>> |
|
27 | + */ |
|
28 | + public function sosaIndividualColumns(iterable $records): array; |
|
29 | 29 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | */ |
22 | 22 | interface HookInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Get the module attached to the hook |
|
26 | - * |
|
27 | - * @return ModuleInterface |
|
28 | - */ |
|
29 | - public function module(): ModuleInterface; |
|
24 | + /** |
|
25 | + * Get the module attached to the hook |
|
26 | + * |
|
27 | + * @return ModuleInterface |
|
28 | + */ |
|
29 | + public function module(): ModuleInterface; |
|
30 | 30 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | */ |
22 | 22 | interface ModuleHookSubscriberInterface extends ModuleInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * List hooks to be subscribed by the module as an array. |
|
26 | - * |
|
27 | - * @return HookInterface[] |
|
28 | - */ |
|
29 | - public function listSubscribedHooks(): array; |
|
24 | + /** |
|
25 | + * List hooks to be subscribed by the module as an array. |
|
26 | + * |
|
27 | + * @return HookInterface[] |
|
28 | + */ |
|
29 | + public function listSubscribedHooks(): array; |
|
30 | 30 | } |