@@ -23,92 +23,92 @@ |
||
23 | 23 | */ |
24 | 24 | class MapColorsConfig implements JsonSerializable |
25 | 25 | { |
26 | - private Color $default; |
|
27 | - private Color $stroke; |
|
28 | - private Color $max_value; |
|
29 | - private Color $hover; |
|
26 | + private Color $default; |
|
27 | + private Color $stroke; |
|
28 | + private Color $max_value; |
|
29 | + private Color $hover; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for MapColorsConfig |
|
33 | - * |
|
34 | - * @param Color $default |
|
35 | - * @param Color $stroke |
|
36 | - * @param Color $max_value |
|
37 | - * @param Color $hover |
|
38 | - */ |
|
39 | - public function __construct( |
|
40 | - Color $default, |
|
41 | - Color $stroke, |
|
42 | - Color $max_value, |
|
43 | - Color $hover |
|
44 | - ) { |
|
45 | - $this->default = $default; |
|
46 | - $this->stroke = $stroke; |
|
47 | - $this->max_value = $max_value; |
|
48 | - $this->hover = $hover; |
|
49 | - } |
|
31 | + /** |
|
32 | + * Constructor for MapColorsConfig |
|
33 | + * |
|
34 | + * @param Color $default |
|
35 | + * @param Color $stroke |
|
36 | + * @param Color $max_value |
|
37 | + * @param Color $hover |
|
38 | + */ |
|
39 | + public function __construct( |
|
40 | + Color $default, |
|
41 | + Color $stroke, |
|
42 | + Color $max_value, |
|
43 | + Color $hover |
|
44 | + ) { |
|
45 | + $this->default = $default; |
|
46 | + $this->stroke = $stroke; |
|
47 | + $this->max_value = $max_value; |
|
48 | + $this->hover = $hover; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Get the default color for the features |
|
53 | - * |
|
54 | - * @return Color |
|
55 | - */ |
|
56 | - public function defaultColor(): Color |
|
57 | - { |
|
58 | - return $this->default; |
|
59 | - } |
|
51 | + /** |
|
52 | + * Get the default color for the features |
|
53 | + * |
|
54 | + * @return Color |
|
55 | + */ |
|
56 | + public function defaultColor(): Color |
|
57 | + { |
|
58 | + return $this->default; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Get the color for the features' strokes |
|
63 | - * |
|
64 | - * @return Color |
|
65 | - */ |
|
66 | - public function strokeColor(): Color |
|
67 | - { |
|
68 | - return $this->stroke; |
|
69 | - } |
|
61 | + /** |
|
62 | + * Get the color for the features' strokes |
|
63 | + * |
|
64 | + * @return Color |
|
65 | + */ |
|
66 | + public function strokeColor(): Color |
|
67 | + { |
|
68 | + return $this->stroke; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get the color for the features with the lowest count |
|
73 | - * |
|
74 | - * @return Color |
|
75 | - */ |
|
76 | - public function minValueColor(): Color |
|
77 | - { |
|
78 | - return new Rgb(255, 255, 255); |
|
79 | - } |
|
71 | + /** |
|
72 | + * Get the color for the features with the lowest count |
|
73 | + * |
|
74 | + * @return Color |
|
75 | + */ |
|
76 | + public function minValueColor(): Color |
|
77 | + { |
|
78 | + return new Rgb(255, 255, 255); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Get the color for the features with the highest count |
|
83 | - * |
|
84 | - * @return Color |
|
85 | - */ |
|
86 | - public function maxValueColor(): Color |
|
87 | - { |
|
88 | - return $this->max_value; |
|
89 | - } |
|
81 | + /** |
|
82 | + * Get the color for the features with the highest count |
|
83 | + * |
|
84 | + * @return Color |
|
85 | + */ |
|
86 | + public function maxValueColor(): Color |
|
87 | + { |
|
88 | + return $this->max_value; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Get the color for feature hovering |
|
93 | - * |
|
94 | - * @return Color |
|
95 | - */ |
|
96 | - public function hoverColor(): Color |
|
97 | - { |
|
98 | - return $this->hover; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Get the color for feature hovering |
|
93 | + * |
|
94 | + * @return Color |
|
95 | + */ |
|
96 | + public function hoverColor(): Color |
|
97 | + { |
|
98 | + return $this->hover; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * {@inheritDoc} |
|
103 | - * @see JsonSerializable::jsonSerialize() |
|
104 | - */ |
|
105 | - public function jsonSerialize() |
|
106 | - { |
|
107 | - return [ |
|
108 | - 'default' => (string) $this->defaultColor()->toHex(), |
|
109 | - 'stroke' => (string) $this->strokeColor()->toHex(), |
|
110 | - 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
111 | - 'hover' => (string) $this->hoverColor()->toHex(), |
|
112 | - ]; |
|
113 | - } |
|
101 | + /** |
|
102 | + * {@inheritDoc} |
|
103 | + * @see JsonSerializable::jsonSerialize() |
|
104 | + */ |
|
105 | + public function jsonSerialize() |
|
106 | + { |
|
107 | + return [ |
|
108 | + 'default' => (string) $this->defaultColor()->toHex(), |
|
109 | + 'stroke' => (string) $this->strokeColor()->toHex(), |
|
110 | + 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
111 | + 'hover' => (string) $this->hoverColor()->toHex(), |
|
112 | + ]; |
|
113 | + } |
|
114 | 114 | } |
@@ -26,61 +26,61 @@ |
||
26 | 26 | */ |
27 | 27 | class NullPlaceMapperConfig implements PlaceMapperConfigInterface |
28 | 28 | { |
29 | - /** |
|
30 | - * {@inheritDoc} |
|
31 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
32 | - */ |
|
33 | - public function get(string $key, $default = null) |
|
34 | - { |
|
35 | - return $default; |
|
36 | - } |
|
29 | + /** |
|
30 | + * {@inheritDoc} |
|
31 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
32 | + */ |
|
33 | + public function get(string $key, $default = null) |
|
34 | + { |
|
35 | + return $default; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritDoc} |
|
40 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
41 | - */ |
|
42 | - public function has(string $key): bool |
|
43 | - { |
|
44 | - return false; |
|
45 | - } |
|
38 | + /** |
|
39 | + * {@inheritDoc} |
|
40 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
41 | + */ |
|
42 | + public function has(string $key): bool |
|
43 | + { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
50 | - * |
|
51 | - * @param mixed $config |
|
52 | - * @return $this |
|
53 | - */ |
|
54 | - public function jsonDeserialize($config): self |
|
55 | - { |
|
56 | - return $this; |
|
57 | - } |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
50 | + * |
|
51 | + * @param mixed $config |
|
52 | + * @return $this |
|
53 | + */ |
|
54 | + public function jsonDeserialize($config): self |
|
55 | + { |
|
56 | + return $this; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see JsonSerializable::jsonSerialize() |
|
62 | - */ |
|
63 | - public function jsonSerialize() |
|
64 | - { |
|
65 | - return []; |
|
66 | - } |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see JsonSerializable::jsonSerialize() |
|
62 | + */ |
|
63 | + public function jsonSerialize() |
|
64 | + { |
|
65 | + return []; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
71 | - */ |
|
72 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
73 | - { |
|
74 | - return ''; |
|
75 | - } |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
71 | + */ |
|
72 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
73 | + { |
|
74 | + return ''; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * {@inheritDoc} |
|
79 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
80 | - * @return $this |
|
81 | - */ |
|
82 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
83 | - { |
|
84 | - return $this; |
|
85 | - } |
|
77 | + /** |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
80 | + * @return $this |
|
81 | + */ |
|
82 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
83 | + { |
|
84 | + return $this; |
|
85 | + } |
|
86 | 86 | } |
@@ -23,51 +23,51 @@ |
||
23 | 23 | */ |
24 | 24 | class MapViewConfig implements MapViewConfigInterface |
25 | 25 | { |
26 | - private string $map_mapping_property; |
|
27 | - private PlaceMapperConfigInterface $mapper_config; |
|
26 | + private string $map_mapping_property; |
|
27 | + private PlaceMapperConfigInterface $mapper_config; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor for MapViewConfig |
|
31 | - * |
|
32 | - * @param string $map_mapping_property |
|
33 | - * @param PlaceMapperConfigInterface $mapper_config |
|
34 | - */ |
|
35 | - public function __construct( |
|
36 | - string $map_mapping_property, |
|
37 | - PlaceMapperConfigInterface $mapper_config = null |
|
38 | - ) { |
|
39 | - $this->map_mapping_property = $map_mapping_property; |
|
40 | - $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
41 | - } |
|
29 | + /** |
|
30 | + * Constructor for MapViewConfig |
|
31 | + * |
|
32 | + * @param string $map_mapping_property |
|
33 | + * @param PlaceMapperConfigInterface $mapper_config |
|
34 | + */ |
|
35 | + public function __construct( |
|
36 | + string $map_mapping_property, |
|
37 | + PlaceMapperConfigInterface $mapper_config = null |
|
38 | + ) { |
|
39 | + $this->map_mapping_property = $map_mapping_property; |
|
40 | + $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
46 | - */ |
|
47 | - public function mapMappingProperty(): string |
|
48 | - { |
|
49 | - return $this->map_mapping_property; |
|
50 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
46 | + */ |
|
47 | + public function mapMappingProperty(): string |
|
48 | + { |
|
49 | + return $this->map_mapping_property; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
55 | - */ |
|
56 | - public function mapperConfig(): PlaceMapperConfigInterface |
|
57 | - { |
|
58 | - return $this->mapper_config; |
|
59 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
55 | + */ |
|
56 | + public function mapperConfig(): PlaceMapperConfigInterface |
|
57 | + { |
|
58 | + return $this->mapper_config; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * {@inheritDoc} |
|
63 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
64 | - * @return static |
|
65 | - */ |
|
66 | - public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
67 | - { |
|
68 | - $new = clone $this; |
|
69 | - $new->map_mapping_property = $mapping_property; |
|
70 | - $new->mapper_config = $mapper_config; |
|
71 | - return $new; |
|
72 | - } |
|
61 | + /** |
|
62 | + * {@inheritDoc} |
|
63 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
64 | + * @return static |
|
65 | + */ |
|
66 | + public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
67 | + { |
|
68 | + $new = clone $this; |
|
69 | + $new->map_mapping_property = $mapping_property; |
|
70 | + $new->mapper_config = $mapper_config; |
|
71 | + return $new; |
|
72 | + } |
|
73 | 73 | } |
@@ -30,294 +30,294 @@ |
||
30 | 30 | */ |
31 | 31 | class SosaRecordsService |
32 | 32 | { |
33 | - private ?int $max_system_generations = null; |
|
33 | + private ?int $max_system_generations = null; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Maximum number of generation the system is able to hold. |
|
37 | - * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | - * |
|
39 | - * @return int |
|
40 | - */ |
|
41 | - public function maxSystemGenerations(): int |
|
42 | - { |
|
43 | - if ($this->max_system_generations === null) { |
|
44 | - $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | - } |
|
46 | - return $this->max_system_generations; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Maximum number of generation the system is able to hold. |
|
37 | + * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | + * |
|
39 | + * @return int |
|
40 | + */ |
|
41 | + public function maxSystemGenerations(): int |
|
42 | + { |
|
43 | + if ($this->max_system_generations === null) { |
|
44 | + $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | + } |
|
46 | + return $this->max_system_generations; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Calculate the generation of a sosa |
|
51 | - * Sosa 1 is of generation 1. |
|
52 | - * |
|
53 | - * @param int $sosa |
|
54 | - * @return int |
|
55 | - */ |
|
56 | - public function generation(int $sosa): int |
|
57 | - { |
|
58 | - return BigInteger::of($sosa)->getBitLength(); |
|
59 | - } |
|
49 | + /** |
|
50 | + * Calculate the generation of a sosa |
|
51 | + * Sosa 1 is of generation 1. |
|
52 | + * |
|
53 | + * @param int $sosa |
|
54 | + * @return int |
|
55 | + */ |
|
56 | + public function generation(int $sosa): int |
|
57 | + { |
|
58 | + return BigInteger::of($sosa)->getBitLength(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | - * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | - * |
|
65 | - * @param int $sosa |
|
66 | - * @param int $gen |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | - { |
|
71 | - $gen_sosa = $this->generation($sosa); |
|
72 | - return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | - ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | - ->toInt(); |
|
75 | - } |
|
61 | + /** |
|
62 | + * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | + * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | + * |
|
65 | + * @param int $sosa |
|
66 | + * @param int $gen |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | + { |
|
71 | + $gen_sosa = $this->generation($sosa); |
|
72 | + return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | + ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | + ->toInt(); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Check whether an individual is a Sosa ancestor. |
|
79 | - * |
|
80 | - * @param Tree $tree |
|
81 | - * @param UserInterface $user |
|
82 | - * @param Individual $indi |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | - { |
|
87 | - return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | - } |
|
77 | + /** |
|
78 | + * Check whether an individual is a Sosa ancestor. |
|
79 | + * |
|
80 | + * @param Tree $tree |
|
81 | + * @param UserInterface $user |
|
82 | + * @param Individual $indi |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | + { |
|
87 | + return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns all Sosa numbers associated to an Individual |
|
92 | - * |
|
93 | - * @param Tree $tree |
|
94 | - * @param UserInterface $user |
|
95 | - * @param Individual $indi |
|
96 | - * @return Collection<int, int> |
|
97 | - */ |
|
98 | - public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | - { |
|
100 | - return Registry::cache()->array()->remember( |
|
101 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | - function () use ($tree, $user, $indi): Collection { |
|
103 | - return DB::table('maj_sosa') |
|
104 | - ->select(['majs_sosa', 'majs_gen']) |
|
105 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | - ->where('majs_user_id', '=', $user->id()) |
|
107 | - ->where('majs_i_id', '=', $indi->xref()) |
|
108 | - ->orderBy('majs_sosa') |
|
109 | - ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | - } |
|
111 | - ); |
|
112 | - } |
|
90 | + /** |
|
91 | + * Returns all Sosa numbers associated to an Individual |
|
92 | + * |
|
93 | + * @param Tree $tree |
|
94 | + * @param UserInterface $user |
|
95 | + * @param Individual $indi |
|
96 | + * @return Collection<int, int> |
|
97 | + */ |
|
98 | + public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | + { |
|
100 | + return Registry::cache()->array()->remember( |
|
101 | + 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | + function () use ($tree, $user, $indi): Collection { |
|
103 | + return DB::table('maj_sosa') |
|
104 | + ->select(['majs_sosa', 'majs_gen']) |
|
105 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | + ->where('majs_user_id', '=', $user->id()) |
|
107 | + ->where('majs_i_id', '=', $indi->xref()) |
|
108 | + ->orderBy('majs_sosa') |
|
109 | + ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | + } |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Return a list of the Sosa ancestors across all generation |
|
116 | - * |
|
117 | - * @param Tree $tree |
|
118 | - * @param UserInterface $user |
|
119 | - * @return Collection<\stdClass> |
|
120 | - */ |
|
121 | - public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | - { |
|
123 | - return DB::table('maj_sosa') |
|
124 | - ->select(['majs_sosa', 'majs_i_id']) |
|
125 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | - ->where('majs_user_id', '=', $user->id()) |
|
127 | - ->orderBy('majs_sosa') |
|
128 | - ->get(); |
|
129 | - } |
|
114 | + /** |
|
115 | + * Return a list of the Sosa ancestors across all generation |
|
116 | + * |
|
117 | + * @param Tree $tree |
|
118 | + * @param UserInterface $user |
|
119 | + * @return Collection<\stdClass> |
|
120 | + */ |
|
121 | + public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | + { |
|
123 | + return DB::table('maj_sosa') |
|
124 | + ->select(['majs_sosa', 'majs_i_id']) |
|
125 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | + ->where('majs_user_id', '=', $user->id()) |
|
127 | + ->orderBy('majs_sosa') |
|
128 | + ->get(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Return a list of the Sosa ancestors at a given generation |
|
133 | - * |
|
134 | - * @param Tree $tree |
|
135 | - * @param UserInterface $user |
|
136 | - * @param int $gen |
|
137 | - * @return Collection<\stdClass> |
|
138 | - */ |
|
139 | - public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | - { |
|
141 | - return DB::table('maj_sosa') |
|
142 | - ->select(['majs_sosa', 'majs_i_id']) |
|
143 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | - ->where('majs_user_id', '=', $user->id()) |
|
145 | - ->where('majs_gen', '=', $gen) |
|
146 | - ->orderBy('majs_sosa') |
|
147 | - ->get(); |
|
148 | - } |
|
131 | + /** |
|
132 | + * Return a list of the Sosa ancestors at a given generation |
|
133 | + * |
|
134 | + * @param Tree $tree |
|
135 | + * @param UserInterface $user |
|
136 | + * @param int $gen |
|
137 | + * @return Collection<\stdClass> |
|
138 | + */ |
|
139 | + public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | + { |
|
141 | + return DB::table('maj_sosa') |
|
142 | + ->select(['majs_sosa', 'majs_i_id']) |
|
143 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | + ->where('majs_user_id', '=', $user->id()) |
|
145 | + ->where('majs_gen', '=', $gen) |
|
146 | + ->orderBy('majs_sosa') |
|
147 | + ->get(); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Return a list of the Sosa families at a given generation |
|
152 | - * |
|
153 | - * @param Tree $tree |
|
154 | - * @param UserInterface $user |
|
155 | - * @param int $gen |
|
156 | - * @return Collection<\stdClass> |
|
157 | - */ |
|
158 | - public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | - { |
|
160 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | - return DB::table('families') |
|
162 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | - // Link to family husband |
|
164 | - $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | - ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | - ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | - ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | - }) |
|
169 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | - // Link to family husband |
|
171 | - $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | - ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | - ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | - ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | - }) |
|
176 | - ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | - ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | - ->orderBy('sosa_husb.majs_sosa') |
|
180 | - ->get(); |
|
181 | - } |
|
150 | + /** |
|
151 | + * Return a list of the Sosa families at a given generation |
|
152 | + * |
|
153 | + * @param Tree $tree |
|
154 | + * @param UserInterface $user |
|
155 | + * @param int $gen |
|
156 | + * @return Collection<\stdClass> |
|
157 | + */ |
|
158 | + public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | + { |
|
160 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | + return DB::table('families') |
|
162 | + ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | + // Link to family husband |
|
164 | + $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | + ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | + ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | + ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | + }) |
|
169 | + ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | + // Link to family husband |
|
171 | + $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | + ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | + ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | + ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | + }) |
|
176 | + ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | + ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | + ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | + ->orderBy('sosa_husb.majs_sosa') |
|
180 | + ->get(); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Return a list of Sosa ancestors missing at a given generation. |
|
185 | - * It includes the reference of either parent if it is known. |
|
186 | - * |
|
187 | - * @param Tree $tree |
|
188 | - * @param UserInterface $user |
|
189 | - * @param int $gen |
|
190 | - * @return Collection<\stdClass> |
|
191 | - */ |
|
192 | - public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | - { |
|
194 | - if ($gen == 1) { |
|
195 | - return collect(); |
|
196 | - } |
|
183 | + /** |
|
184 | + * Return a list of Sosa ancestors missing at a given generation. |
|
185 | + * It includes the reference of either parent if it is known. |
|
186 | + * |
|
187 | + * @param Tree $tree |
|
188 | + * @param UserInterface $user |
|
189 | + * @param int $gen |
|
190 | + * @return Collection<\stdClass> |
|
191 | + */ |
|
192 | + public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | + { |
|
194 | + if ($gen == 1) { |
|
195 | + return collect(); |
|
196 | + } |
|
197 | 197 | |
198 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | - return DB::table('maj_sosa AS sosa') |
|
200 | - ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | - // Link to sosa's father |
|
204 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | - ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | - ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | - }) |
|
208 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | - // Link to sosa's mother |
|
210 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | - ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | - ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | - }) |
|
214 | - ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | - ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | - ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | - ->where(function (Builder $query): void { |
|
218 | - $query->whereNull('sosa_fat.majs_i_id') |
|
219 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | - }) |
|
221 | - ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | - ->get(); |
|
224 | - } |
|
198 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | + return DB::table('maj_sosa AS sosa') |
|
200 | + ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | + ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | + // Link to sosa's father |
|
204 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | + ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | + ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | + }) |
|
208 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | + // Link to sosa's mother |
|
210 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | + ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | + ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | + }) |
|
214 | + ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | + ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | + ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | + ->where(function (Builder $query): void { |
|
218 | + $query->whereNull('sosa_fat.majs_i_id') |
|
219 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | + }) |
|
221 | + ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | + ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | + ->get(); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Remove all Sosa entries related to the gedcom file and user |
|
228 | - * |
|
229 | - * @param Tree $tree |
|
230 | - * @param UserInterface $user |
|
231 | - */ |
|
232 | - public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | - { |
|
234 | - DB::table('maj_sosa') |
|
235 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | - ->where('majs_user_id', '=', $user->id()) |
|
237 | - ->delete(); |
|
238 | - } |
|
226 | + /** |
|
227 | + * Remove all Sosa entries related to the gedcom file and user |
|
228 | + * |
|
229 | + * @param Tree $tree |
|
230 | + * @param UserInterface $user |
|
231 | + */ |
|
232 | + public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | + { |
|
234 | + DB::table('maj_sosa') |
|
235 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | + ->where('majs_user_id', '=', $user->id()) |
|
237 | + ->delete(); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * |
|
242 | - * @param Tree $tree |
|
243 | - * @param UserInterface $user |
|
244 | - * @param int $sosa |
|
245 | - */ |
|
246 | - public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | - { |
|
248 | - DB::table('maj_sosa') |
|
249 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | - ->where('majs_user_id', '=', $user->id()) |
|
251 | - ->where('majs_sosa', '>=', $sosa) |
|
252 | - ->whereRaw( |
|
253 | - 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | - [$this->generation($sosa), $sosa] |
|
255 | - ) |
|
256 | - ->delete(); |
|
257 | - } |
|
240 | + /** |
|
241 | + * |
|
242 | + * @param Tree $tree |
|
243 | + * @param UserInterface $user |
|
244 | + * @param int $sosa |
|
245 | + */ |
|
246 | + public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | + { |
|
248 | + DB::table('maj_sosa') |
|
249 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | + ->where('majs_user_id', '=', $user->id()) |
|
251 | + ->where('majs_sosa', '>=', $sosa) |
|
252 | + ->whereRaw( |
|
253 | + 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | + [$this->generation($sosa), $sosa] |
|
255 | + ) |
|
256 | + ->delete(); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Insert (or update if already existing) a list of Sosa individuals |
|
261 | - * |
|
262 | - * @param Tree $tree |
|
263 | - * @param UserInterface $user |
|
264 | - * @param array<array<string,mixed>> $sosa_records |
|
265 | - */ |
|
266 | - public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | - { |
|
268 | - $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
259 | + /** |
|
260 | + * Insert (or update if already existing) a list of Sosa individuals |
|
261 | + * |
|
262 | + * @param Tree $tree |
|
263 | + * @param UserInterface $user |
|
264 | + * @param array<array<string,mixed>> $sosa_records |
|
265 | + */ |
|
266 | + public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | + { |
|
268 | + $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
269 | 269 | |
270 | - $bindings_placeholders = $bindings_values = []; |
|
271 | - $has_records = false; |
|
272 | - foreach ($sosa_records as $i => $row) { |
|
273 | - $gen = $this->generation($row['sosa']); |
|
274 | - if ($gen <= $this->maxSystemGenerations()) { |
|
275 | - $has_records = true; |
|
276 | - if ($mass_update) { |
|
277 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | - $bindings_values = array_merge( |
|
281 | - $bindings_values, |
|
282 | - [ |
|
283 | - 'tree_id' . $i => $tree->id(), |
|
284 | - 'user_id' . $i => $user->id(), |
|
285 | - 'sosa' . $i => $row['sosa'], |
|
286 | - 'indi_id' . $i => $row['indi'], |
|
287 | - 'gen' . $i => $gen, |
|
288 | - 'byear' . $i => $row['birth_year'], |
|
289 | - 'byearest' . $i => $row['birth_year_est'], |
|
290 | - 'dyear' . $i => $row['death_year'], |
|
291 | - 'dyearest' . $i => $row['death_year_est'] |
|
292 | - ] |
|
293 | - ); |
|
294 | - } else { |
|
295 | - DB::table('maj_sosa')->updateOrInsert( |
|
296 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
297 | - [ |
|
298 | - 'majs_i_id' => $row['indi'], |
|
299 | - 'majs_gen' => $gen, |
|
300 | - 'majs_birth_year' => $row['birth_year'], |
|
301 | - 'majs_birth_year_est' => $row['birth_year_est'], |
|
302 | - 'majs_death_year' => $row['death_year'], |
|
303 | - 'majs_death_year_est' => $row['death_year_est'] |
|
304 | - ] |
|
305 | - ); |
|
306 | - } |
|
307 | - } |
|
308 | - } |
|
270 | + $bindings_placeholders = $bindings_values = []; |
|
271 | + $has_records = false; |
|
272 | + foreach ($sosa_records as $i => $row) { |
|
273 | + $gen = $this->generation($row['sosa']); |
|
274 | + if ($gen <= $this->maxSystemGenerations()) { |
|
275 | + $has_records = true; |
|
276 | + if ($mass_update) { |
|
277 | + $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | + ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | + ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | + $bindings_values = array_merge( |
|
281 | + $bindings_values, |
|
282 | + [ |
|
283 | + 'tree_id' . $i => $tree->id(), |
|
284 | + 'user_id' . $i => $user->id(), |
|
285 | + 'sosa' . $i => $row['sosa'], |
|
286 | + 'indi_id' . $i => $row['indi'], |
|
287 | + 'gen' . $i => $gen, |
|
288 | + 'byear' . $i => $row['birth_year'], |
|
289 | + 'byearest' . $i => $row['birth_year_est'], |
|
290 | + 'dyear' . $i => $row['death_year'], |
|
291 | + 'dyearest' . $i => $row['death_year_est'] |
|
292 | + ] |
|
293 | + ); |
|
294 | + } else { |
|
295 | + DB::table('maj_sosa')->updateOrInsert( |
|
296 | + [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
297 | + [ |
|
298 | + 'majs_i_id' => $row['indi'], |
|
299 | + 'majs_gen' => $gen, |
|
300 | + 'majs_birth_year' => $row['birth_year'], |
|
301 | + 'majs_birth_year_est' => $row['birth_year_est'], |
|
302 | + 'majs_death_year' => $row['death_year'], |
|
303 | + 'majs_death_year_est' => $row['death_year_est'] |
|
304 | + ] |
|
305 | + ); |
|
306 | + } |
|
307 | + } |
|
308 | + } |
|
309 | 309 | |
310 | - if ($has_records && $mass_update) { |
|
311 | - DB::connection()->statement( |
|
312 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
313 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
314 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
315 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
316 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
317 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
318 | - ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
319 | - $bindings_values |
|
320 | - ); |
|
321 | - } |
|
322 | - } |
|
310 | + if ($has_records && $mass_update) { |
|
311 | + DB::connection()->statement( |
|
312 | + 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
313 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
314 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
315 | + ' VALUES ' . implode(',', $bindings_placeholders) . |
|
316 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
317 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
318 | + ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
319 | + $bindings_values |
|
320 | + ); |
|
321 | + } |
|
322 | + } |
|
323 | 323 | } |
@@ -33,161 +33,161 @@ |
||
33 | 33 | */ |
34 | 34 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
35 | 35 | { |
36 | - use ModuleMyArtJaubTrait; |
|
37 | - use ModuleBlockTrait; |
|
38 | - |
|
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | - */ |
|
43 | - public function title(): string |
|
44 | - { |
|
45 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
51 | - */ |
|
52 | - public function description(): string |
|
53 | - { |
|
54 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
55 | - return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
61 | - */ |
|
62 | - public function loadRoutes(Map $router): void |
|
63 | - { |
|
64 | - $router->attach('', '', static function (Map $router): void { |
|
65 | - |
|
66 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
67 | - $router->tokens(['block_id' => '\d+']); |
|
68 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
69 | - }); |
|
70 | - }); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
76 | - */ |
|
77 | - public function customModuleVersion(): string |
|
78 | - { |
|
79 | - return '2.0.11-v.2'; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * {@inheritDoc} |
|
84 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
85 | - * |
|
86 | - * @param mixed[] $config |
|
87 | - */ |
|
88 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
89 | - { |
|
90 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
91 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | - |
|
93 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
94 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
95 | - |
|
96 | - $content = view($this->name() . '::block-embed', [ |
|
97 | - 'block_id' => $block_id, |
|
98 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
99 | - 'fab_login_block_view' => $fab_login_block_view, |
|
100 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
101 | - 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
102 | - ]); |
|
103 | - |
|
104 | - if ($context !== self::CONTEXT_EMBED) { |
|
105 | - return view('modules/block-template', [ |
|
106 | - 'block' => Str::kebab($this->name()), |
|
107 | - 'id' => $block_id, |
|
108 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
109 | - 'title' => $tree->title(), |
|
110 | - 'content' => $content, |
|
111 | - ]); |
|
112 | - } |
|
113 | - |
|
114 | - return $content; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * {@inheritDoc} |
|
119 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
120 | - */ |
|
121 | - public function isTreeBlock(): bool |
|
122 | - { |
|
123 | - return true; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * {@inheritDoc} |
|
128 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
129 | - */ |
|
130 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
131 | - { |
|
132 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * {@inheritDoc} |
|
137 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
138 | - */ |
|
139 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
140 | - { |
|
141 | - $params = (array) $request->getParsedBody(); |
|
142 | - |
|
143 | - $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
144 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
145 | - if (!$matomo_enabled) { |
|
146 | - return; |
|
147 | - } |
|
148 | - |
|
149 | - if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
150 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
155 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - $this |
|
160 | - ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
161 | - ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
162 | - ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
163 | - |
|
164 | - Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
169 | - * |
|
170 | - * @param int $block_id |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public function isMatomoEnabled(int $block_id): bool |
|
174 | - { |
|
175 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
180 | - * |
|
181 | - * @param int $block_id |
|
182 | - * @return array<string, mixed> |
|
183 | - */ |
|
184 | - public function matomoSettings(int $block_id): array |
|
185 | - { |
|
186 | - return [ |
|
187 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
188 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
189 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
190 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
191 | - ]; |
|
192 | - } |
|
36 | + use ModuleMyArtJaubTrait; |
|
37 | + use ModuleBlockTrait; |
|
38 | + |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | + */ |
|
43 | + public function title(): string |
|
44 | + { |
|
45 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
51 | + */ |
|
52 | + public function description(): string |
|
53 | + { |
|
54 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
55 | + return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
61 | + */ |
|
62 | + public function loadRoutes(Map $router): void |
|
63 | + { |
|
64 | + $router->attach('', '', static function (Map $router): void { |
|
65 | + |
|
66 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
67 | + $router->tokens(['block_id' => '\d+']); |
|
68 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
69 | + }); |
|
70 | + }); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
76 | + */ |
|
77 | + public function customModuleVersion(): string |
|
78 | + { |
|
79 | + return '2.0.11-v.2'; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * {@inheritDoc} |
|
84 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
85 | + * |
|
86 | + * @param mixed[] $config |
|
87 | + */ |
|
88 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
89 | + { |
|
90 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
91 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | + |
|
93 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
94 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
95 | + |
|
96 | + $content = view($this->name() . '::block-embed', [ |
|
97 | + 'block_id' => $block_id, |
|
98 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
99 | + 'fab_login_block_view' => $fab_login_block_view, |
|
100 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
101 | + 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
102 | + ]); |
|
103 | + |
|
104 | + if ($context !== self::CONTEXT_EMBED) { |
|
105 | + return view('modules/block-template', [ |
|
106 | + 'block' => Str::kebab($this->name()), |
|
107 | + 'id' => $block_id, |
|
108 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
109 | + 'title' => $tree->title(), |
|
110 | + 'content' => $content, |
|
111 | + ]); |
|
112 | + } |
|
113 | + |
|
114 | + return $content; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * {@inheritDoc} |
|
119 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
120 | + */ |
|
121 | + public function isTreeBlock(): bool |
|
122 | + { |
|
123 | + return true; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * {@inheritDoc} |
|
128 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
129 | + */ |
|
130 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
131 | + { |
|
132 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * {@inheritDoc} |
|
137 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
138 | + */ |
|
139 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
140 | + { |
|
141 | + $params = (array) $request->getParsedBody(); |
|
142 | + |
|
143 | + $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
144 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
145 | + if (!$matomo_enabled) { |
|
146 | + return; |
|
147 | + } |
|
148 | + |
|
149 | + if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
150 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
155 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + $this |
|
160 | + ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
161 | + ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
162 | + ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
163 | + |
|
164 | + Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
169 | + * |
|
170 | + * @param int $block_id |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public function isMatomoEnabled(int $block_id): bool |
|
174 | + { |
|
175 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
180 | + * |
|
181 | + * @param int $block_id |
|
182 | + * @return array<string, mixed> |
|
183 | + */ |
|
184 | + public function matomoSettings(int $block_id): array |
|
185 | + { |
|
186 | + return [ |
|
187 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
188 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
189 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
190 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
191 | + ]; |
|
192 | + } |
|
193 | 193 | } |
@@ -26,82 +26,82 @@ |
||
26 | 26 | */ |
27 | 27 | trait ModuleMyArtJaubTrait |
28 | 28 | { |
29 | - use ModuleCustomTrait; |
|
30 | - |
|
31 | - /** |
|
32 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
33 | - */ |
|
34 | - public function boot(): void |
|
35 | - { |
|
36 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | - |
|
38 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
43 | - */ |
|
44 | - public function resourcesFolder(): string |
|
45 | - { |
|
46 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
51 | - */ |
|
52 | - public function customModuleAuthorName(): string |
|
53 | - { |
|
54 | - return 'Jonathan Jaubart'; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
59 | - */ |
|
60 | - public function customModuleSupportUrl(): string |
|
61 | - { |
|
62 | - return 'https://github.com/jon48/webtrees-lib'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
67 | - * |
|
68 | - * @return array<string, string> |
|
69 | - */ |
|
70 | - public function customTranslations(string $language): array |
|
71 | - { |
|
72 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
73 | - |
|
74 | - try { |
|
75 | - $translation = new Translation($translation_file); |
|
76 | - return $translation->asArray(); |
|
77 | - } catch (\Exception $e) { |
|
78 | - } |
|
79 | - |
|
80 | - return []; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
85 | - * |
|
86 | - * @param Map<\Aura\Router\Route> $router |
|
87 | - */ |
|
88 | - public function loadRoutes(Map $router): void |
|
89 | - { |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
94 | - */ |
|
95 | - public function moduleCssUrl(): string |
|
96 | - { |
|
97 | - /** @var ModuleThemeInterface $theme */ |
|
98 | - $theme = app(ModuleThemeInterface::class); |
|
99 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
100 | - |
|
101 | - if (file_exists($css_file)) { |
|
102 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
103 | - } else { |
|
104 | - return $this->assetUrl('css/default.min.css'); |
|
105 | - } |
|
106 | - } |
|
29 | + use ModuleCustomTrait; |
|
30 | + |
|
31 | + /** |
|
32 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
33 | + */ |
|
34 | + public function boot(): void |
|
35 | + { |
|
36 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | + |
|
38 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
43 | + */ |
|
44 | + public function resourcesFolder(): string |
|
45 | + { |
|
46 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
51 | + */ |
|
52 | + public function customModuleAuthorName(): string |
|
53 | + { |
|
54 | + return 'Jonathan Jaubart'; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
59 | + */ |
|
60 | + public function customModuleSupportUrl(): string |
|
61 | + { |
|
62 | + return 'https://github.com/jon48/webtrees-lib'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
67 | + * |
|
68 | + * @return array<string, string> |
|
69 | + */ |
|
70 | + public function customTranslations(string $language): array |
|
71 | + { |
|
72 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
73 | + |
|
74 | + try { |
|
75 | + $translation = new Translation($translation_file); |
|
76 | + return $translation->asArray(); |
|
77 | + } catch (\Exception $e) { |
|
78 | + } |
|
79 | + |
|
80 | + return []; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
85 | + * |
|
86 | + * @param Map<\Aura\Router\Route> $router |
|
87 | + */ |
|
88 | + public function loadRoutes(Map $router): void |
|
89 | + { |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
94 | + */ |
|
95 | + public function moduleCssUrl(): string |
|
96 | + { |
|
97 | + /** @var ModuleThemeInterface $theme */ |
|
98 | + $theme = app(ModuleThemeInterface::class); |
|
99 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
100 | + |
|
101 | + if (file_exists($css_file)) { |
|
102 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
103 | + } else { |
|
104 | + return $this->assetUrl('css/default.min.css'); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | } |
@@ -32,129 +32,129 @@ |
||
32 | 32 | */ |
33 | 33 | class CertificateFilesystemService |
34 | 34 | { |
35 | - /** |
|
36 | - * @var array<int,FilesystemOperator> $filesystem |
|
37 | - */ |
|
38 | - private array $filesystem = []; |
|
35 | + /** |
|
36 | + * @var array<int,FilesystemOperator> $filesystem |
|
37 | + */ |
|
38 | + private array $filesystem = []; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get the filesystem containing certificates for a tree. |
|
42 | - * |
|
43 | - * @param Tree $tree |
|
44 | - * @return FilesystemOperator |
|
45 | - */ |
|
46 | - public function filesystem(Tree $tree): FilesystemOperator |
|
47 | - { |
|
48 | - if (!isset($this->filesystem[$tree->id()])) { |
|
49 | - $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
50 | - $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
40 | + /** |
|
41 | + * Get the filesystem containing certificates for a tree. |
|
42 | + * |
|
43 | + * @param Tree $tree |
|
44 | + * @return FilesystemOperator |
|
45 | + */ |
|
46 | + public function filesystem(Tree $tree): FilesystemOperator |
|
47 | + { |
|
48 | + if (!isset($this->filesystem[$tree->id()])) { |
|
49 | + $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
50 | + $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
51 | 51 | |
52 | - $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
53 | - } |
|
54 | - return $this->filesystem[$tree->id()]; |
|
55 | - } |
|
52 | + $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
53 | + } |
|
54 | + return $this->filesystem[$tree->id()]; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Set the filesystem containing certificates for a tree. |
|
59 | - * |
|
60 | - * @param Tree $tree |
|
61 | - * @param FilesystemOperator $filesystem |
|
62 | - */ |
|
63 | - public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
64 | - { |
|
65 | - $this->filesystem[$tree->id()] = $filesystem; |
|
66 | - } |
|
57 | + /** |
|
58 | + * Set the filesystem containing certificates for a tree. |
|
59 | + * |
|
60 | + * @param Tree $tree |
|
61 | + * @param FilesystemOperator $filesystem |
|
62 | + */ |
|
63 | + public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
64 | + { |
|
65 | + $this->filesystem[$tree->id()] = $filesystem; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Create the Certificate object defined by a path on the filesystem. |
|
70 | - * |
|
71 | - * @param Tree $tree |
|
72 | - * @param string $path |
|
73 | - * @return Certificate|NULL |
|
74 | - */ |
|
75 | - public function certificate(Tree $tree, string $path): ?Certificate |
|
76 | - { |
|
77 | - $filesystem = $this->filesystem($tree); |
|
78 | - if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
79 | - return new Certificate($tree, $path); |
|
80 | - } |
|
81 | - return null; |
|
82 | - } |
|
68 | + /** |
|
69 | + * Create the Certificate object defined by a path on the filesystem. |
|
70 | + * |
|
71 | + * @param Tree $tree |
|
72 | + * @param string $path |
|
73 | + * @return Certificate|NULL |
|
74 | + */ |
|
75 | + public function certificate(Tree $tree, string $path): ?Certificate |
|
76 | + { |
|
77 | + $filesystem = $this->filesystem($tree); |
|
78 | + if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
79 | + return new Certificate($tree, $path); |
|
80 | + } |
|
81 | + return null; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get the cities (first-level folder) available in a the filesystem. |
|
86 | - * |
|
87 | - * @param Tree $tree |
|
88 | - * @return string[] |
|
89 | - */ |
|
90 | - public function cities(Tree $tree): array |
|
91 | - { |
|
92 | - $cities = $this->filesystem($tree) |
|
93 | - ->listContents('') |
|
94 | - ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
96 | - ->toArray(); |
|
97 | - usort($cities, I18N::comparator()); |
|
98 | - return $cities; |
|
99 | - } |
|
84 | + /** |
|
85 | + * Get the cities (first-level folder) available in a the filesystem. |
|
86 | + * |
|
87 | + * @param Tree $tree |
|
88 | + * @return string[] |
|
89 | + */ |
|
90 | + public function cities(Tree $tree): array |
|
91 | + { |
|
92 | + $cities = $this->filesystem($tree) |
|
93 | + ->listContents('') |
|
94 | + ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
95 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
96 | + ->toArray(); |
|
97 | + usort($cities, I18N::comparator()); |
|
98 | + return $cities; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the certificates available for a city (first-level folder). |
|
103 | - * |
|
104 | - * @param Tree $tree |
|
105 | - * @param string $city |
|
106 | - * @return Collection<Certificate> |
|
107 | - */ |
|
108 | - public function certificatesForCity(Tree $tree, string $city): Collection |
|
109 | - { |
|
110 | - $filesystem = $this->filesystem($tree); |
|
111 | - $certificates_paths = $filesystem->listContents($city) |
|
112 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
113 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
114 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
115 | - ->toArray(); |
|
116 | - usort($certificates_paths, I18N::comparator()); |
|
117 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
118 | - } |
|
101 | + /** |
|
102 | + * Get the certificates available for a city (first-level folder). |
|
103 | + * |
|
104 | + * @param Tree $tree |
|
105 | + * @param string $city |
|
106 | + * @return Collection<Certificate> |
|
107 | + */ |
|
108 | + public function certificatesForCity(Tree $tree, string $city): Collection |
|
109 | + { |
|
110 | + $filesystem = $this->filesystem($tree); |
|
111 | + $certificates_paths = $filesystem->listContents($city) |
|
112 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
113 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
114 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
115 | + ->toArray(); |
|
116 | + usort($certificates_paths, I18N::comparator()); |
|
117 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Get the certificates available for a city (first-level folder), containing a specified text. |
|
122 | - * |
|
123 | - * @param Tree $tree |
|
124 | - * @param string $city |
|
125 | - * @param string $contains |
|
126 | - * @return Collection<Certificate> |
|
127 | - */ |
|
128 | - public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
129 | - { |
|
130 | - $filesystem = $this->filesystem($tree); |
|
131 | - $certificates_paths = $filesystem->listContents($city) |
|
132 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
133 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
134 | - && mb_stripos($attributes->path(), $contains) !== false) |
|
135 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
136 | - ->toArray(); |
|
137 | - usort($certificates_paths, I18N::comparator()); |
|
138 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
139 | - } |
|
120 | + /** |
|
121 | + * Get the certificates available for a city (first-level folder), containing a specified text. |
|
122 | + * |
|
123 | + * @param Tree $tree |
|
124 | + * @param string $city |
|
125 | + * @param string $contains |
|
126 | + * @return Collection<Certificate> |
|
127 | + */ |
|
128 | + public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
129 | + { |
|
130 | + $filesystem = $this->filesystem($tree); |
|
131 | + $certificates_paths = $filesystem->listContents($city) |
|
132 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
133 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
134 | + && mb_stripos($attributes->path(), $contains) !== false) |
|
135 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
136 | + ->toArray(); |
|
137 | + usort($certificates_paths, I18N::comparator()); |
|
138 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Check if a file on the filesystem is supported by the certificate module. |
|
143 | - * |
|
144 | - * @param FilesystemOperator $filesystem |
|
145 | - * @param string $path |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
149 | - { |
|
150 | - try { |
|
151 | - $mime = $filesystem->mimeType($path); |
|
152 | - return Registry::cache()->array()->remember( |
|
153 | - 'maj-certif-supportedfiles-' . $mime, |
|
154 | - fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
155 | - ); |
|
156 | - } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
157 | - } |
|
158 | - return false; |
|
159 | - } |
|
141 | + /** |
|
142 | + * Check if a file on the filesystem is supported by the certificate module. |
|
143 | + * |
|
144 | + * @param FilesystemOperator $filesystem |
|
145 | + * @param string $path |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
149 | + { |
|
150 | + try { |
|
151 | + $mime = $filesystem->mimeType($path); |
|
152 | + return Registry::cache()->array()->remember( |
|
153 | + 'maj-certif-supportedfiles-' . $mime, |
|
154 | + fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
155 | + ); |
|
156 | + } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
157 | + } |
|
158 | + return false; |
|
159 | + } |
|
160 | 160 | } |
@@ -29,144 +29,144 @@ |
||
29 | 29 | class CertificateDataService |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Find individuals linked to a certificate. |
|
34 | - * |
|
35 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
36 | - * but does not work with Sqlite if no default escape has been defined} |
|
37 | - * |
|
38 | - * @param Certificate $certificate |
|
39 | - * @return Collection<\Fisharebest\Webtrees\Individual> |
|
40 | - */ |
|
41 | - public function linkedIndividuals(Certificate $certificate): Collection |
|
42 | - { |
|
43 | - $tree = $certificate->tree(); |
|
44 | - return DB::table('individuals') |
|
45 | - ->where('i_file', '=', $tree->id()) |
|
46 | - ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
47 | - ->select(['individuals.*']) |
|
48 | - ->get() |
|
49 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
50 | - ->filter(GedcomRecord::accessFilter()); |
|
51 | - } |
|
32 | + /** |
|
33 | + * Find individuals linked to a certificate. |
|
34 | + * |
|
35 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
36 | + * but does not work with Sqlite if no default escape has been defined} |
|
37 | + * |
|
38 | + * @param Certificate $certificate |
|
39 | + * @return Collection<\Fisharebest\Webtrees\Individual> |
|
40 | + */ |
|
41 | + public function linkedIndividuals(Certificate $certificate): Collection |
|
42 | + { |
|
43 | + $tree = $certificate->tree(); |
|
44 | + return DB::table('individuals') |
|
45 | + ->where('i_file', '=', $tree->id()) |
|
46 | + ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
47 | + ->select(['individuals.*']) |
|
48 | + ->get() |
|
49 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
50 | + ->filter(GedcomRecord::accessFilter()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Find families linked to a certificate. |
|
55 | - * |
|
56 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
57 | - * but does not work with Sqlite if no default escape has been defined} |
|
58 | - * |
|
59 | - * @param Certificate $certificate |
|
60 | - * @return Collection<\Fisharebest\Webtrees\Family> |
|
61 | - */ |
|
62 | - public function linkedFamilies(Certificate $certificate): Collection |
|
63 | - { |
|
64 | - $tree = $certificate->tree(); |
|
65 | - return DB::table('families') |
|
66 | - ->where('f_file', '=', $tree->id()) |
|
67 | - ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
68 | - ->select(['families.*']) |
|
69 | - ->get() |
|
70 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
71 | - ->filter(GedcomRecord::accessFilter()); |
|
72 | - } |
|
53 | + /** |
|
54 | + * Find families linked to a certificate. |
|
55 | + * |
|
56 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
57 | + * but does not work with Sqlite if no default escape has been defined} |
|
58 | + * |
|
59 | + * @param Certificate $certificate |
|
60 | + * @return Collection<\Fisharebest\Webtrees\Family> |
|
61 | + */ |
|
62 | + public function linkedFamilies(Certificate $certificate): Collection |
|
63 | + { |
|
64 | + $tree = $certificate->tree(); |
|
65 | + return DB::table('families') |
|
66 | + ->where('f_file', '=', $tree->id()) |
|
67 | + ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
68 | + ->select(['families.*']) |
|
69 | + ->get() |
|
70 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
71 | + ->filter(GedcomRecord::accessFilter()); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Find media objects linked to a certificate. |
|
76 | - * |
|
77 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
78 | - * but does not work with Sqlite if no default escape has been defined} |
|
79 | - * |
|
80 | - * @param Certificate $certificate |
|
81 | - * @return Collection<\Fisharebest\Webtrees\Media> |
|
82 | - */ |
|
83 | - public function linkedMedias(Certificate $certificate): Collection |
|
84 | - { |
|
85 | - $tree = $certificate->tree(); |
|
86 | - return DB::table('media') |
|
87 | - ->where('m_file', '=', $tree->id()) |
|
88 | - ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
89 | - ->select(['media.*']) |
|
90 | - ->get() |
|
91 | - ->map(Registry::mediaFactory()->mapper($tree)) |
|
92 | - ->filter(GedcomRecord::accessFilter()); |
|
93 | - } |
|
74 | + /** |
|
75 | + * Find media objects linked to a certificate. |
|
76 | + * |
|
77 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
78 | + * but does not work with Sqlite if no default escape has been defined} |
|
79 | + * |
|
80 | + * @param Certificate $certificate |
|
81 | + * @return Collection<\Fisharebest\Webtrees\Media> |
|
82 | + */ |
|
83 | + public function linkedMedias(Certificate $certificate): Collection |
|
84 | + { |
|
85 | + $tree = $certificate->tree(); |
|
86 | + return DB::table('media') |
|
87 | + ->where('m_file', '=', $tree->id()) |
|
88 | + ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
89 | + ->select(['media.*']) |
|
90 | + ->get() |
|
91 | + ->map(Registry::mediaFactory()->mapper($tree)) |
|
92 | + ->filter(GedcomRecord::accessFilter()); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Find notes linked to a certificate. |
|
97 | - * |
|
98 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
99 | - * but does not work with Sqlite if no default escape has been defined} |
|
100 | - * |
|
101 | - * @param Certificate $certificate |
|
102 | - * @return Collection<\Fisharebest\Webtrees\Note> |
|
103 | - */ |
|
104 | - public function linkedNotes(Certificate $certificate): Collection |
|
105 | - { |
|
106 | - $tree = $certificate->tree(); |
|
107 | - return DB::table('other') |
|
108 | - ->where('o_file', '=', $tree->id()) |
|
109 | - ->where('o_type', '=', 'NOTE') |
|
110 | - ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
111 | - ->select(['other.*']) |
|
112 | - ->get() |
|
113 | - ->map(Registry::noteFactory()->mapper($tree)) |
|
114 | - ->filter(GedcomRecord::accessFilter()); |
|
115 | - } |
|
95 | + /** |
|
96 | + * Find notes linked to a certificate. |
|
97 | + * |
|
98 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
99 | + * but does not work with Sqlite if no default escape has been defined} |
|
100 | + * |
|
101 | + * @param Certificate $certificate |
|
102 | + * @return Collection<\Fisharebest\Webtrees\Note> |
|
103 | + */ |
|
104 | + public function linkedNotes(Certificate $certificate): Collection |
|
105 | + { |
|
106 | + $tree = $certificate->tree(); |
|
107 | + return DB::table('other') |
|
108 | + ->where('o_file', '=', $tree->id()) |
|
109 | + ->where('o_type', '=', 'NOTE') |
|
110 | + ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
111 | + ->select(['other.*']) |
|
112 | + ->get() |
|
113 | + ->map(Registry::noteFactory()->mapper($tree)) |
|
114 | + ->filter(GedcomRecord::accessFilter()); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Return an escaped string to be used in SQL LIKE comparisons. |
|
119 | - * This would not work well for Sqlite, if the escape character is not defined. |
|
120 | - * |
|
121 | - * @param Certificate $certificate |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - protected function escapedSqlPath(Certificate $certificate): string |
|
125 | - { |
|
126 | - return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
127 | - } |
|
117 | + /** |
|
118 | + * Return an escaped string to be used in SQL LIKE comparisons. |
|
119 | + * This would not work well for Sqlite, if the escape character is not defined. |
|
120 | + * |
|
121 | + * @param Certificate $certificate |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + protected function escapedSqlPath(Certificate $certificate): string |
|
125 | + { |
|
126 | + return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Find a source linked to a citation where a certificate file is referenced. |
|
131 | - * |
|
132 | - * @param Certificate $certificate |
|
133 | - * @return Source|NULL |
|
134 | - */ |
|
135 | - public function oneLinkedSource(Certificate $certificate): ?Source |
|
136 | - { |
|
137 | - $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
138 | - $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
129 | + /** |
|
130 | + * Find a source linked to a citation where a certificate file is referenced. |
|
131 | + * |
|
132 | + * @param Certificate $certificate |
|
133 | + * @return Source|NULL |
|
134 | + */ |
|
135 | + public function oneLinkedSource(Certificate $certificate): ?Source |
|
136 | + { |
|
137 | + $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
138 | + $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
139 | 139 | |
140 | - foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
141 | - foreach ($linked_records as $gedcom_record) { |
|
142 | - foreach ($gedcom_record->facts() as $fact) { |
|
143 | - if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
144 | - foreach ($matches as $match) { |
|
145 | - $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
146 | - if ($source !== null && $source->canShowName()) { |
|
147 | - return $source; |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
140 | + foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
141 | + foreach ($linked_records as $gedcom_record) { |
|
142 | + foreach ($gedcom_record->facts() as $fact) { |
|
143 | + if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
144 | + foreach ($matches as $match) { |
|
145 | + $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
146 | + if ($source !== null && $source->canShowName()) { |
|
147 | + return $source; |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - return null; |
|
156 | - } |
|
155 | + return null; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Yield lists of gedcom records linked to a certificate. |
|
160 | - * |
|
161 | - * @param Certificate $certificate |
|
162 | - * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
163 | - * @psalm-suppress InvalidReturnType |
|
164 | - */ |
|
165 | - protected function linkedRecordsLists(Certificate $certificate): Generator |
|
166 | - { |
|
167 | - yield $this->linkedIndividuals($certificate); |
|
168 | - yield $this->linkedFamilies($certificate); |
|
169 | - yield $this->linkedMedias($certificate); |
|
170 | - yield $this->linkedNotes($certificate); |
|
171 | - } |
|
158 | + /** |
|
159 | + * Yield lists of gedcom records linked to a certificate. |
|
160 | + * |
|
161 | + * @param Certificate $certificate |
|
162 | + * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
163 | + * @psalm-suppress InvalidReturnType |
|
164 | + */ |
|
165 | + protected function linkedRecordsLists(Certificate $certificate): Generator |
|
166 | + { |
|
167 | + yield $this->linkedIndividuals($certificate); |
|
168 | + yield $this->linkedFamilies($certificate); |
|
169 | + yield $this->linkedMedias($certificate); |
|
170 | + yield $this->linkedNotes($certificate); |
|
171 | + } |
|
172 | 172 | } |
@@ -25,193 +25,193 @@ |
||
25 | 25 | */ |
26 | 26 | class Certificate |
27 | 27 | { |
28 | - /** |
|
29 | - * Pattern to extract information from a file name. |
|
30 | - * Specific to the author's workflow. |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | - |
|
35 | - private Tree $tree; |
|
36 | - private string $path; |
|
37 | - private ?string $city = null; |
|
38 | - private ?string $basename = null; |
|
39 | - private ?string $filename = null; |
|
40 | - private ?string $extension = null; |
|
41 | - private ?string $type = null; |
|
42 | - private ?string $description = null; |
|
43 | - private ?Date $date = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * Contructor for Certificate |
|
47 | - * |
|
48 | - * @param Tree $tree |
|
49 | - * @param string $path |
|
50 | - */ |
|
51 | - public function __construct(Tree $tree, string $path) |
|
52 | - { |
|
53 | - $this->tree = $tree; |
|
54 | - $this->path = $path; |
|
55 | - $this->extractDataFromPath($path); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | - * Logic specific to the author. |
|
61 | - * |
|
62 | - * @param string $path |
|
63 | - */ |
|
64 | - protected function extractDataFromPath(string $path): void |
|
65 | - { |
|
66 | - $path_parts = pathinfo($path); |
|
67 | - $this->city = $path_parts['dirname']; |
|
68 | - $this->basename = $path_parts['basename']; |
|
69 | - $this->filename = $path_parts['filename']; |
|
70 | - $this->extension = strtolower($path_parts['extension'] ?? ''); |
|
71 | - |
|
72 | - if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | - $this->type = $match['type']; |
|
74 | - $this->description = $match['descr']; |
|
75 | - |
|
76 | - $day = $match['day'] ?? ''; |
|
77 | - $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | - $year = $match['year'] ?? ''; |
|
80 | - |
|
81 | - $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | - } else { |
|
83 | - $this->description = $this->filename; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get the family tree of the certificate |
|
89 | - * |
|
90 | - * @return Tree |
|
91 | - */ |
|
92 | - public function tree(): Tree |
|
93 | - { |
|
94 | - return $this->tree; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get the path of the certificate in the file system. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function path(): string |
|
103 | - { |
|
104 | - return $this->path; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * The the path of the certificate, in a Gedcom canonical form. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function gedcomPath(): string |
|
113 | - { |
|
114 | - return str_replace('\\', '/', $this->path); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get the certificate name. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function name(): string |
|
123 | - { |
|
124 | - return $this->filename ?? ''; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get the certificate file name. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function filename(): string |
|
133 | - { |
|
134 | - return $this->basename ?? ''; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get the certificate's city (the first level folder). |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function city(): string |
|
143 | - { |
|
144 | - return $this->city ?? ''; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the certificate's date. Extracted from the file name. |
|
149 | - * |
|
150 | - * @return Date |
|
151 | - */ |
|
152 | - public function date(): Date |
|
153 | - { |
|
154 | - return $this->date ?? new Date(''); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Get the certificate's type. Extracted from the file name. |
|
159 | - * |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function type(): string |
|
163 | - { |
|
164 | - return $this->type ?? ''; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the certificate's description. Extracted from the file name. |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function description(): string |
|
172 | - { |
|
173 | - return $this->description ?? ''; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Get the certificate's description to be used for sorting. |
|
178 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function sortDescription(): string |
|
183 | - { |
|
184 | - $sort_prefix = ''; |
|
185 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | - return $match[1]; |
|
188 | - }, $matches)) . '_'; |
|
189 | - } |
|
190 | - return $sort_prefix . $this->description(); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get the certificate's MIME type. |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function mimeType(): string |
|
199 | - { |
|
200 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the base parameters to be used in url referencing the certificate. |
|
205 | - * |
|
206 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | - * @return array{tree: string, cid: mixed} |
|
208 | - */ |
|
209 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | - { |
|
211 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | - return [ |
|
213 | - 'tree' => $this->tree->name(), |
|
214 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | - ]; |
|
216 | - } |
|
28 | + /** |
|
29 | + * Pattern to extract information from a file name. |
|
30 | + * Specific to the author's workflow. |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | + |
|
35 | + private Tree $tree; |
|
36 | + private string $path; |
|
37 | + private ?string $city = null; |
|
38 | + private ?string $basename = null; |
|
39 | + private ?string $filename = null; |
|
40 | + private ?string $extension = null; |
|
41 | + private ?string $type = null; |
|
42 | + private ?string $description = null; |
|
43 | + private ?Date $date = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * Contructor for Certificate |
|
47 | + * |
|
48 | + * @param Tree $tree |
|
49 | + * @param string $path |
|
50 | + */ |
|
51 | + public function __construct(Tree $tree, string $path) |
|
52 | + { |
|
53 | + $this->tree = $tree; |
|
54 | + $this->path = $path; |
|
55 | + $this->extractDataFromPath($path); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | + * Logic specific to the author. |
|
61 | + * |
|
62 | + * @param string $path |
|
63 | + */ |
|
64 | + protected function extractDataFromPath(string $path): void |
|
65 | + { |
|
66 | + $path_parts = pathinfo($path); |
|
67 | + $this->city = $path_parts['dirname']; |
|
68 | + $this->basename = $path_parts['basename']; |
|
69 | + $this->filename = $path_parts['filename']; |
|
70 | + $this->extension = strtolower($path_parts['extension'] ?? ''); |
|
71 | + |
|
72 | + if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | + $this->type = $match['type']; |
|
74 | + $this->description = $match['descr']; |
|
75 | + |
|
76 | + $day = $match['day'] ?? ''; |
|
77 | + $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | + $year = $match['year'] ?? ''; |
|
80 | + |
|
81 | + $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | + } else { |
|
83 | + $this->description = $this->filename; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get the family tree of the certificate |
|
89 | + * |
|
90 | + * @return Tree |
|
91 | + */ |
|
92 | + public function tree(): Tree |
|
93 | + { |
|
94 | + return $this->tree; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get the path of the certificate in the file system. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function path(): string |
|
103 | + { |
|
104 | + return $this->path; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * The the path of the certificate, in a Gedcom canonical form. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function gedcomPath(): string |
|
113 | + { |
|
114 | + return str_replace('\\', '/', $this->path); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get the certificate name. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function name(): string |
|
123 | + { |
|
124 | + return $this->filename ?? ''; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get the certificate file name. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function filename(): string |
|
133 | + { |
|
134 | + return $this->basename ?? ''; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get the certificate's city (the first level folder). |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function city(): string |
|
143 | + { |
|
144 | + return $this->city ?? ''; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the certificate's date. Extracted from the file name. |
|
149 | + * |
|
150 | + * @return Date |
|
151 | + */ |
|
152 | + public function date(): Date |
|
153 | + { |
|
154 | + return $this->date ?? new Date(''); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Get the certificate's type. Extracted from the file name. |
|
159 | + * |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function type(): string |
|
163 | + { |
|
164 | + return $this->type ?? ''; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the certificate's description. Extracted from the file name. |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function description(): string |
|
172 | + { |
|
173 | + return $this->description ?? ''; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Get the certificate's description to be used for sorting. |
|
178 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function sortDescription(): string |
|
183 | + { |
|
184 | + $sort_prefix = ''; |
|
185 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | + return $match[1]; |
|
188 | + }, $matches)) . '_'; |
|
189 | + } |
|
190 | + return $sort_prefix . $this->description(); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get the certificate's MIME type. |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function mimeType(): string |
|
199 | + { |
|
200 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the base parameters to be used in url referencing the certificate. |
|
205 | + * |
|
206 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | + * @return array{tree: string, cid: mixed} |
|
208 | + */ |
|
209 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | + { |
|
211 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | + return [ |
|
213 | + 'tree' => $this->tree->name(), |
|
214 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | + ]; |
|
216 | + } |
|
217 | 217 | } |