@@ -21,102 +21,102 @@ |
||
21 | 21 | */ |
22 | 22 | class PlacesReferenceTableService |
23 | 23 | { |
24 | - /** |
|
25 | - * Mapping format placeholder tags => table column names |
|
26 | - * @var array<string, string> |
|
27 | - */ |
|
28 | - private const COLUMN_MAPPING = [ |
|
29 | - 'name' => 'majgr_place_name', |
|
30 | - 'id' => 'majgr_place_admin_id', |
|
31 | - 'zip' => 'majgr_place_zip', |
|
32 | - 'gov' => 'majgr_place_gov_id', |
|
33 | - 'mls' => 'majgr_place_mls_id' |
|
34 | - ]; |
|
24 | + /** |
|
25 | + * Mapping format placeholder tags => table column names |
|
26 | + * @var array<string, string> |
|
27 | + */ |
|
28 | + private const COLUMN_MAPPING = [ |
|
29 | + 'name' => 'majgr_place_name', |
|
30 | + 'id' => 'majgr_place_admin_id', |
|
31 | + 'zip' => 'majgr_place_zip', |
|
32 | + 'gov' => 'majgr_place_gov_id', |
|
33 | + 'mls' => 'majgr_place_mls_id' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the formatted target mapping value of a place defined by a source format. |
|
38 | - * |
|
39 | - * @param string $source |
|
40 | - * @param string $source_format |
|
41 | - * @param string $target_format |
|
42 | - * @return string|NULL |
|
43 | - */ |
|
44 | - public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | - { |
|
46 | - // Extract parts for the WHERE clause |
|
47 | - $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | - $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | - if ($source_parts === false) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $source_parts = array_map(function (string $part): string { |
|
53 | - if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | - return $this->columnName($column_id[1]); |
|
55 | - } |
|
56 | - return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | - }, array_filter($source_parts)); |
|
58 | - $source_parts[] = "'%'"; |
|
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
36 | + /** |
|
37 | + * Get the formatted target mapping value of a place defined by a source format. |
|
38 | + * |
|
39 | + * @param string $source |
|
40 | + * @param string $source_format |
|
41 | + * @param string $target_format |
|
42 | + * @return string|NULL |
|
43 | + */ |
|
44 | + public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | + { |
|
46 | + // Extract parts for the WHERE clause |
|
47 | + $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | + $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | + if ($source_parts === false) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $source_parts = array_map(function (string $part): string { |
|
53 | + if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | + return $this->columnName($column_id[1]); |
|
55 | + } |
|
56 | + return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | + }, array_filter($source_parts)); |
|
58 | + $source_parts[] = "'%'"; |
|
59 | + $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
60 | 60 | |
61 | - // Extract columns used in target |
|
62 | - $columns = []; |
|
63 | - if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | - $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | - } |
|
61 | + // Extract columns used in target |
|
62 | + $columns = []; |
|
63 | + if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | + $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | + } |
|
66 | 66 | |
67 | - // Get the mapping |
|
68 | - $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | - ->select($columns) |
|
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | - ->get(); |
|
67 | + // Get the mapping |
|
68 | + $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | + ->select($columns) |
|
70 | + ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | + ->get(); |
|
72 | 72 | |
73 | - // Format the output ID |
|
74 | - if ($rows->count() === 0) { |
|
75 | - return null; |
|
76 | - } |
|
73 | + // Format the output ID |
|
74 | + if ($rows->count() === 0) { |
|
75 | + return null; |
|
76 | + } |
|
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
79 | - if (count($columns_select) === 0) { |
|
80 | - return $target_format; |
|
81 | - } |
|
78 | + $mapping = (array) $rows->first(); |
|
79 | + if (count($columns_select) === 0) { |
|
80 | + return $target_format; |
|
81 | + } |
|
82 | 82 | |
83 | - return str_replace( |
|
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | - array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | - $target_format |
|
87 | - ); |
|
88 | - } |
|
83 | + return str_replace( |
|
84 | + array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | + array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | + $target_format |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get the column name for a format placeholder tag |
|
92 | - * |
|
93 | - * @param string $placeholder |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - private function columnName(string $placeholder): string |
|
97 | - { |
|
98 | - return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | - } |
|
90 | + /** |
|
91 | + * Get the column name for a format placeholder tag |
|
92 | + * |
|
93 | + * @param string $placeholder |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + private function columnName(string $placeholder): string |
|
97 | + { |
|
98 | + return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the placeholder tag for a column_name |
|
103 | - * |
|
104 | - * @param string $column_name |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - private function tagName(string $column_name): string |
|
108 | - { |
|
109 | - return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | - } |
|
101 | + /** |
|
102 | + * Get the placeholder tag for a column_name |
|
103 | + * |
|
104 | + * @param string $column_name |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + private function tagName(string $column_name): string |
|
108 | + { |
|
109 | + return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Sanitize string for use in a SQL query. |
|
114 | - * |
|
115 | - * @param string $string |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function sanitizeString(string $string): string |
|
119 | - { |
|
120 | - return DB::connection()->getPdo()->quote($string); |
|
121 | - } |
|
112 | + /** |
|
113 | + * Sanitize string for use in a SQL query. |
|
114 | + * |
|
115 | + * @param string $string |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function sanitizeString(string $string): string |
|
119 | + { |
|
120 | + return DB::connection()->getPdo()->quote($string); |
|
121 | + } |
|
122 | 122 | } |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | if ($source_parts === false) { |
50 | 50 | return null; |
51 | 51 | } |
52 | - $source_parts = array_map(function (string $part): string { |
|
52 | + $source_parts = array_map(function(string $part): string { |
|
53 | 53 | if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
54 | 54 | return $this->columnName($column_id[1]); |
55 | 55 | } |
56 | 56 | return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
57 | 57 | }, array_filter($source_parts)); |
58 | 58 | $source_parts[] = "'%'"; |
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
59 | + $concat_statement = 'CONCAT('.implode(', ', $source_parts).')'; |
|
60 | 60 | |
61 | 61 | // Extract columns used in target |
62 | 62 | $columns = []; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // Get the mapping |
68 | 68 | $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
69 | 69 | ->select($columns) |
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
70 | + ->whereRaw($this->sanitizeString($source)." LIKE ".$concat_statement) |
|
71 | 71 | ->get(); |
72 | 72 | |
73 | 73 | // Format the output ID |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | return null; |
76 | 76 | } |
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
78 | + $mapping = (array)$rows->first(); |
|
79 | 79 | if (count($columns_select) === 0) { |
80 | 80 | return $target_format; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return str_replace( |
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
84 | + array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]), |
|
85 | 85 | array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
86 | 86 | $target_format |
87 | 87 | ); |
@@ -74,14 +74,14 @@ |
||
74 | 74 | |
75 | 75 | return $query_individuals->unionAll($query_families) |
76 | 76 | ->get()->pluck('g_gedcom') |
77 | - ->flatMap(static function (string $gedcom): array { |
|
77 | + ->flatMap(static function(string $gedcom): array { |
|
78 | 78 | preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
79 | 79 | return $matches[1] ?? []; |
80 | 80 | }) |
81 | 81 | ->sort(I18N::comparator())->reverse() |
82 | - ->mapWithKeys(static function (string $place): array { |
|
82 | + ->mapWithKeys(static function(string $place): array { |
|
83 | 83 | $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
84 | - return [ count($place_array) => $place_array ]; |
|
84 | + return [count($place_array) => $place_array]; |
|
85 | 85 | }) |
86 | 86 | ->sortKeys() |
87 | 87 | ->last(); |
@@ -26,64 +26,64 @@ |
||
26 | 26 | */ |
27 | 27 | class GeoAnalysisDataService |
28 | 28 | { |
29 | - /** |
|
30 | - * Yields indviduals and family records for a specified tree. |
|
31 | - * |
|
32 | - * @param Tree $tree |
|
33 | - * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
34 | - */ |
|
35 | - public function individualsAndFamilies(Tree $tree): Generator |
|
36 | - { |
|
37 | - yield from DB::table('individuals') |
|
38 | - ->where('i_file', '=', $tree->id()) |
|
39 | - ->select(['individuals.*']) |
|
40 | - ->get() |
|
41 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
42 | - ->filter(GedcomRecord::accessFilter()) |
|
43 | - ->all(); |
|
29 | + /** |
|
30 | + * Yields indviduals and family records for a specified tree. |
|
31 | + * |
|
32 | + * @param Tree $tree |
|
33 | + * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
34 | + */ |
|
35 | + public function individualsAndFamilies(Tree $tree): Generator |
|
36 | + { |
|
37 | + yield from DB::table('individuals') |
|
38 | + ->where('i_file', '=', $tree->id()) |
|
39 | + ->select(['individuals.*']) |
|
40 | + ->get() |
|
41 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
42 | + ->filter(GedcomRecord::accessFilter()) |
|
43 | + ->all(); |
|
44 | 44 | |
45 | - yield from DB::table('families') |
|
46 | - ->where('f_file', '=', $tree->id()) |
|
47 | - ->select(['families.*']) |
|
48 | - ->get() |
|
49 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
50 | - ->filter(GedcomRecord::accessFilter()) |
|
51 | - ->all(); |
|
52 | - } |
|
45 | + yield from DB::table('families') |
|
46 | + ->where('f_file', '=', $tree->id()) |
|
47 | + ->select(['families.*']) |
|
48 | + ->get() |
|
49 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
50 | + ->filter(GedcomRecord::accessFilter()) |
|
51 | + ->all(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest |
|
56 | - * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first). |
|
57 | - * |
|
58 | - * {@internal The places are taken only from the individuals and families records.} |
|
59 | - * |
|
60 | - * @param Tree $tree |
|
61 | - * @return array<int, string[]> |
|
62 | - */ |
|
63 | - public function placeHierarchyExample(Tree $tree): array |
|
64 | - { |
|
65 | - $query_individuals = DB::table('individuals') |
|
66 | - ->select(['i_gedcom AS g_gedcom']) |
|
67 | - ->where('i_file', '=', $tree->id()) |
|
68 | - ->where('i_gedcom', 'like', '%2 PLAC %'); |
|
54 | + /** |
|
55 | + * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest |
|
56 | + * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first). |
|
57 | + * |
|
58 | + * {@internal The places are taken only from the individuals and families records.} |
|
59 | + * |
|
60 | + * @param Tree $tree |
|
61 | + * @return array<int, string[]> |
|
62 | + */ |
|
63 | + public function placeHierarchyExample(Tree $tree): array |
|
64 | + { |
|
65 | + $query_individuals = DB::table('individuals') |
|
66 | + ->select(['i_gedcom AS g_gedcom']) |
|
67 | + ->where('i_file', '=', $tree->id()) |
|
68 | + ->where('i_gedcom', 'like', '%2 PLAC %'); |
|
69 | 69 | |
70 | - $query_families = DB::table('families') |
|
71 | - ->select(['f_gedcom AS g_gedcom']) |
|
72 | - ->where('f_file', '=', $tree->id()) |
|
73 | - ->where('f_gedcom', 'like', '%2 PLAC %'); |
|
70 | + $query_families = DB::table('families') |
|
71 | + ->select(['f_gedcom AS g_gedcom']) |
|
72 | + ->where('f_file', '=', $tree->id()) |
|
73 | + ->where('f_gedcom', 'like', '%2 PLAC %'); |
|
74 | 74 | |
75 | - return $query_individuals->unionAll($query_families) |
|
76 | - ->get()->pluck('g_gedcom') |
|
77 | - ->flatMap(static function (string $gedcom): array { |
|
78 | - preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
|
79 | - return $matches[1] ?? []; |
|
80 | - }) |
|
81 | - ->sort(I18N::comparator())->reverse() |
|
82 | - ->mapWithKeys(static function (string $place): array { |
|
83 | - $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
|
84 | - return [ count($place_array) => $place_array ]; |
|
85 | - }) |
|
86 | - ->sortKeys() |
|
87 | - ->last(); |
|
88 | - } |
|
75 | + return $query_individuals->unionAll($query_families) |
|
76 | + ->get()->pluck('g_gedcom') |
|
77 | + ->flatMap(static function (string $gedcom): array { |
|
78 | + preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
|
79 | + return $matches[1] ?? []; |
|
80 | + }) |
|
81 | + ->sort(I18N::comparator())->reverse() |
|
82 | + ->mapWithKeys(static function (string $place): array { |
|
83 | + $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
|
84 | + return [ count($place_array) => $place_array ]; |
|
85 | + }) |
|
86 | + ->sortKeys() |
|
87 | + ->last(); |
|
88 | + } |
|
89 | 89 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | private function mapAdapterMapper(): Closure |
134 | 134 | { |
135 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
135 | + return function(stdClass $row): ?GeoAnalysisMapAdapter { |
|
136 | 136 | if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
137 | 137 | return null; |
138 | 138 | } |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | return new GeoAnalysisMapAdapter( |
146 | - (int) $row->majgm_id, |
|
147 | - (int) $row->majgm_majgv_id, |
|
146 | + (int)$row->majgm_id, |
|
147 | + (int)$row->majgm_majgv_id, |
|
148 | 148 | $map, |
149 | 149 | app($row->majgm_mapper), |
150 | 150 | new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
@@ -31,171 +31,171 @@ |
||
31 | 31 | */ |
32 | 32 | class MapAdapterDataService |
33 | 33 | { |
34 | - private MapDefinitionsService $mapdefinition_service; |
|
34 | + private MapDefinitionsService $mapdefinition_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for MapAdapterDataService |
|
38 | - * |
|
39 | - * @param MapDefinitionsService $mapdefinition_service |
|
40 | - */ |
|
41 | - public function __construct(MapDefinitionsService $mapdefinition_service) |
|
42 | - { |
|
43 | - $this->mapdefinition_service = $mapdefinition_service; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for MapAdapterDataService |
|
38 | + * |
|
39 | + * @param MapDefinitionsService $mapdefinition_service |
|
40 | + */ |
|
41 | + public function __construct(MapDefinitionsService $mapdefinition_service) |
|
42 | + { |
|
43 | + $this->mapdefinition_service = $mapdefinition_service; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Find a GeoAnalysisMapAdapter by ID |
|
48 | - * |
|
49 | - * @param int $id |
|
50 | - * @return GeoAnalysisMapAdapter|NULL |
|
51 | - */ |
|
52 | - public function find(int $id): ?GeoAnalysisMapAdapter |
|
53 | - { |
|
54 | - return DB::table('maj_geodisp_mapviews') |
|
55 | - ->select('maj_geodisp_mapviews.*') |
|
56 | - ->where('majgm_id', '=', $id) |
|
57 | - ->get() |
|
58 | - ->map($this->mapAdapterMapper()) |
|
59 | - ->first(); |
|
60 | - } |
|
46 | + /** |
|
47 | + * Find a GeoAnalysisMapAdapter by ID |
|
48 | + * |
|
49 | + * @param int $id |
|
50 | + * @return GeoAnalysisMapAdapter|NULL |
|
51 | + */ |
|
52 | + public function find(int $id): ?GeoAnalysisMapAdapter |
|
53 | + { |
|
54 | + return DB::table('maj_geodisp_mapviews') |
|
55 | + ->select('maj_geodisp_mapviews.*') |
|
56 | + ->where('majgm_id', '=', $id) |
|
57 | + ->get() |
|
58 | + ->map($this->mapAdapterMapper()) |
|
59 | + ->first(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
64 | - * |
|
65 | - * @param GeoAnalysisMap $map_view |
|
66 | - * @param bool $show_invalid |
|
67 | - * @return Collection<GeoAnalysisMapAdapter|null> |
|
68 | - */ |
|
69 | - public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
70 | - { |
|
71 | - $map_adapters = DB::table('maj_geodisp_mapviews') |
|
72 | - ->select('maj_geodisp_mapviews.*') |
|
73 | - ->where('majgm_majgv_id', '=', $map_view->id()) |
|
74 | - ->get() |
|
75 | - ->map($this->mapAdapterMapper()); |
|
76 | - return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
77 | - } |
|
62 | + /** |
|
63 | + * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
64 | + * |
|
65 | + * @param GeoAnalysisMap $map_view |
|
66 | + * @param bool $show_invalid |
|
67 | + * @return Collection<GeoAnalysisMapAdapter|null> |
|
68 | + */ |
|
69 | + public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
70 | + { |
|
71 | + $map_adapters = DB::table('maj_geodisp_mapviews') |
|
72 | + ->select('maj_geodisp_mapviews.*') |
|
73 | + ->where('majgm_majgv_id', '=', $map_view->id()) |
|
74 | + ->get() |
|
75 | + ->map($this->mapAdapterMapper()); |
|
76 | + return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Insert a GeoAnalysisMapAdapter in the database. |
|
81 | - * |
|
82 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
86 | - { |
|
87 | - return DB::table('maj_geodisp_mapviews') |
|
88 | - ->insertGetId([ |
|
89 | - 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
90 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
91 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
92 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
93 | - 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
94 | - ]); |
|
95 | - } |
|
79 | + /** |
|
80 | + * Insert a GeoAnalysisMapAdapter in the database. |
|
81 | + * |
|
82 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
86 | + { |
|
87 | + return DB::table('maj_geodisp_mapviews') |
|
88 | + ->insertGetId([ |
|
89 | + 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
90 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
91 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
92 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
93 | + 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Update a GeoAnalysisMapAdapter in the database. |
|
99 | - * |
|
100 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
101 | - * @return int |
|
102 | - */ |
|
103 | - public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
104 | - { |
|
105 | - return DB::table('maj_geodisp_mapviews') |
|
106 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
107 | - ->update([ |
|
108 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
109 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
110 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
111 | - 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
112 | - ]); |
|
113 | - } |
|
97 | + /** |
|
98 | + * Update a GeoAnalysisMapAdapter in the database. |
|
99 | + * |
|
100 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
101 | + * @return int |
|
102 | + */ |
|
103 | + public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
104 | + { |
|
105 | + return DB::table('maj_geodisp_mapviews') |
|
106 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
107 | + ->update([ |
|
108 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
109 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
110 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
111 | + 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
112 | + ]); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Delete a GeoAnalysisMapAdapter from the database. |
|
117 | - * |
|
118 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
122 | - { |
|
123 | - return DB::table('maj_geodisp_mapviews') |
|
124 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
125 | - ->delete(); |
|
126 | - } |
|
115 | + /** |
|
116 | + * Delete a GeoAnalysisMapAdapter from the database. |
|
117 | + * |
|
118 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
122 | + { |
|
123 | + return DB::table('maj_geodisp_mapviews') |
|
124 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
125 | + ->delete(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Delete invalid GeoAnalysisMapAdapters from the database. |
|
130 | - * |
|
131 | - * @param AbstractGeoAnalysisView $view |
|
132 | - * @param Collection<int> $valid_map_adapters |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
136 | - { |
|
137 | - return DB::table('maj_geodisp_mapviews') |
|
138 | - ->where('majgm_majgv_id', '=', $view->id()) |
|
139 | - ->whereNotIn('majgm_id', $valid_map_adapters) |
|
140 | - ->delete(); |
|
141 | - } |
|
128 | + /** |
|
129 | + * Delete invalid GeoAnalysisMapAdapters from the database. |
|
130 | + * |
|
131 | + * @param AbstractGeoAnalysisView $view |
|
132 | + * @param Collection<int> $valid_map_adapters |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
136 | + { |
|
137 | + return DB::table('maj_geodisp_mapviews') |
|
138 | + ->where('majgm_majgv_id', '=', $view->id()) |
|
139 | + ->whereNotIn('majgm_id', $valid_map_adapters) |
|
140 | + ->delete(); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
145 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
146 | - * or if the types do not match with the ones expected. |
|
147 | - * |
|
148 | - * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
149 | - */ |
|
150 | - private function mapAdapterMapper(): Closure |
|
151 | - { |
|
152 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
153 | - if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
154 | - return null; |
|
155 | - } |
|
156 | - try { |
|
157 | - $mapper = app($row->majgm_mapper); |
|
158 | - if (!($mapper instanceof PlaceMapperInterface)) { |
|
159 | - return null; |
|
160 | - } |
|
143 | + /** |
|
144 | + * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
145 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
146 | + * or if the types do not match with the ones expected. |
|
147 | + * |
|
148 | + * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
149 | + */ |
|
150 | + private function mapAdapterMapper(): Closure |
|
151 | + { |
|
152 | + return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
153 | + if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
154 | + return null; |
|
155 | + } |
|
156 | + try { |
|
157 | + $mapper = app($row->majgm_mapper); |
|
158 | + if (!($mapper instanceof PlaceMapperInterface)) { |
|
159 | + return null; |
|
160 | + } |
|
161 | 161 | |
162 | - return new GeoAnalysisMapAdapter( |
|
163 | - (int) $row->majgm_id, |
|
164 | - (int) $row->majgm_majgv_id, |
|
165 | - $map, |
|
166 | - app($row->majgm_mapper), |
|
167 | - new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
168 | - ); |
|
169 | - } catch (BindingResolutionException $ex) { |
|
170 | - return null; |
|
171 | - } |
|
172 | - }; |
|
173 | - } |
|
162 | + return new GeoAnalysisMapAdapter( |
|
163 | + (int) $row->majgm_id, |
|
164 | + (int) $row->majgm_majgv_id, |
|
165 | + $map, |
|
166 | + app($row->majgm_mapper), |
|
167 | + new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
168 | + ); |
|
169 | + } catch (BindingResolutionException $ex) { |
|
170 | + return null; |
|
171 | + } |
|
172 | + }; |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
177 | - * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
178 | - * through the Laravel container or if the type do not match with the one expected. |
|
179 | - * |
|
180 | - * @param string $json_config |
|
181 | - * @return PlaceMapperConfigInterface|NULL |
|
182 | - */ |
|
183 | - private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
184 | - { |
|
185 | - $config = $json_config === null ? [] : json_decode($json_config, true); |
|
186 | - $class = $config['class'] ?? null; |
|
187 | - $json_mapper_config = $config['config'] ?? null; |
|
188 | - if ($class === null || $json_mapper_config === null) { |
|
189 | - return null; |
|
190 | - } |
|
191 | - try { |
|
192 | - $mapper_config = app($class); |
|
193 | - if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - return $mapper_config->jsonDeserialize($json_mapper_config); |
|
197 | - } catch (BindingResolutionException $ex) { |
|
198 | - return null; |
|
199 | - } |
|
200 | - } |
|
175 | + /** |
|
176 | + * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
177 | + * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
178 | + * through the Laravel container or if the type do not match with the one expected. |
|
179 | + * |
|
180 | + * @param string $json_config |
|
181 | + * @return PlaceMapperConfigInterface|NULL |
|
182 | + */ |
|
183 | + private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
184 | + { |
|
185 | + $config = $json_config === null ? [] : json_decode($json_config, true); |
|
186 | + $class = $config['class'] ?? null; |
|
187 | + $json_mapper_config = $config['config'] ?? null; |
|
188 | + if ($class === null || $json_mapper_config === null) { |
|
189 | + return null; |
|
190 | + } |
|
191 | + try { |
|
192 | + $mapper_config = app($class); |
|
193 | + if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + return $mapper_config->jsonDeserialize($json_mapper_config); |
|
197 | + } catch (BindingResolutionException $ex) { |
|
198 | + return null; |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -26,55 +26,55 @@ |
||
26 | 26 | */ |
27 | 27 | class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface |
28 | 28 | { |
29 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
29 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
30 | 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 | - } |
|
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 | 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 | - } |
|
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 | 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 | - } |
|
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 | 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(); |
|
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 | 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 | - } |
|
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 | 77 | |
78 | - return $results; |
|
79 | - } |
|
78 | + return $results; |
|
79 | + } |
|
80 | 80 | } |
@@ -28,66 +28,66 @@ |
||
28 | 28 | */ |
29 | 29 | class AllEventsByCenturyGeoAnalysis implements GeoAnalysisInterface |
30 | 30 | { |
31 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | - private CenturyService $century_service; |
|
31 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | + private CenturyService $century_service; |
|
33 | 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 | - } |
|
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 | 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 | - } |
|
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 | 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 | - } |
|
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 | 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(); |
|
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 | 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 | - } |
|
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 | 90 | |
91 | - return $results; |
|
92 | - } |
|
91 | + return $results; |
|
92 | + } |
|
93 | 93 | } |
@@ -24,23 +24,23 @@ |
||
24 | 24 | */ |
25 | 25 | class SimplePlaceMapper implements PlaceMapperInterface |
26 | 26 | { |
27 | - use PlaceMapperTrait; |
|
27 | + use PlaceMapperTrait; |
|
28 | 28 | |
29 | - /** |
|
30 | - * {@inheritDoc} |
|
31 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
32 | - */ |
|
33 | - public function title(): string |
|
34 | - { |
|
35 | - return I18N::translate('Mapping on place name'); |
|
36 | - } |
|
29 | + /** |
|
30 | + * {@inheritDoc} |
|
31 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
32 | + */ |
|
33 | + public function title(): string |
|
34 | + { |
|
35 | + return I18N::translate('Mapping on place name'); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritDoc} |
|
40 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
41 | - */ |
|
42 | - public function map(Place $place, string $feature_property): ?string |
|
43 | - { |
|
44 | - return $place->firstParts(1)->first(); |
|
45 | - } |
|
38 | + /** |
|
39 | + * {@inheritDoc} |
|
40 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
41 | + */ |
|
42 | + public function map(Place $place, string $feature_property): ?string |
|
43 | + { |
|
44 | + return $place->firstParts(1)->first(); |
|
45 | + } |
|
46 | 46 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | */ |
29 | 29 | class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface |
30 | 30 | { |
31 | - use TopFilteredPlaceMapperTrait; |
|
31 | + use TopFilteredPlaceMapperTrait; |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | - */ |
|
37 | - public function title(): string |
|
38 | - { |
|
39 | - return I18N::translate('Mapping on place name with filter'); |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | + */ |
|
37 | + public function title(): string |
|
38 | + { |
|
39 | + return I18N::translate('Mapping on place name with filter'); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | - */ |
|
46 | - public function boot(): void |
|
47 | - { |
|
48 | - parent::boot(); |
|
49 | - $top_places = $this->config()->get('topPlaces'); |
|
50 | - if (is_array($top_places)) { |
|
51 | - $this->setTopPlaces($top_places); |
|
52 | - } |
|
53 | - } |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | + */ |
|
46 | + public function boot(): void |
|
47 | + { |
|
48 | + parent::boot(); |
|
49 | + $top_places = $this->config()->get('topPlaces'); |
|
50 | + if (is_array($top_places)) { |
|
51 | + $this->setTopPlaces($top_places); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | - */ |
|
59 | - public function config(): PlaceMapperConfigInterface |
|
60 | - { |
|
61 | - if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | - $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | - } |
|
64 | - return parent::config(); |
|
65 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | + */ |
|
59 | + public function config(): PlaceMapperConfigInterface |
|
60 | + { |
|
61 | + if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | + $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | + } |
|
64 | + return parent::config(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | - */ |
|
71 | - public function map(Place $place, string $feature_property): ?string |
|
72 | - { |
|
73 | - if (!$this->belongsToTopLevels($place)) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - return parent::map($place, $feature_property); |
|
77 | - } |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | + */ |
|
71 | + public function map(Place $place, string $feature_property): ?string |
|
72 | + { |
|
73 | + if (!$this->belongsToTopLevels($place)) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + return parent::map($place, $feature_property); |
|
77 | + } |
|
78 | 78 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | if ($cacheKey === null) { |
126 | 126 | return null; |
127 | 127 | } |
128 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
128 | + return Registry::cache()->array()->remember($cacheKey, function(): ?array { |
|
129 | 129 | $map_def = $this->data('map'); |
130 | 130 | if ( |
131 | 131 | !$this->setGeometryEngine() |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
202 | 202 | return null; |
203 | 203 | } |
204 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
204 | + return spl_object_id($this).'-map-'.$map_def->id(); |
|
205 | 205 | } |
206 | 206 | return $this->cache_key; |
207 | 207 | } |
@@ -36,184 +36,184 @@ |
||
36 | 36 | */ |
37 | 37 | class CoordinatesPlaceMapper implements PlaceMapperInterface |
38 | 38 | { |
39 | - use PlaceMapperTrait; |
|
40 | - |
|
41 | - private ?string $cache_key = null; |
|
42 | - |
|
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
46 | - */ |
|
47 | - public function title(): string |
|
48 | - { |
|
49 | - return I18N::translate('Mapping on place coordinates'); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * |
|
55 | - * {@internal The Place is associated to a Point only. |
|
56 | - * PlaceLocation can calculate a BoundingBox. |
|
57 | - * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
58 | - * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
59 | - * This could create the unwanted side effect of a very large area to consider} |
|
60 | - * |
|
61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
62 | - */ |
|
63 | - public function map(Place $place, string $feature_property): ?string |
|
64 | - { |
|
65 | - $location = new PlaceLocation($place->gedcomName()); |
|
66 | - $longitude = $location->longitude(); |
|
67 | - $latitude = $location->latitude(); |
|
68 | - if ($longitude === null || $latitude === null) { |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - $features_index = $this->featuresIndex(); |
|
73 | - if ($features_index === null) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
78 | - $grid_box = $this->getGridCell( |
|
79 | - $place_point, |
|
80 | - $features_index['map_NE'], |
|
81 | - $features_index['map_SW'], |
|
82 | - $features_index['nb_columns'] |
|
83 | - ); |
|
84 | - if ($grid_box === null || !$this->setGeometryEngine()) { |
|
85 | - return null; |
|
86 | - } |
|
87 | - $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
88 | - foreach ($features as $feature) { |
|
89 | - $geometry = $feature->getGeometry(); |
|
90 | - if ($geometry !== null && $place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
91 | - return $feature->getProperty($feature_property); |
|
92 | - } |
|
93 | - } |
|
94 | - return null; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
99 | - * |
|
100 | - * @param Point $point Point to find |
|
101 | - * @param Point $grid_NE North-East point of the bounded grid |
|
102 | - * @param Point $grid_SW South-West point fo the bounded grid |
|
103 | - * @param int $grid_columns Number of columns/rows in the grid |
|
104 | - * @return int[]|NULL |
|
105 | - */ |
|
106 | - protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
107 | - { |
|
108 | - list($x, $y) = $point->toArray(); |
|
109 | - list($x_max, $y_max) = $grid_NE->toArray(); |
|
110 | - list($x_min, $y_min) = $grid_SW->toArray(); |
|
111 | - |
|
112 | - $x_step = ($x_max - $x_min) / $grid_columns; |
|
113 | - $y_step = ($y_max - $y_min) / $grid_columns; |
|
114 | - |
|
115 | - if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
116 | - return [ |
|
117 | - $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
118 | - $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
119 | - ]; |
|
120 | - } |
|
121 | - return null; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get an indexed array of the features of the map. |
|
126 | - * |
|
127 | - * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
128 | - * The grid is computed once for each map, and cached.} |
|
129 | - * |
|
130 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
131 | - * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL |
|
132 | - */ |
|
133 | - protected function featuresIndex(): ?array |
|
134 | - { |
|
135 | - $cacheKey = $this->cacheKey(); |
|
136 | - if ($cacheKey === null) { |
|
137 | - return null; |
|
138 | - } |
|
139 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
140 | - $map_def = $this->data('map'); |
|
141 | - if ( |
|
142 | - !$this->setGeometryEngine() |
|
143 | - || $map_def === null |
|
144 | - || !($map_def instanceof MapDefinitionInterface) |
|
145 | - ) { |
|
146 | - return null; |
|
147 | - } |
|
148 | - $bounding_boxes = []; |
|
149 | - $map_bounding_box = new BoundingBox(); |
|
150 | - $srid = 0; |
|
151 | - foreach ($map_def->features() as $feature) { |
|
152 | - $geometry = $feature->getGeometry(); |
|
153 | - if ($geometry === null) { |
|
154 | - continue; |
|
155 | - } |
|
156 | - $srid = $geometry->SRID(); |
|
157 | - $bounding_box = $geometry->getBoundingBox(); |
|
158 | - $bounding_boxes[] = [$feature, $bounding_box]; |
|
159 | - $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
160 | - } |
|
161 | - $grid_columns = count($bounding_boxes); |
|
162 | - $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
163 | - $map_NE = $map_bounding_box->getNorthEast(); |
|
164 | - $map_SW = $map_bounding_box->getSouthWest(); |
|
165 | - foreach ($bounding_boxes as $item) { |
|
166 | - $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
167 | - $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
168 | - for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
169 | - for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
170 | - $grid[$i][$j][] = $item[0]; |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - return [ |
|
175 | - 'grid' => $grid, |
|
176 | - 'nb_columns' => $grid_columns, |
|
177 | - 'map_NE' => $map_NE, |
|
178 | - 'map_SW' => $map_SW, |
|
179 | - 'SRID' => $srid |
|
180 | - ]; |
|
181 | - }); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Set the Brick Geo Engine to use the database for geospatial computations. |
|
186 | - * The engine is set only if it has not been set beforehand. |
|
187 | - * |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - protected function setGeometryEngine(): bool |
|
191 | - { |
|
192 | - try { |
|
193 | - if (!GeometryEngineRegistry::has()) { |
|
194 | - GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
195 | - } |
|
196 | - $point = Point::xy(1, 1); |
|
197 | - return $point->equals($point); |
|
198 | - } catch (Throwable $ex) { |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the key to cache the indexed grid of features. |
|
205 | - * |
|
206 | - * @return string|NULL |
|
207 | - */ |
|
208 | - protected function cacheKey(): ?string |
|
209 | - { |
|
210 | - if ($this->cache_key === null) { |
|
211 | - $map_def = $this->data('map'); |
|
212 | - if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
213 | - return null; |
|
214 | - } |
|
215 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
216 | - } |
|
217 | - return $this->cache_key; |
|
218 | - } |
|
39 | + use PlaceMapperTrait; |
|
40 | + |
|
41 | + private ?string $cache_key = null; |
|
42 | + |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
46 | + */ |
|
47 | + public function title(): string |
|
48 | + { |
|
49 | + return I18N::translate('Mapping on place coordinates'); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * |
|
55 | + * {@internal The Place is associated to a Point only. |
|
56 | + * PlaceLocation can calculate a BoundingBox. |
|
57 | + * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
58 | + * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
59 | + * This could create the unwanted side effect of a very large area to consider} |
|
60 | + * |
|
61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
62 | + */ |
|
63 | + public function map(Place $place, string $feature_property): ?string |
|
64 | + { |
|
65 | + $location = new PlaceLocation($place->gedcomName()); |
|
66 | + $longitude = $location->longitude(); |
|
67 | + $latitude = $location->latitude(); |
|
68 | + if ($longitude === null || $latitude === null) { |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + $features_index = $this->featuresIndex(); |
|
73 | + if ($features_index === null) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
78 | + $grid_box = $this->getGridCell( |
|
79 | + $place_point, |
|
80 | + $features_index['map_NE'], |
|
81 | + $features_index['map_SW'], |
|
82 | + $features_index['nb_columns'] |
|
83 | + ); |
|
84 | + if ($grid_box === null || !$this->setGeometryEngine()) { |
|
85 | + return null; |
|
86 | + } |
|
87 | + $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
88 | + foreach ($features as $feature) { |
|
89 | + $geometry = $feature->getGeometry(); |
|
90 | + if ($geometry !== null && $place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
91 | + return $feature->getProperty($feature_property); |
|
92 | + } |
|
93 | + } |
|
94 | + return null; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
99 | + * |
|
100 | + * @param Point $point Point to find |
|
101 | + * @param Point $grid_NE North-East point of the bounded grid |
|
102 | + * @param Point $grid_SW South-West point fo the bounded grid |
|
103 | + * @param int $grid_columns Number of columns/rows in the grid |
|
104 | + * @return int[]|NULL |
|
105 | + */ |
|
106 | + protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
107 | + { |
|
108 | + list($x, $y) = $point->toArray(); |
|
109 | + list($x_max, $y_max) = $grid_NE->toArray(); |
|
110 | + list($x_min, $y_min) = $grid_SW->toArray(); |
|
111 | + |
|
112 | + $x_step = ($x_max - $x_min) / $grid_columns; |
|
113 | + $y_step = ($y_max - $y_min) / $grid_columns; |
|
114 | + |
|
115 | + if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
116 | + return [ |
|
117 | + $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
118 | + $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
119 | + ]; |
|
120 | + } |
|
121 | + return null; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get an indexed array of the features of the map. |
|
126 | + * |
|
127 | + * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
128 | + * The grid is computed once for each map, and cached.} |
|
129 | + * |
|
130 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
131 | + * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL |
|
132 | + */ |
|
133 | + protected function featuresIndex(): ?array |
|
134 | + { |
|
135 | + $cacheKey = $this->cacheKey(); |
|
136 | + if ($cacheKey === null) { |
|
137 | + return null; |
|
138 | + } |
|
139 | + return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
140 | + $map_def = $this->data('map'); |
|
141 | + if ( |
|
142 | + !$this->setGeometryEngine() |
|
143 | + || $map_def === null |
|
144 | + || !($map_def instanceof MapDefinitionInterface) |
|
145 | + ) { |
|
146 | + return null; |
|
147 | + } |
|
148 | + $bounding_boxes = []; |
|
149 | + $map_bounding_box = new BoundingBox(); |
|
150 | + $srid = 0; |
|
151 | + foreach ($map_def->features() as $feature) { |
|
152 | + $geometry = $feature->getGeometry(); |
|
153 | + if ($geometry === null) { |
|
154 | + continue; |
|
155 | + } |
|
156 | + $srid = $geometry->SRID(); |
|
157 | + $bounding_box = $geometry->getBoundingBox(); |
|
158 | + $bounding_boxes[] = [$feature, $bounding_box]; |
|
159 | + $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
160 | + } |
|
161 | + $grid_columns = count($bounding_boxes); |
|
162 | + $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
163 | + $map_NE = $map_bounding_box->getNorthEast(); |
|
164 | + $map_SW = $map_bounding_box->getSouthWest(); |
|
165 | + foreach ($bounding_boxes as $item) { |
|
166 | + $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
167 | + $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
168 | + for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
169 | + for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
170 | + $grid[$i][$j][] = $item[0]; |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + return [ |
|
175 | + 'grid' => $grid, |
|
176 | + 'nb_columns' => $grid_columns, |
|
177 | + 'map_NE' => $map_NE, |
|
178 | + 'map_SW' => $map_SW, |
|
179 | + 'SRID' => $srid |
|
180 | + ]; |
|
181 | + }); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Set the Brick Geo Engine to use the database for geospatial computations. |
|
186 | + * The engine is set only if it has not been set beforehand. |
|
187 | + * |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + protected function setGeometryEngine(): bool |
|
191 | + { |
|
192 | + try { |
|
193 | + if (!GeometryEngineRegistry::has()) { |
|
194 | + GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
195 | + } |
|
196 | + $point = Point::xy(1, 1); |
|
197 | + return $point->equals($point); |
|
198 | + } catch (Throwable $ex) { |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the key to cache the indexed grid of features. |
|
205 | + * |
|
206 | + * @return string|NULL |
|
207 | + */ |
|
208 | + protected function cacheKey(): ?string |
|
209 | + { |
|
210 | + if ($this->cache_key === null) { |
|
211 | + $map_def = $this->data('map'); |
|
212 | + if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
213 | + return null; |
|
214 | + } |
|
215 | + return spl_object_id($this) . '-map-' . $map_def->id(); |
|
216 | + } |
|
217 | + return $this->cache_key; |
|
218 | + } |
|
219 | 219 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function loadRoutes($router): void |
104 | 104 | { |
105 | - $router->attach('', '', static function (Map $router): void { |
|
105 | + $router->attach('', '', static function(Map $router): void { |
|
106 | 106 | |
107 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
107 | + $router->attach('', '/module-maj/certificates', static function(Map $router): void { |
|
108 | 108 | |
109 | - $router->attach('', '/admin', static function (Map $router): void { |
|
109 | + $router->attach('', '/admin', static function(Map $router): void { |
|
110 | 110 | |
111 | 111 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
112 | 112 | $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
130 | 130 | ]); |
131 | 131 | |
132 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
132 | + $router->attach('', '/certificate/{tree}/{cid}', static function(Map $router): void { |
|
133 | 133 | |
134 | 134 | $router->extras([ |
135 | 135 | 'middleware' => [AuthTreePreference::class], |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function headContent(): string |
169 | 169 | { |
170 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
170 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function listUrl(Tree $tree, array $parameters = []): string |
178 | 178 | { |
179 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
179 | + return route(CertificatesList::class, ['tree' => $tree->name()] + $parameters); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function listIsEmpty(Tree $tree): bool |
196 | 196 | { |
197 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
197 | + return Auth::accessLevel($tree) > (int)$tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string)Auth::PRIV_HIDE); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -44,180 +44,180 @@ |
||
44 | 44 | * Certificates Module. |
45 | 45 | */ |
46 | 46 | class CertificatesModule extends AbstractModule implements |
47 | - ModuleMyArtJaubInterface, |
|
48 | - ModuleConfigInterface, |
|
49 | - ModuleGlobalInterface, |
|
50 | - ModuleListInterface, |
|
51 | - ModuleHookSubscriberInterface |
|
47 | + ModuleMyArtJaubInterface, |
|
48 | + ModuleConfigInterface, |
|
49 | + ModuleGlobalInterface, |
|
50 | + ModuleListInterface, |
|
51 | + ModuleHookSubscriberInterface |
|
52 | 52 | { |
53 | - use ModuleMyArtJaubTrait { |
|
54 | - ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | - } |
|
56 | - use ModuleConfigTrait; |
|
57 | - use ModuleGlobalTrait; |
|
58 | - use ModuleListTrait; |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | - */ |
|
64 | - public function title(): string |
|
65 | - { |
|
66 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | - */ |
|
73 | - public function description(): string |
|
74 | - { |
|
75 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * {@inheritDoc} |
|
81 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | - */ |
|
83 | - public function boot(): void |
|
84 | - { |
|
85 | - $this->traitMajBoot(); |
|
86 | - |
|
87 | - Registry::elementFactory()->registerTags([ |
|
88 | - 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | - 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | - 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | - 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | - 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | - 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | - 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | - 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | - ]); |
|
97 | - |
|
98 | - Registry::elementFactory()->registerSubTags([ |
|
99 | - 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | - 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | - 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | - 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | - 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | - 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | - 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | - 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | - ]); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | - */ |
|
114 | - public function loadRoutes($router): void |
|
115 | - { |
|
116 | - $router->attach('', '', static function (Map $router): void { |
|
117 | - |
|
118 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | - |
|
120 | - $router->attach('', '/admin', static function (Map $router): void { |
|
121 | - |
|
122 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | - ->extras([ |
|
125 | - 'middleware' => [ |
|
126 | - AuthManager::class, |
|
127 | - ], |
|
128 | - ]); |
|
129 | - }); |
|
130 | - |
|
131 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | - ->extras([ |
|
133 | - 'middleware' => [AuthTreePreference::class], |
|
134 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | - ]); |
|
136 | - |
|
137 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | - ->extras([ |
|
139 | - 'middleware' => [AuthTreePreference::class], |
|
140 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | - ]); |
|
142 | - |
|
143 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | - |
|
145 | - $router->extras([ |
|
146 | - 'middleware' => [AuthTreePreference::class], |
|
147 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | - ]); |
|
149 | - |
|
150 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | - }); |
|
153 | - }); |
|
154 | - }); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * {@inheritDoc} |
|
159 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | - */ |
|
161 | - public function customModuleVersion(): string |
|
162 | - { |
|
163 | - return '2.1.1-v.1'; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * {@inheritDoc} |
|
168 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | - */ |
|
170 | - public function getConfigLink(): string |
|
171 | - { |
|
172 | - return route(AdminConfigPage::class); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * {@inheritDoc} |
|
177 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | - */ |
|
179 | - public function headContent(): string |
|
180 | - { |
|
181 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * {@inheritDoc} |
|
186 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | - * |
|
188 | - * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | - */ |
|
190 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | - { |
|
192 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * {@inheritDoc} |
|
197 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | - */ |
|
199 | - public function listMenuClass(): string |
|
200 | - { |
|
201 | - return 'menu-maj-certificates'; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * {@inheritDoc} |
|
206 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | - */ |
|
208 | - public function listIsEmpty(Tree $tree): bool |
|
209 | - { |
|
210 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * {@inheritDoc} |
|
215 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | - */ |
|
217 | - public function listSubscribedHooks(): array |
|
218 | - { |
|
219 | - return [ |
|
220 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | - ]; |
|
222 | - } |
|
53 | + use ModuleMyArtJaubTrait { |
|
54 | + ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | + } |
|
56 | + use ModuleConfigTrait; |
|
57 | + use ModuleGlobalTrait; |
|
58 | + use ModuleListTrait; |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | + */ |
|
64 | + public function title(): string |
|
65 | + { |
|
66 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | + */ |
|
73 | + public function description(): string |
|
74 | + { |
|
75 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * {@inheritDoc} |
|
81 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | + */ |
|
83 | + public function boot(): void |
|
84 | + { |
|
85 | + $this->traitMajBoot(); |
|
86 | + |
|
87 | + Registry::elementFactory()->registerTags([ |
|
88 | + 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | + 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | + 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | + 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | + 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | + 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | + 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | + 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | + ]); |
|
97 | + |
|
98 | + Registry::elementFactory()->registerSubTags([ |
|
99 | + 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | + 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | + 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | + 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | + 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | + 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | + 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | + 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | + ]); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | + */ |
|
114 | + public function loadRoutes($router): void |
|
115 | + { |
|
116 | + $router->attach('', '', static function (Map $router): void { |
|
117 | + |
|
118 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | + |
|
120 | + $router->attach('', '/admin', static function (Map $router): void { |
|
121 | + |
|
122 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | + ->extras([ |
|
125 | + 'middleware' => [ |
|
126 | + AuthManager::class, |
|
127 | + ], |
|
128 | + ]); |
|
129 | + }); |
|
130 | + |
|
131 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | + ->extras([ |
|
133 | + 'middleware' => [AuthTreePreference::class], |
|
134 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | + ]); |
|
136 | + |
|
137 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | + ->extras([ |
|
139 | + 'middleware' => [AuthTreePreference::class], |
|
140 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | + ]); |
|
142 | + |
|
143 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | + |
|
145 | + $router->extras([ |
|
146 | + 'middleware' => [AuthTreePreference::class], |
|
147 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | + ]); |
|
149 | + |
|
150 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | + }); |
|
153 | + }); |
|
154 | + }); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * {@inheritDoc} |
|
159 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | + */ |
|
161 | + public function customModuleVersion(): string |
|
162 | + { |
|
163 | + return '2.1.1-v.1'; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * {@inheritDoc} |
|
168 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | + */ |
|
170 | + public function getConfigLink(): string |
|
171 | + { |
|
172 | + return route(AdminConfigPage::class); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * {@inheritDoc} |
|
177 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | + */ |
|
179 | + public function headContent(): string |
|
180 | + { |
|
181 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * {@inheritDoc} |
|
186 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | + * |
|
188 | + * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | + */ |
|
190 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | + { |
|
192 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * {@inheritDoc} |
|
197 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | + */ |
|
199 | + public function listMenuClass(): string |
|
200 | + { |
|
201 | + return 'menu-maj-certificates'; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * {@inheritDoc} |
|
206 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | + */ |
|
208 | + public function listIsEmpty(Tree $tree): bool |
|
209 | + { |
|
210 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * {@inheritDoc} |
|
215 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | + */ |
|
217 | + public function listSubscribedHooks(): array |
|
218 | + { |
|
219 | + return [ |
|
220 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | + ]; |
|
222 | + } |
|
223 | 223 | } |