Passed
Push — main ( 4197a4...465e30 )
by Jonathan
05:10
created
app/Module/GeoDispersion/Model/GeoAnalysisMapAdapter.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -29,189 +29,189 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMapAdapter
31 31
 {
32
-    private int $id;
33
-    private int $view_id;
34
-    private MapDefinitionInterface $map;
35
-    private PlaceMapperInterface $place_mapper;
36
-    private MapViewConfigInterface $config;
37
-
38
-    /**
39
-     * Constructor for GeoAnalysisMapAdapter
40
-     *
41
-     * @param int $id
42
-     * @param MapDefinitionInterface $map
43
-     * @param PlaceMapperInterface $mapper
44
-     * @param MapViewConfigInterface $config
45
-     */
46
-    public function __construct(
47
-        int $id,
48
-        int $view_id,
49
-        MapDefinitionInterface $map,
50
-        PlaceMapperInterface $mapper,
51
-        MapViewConfigInterface $config
52
-    ) {
53
-        $this->id = $id;
54
-        $this->view_id = $view_id;
55
-        $this->map = $map;
56
-        $this->place_mapper = $mapper;
57
-        $this->config = $config;
58
-        $this->place_mapper->setConfig($this->config->mapperConfig());
59
-        $this->place_mapper->setData('map', $map);
60
-        $this->place_mapper->boot();
61
-    }
62
-
63
-    /**
64
-     * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
-     *
66
-     * @param MapDefinitionInterface $map
67
-     * @param PlaceMapperInterface $mapper
68
-     * @param string $mapping_property
69
-     * @return static
70
-     */
71
-    public function with(
72
-        MapDefinitionInterface $map,
73
-        PlaceMapperInterface $mapper,
74
-        string $mapping_property
75
-    ): self {
76
-        $new = clone $this;
77
-        $new->map = $map;
78
-        $new->place_mapper = $mapper;
79
-        $new->config = $this->config->with($mapping_property, $mapper->config());
80
-        return $new;
81
-    }
82
-
83
-    /**
84
-     * Get the GeoAnalysisMapAdapter ID
85
-     *
86
-     * @return int
87
-     */
88
-    public function id(): int
89
-    {
90
-        return $this->id;
91
-    }
92
-
93
-    /**
94
-     * Get the ID of the associated GeoAnalysisView
95
-     *
96
-     * @return int
97
-     */
98
-    public function geoAnalysisViewId(): int
99
-    {
100
-        return $this->view_id;
101
-    }
102
-
103
-    /**
104
-     * Get the associated target map
105
-     *
106
-     * @return MapDefinitionInterface
107
-     */
108
-    public function map(): MapDefinitionInterface
109
-    {
110
-        return $this->map;
111
-    }
112
-
113
-    /**
114
-     * Get the Place Mapper used for the mapping
115
-     *
116
-     * @return PlaceMapperInterface
117
-     */
118
-    public function placeMapper(): PlaceMapperInterface
119
-    {
120
-        return $this->place_mapper;
121
-    }
122
-
123
-    /**
124
-     * Get the configuration of the Map View.
125
-     *
126
-     * @return MapViewConfigInterface
127
-     */
128
-    public function viewConfig(): MapViewConfigInterface
129
-    {
130
-        return $this->config;
131
-    }
132
-
133
-    /**
134
-     * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
-     *
136
-     * @param GeoAnalysisResult $result
137
-     * @return MapAdapterResult
138
-     */
139
-    public function convert(GeoAnalysisResult $result): MapAdapterResult
140
-    {
141
-        $result = $result->copy();
142
-
143
-        $features = [];
144
-        list($features_data, $result) = $this->featureAnalysisData($result);
145
-
146
-        $places_found = $result->countFound();
147
-        foreach ($this->map->features() as $feature) {
148
-            $feature_id = $this->featureId($feature);
149
-            if ($feature_id !== null && $features_data->has($feature_id)) {
150
-                /** @var MapFeatureAnalysisData $feature_data */
151
-                $feature_data = $features_data->get($feature_id)->tagAsExisting();
152
-                $place_count = $feature_data->count();
153
-                $features[] = $feature
154
-                    ->withProperty('count', $place_count)
155
-                    ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
-                    ->withProperty(
157
-                        'places',
158
-                        $feature_data->places()
159
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
-                            ->sort(I18N::comparator())
161
-                            ->toArray()
162
-                    );
163
-            } else {
164
-                $features[] = $feature;
165
-            }
166
-        }
167
-
168
-        $features_data
169
-            ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
-            ->each(
171
-                fn (MapFeatureAnalysisData $data) =>
172
-                    $data->places()->each(
173
-                        fn(GeoAnalysisPlace $place) => $result->exclude($place)
174
-                    )
175
-            );
176
-
177
-        return new MapAdapterResult($result, $features);
178
-    }
179
-
180
-    /**
181
-     * Populate the map features with the mapped Places and total count
182
-     *
183
-     * @param GeoAnalysisResult $result
184
-     * @return mixed[]
185
-     */
186
-    protected function featureAnalysisData(GeoAnalysisResult $result): array
187
-    {
188
-        $features_mapping = new Collection();
189
-
190
-        $byplaces = $result->knownPlaces();
191
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
192
-            $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
193
-
194
-            if ($id !== null && mb_strlen($id) > 0) {
195
-                $features_mapping->put(
196
-                    $id,
197
-                    $features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
198
-                );
199
-            } else {
200
-                $result->exclude($item->place());
201
-            }
202
-        });
203
-
204
-        return [ $features_mapping, $result];
205
-    }
206
-
207
-    /**
208
-     * Get the value of the feature property used for the mapping
209
-     *
210
-     * @param Feature $feature
211
-     * @return string|NULL
212
-     */
213
-    protected function featureId(Feature $feature): ?string
214
-    {
215
-        return $feature->getProperty($this->config->mapMappingProperty());
216
-    }
32
+	private int $id;
33
+	private int $view_id;
34
+	private MapDefinitionInterface $map;
35
+	private PlaceMapperInterface $place_mapper;
36
+	private MapViewConfigInterface $config;
37
+
38
+	/**
39
+	 * Constructor for GeoAnalysisMapAdapter
40
+	 *
41
+	 * @param int $id
42
+	 * @param MapDefinitionInterface $map
43
+	 * @param PlaceMapperInterface $mapper
44
+	 * @param MapViewConfigInterface $config
45
+	 */
46
+	public function __construct(
47
+		int $id,
48
+		int $view_id,
49
+		MapDefinitionInterface $map,
50
+		PlaceMapperInterface $mapper,
51
+		MapViewConfigInterface $config
52
+	) {
53
+		$this->id = $id;
54
+		$this->view_id = $view_id;
55
+		$this->map = $map;
56
+		$this->place_mapper = $mapper;
57
+		$this->config = $config;
58
+		$this->place_mapper->setConfig($this->config->mapperConfig());
59
+		$this->place_mapper->setData('map', $map);
60
+		$this->place_mapper->boot();
61
+	}
62
+
63
+	/**
64
+	 * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
+	 *
66
+	 * @param MapDefinitionInterface $map
67
+	 * @param PlaceMapperInterface $mapper
68
+	 * @param string $mapping_property
69
+	 * @return static
70
+	 */
71
+	public function with(
72
+		MapDefinitionInterface $map,
73
+		PlaceMapperInterface $mapper,
74
+		string $mapping_property
75
+	): self {
76
+		$new = clone $this;
77
+		$new->map = $map;
78
+		$new->place_mapper = $mapper;
79
+		$new->config = $this->config->with($mapping_property, $mapper->config());
80
+		return $new;
81
+	}
82
+
83
+	/**
84
+	 * Get the GeoAnalysisMapAdapter ID
85
+	 *
86
+	 * @return int
87
+	 */
88
+	public function id(): int
89
+	{
90
+		return $this->id;
91
+	}
92
+
93
+	/**
94
+	 * Get the ID of the associated GeoAnalysisView
95
+	 *
96
+	 * @return int
97
+	 */
98
+	public function geoAnalysisViewId(): int
99
+	{
100
+		return $this->view_id;
101
+	}
102
+
103
+	/**
104
+	 * Get the associated target map
105
+	 *
106
+	 * @return MapDefinitionInterface
107
+	 */
108
+	public function map(): MapDefinitionInterface
109
+	{
110
+		return $this->map;
111
+	}
112
+
113
+	/**
114
+	 * Get the Place Mapper used for the mapping
115
+	 *
116
+	 * @return PlaceMapperInterface
117
+	 */
118
+	public function placeMapper(): PlaceMapperInterface
119
+	{
120
+		return $this->place_mapper;
121
+	}
122
+
123
+	/**
124
+	 * Get the configuration of the Map View.
125
+	 *
126
+	 * @return MapViewConfigInterface
127
+	 */
128
+	public function viewConfig(): MapViewConfigInterface
129
+	{
130
+		return $this->config;
131
+	}
132
+
133
+	/**
134
+	 * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
+	 *
136
+	 * @param GeoAnalysisResult $result
137
+	 * @return MapAdapterResult
138
+	 */
139
+	public function convert(GeoAnalysisResult $result): MapAdapterResult
140
+	{
141
+		$result = $result->copy();
142
+
143
+		$features = [];
144
+		list($features_data, $result) = $this->featureAnalysisData($result);
145
+
146
+		$places_found = $result->countFound();
147
+		foreach ($this->map->features() as $feature) {
148
+			$feature_id = $this->featureId($feature);
149
+			if ($feature_id !== null && $features_data->has($feature_id)) {
150
+				/** @var MapFeatureAnalysisData $feature_data */
151
+				$feature_data = $features_data->get($feature_id)->tagAsExisting();
152
+				$place_count = $feature_data->count();
153
+				$features[] = $feature
154
+					->withProperty('count', $place_count)
155
+					->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
+					->withProperty(
157
+						'places',
158
+						$feature_data->places()
159
+							->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
+							->sort(I18N::comparator())
161
+							->toArray()
162
+					);
163
+			} else {
164
+				$features[] = $feature;
165
+			}
166
+		}
167
+
168
+		$features_data
169
+			->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
+			->each(
171
+				fn (MapFeatureAnalysisData $data) =>
172
+					$data->places()->each(
173
+						fn(GeoAnalysisPlace $place) => $result->exclude($place)
174
+					)
175
+			);
176
+
177
+		return new MapAdapterResult($result, $features);
178
+	}
179
+
180
+	/**
181
+	 * Populate the map features with the mapped Places and total count
182
+	 *
183
+	 * @param GeoAnalysisResult $result
184
+	 * @return mixed[]
185
+	 */
186
+	protected function featureAnalysisData(GeoAnalysisResult $result): array
187
+	{
188
+		$features_mapping = new Collection();
189
+
190
+		$byplaces = $result->knownPlaces();
191
+		$byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
192
+			$id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
193
+
194
+			if ($id !== null && mb_strlen($id) > 0) {
195
+				$features_mapping->put(
196
+					$id,
197
+					$features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
198
+				);
199
+			} else {
200
+				$result->exclude($item->place());
201
+			}
202
+		});
203
+
204
+		return [ $features_mapping, $result];
205
+	}
206
+
207
+	/**
208
+	 * Get the value of the feature property used for the mapping
209
+	 *
210
+	 * @param Feature $feature
211
+	 * @return string|NULL
212
+	 */
213
+	protected function featureId(Feature $feature): ?string
214
+	{
215
+		return $feature->getProperty($this->config->mapMappingProperty());
216
+	}
217 217
 }
Please login to merge, or discard this patch.
app/Module/PatronymicLineage/Model/LineageNode.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -25,106 +25,106 @@
 block discarded – undo
25 25
 class LineageNode
26 26
 {
27 27
 
28
-    /**
29
-     * @var Collection<string, stdClass>  $linked_fams Spouse families linked to the node
30
-     */
31
-    private Collection $linked_fams;
28
+	/**
29
+	 * @var Collection<string, stdClass>  $linked_fams Spouse families linked to the node
30
+	 */
31
+	private Collection $linked_fams;
32 32
 
33
-    private ?Individual $node_indi;
34
-    private LineageRootNode $root_node;
35
-    private ?string $alt_surname;
33
+	private ?Individual $node_indi;
34
+	private LineageRootNode $root_node;
35
+	private ?string $alt_surname;
36 36
 
37
-    /**
38
-     * Constructor for Lineage node
39
-     *
40
-     * @param Individual $node_indi Main individual
41
-     * @param LineageRootNode $root_node Node of the lineage root
42
-     * @param null|string $alt_surname Follow-up surname
43
-     */
44
-    public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
45
-    {
46
-        $this->node_indi = $node_indi;
47
-        $this->root_node = $root_node;
48
-        $this->alt_surname = $alt_surname;
49
-        $this->linked_fams = new Collection();
50
-    }
37
+	/**
38
+	 * Constructor for Lineage node
39
+	 *
40
+	 * @param Individual $node_indi Main individual
41
+	 * @param LineageRootNode $root_node Node of the lineage root
42
+	 * @param null|string $alt_surname Follow-up surname
43
+	 */
44
+	public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
45
+	{
46
+		$this->node_indi = $node_indi;
47
+		$this->root_node = $root_node;
48
+		$this->alt_surname = $alt_surname;
49
+		$this->linked_fams = new Collection();
50
+	}
51 51
 
52
-    /**
53
-     * Add a spouse family to the node
54
-     *
55
-     * @param Family $fams
56
-     * @return stdClass
57
-     */
58
-    public function addFamily(Family $fams): object
59
-    {
60
-        if (!$this->linked_fams->has($fams->xref())) {
61
-            $this->linked_fams->put($fams->xref(), (object) [
62
-                'family'   =>  $fams,
63
-                'children' =>  new Collection()
64
-            ]);
65
-        }
66
-        return $this->linked_fams->get($fams->xref());
67
-    }
52
+	/**
53
+	 * Add a spouse family to the node
54
+	 *
55
+	 * @param Family $fams
56
+	 * @return stdClass
57
+	 */
58
+	public function addFamily(Family $fams): object
59
+	{
60
+		if (!$this->linked_fams->has($fams->xref())) {
61
+			$this->linked_fams->put($fams->xref(), (object) [
62
+				'family'   =>  $fams,
63
+				'children' =>  new Collection()
64
+			]);
65
+		}
66
+		return $this->linked_fams->get($fams->xref());
67
+	}
68 68
 
69
-    /**
70
-     * Add a child LineageNode to the node
71
-     *
72
-     * @param Family $fams
73
-     * @param LineageNode $child
74
-     */
75
-    public function addChild(Family $fams, LineageNode $child = null): void
76
-    {
77
-        $this->addFamily($fams)->children->push($child);
78
-        $this->root_node->incrementChildNodes();
79
-    }
69
+	/**
70
+	 * Add a child LineageNode to the node
71
+	 *
72
+	 * @param Family $fams
73
+	 * @param LineageNode $child
74
+	 */
75
+	public function addChild(Family $fams, LineageNode $child = null): void
76
+	{
77
+		$this->addFamily($fams)->children->push($child);
78
+		$this->root_node->incrementChildNodes();
79
+	}
80 80
 
81
-    /**
82
-     * Returns the node individual
83
-     *
84
-     * @return Individual|NULL
85
-     */
86
-    public function individual(): ?Individual
87
-    {
88
-        return $this->node_indi;
89
-    }
81
+	/**
82
+	 * Returns the node individual
83
+	 *
84
+	 * @return Individual|NULL
85
+	 */
86
+	public function individual(): ?Individual
87
+	{
88
+		return $this->node_indi;
89
+	}
90 90
 
91
-    /**
92
-     * Returns the lineage root node individual
93
-     *
94
-     * @return LineageRootNode
95
-     */
96
-    public function rootNode(): LineageRootNode
97
-    {
98
-        return $this->root_node;
99
-    }
91
+	/**
92
+	 * Returns the lineage root node individual
93
+	 *
94
+	 * @return LineageRootNode
95
+	 */
96
+	public function rootNode(): LineageRootNode
97
+	{
98
+		return $this->root_node;
99
+	}
100 100
 
101
-    /**
102
-     * Returns the spouse families linked to the node
103
-     *
104
-     * @return Collection<string, \stdClass>
105
-     */
106
-    public function families(): Collection
107
-    {
108
-        return $this->linked_fams;
109
-    }
101
+	/**
102
+	 * Returns the spouse families linked to the node
103
+	 *
104
+	 * @return Collection<string, \stdClass>
105
+	 */
106
+	public function families(): Collection
107
+	{
108
+		return $this->linked_fams;
109
+	}
110 110
 
111
-    /**
112
-     * Returns the follow-up surname
113
-     *
114
-     * @return string
115
-     */
116
-    public function followUpSurname(): string
117
-    {
118
-        return $this->alt_surname ?? '';
119
-    }
111
+	/**
112
+	 * Returns the follow-up surname
113
+	 *
114
+	 * @return string
115
+	 */
116
+	public function followUpSurname(): string
117
+	{
118
+		return $this->alt_surname ?? '';
119
+	}
120 120
 
121
-    /**
122
-     * Indicates whether the node has a follow up surname
123
-     *
124
-     * @return boolean
125
-     */
126
-    public function hasFollowUpSurname(): bool
127
-    {
128
-        return mb_strlen($this->followUpSurname()) > 0 ;
129
-    }
121
+	/**
122
+	 * Indicates whether the node has a follow up surname
123
+	 *
124
+	 * @return boolean
125
+	 */
126
+	public function hasFollowUpSurname(): bool
127
+	{
128
+		return mb_strlen($this->followUpSurname()) > 0 ;
129
+	}
130 130
 }
Please login to merge, or discard this patch.
app/Module/PatronymicLineage/Model/LineageBuilder.php 1 patch
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -28,210 +28,210 @@
 block discarded – undo
28 28
  */
29 29
 class LineageBuilder
30 30
 {
31
-    private string $surname;
32
-    private Tree $tree;
33
-    private ?IndividualListModule $indilist_module;
34
-
35
-    /**
36
-     * @var Collection<string, bool> $used_indis Individuals already processed
37
-     */
38
-    private Collection $used_indis;
39
-
40
-    /**
41
-     * Constructor for Lineage Builder
42
-     *
43
-     * @param string $surname Reference surname
44
-     * @param Tree $tree Gedcom tree
45
-     */
46
-    public function __construct($surname, Tree $tree, IndividualListModule $indilist_module)
47
-    {
48
-        $this->surname = $surname;
49
-        $this->tree = $tree;
50
-        $this->indilist_module = $indilist_module;
51
-        $this->used_indis = new Collection();
52
-    }
53
-
54
-    /**
55
-     * Build all patronymic lineages for the reference surname.
56
-     *
57
-     * @return Collection<LineageRootNode>|NULL List of root patronymic lineages
58
-     */
59
-    public function buildLineages(): ?Collection
60
-    {
61
-        if ($this->indilist_module === null) {
62
-            return null;
63
-        }
64
-
65
-        $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale());
66
-        //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality
67
-        if (count($indis) == 0) {
68
-            return null;
69
-        }
70
-
71
-        $root_lineages = new Collection();
72
-
73
-        foreach ($indis as $indi) {
74
-            /** @var Individual $indi */
75
-            if ($this->used_indis->get($indi->xref(), false) === false) {
76
-                $indi_first = $this->getLineageRootIndividual($indi);
77
-                if ($indi_first !== null) {
78
-                    // The root lineage needs to be recreated from the Factory, to retrieve the proper object
79
-                    $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree);
80
-                }
81
-                if ($indi_first === null) {
82
-                    continue;
83
-                }
84
-                $this->used_indis->put($indi_first->xref(), true);
85
-                if ($indi_first->canShow()) {
86
-                    //Check if the root individual has brothers and sisters, without parents
87
-                    $indi_first_child_family = $indi_first->childFamilies()->first();
88
-                    if ($indi_first_child_family !== null) {
89
-                        $root_node = new LineageRootNode(null);
90
-                        $root_node->addFamily($indi_first_child_family);
91
-                    } else {
92
-                        $root_node = new LineageRootNode($indi_first);
93
-                    }
94
-                    $root_node = $this->buildLineage($root_node);
95
-                    $root_lineages->add($root_node);
96
-                }
97
-            }
98
-        }
99
-
100
-        return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) {
101
-
102
-            if ($a->numberChildNodes() == $b->numberChildNodes()) {
103
-                return 0;
104
-            }
105
-            return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1;
106
-        });
107
-    }
108
-
109
-    /**
110
-     * Retrieve the root individual, from any individual, by recursion.
111
-     * The Root individual is the individual without a father, or without a mother holding the same name.
112
-     *
113
-     * @param Individual $indi
114
-     * @return Individual|NULL Root individual
115
-     */
116
-    private function getLineageRootIndividual(Individual $indi): ?Individual
117
-    {
118
-        $child_families = $indi->childFamilies();
119
-        if ($this->used_indis->get($indi->xref(), false) !== false) {
120
-            return null;
121
-        }
122
-
123
-        foreach ($child_families as $child_family) {
124
-            /** @var Family $child_family */
125
-            $child_family->husband();
126
-            if (($husb = $child_family->husband()) !== null) {
127
-                if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') {
128
-                    return $indi;
129
-                }
130
-                return $this->getLineageRootIndividual($husb);
131
-            } elseif (($wife = $child_family->wife()) !== null) {
132
-                if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
133
-                    $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname'];
134
-                    $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname'];
135
-                    if (
136
-                        $indi->canShowName()
137
-                        && $wife->canShowName()
138
-                        && I18N::comparator()($indi_surname, $wife_surname) == 0
139
-                    ) {
140
-                            return $this->getLineageRootIndividual($wife);
141
-                    }
142
-                }
143
-                return $indi;
144
-            }
145
-        }
146
-        return $indi;
147
-    }
148
-
149
-    /**
150
-     * Computes descendent Lineage from a node.
151
-     * Uses recursion to build the lineage tree
152
-     *
153
-     * @param LineageNode $node
154
-     * @return LineageNode Computed lineage
155
-     */
156
-    private function buildLineage(LineageNode $node): LineageNode
157
-    {
158
-        $indi_surname = '';
159
-
160
-        $indi_node = $node->individual();
161
-        if ($indi_node !== null) {
162
-            if ($node->families()->count() == 0) {
163
-                foreach ($indi_node->spouseFamilies() as $spouse_family) {
164
-                    $node->addFamily($spouse_family);
165
-                }
166
-            }
167
-
168
-            $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? '';
169
-            $node->rootNode()->addPlace($indi_node->getBirthPlace());
170
-
171
-            //Tag the individual as used
172
-            $this->used_indis->put($indi_node->xref(), true);
173
-        }
174
-
175
-        foreach ($node->families() as $family_node) {
176
-            /** @var Family $spouse_family */
177
-            $spouse_family = $family_node->family;
178
-            $spouse_surname = '';
179
-            $spouse = null;
180
-            if (
181
-                $indi_node !== null &&
182
-                ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName()
183
-            ) {
184
-                $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? '';
185
-            }
186
-
187
-            $nb_children = $nb_natural = 0;
188
-
189
-            foreach ($spouse_family->children() as $child) {
190
-                if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
191
-                    $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? '';
192
-
193
-                    $nb_children++;
194
-                    if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother
195
-                        //Print only lineages of children with the same surname as their mother
196
-                        //(supposing they are natural children)
197
-                        /** @psalm-suppress RedundantCondition */
198
-                        if (
199
-                            $spouse === null ||
200
-                            ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0)
201
-                        ) {
202
-                            if (I18N::comparator()($child_surname, $indi_surname) == 0) {
203
-                                $nb_natural++;
204
-                                $node_child = new LineageNode($child, $node->rootNode());
205
-                                $node_child = $this->buildLineage($node_child);
206
-                                $node->addChild($spouse_family, $node_child);
207
-                            }
208
-                        }
209
-                    } else { //If the root individual is the father
210
-                        $nb_natural++;
211
-                        //Print if the children does not bear the same name as his mother
212
-                        //(and different from his father)
213
-                        if (
214
-                            mb_strlen($child_surname) == 0 ||
215
-                            mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
216
-                            I18N::comparator()($child_surname, $indi_surname) == 0 ||
217
-                            I18N::comparator()($child_surname, $spouse_surname) != 0
218
-                        ) {
219
-                            $node_child = new LineageNode($child, $node->rootNode());
220
-                            $node_child = $this->buildLineage($node_child);
221
-                        } else {
222
-                            $node_child = new LineageNode($child, $node->rootNode(), $child_surname);
223
-                        }
224
-                        $node->addChild($spouse_family, $node_child);
225
-                    }
226
-                }
227
-            }
228
-
229
-            //Do not print other children
230
-            if (($nb_children - $nb_natural) > 0) {
231
-                $node->addChild($spouse_family, null);
232
-            }
233
-        }
234
-
235
-        return $node;
236
-    }
31
+	private string $surname;
32
+	private Tree $tree;
33
+	private ?IndividualListModule $indilist_module;
34
+
35
+	/**
36
+	 * @var Collection<string, bool> $used_indis Individuals already processed
37
+	 */
38
+	private Collection $used_indis;
39
+
40
+	/**
41
+	 * Constructor for Lineage Builder
42
+	 *
43
+	 * @param string $surname Reference surname
44
+	 * @param Tree $tree Gedcom tree
45
+	 */
46
+	public function __construct($surname, Tree $tree, IndividualListModule $indilist_module)
47
+	{
48
+		$this->surname = $surname;
49
+		$this->tree = $tree;
50
+		$this->indilist_module = $indilist_module;
51
+		$this->used_indis = new Collection();
52
+	}
53
+
54
+	/**
55
+	 * Build all patronymic lineages for the reference surname.
56
+	 *
57
+	 * @return Collection<LineageRootNode>|NULL List of root patronymic lineages
58
+	 */
59
+	public function buildLineages(): ?Collection
60
+	{
61
+		if ($this->indilist_module === null) {
62
+			return null;
63
+		}
64
+
65
+		$indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale());
66
+		//Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality
67
+		if (count($indis) == 0) {
68
+			return null;
69
+		}
70
+
71
+		$root_lineages = new Collection();
72
+
73
+		foreach ($indis as $indi) {
74
+			/** @var Individual $indi */
75
+			if ($this->used_indis->get($indi->xref(), false) === false) {
76
+				$indi_first = $this->getLineageRootIndividual($indi);
77
+				if ($indi_first !== null) {
78
+					// The root lineage needs to be recreated from the Factory, to retrieve the proper object
79
+					$indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree);
80
+				}
81
+				if ($indi_first === null) {
82
+					continue;
83
+				}
84
+				$this->used_indis->put($indi_first->xref(), true);
85
+				if ($indi_first->canShow()) {
86
+					//Check if the root individual has brothers and sisters, without parents
87
+					$indi_first_child_family = $indi_first->childFamilies()->first();
88
+					if ($indi_first_child_family !== null) {
89
+						$root_node = new LineageRootNode(null);
90
+						$root_node->addFamily($indi_first_child_family);
91
+					} else {
92
+						$root_node = new LineageRootNode($indi_first);
93
+					}
94
+					$root_node = $this->buildLineage($root_node);
95
+					$root_lineages->add($root_node);
96
+				}
97
+			}
98
+		}
99
+
100
+		return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) {
101
+
102
+			if ($a->numberChildNodes() == $b->numberChildNodes()) {
103
+				return 0;
104
+			}
105
+			return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1;
106
+		});
107
+	}
108
+
109
+	/**
110
+	 * Retrieve the root individual, from any individual, by recursion.
111
+	 * The Root individual is the individual without a father, or without a mother holding the same name.
112
+	 *
113
+	 * @param Individual $indi
114
+	 * @return Individual|NULL Root individual
115
+	 */
116
+	private function getLineageRootIndividual(Individual $indi): ?Individual
117
+	{
118
+		$child_families = $indi->childFamilies();
119
+		if ($this->used_indis->get($indi->xref(), false) !== false) {
120
+			return null;
121
+		}
122
+
123
+		foreach ($child_families as $child_family) {
124
+			/** @var Family $child_family */
125
+			$child_family->husband();
126
+			if (($husb = $child_family->husband()) !== null) {
127
+				if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') {
128
+					return $indi;
129
+				}
130
+				return $this->getLineageRootIndividual($husb);
131
+			} elseif (($wife = $child_family->wife()) !== null) {
132
+				if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
133
+					$indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname'];
134
+					$wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname'];
135
+					if (
136
+						$indi->canShowName()
137
+						&& $wife->canShowName()
138
+						&& I18N::comparator()($indi_surname, $wife_surname) == 0
139
+					) {
140
+							return $this->getLineageRootIndividual($wife);
141
+					}
142
+				}
143
+				return $indi;
144
+			}
145
+		}
146
+		return $indi;
147
+	}
148
+
149
+	/**
150
+	 * Computes descendent Lineage from a node.
151
+	 * Uses recursion to build the lineage tree
152
+	 *
153
+	 * @param LineageNode $node
154
+	 * @return LineageNode Computed lineage
155
+	 */
156
+	private function buildLineage(LineageNode $node): LineageNode
157
+	{
158
+		$indi_surname = '';
159
+
160
+		$indi_node = $node->individual();
161
+		if ($indi_node !== null) {
162
+			if ($node->families()->count() == 0) {
163
+				foreach ($indi_node->spouseFamilies() as $spouse_family) {
164
+					$node->addFamily($spouse_family);
165
+				}
166
+			}
167
+
168
+			$indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? '';
169
+			$node->rootNode()->addPlace($indi_node->getBirthPlace());
170
+
171
+			//Tag the individual as used
172
+			$this->used_indis->put($indi_node->xref(), true);
173
+		}
174
+
175
+		foreach ($node->families() as $family_node) {
176
+			/** @var Family $spouse_family */
177
+			$spouse_family = $family_node->family;
178
+			$spouse_surname = '';
179
+			$spouse = null;
180
+			if (
181
+				$indi_node !== null &&
182
+				($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName()
183
+			) {
184
+				$spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? '';
185
+			}
186
+
187
+			$nb_children = $nb_natural = 0;
188
+
189
+			foreach ($spouse_family->children() as $child) {
190
+				if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) {
191
+					$child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? '';
192
+
193
+					$nb_children++;
194
+					if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother
195
+						//Print only lineages of children with the same surname as their mother
196
+						//(supposing they are natural children)
197
+						/** @psalm-suppress RedundantCondition */
198
+						if (
199
+							$spouse === null ||
200
+							($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0)
201
+						) {
202
+							if (I18N::comparator()($child_surname, $indi_surname) == 0) {
203
+								$nb_natural++;
204
+								$node_child = new LineageNode($child, $node->rootNode());
205
+								$node_child = $this->buildLineage($node_child);
206
+								$node->addChild($spouse_family, $node_child);
207
+							}
208
+						}
209
+					} else { //If the root individual is the father
210
+						$nb_natural++;
211
+						//Print if the children does not bear the same name as his mother
212
+						//(and different from his father)
213
+						if (
214
+							mb_strlen($child_surname) == 0 ||
215
+							mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 ||
216
+							I18N::comparator()($child_surname, $indi_surname) == 0 ||
217
+							I18N::comparator()($child_surname, $spouse_surname) != 0
218
+						) {
219
+							$node_child = new LineageNode($child, $node->rootNode());
220
+							$node_child = $this->buildLineage($node_child);
221
+						} else {
222
+							$node_child = new LineageNode($child, $node->rootNode(), $child_surname);
223
+						}
224
+						$node->addChild($spouse_family, $node_child);
225
+					}
226
+				}
227
+			}
228
+
229
+			//Do not print other children
230
+			if (($nb_children - $nb_natural) > 0) {
231
+				$node->addChild($spouse_family, null);
232
+			}
233
+		}
234
+
235
+		return $node;
236
+	}
237 237
 }
Please login to merge, or discard this patch.
app/Common/GeoDispersion/GeoAnalysis/GeoAnalysisResults.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -23,104 +23,104 @@
 block discarded – undo
23 23
  */
24 24
 class GeoAnalysisResults
25 25
 {
26
-    private GeoAnalysisResult $global;
26
+	private GeoAnalysisResult $global;
27 27
 
28
-    /**
29
-     * @var Collection<string, GeoAnalysisResult> $detailed
30
-     */
31
-    private Collection $detailed;
28
+	/**
29
+	 * @var Collection<string, GeoAnalysisResult> $detailed
30
+	 */
31
+	private Collection $detailed;
32 32
 
33
-    /**
34
-     * Constructor for GeoAnalysisResults
35
-     */
36
-    public function __construct()
37
-    {
38
-        $this->global = new GeoAnalysisResult('Global', 0);
39
-        $this->detailed = new Collection();
40
-    }
33
+	/**
34
+	 * Constructor for GeoAnalysisResults
35
+	 */
36
+	public function __construct()
37
+	{
38
+		$this->global = new GeoAnalysisResult('Global', 0);
39
+		$this->detailed = new Collection();
40
+	}
41 41
 
42
-    /**
43
-     * Global result of the geographical analysis
44
-     *
45
-     * @return GeoAnalysisResult
46
-     */
47
-    public function global(): GeoAnalysisResult
48
-    {
49
-        return $this->global;
50
-    }
42
+	/**
43
+	 * Global result of the geographical analysis
44
+	 *
45
+	 * @return GeoAnalysisResult
46
+	 */
47
+	public function global(): GeoAnalysisResult
48
+	{
49
+		return $this->global;
50
+	}
51 51
 
52
-    /**
53
-     * List of results by category of the geographical analysis
54
-     *
55
-     * @return Collection<string, GeoAnalysisResult>
56
-     */
57
-    public function detailed(): Collection
58
-    {
59
-        return $this->detailed;
60
-    }
52
+	/**
53
+	 * List of results by category of the geographical analysis
54
+	 *
55
+	 * @return Collection<string, GeoAnalysisResult>
56
+	 */
57
+	public function detailed(): Collection
58
+	{
59
+		return $this->detailed;
60
+	}
61 61
 
62
-    /**
63
-     * List of results by category of the geographical analysis.
64
-     * The list is sorted first by the category order, then by the category description
65
-     *
66
-     * @return Collection<string, GeoAnalysisResult>
67
-     */
68
-    public function sortedDetailed(): Collection
69
-    {
70
-        return $this->detailed->sortBy([
71
-            fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(),
72
-            fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int =>
73
-                I18N::comparator()($a->description(), $b->description())
74
-        ]);
75
-    }
62
+	/**
63
+	 * List of results by category of the geographical analysis.
64
+	 * The list is sorted first by the category order, then by the category description
65
+	 *
66
+	 * @return Collection<string, GeoAnalysisResult>
67
+	 */
68
+	public function sortedDetailed(): Collection
69
+	{
70
+		return $this->detailed->sortBy([
71
+			fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(),
72
+			fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int =>
73
+				I18N::comparator()($a->description(), $b->description())
74
+		]);
75
+	}
76 76
 
77
-    /**
78
-     * Add a GeoAnalysis Place to the global result
79
-     *
80
-     * @param GeoAnalysisPlace $place
81
-     */
82
-    public function addPlace(GeoAnalysisPlace $place): void
83
-    {
84
-        $this->global()->addPlace($place);
85
-    }
77
+	/**
78
+	 * Add a GeoAnalysis Place to the global result
79
+	 *
80
+	 * @param GeoAnalysisPlace $place
81
+	 */
82
+	public function addPlace(GeoAnalysisPlace $place): void
83
+	{
84
+		$this->global()->addPlace($place);
85
+	}
86 86
 
87
-    /**
88
-     * Add a new category to the list of results, if it does not exist yet
89
-     *
90
-     * @param string $description
91
-     * @param int $order
92
-     */
93
-    public function addCategory(string $description, int $order): void
94
-    {
95
-        if (!$this->detailed->has($description)) {
96
-            $this->detailed->put($description, new GeoAnalysisResult($description, $order));
97
-        }
98
-    }
87
+	/**
88
+	 * Add a new category to the list of results, if it does not exist yet
89
+	 *
90
+	 * @param string $description
91
+	 * @param int $order
92
+	 */
93
+	public function addCategory(string $description, int $order): void
94
+	{
95
+		if (!$this->detailed->has($description)) {
96
+			$this->detailed->put($description, new GeoAnalysisResult($description, $order));
97
+		}
98
+	}
99 99
 
100
-    /**
101
-     * Add a GeoAnalysis Place to a category result, if the category exist.
102
-     *
103
-     * @param string $category_name
104
-     * @param GeoAnalysisPlace $place
105
-     */
106
-    public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void
107
-    {
108
-        if ($this->detailed->has($category_name)) {
109
-            $this->detailed->get($category_name)->addPlace($place);
110
-        }
111
-    }
100
+	/**
101
+	 * Add a GeoAnalysis Place to a category result, if the category exist.
102
+	 *
103
+	 * @param string $category_name
104
+	 * @param GeoAnalysisPlace $place
105
+	 */
106
+	public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void
107
+	{
108
+		if ($this->detailed->has($category_name)) {
109
+			$this->detailed->get($category_name)->addPlace($place);
110
+		}
111
+	}
112 112
 
113
-    /**
114
-     * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist.
115
-     *
116
-     * @param string $category_name
117
-     * @param GeoAnalysisPlace $place
118
-     */
119
-    public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void
120
-    {
121
-        if (!$this->detailed->has($category_name)) {
122
-            $this->addCategory($category_name, $category_order);
123
-        }
124
-        $this->addPlaceInCreatedCategory($category_name, $place);
125
-    }
113
+	/**
114
+	 * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist.
115
+	 *
116
+	 * @param string $category_name
117
+	 * @param GeoAnalysisPlace $place
118
+	 */
119
+	public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void
120
+	{
121
+		if (!$this->detailed->has($category_name)) {
122
+			$this->addCategory($category_name, $category_order);
123
+		}
124
+		$this->addPlaceInCreatedCategory($category_name, $place);
125
+	}
126 126
 }
Please login to merge, or discard this patch.
app/Common/GeoDispersion/Config/GenericPlaceMapperConfig.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -25,105 +25,105 @@
 block discarded – undo
25 25
  */
26 26
 class GenericPlaceMapperConfig implements PlaceMapperConfigInterface
27 27
 {
28
-    /** @var array<string, mixed> $config */
29
-    private array $config = [];
28
+	/** @var array<string, mixed> $config */
29
+	private array $config = [];
30 30
 
31
-    /**
32
-     * Get the generic mapper's config
33
-     *
34
-     * @return array<string, mixed>
35
-     */
36
-    public function config(): array
37
-    {
38
-        return $this->config;
39
-    }
31
+	/**
32
+	 * Get the generic mapper's config
33
+	 *
34
+	 * @return array<string, mixed>
35
+	 */
36
+	public function config(): array
37
+	{
38
+		return $this->config;
39
+	}
40 40
 
41
-    /**
42
-     * Set the generic mapper's config
43
-     *
44
-     * @param array<string, mixed> $config
45
-     * @return $this
46
-     */
47
-    public function setConfig(array $config): self
48
-    {
49
-        $this->config = $config;
50
-        return $this;
51
-    }
41
+	/**
42
+	 * Set the generic mapper's config
43
+	 *
44
+	 * @param array<string, mixed> $config
45
+	 * @return $this
46
+	 */
47
+	public function setConfig(array $config): self
48
+	{
49
+		$this->config = $config;
50
+		return $this;
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get()
56
-     */
57
-    public function get(string $key, $default = null)
58
-    {
59
-        return $this->config[$key] ?? $default;
60
-    }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get()
56
+	 */
57
+	public function get(string $key, $default = null)
58
+	{
59
+		return $this->config[$key] ?? $default;
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritDoc}
64
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has()
65
-     */
66
-    public function has(string $key): bool
67
-    {
68
-        return key_exists($key, $this->config);
69
-    }
62
+	/**
63
+	 * {@inheritDoc}
64
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has()
65
+	 */
66
+	public function has(string $key): bool
67
+	{
68
+		return key_exists($key, $this->config);
69
+	}
70 70
 
71
-    /**
72
-     * {@inheritDoc}
73
-     * @see \JsonSerializable::jsonSerialize()
74
-     */
75
-    public function jsonSerialize()
76
-    {
77
-        return [
78
-            'class'     =>  get_class($this),
79
-            'config'    =>  $this->jsonSerializeConfig()
80
-        ];
81
-    }
71
+	/**
72
+	 * {@inheritDoc}
73
+	 * @see \JsonSerializable::jsonSerialize()
74
+	 */
75
+	public function jsonSerialize()
76
+	{
77
+		return [
78
+			'class'     =>  get_class($this),
79
+			'config'    =>  $this->jsonSerializeConfig()
80
+		];
81
+	}
82 82
 
83
-    /**
84
-     * Returns a representation of the mapper config compatible with Json serialisation
85
-     *
86
-     * @return mixed
87
-     */
88
-    public function jsonSerializeConfig()
89
-    {
90
-        return $this->config;
91
-    }
83
+	/**
84
+	 * Returns a representation of the mapper config compatible with Json serialisation
85
+	 *
86
+	 * @return mixed
87
+	 */
88
+	public function jsonSerializeConfig()
89
+	{
90
+		return $this->config;
91
+	}
92 92
 
93
-    /**
94
-     * {@inheritDoc}
95
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize()
96
-     *
97
-     * @param mixed $config
98
-     * @return $this
99
-     */
100
-    public function jsonDeserialize($config): self
101
-    {
102
-        if (is_string($config)) {
103
-            return $this->jsonDeserialize(json_decode($config));
104
-        }
105
-        if (is_array($config)) {
106
-            return $this->setConfig($config);
107
-        }
108
-        return $this;
109
-    }
93
+	/**
94
+	 * {@inheritDoc}
95
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize()
96
+	 *
97
+	 * @param mixed $config
98
+	 * @return $this
99
+	 */
100
+	public function jsonDeserialize($config): self
101
+	{
102
+		if (is_string($config)) {
103
+			return $this->jsonDeserialize(json_decode($config));
104
+		}
105
+		if (is_array($config)) {
106
+			return $this->setConfig($config);
107
+		}
108
+		return $this;
109
+	}
110 110
 
111
-    /**
112
-     * {@inheritDoc}
113
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent()
114
-     */
115
-    public function configContent(ModuleInterface $module, Tree $tree): string
116
-    {
117
-        return '';
118
-    }
111
+	/**
112
+	 * {@inheritDoc}
113
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent()
114
+	 */
115
+	public function configContent(ModuleInterface $module, Tree $tree): string
116
+	{
117
+		return '';
118
+	}
119 119
 
120
-    /**
121
-     * {@inheritDoc}
122
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate()
123
-     * @return $this
124
-     */
125
-    public function withConfigUpdate(ServerRequestInterface $request): self
126
-    {
127
-        return $this;
128
-    }
120
+	/**
121
+	 * {@inheritDoc}
122
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate()
123
+	 * @return $this
124
+	 */
125
+	public function withConfigUpdate(ServerRequestInterface $request): self
126
+	{
127
+		return $this;
128
+	}
129 129
 }
Please login to merge, or discard this patch.
app/Common/Tasks/TaskSchedule.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -24,252 +24,252 @@
 block discarded – undo
24 24
  */
25 25
 class TaskSchedule
26 26
 {
27
-    private int $id;
28
-    private bool $enabled;
29
-    private string $task_id;
30
-    private Carbon $last_run;
31
-    private bool $last_result;
32
-    private CarbonInterval $frequency;
33
-    private int $nb_occurrences;
34
-    private bool $is_running;
27
+	private int $id;
28
+	private bool $enabled;
29
+	private string $task_id;
30
+	private Carbon $last_run;
31
+	private bool $last_result;
32
+	private CarbonInterval $frequency;
33
+	private int $nb_occurrences;
34
+	private bool $is_running;
35 35
 
36
-    /**
37
-     * Constructor for TaskSchedule
38
-     *
39
-     * @param int $id Schedule ID
40
-     * @param string $task_id Task ID
41
-     * @param bool $enabled Is the schedule enabled
42
-     * @param Carbon $last_run Last successful run date/time
43
-     * @param bool $last_result Result of the last run
44
-     * @param CarbonInterval $frequency Schedule frequency
45
-     * @param int $nb_occurrences Number of remaining occurrences to be run
46
-     * @param bool $is_running Is the task currently running
47
-     */
48
-    public function __construct(
49
-        int $id,
50
-        string $task_id,
51
-        bool $enabled,
52
-        Carbon $last_run,
53
-        bool $last_result,
54
-        CarbonInterval $frequency,
55
-        int $nb_occurrences,
56
-        bool $is_running
57
-    ) {
58
-        $this->id = $id;
59
-        $this->task_id = $task_id;
60
-        $this->enabled = $enabled;
61
-        $this->last_run = $last_run;
62
-        $this->last_result = $last_result;
63
-        $this->frequency = $frequency;
64
-        $this->nb_occurrences = $nb_occurrences;
65
-        $this->is_running = $is_running;
66
-    }
36
+	/**
37
+	 * Constructor for TaskSchedule
38
+	 *
39
+	 * @param int $id Schedule ID
40
+	 * @param string $task_id Task ID
41
+	 * @param bool $enabled Is the schedule enabled
42
+	 * @param Carbon $last_run Last successful run date/time
43
+	 * @param bool $last_result Result of the last run
44
+	 * @param CarbonInterval $frequency Schedule frequency
45
+	 * @param int $nb_occurrences Number of remaining occurrences to be run
46
+	 * @param bool $is_running Is the task currently running
47
+	 */
48
+	public function __construct(
49
+		int $id,
50
+		string $task_id,
51
+		bool $enabled,
52
+		Carbon $last_run,
53
+		bool $last_result,
54
+		CarbonInterval $frequency,
55
+		int $nb_occurrences,
56
+		bool $is_running
57
+	) {
58
+		$this->id = $id;
59
+		$this->task_id = $task_id;
60
+		$this->enabled = $enabled;
61
+		$this->last_run = $last_run;
62
+		$this->last_result = $last_result;
63
+		$this->frequency = $frequency;
64
+		$this->nb_occurrences = $nb_occurrences;
65
+		$this->is_running = $is_running;
66
+	}
67 67
 
68
-    /**
69
-     * Get the schedule ID.
70
-     *
71
-     * @return int
72
-     */
73
-    public function id(): int
74
-    {
75
-        return $this->id;
76
-    }
68
+	/**
69
+	 * Get the schedule ID.
70
+	 *
71
+	 * @return int
72
+	 */
73
+	public function id(): int
74
+	{
75
+		return $this->id;
76
+	}
77 77
 
78
-    /**
79
-     * Get the task ID.
80
-     *
81
-     * @return string
82
-     */
83
-    public function taskId(): string
84
-    {
85
-        return $this->task_id;
86
-    }
78
+	/**
79
+	 * Get the task ID.
80
+	 *
81
+	 * @return string
82
+	 */
83
+	public function taskId(): string
84
+	{
85
+		return $this->task_id;
86
+	}
87 87
 
88
-    /**
89
-     * Returns whether the schedule is enabled
90
-     *
91
-     * @return bool
92
-     */
93
-    public function isEnabled(): bool
94
-    {
95
-        return $this->enabled;
96
-    }
88
+	/**
89
+	 * Returns whether the schedule is enabled
90
+	 *
91
+	 * @return bool
92
+	 */
93
+	public function isEnabled(): bool
94
+	{
95
+		return $this->enabled;
96
+	}
97 97
 
98
-    /**
99
-     * Enable the schedule
100
-     *
101
-     * @return $this
102
-     */
103
-    public function enable(): self
104
-    {
105
-        $this->enabled = true;
106
-        return $this;
107
-    }
98
+	/**
99
+	 * Enable the schedule
100
+	 *
101
+	 * @return $this
102
+	 */
103
+	public function enable(): self
104
+	{
105
+		$this->enabled = true;
106
+		return $this;
107
+	}
108 108
 
109
-    /**
110
-     * Disable the schedule
111
-     *
112
-     * @return $this
113
-     */
114
-    public function disable(): self
115
-    {
116
-        $this->enabled = false;
117
-        return $this;
118
-    }
109
+	/**
110
+	 * Disable the schedule
111
+	 *
112
+	 * @return $this
113
+	 */
114
+	public function disable(): self
115
+	{
116
+		$this->enabled = false;
117
+		return $this;
118
+	}
119 119
 
120
-    /**
121
-     * Get the frequency of the schedule
122
-     *
123
-     * @return CarbonInterval
124
-     */
125
-    public function frequency(): CarbonInterval
126
-    {
127
-        return $this->frequency;
128
-    }
120
+	/**
121
+	 * Get the frequency of the schedule
122
+	 *
123
+	 * @return CarbonInterval
124
+	 */
125
+	public function frequency(): CarbonInterval
126
+	{
127
+		return $this->frequency;
128
+	}
129 129
 
130
-    /**
131
-     * Set the frequency of the schedule
132
-     *
133
-     * @param CarbonInterval $frequency
134
-     * @return $this
135
-     */
136
-    public function setFrequency(CarbonInterval $frequency): self
137
-    {
138
-        $this->frequency = $frequency;
139
-        return $this;
140
-    }
130
+	/**
131
+	 * Set the frequency of the schedule
132
+	 *
133
+	 * @param CarbonInterval $frequency
134
+	 * @return $this
135
+	 */
136
+	public function setFrequency(CarbonInterval $frequency): self
137
+	{
138
+		$this->frequency = $frequency;
139
+		return $this;
140
+	}
141 141
 
142
-    /**
143
-     * Get the date/time of the last successful run.
144
-     *
145
-     * @return Carbon
146
-     */
147
-    public function lastRunTime(): Carbon
148
-    {
149
-        return $this->last_run;
150
-    }
142
+	/**
143
+	 * Get the date/time of the last successful run.
144
+	 *
145
+	 * @return Carbon
146
+	 */
147
+	public function lastRunTime(): Carbon
148
+	{
149
+		return $this->last_run;
150
+	}
151 151
 
152
-    /**
153
-     * Set the last successful run date/time
154
-     *
155
-     * @param Carbon $last_run
156
-     * @return $this
157
-     */
158
-    public function setLastRunTime(Carbon $last_run): self
159
-    {
160
-        $this->last_run = $last_run;
161
-        return $this;
162
-    }
152
+	/**
153
+	 * Set the last successful run date/time
154
+	 *
155
+	 * @param Carbon $last_run
156
+	 * @return $this
157
+	 */
158
+	public function setLastRunTime(Carbon $last_run): self
159
+	{
160
+		$this->last_run = $last_run;
161
+		return $this;
162
+	}
163 163
 
164
-    /**
165
-     * Returns whether the last run was successful
166
-     *
167
-     * @return bool
168
-     */
169
-    public function wasLastRunSuccess(): bool
170
-    {
171
-        return $this->last_result;
172
-    }
164
+	/**
165
+	 * Returns whether the last run was successful
166
+	 *
167
+	 * @return bool
168
+	 */
169
+	public function wasLastRunSuccess(): bool
170
+	{
171
+		return $this->last_result;
172
+	}
173 173
 
174
-    /**
175
-     * Set the last run result
176
-     *
177
-     * @param bool $last_result
178
-     * @return $this
179
-     */
180
-    public function setLastResult(bool $last_result): self
181
-    {
182
-        $this->last_result = $last_result;
183
-        return $this;
184
-    }
174
+	/**
175
+	 * Set the last run result
176
+	 *
177
+	 * @param bool $last_result
178
+	 * @return $this
179
+	 */
180
+	public function setLastResult(bool $last_result): self
181
+	{
182
+		$this->last_result = $last_result;
183
+		return $this;
184
+	}
185 185
 
186
-    /**
187
-     * Get the number of remaining of occurrences of task runs.
188
-     * Returns 0 if the tasks must be run indefinitely.
189
-     *
190
-     * @return int
191
-     */
192
-    public function remainingOccurences(): int
193
-    {
194
-        return $this->nb_occurrences;
195
-    }
186
+	/**
187
+	 * Get the number of remaining of occurrences of task runs.
188
+	 * Returns 0 if the tasks must be run indefinitely.
189
+	 *
190
+	 * @return int
191
+	 */
192
+	public function remainingOccurences(): int
193
+	{
194
+		return $this->nb_occurrences;
195
+	}
196 196
 
197
-    /**
198
-     * Decrements the number of remaining occurences by 1.
199
-     * The task will be disabled when the number reaches 0.
200
-     *
201
-     * @return $this
202
-     */
203
-    public function decrementRemainingOccurences(): self
204
-    {
205
-        if ($this->nb_occurrences > 0) {
206
-            $this->nb_occurrences--;
207
-            if ($this->nb_occurrences == 0) {
208
-                $this->disable();
209
-            }
210
-        }
211
-        return $this;
212
-    }
197
+	/**
198
+	 * Decrements the number of remaining occurences by 1.
199
+	 * The task will be disabled when the number reaches 0.
200
+	 *
201
+	 * @return $this
202
+	 */
203
+	public function decrementRemainingOccurences(): self
204
+	{
205
+		if ($this->nb_occurrences > 0) {
206
+			$this->nb_occurrences--;
207
+			if ($this->nb_occurrences == 0) {
208
+				$this->disable();
209
+			}
210
+		}
211
+		return $this;
212
+	}
213 213
 
214
-    /**
215
-     * Set the number of remaining occurences of task runs.
216
-     *
217
-     * @param int $nb_occurrences
218
-     * @return $this
219
-     */
220
-    public function setRemainingOccurences(int $nb_occurrences): self
221
-    {
222
-        $this->nb_occurrences = $nb_occurrences;
223
-        return $this;
224
-    }
214
+	/**
215
+	 * Set the number of remaining occurences of task runs.
216
+	 *
217
+	 * @param int $nb_occurrences
218
+	 * @return $this
219
+	 */
220
+	public function setRemainingOccurences(int $nb_occurrences): self
221
+	{
222
+		$this->nb_occurrences = $nb_occurrences;
223
+		return $this;
224
+	}
225 225
 
226
-    /**
227
-     * Returns whether the task is running
228
-     * @return bool
229
-     */
230
-    public function isRunning(): bool
231
-    {
232
-        return $this->is_running;
233
-    }
226
+	/**
227
+	 * Returns whether the task is running
228
+	 * @return bool
229
+	 */
230
+	public function isRunning(): bool
231
+	{
232
+		return $this->is_running;
233
+	}
234 234
 
235
-    /**
236
-     * Informs the schedule that the task is going to run
237
-     *
238
-     * @return $this
239
-     */
240
-    public function startRunning(): self
241
-    {
242
-        $this->is_running = true;
243
-        return $this;
244
-    }
235
+	/**
236
+	 * Informs the schedule that the task is going to run
237
+	 *
238
+	 * @return $this
239
+	 */
240
+	public function startRunning(): self
241
+	{
242
+		$this->is_running = true;
243
+		return $this;
244
+	}
245 245
 
246
-    /**
247
-     * Informs the schedule that the task has stopped running.
248
-     * @return $this
249
-     */
250
-    public function stopRunning(): self
251
-    {
252
-        $this->is_running = false;
253
-        return $this;
254
-    }
246
+	/**
247
+	 * Informs the schedule that the task has stopped running.
248
+	 * @return $this
249
+	 */
250
+	public function stopRunning(): self
251
+	{
252
+		$this->is_running = false;
253
+		return $this;
254
+	}
255 255
 
256
-    /**
257
-     * Returns the schedule details as an associate array
258
-     *
259
-     * @phpcs:ignore Generic.Files.LineLength.TooLong
260
-     * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool}
261
-     */
262
-    public function toArray(): array
263
-    {
264
-        return [
265
-            'id'            =>  $this->id,
266
-            'task_id'       =>  $this->task_id,
267
-            'enabled'       =>  $this->enabled,
268
-            'last_run'      =>  $this->last_run,
269
-            'last_result'   =>  $this->last_result,
270
-            'frequency'     =>  $this->frequency,
271
-            'nb_occurrences' =>  $this->nb_occurrences,
272
-            'is_running'    =>  $this->is_running
273
-        ];
274
-    }
256
+	/**
257
+	 * Returns the schedule details as an associate array
258
+	 *
259
+	 * @phpcs:ignore Generic.Files.LineLength.TooLong
260
+	 * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool}
261
+	 */
262
+	public function toArray(): array
263
+	{
264
+		return [
265
+			'id'            =>  $this->id,
266
+			'task_id'       =>  $this->task_id,
267
+			'enabled'       =>  $this->enabled,
268
+			'last_run'      =>  $this->last_run,
269
+			'last_result'   =>  $this->last_result,
270
+			'frequency'     =>  $this->frequency,
271
+			'nb_occurrences' =>  $this->nb_occurrences,
272
+			'is_running'    =>  $this->is_running
273
+		];
274
+	}
275 275
 }
Please login to merge, or discard this patch.
app/Common/Hooks/AbstractHookCollector.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -28,78 +28,78 @@
 block discarded – undo
28 28
  */
29 29
 abstract class AbstractHookCollector implements HookCollectorInterface, HookInterface
30 30
 {
31
-    /** @var Collection<THook> $hooks */
32
-    protected Collection $hooks;
31
+	/** @var Collection<THook> $hooks */
32
+	protected Collection $hooks;
33 33
 
34
-    private ModuleInterface $module;
34
+	private ModuleInterface $module;
35 35
 
36
-    /**
37
-     * Constructor for AbstractHookCollector
38
-     *
39
-     * @param ModuleInterface $module
40
-     */
41
-    public function __construct(ModuleInterface $module)
42
-    {
43
-        $this->hooks = new Collection();
44
-        $this->module = $module;
45
-    }
36
+	/**
37
+	 * Constructor for AbstractHookCollector
38
+	 *
39
+	 * @param ModuleInterface $module
40
+	 */
41
+	public function __construct(ModuleInterface $module)
42
+	{
43
+		$this->hooks = new Collection();
44
+		$this->module = $module;
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
50
-     */
51
-    public function module(): ModuleInterface
52
-    {
53
-        return $this->module;
54
-    }
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
50
+	 */
51
+	public function module(): ModuleInterface
52
+	{
53
+		return $this->module;
54
+	}
55 55
 
56
-    /**
57
-     * {@inheritDoc}
58
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name()
59
-     */
60
-    public function name(): string
61
-    {
62
-        return $this->module->name() . '-' .
63
-            mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64);
64
-    }
56
+	/**
57
+	 * {@inheritDoc}
58
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name()
59
+	 */
60
+	public function name(): string
61
+	{
62
+		return $this->module->name() . '-' .
63
+			mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64);
64
+	}
65 65
 
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title()
69
-     */
70
-    abstract public function title(): string;
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title()
69
+	 */
70
+	abstract public function title(): string;
71 71
 
72
-    /**
73
-     * {@inheritDoc}
74
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description()
75
-     */
76
-    abstract public function description(): string;
72
+	/**
73
+	 * {@inheritDoc}
74
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description()
75
+	 */
76
+	abstract public function description(): string;
77 77
 
78
-    /**
79
-     * {@inheritDoc}
80
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface()
81
-     */
82
-    abstract public function hookInterface(): string;
78
+	/**
79
+	 * {@inheritDoc}
80
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface()
81
+	 */
82
+	abstract public function hookInterface(): string;
83 83
 
84
-    /**
85
-     * {@inheritDoc}
86
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register()
87
-     */
88
-    public function register(HookInterface $hook_instance, int $order): void
89
-    {
90
-        if ($this->hooks->has($order)) {
91
-            $this->hooks->splice($order + 1, 0, [$hook_instance]);
92
-        } else {
93
-            $this->hooks->put($order, $hook_instance);
94
-        }
95
-    }
84
+	/**
85
+	 * {@inheritDoc}
86
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register()
87
+	 */
88
+	public function register(HookInterface $hook_instance, int $order): void
89
+	{
90
+		if ($this->hooks->has($order)) {
91
+			$this->hooks->splice($order + 1, 0, [$hook_instance]);
92
+		} else {
93
+			$this->hooks->put($order, $hook_instance);
94
+		}
95
+	}
96 96
 
97
-    /**
98
-     * {@inheritDoc}
99
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks()
100
-     */
101
-    public function hooks(): Collection
102
-    {
103
-        return $this->hooks->sortKeys();
104
-    }
97
+	/**
98
+	 * {@inheritDoc}
99
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks()
100
+	 */
101
+	public function hooks(): Collection
102
+	{
103
+		return $this->hooks->sortKeys();
104
+	}
105 105
 }
Please login to merge, or discard this patch.
app/Module/Certificates/Http/RequestHandlers/CertificateImage.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -37,128 +37,128 @@
 block discarded – undo
37 37
  */
38 38
 class CertificateImage implements RequestHandlerInterface
39 39
 {
40
-    /**
41
-     * @var CertificatesModule|null $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var CertificateFilesystemService $certif_filesystem
47
-     */
48
-    private $certif_filesystem;
49
-
50
-    /**
51
-     * @var CertificateImageFactory $certif_image_factory
52
-     */
53
-    private $certif_image_factory;
54
-
55
-    /**
56
-     * @var CertificateDataService $certif_data_service
57
-     */
58
-    private $certif_data_service;
59
-
60
-    /**
61
-     * @var UrlObfuscatorService $url_obfuscator_service
62
-     */
63
-    private $url_obfuscator_service;
64
-
65
-    /**
66
-     * Constructor for Certificate Image Request Handler
67
-     *
68
-     * @param ModuleService $module_service
69
-     */
70
-    public function __construct(
71
-        ModuleService $module_service,
72
-        CertificateFilesystemService $certif_filesystem,
73
-        CertificateDataService $certif_data_service,
74
-        UrlObfuscatorService $url_obfuscator_service
75
-    ) {
76
-        $this->module = $module_service->findByInterface(CertificatesModule::class)->first();
77
-        $this->certif_filesystem = $certif_filesystem;
78
-        $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem);
79
-        $this->certif_data_service = $certif_data_service;
80
-        $this->url_obfuscator_service = $url_obfuscator_service;
81
-    }
82
-
83
-    /**
84
-     * {@inheritDoc}
85
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
86
-     */
87
-    public function handle(ServerRequestInterface $request): ResponseInterface
88
-    {
89
-        if ($this->module === null) {
90
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
91
-        }
92
-
93
-        $tree = $request->getAttribute('tree');
94
-        assert($tree instanceof Tree);
95
-
96
-        $user = $request->getAttribute('user');
97
-        assert($user instanceof UserInterface);
98
-
99
-        $certif_path = $request->getAttribute('cid');
100
-        $certificate = null;
101
-        if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) {
102
-            $certificate = $this->certif_filesystem->certificate($tree, $certif_path);
103
-        }
104
-
105
-        if ($certificate === null) {
106
-            return $this->certif_image_factory
107
-            ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND)
108
-            ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.'))
109
-            ;
110
-        }
111
-
112
-        $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user);
113
-        $watermark = $use_watermark ? $this->watermark($request, $certificate) : null;
114
-
115
-        return $this->certif_image_factory->certificateFileResponse(
116
-            $certificate,
117
-            $use_watermark,
118
-            $watermark
119
-        );
120
-    }
121
-
122
-    /**
123
-     * Get watermark data for a certificate.
124
-     *
125
-     * @param ServerRequestInterface $request
126
-     * @param Certificate $certificate
127
-     * @return Watermark
128
-     */
129
-    private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark
130
-    {
131
-        $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR);
132
-        $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE');
133
-        $text = $this->watermarkText($request, $certificate);
134
-
135
-        return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE);
136
-    }
137
-
138
-    /**
139
-     * Get the text to be watermarked for a certificate.
140
-     *
141
-     * @param ServerRequestInterface $request
142
-     * @param Certificate $certificate
143
-     * @return string
144
-     */
145
-    private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string
146
-    {
147
-        $sid = $request->getQueryParams()['sid'] ?? '';
148
-        if ($sid !== '') {
149
-            $source = Registry::sourceFactory()->make($sid, $certificate->tree());
150
-        } else {
151
-            $source = $this->certif_data_service->oneLinkedSource($certificate);
152
-        }
153
-
154
-        if ($source !== null && $source->canShowName()) {
155
-            $repo = $source->facts(['REPO'])->first();
156
-            if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) {
157
-                return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName()));
158
-            }
159
-            return strip_tags($source->fullName());
160
-        }
161
-        $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT');
162
-        return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.');
163
-    }
40
+	/**
41
+	 * @var CertificatesModule|null $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var CertificateFilesystemService $certif_filesystem
47
+	 */
48
+	private $certif_filesystem;
49
+
50
+	/**
51
+	 * @var CertificateImageFactory $certif_image_factory
52
+	 */
53
+	private $certif_image_factory;
54
+
55
+	/**
56
+	 * @var CertificateDataService $certif_data_service
57
+	 */
58
+	private $certif_data_service;
59
+
60
+	/**
61
+	 * @var UrlObfuscatorService $url_obfuscator_service
62
+	 */
63
+	private $url_obfuscator_service;
64
+
65
+	/**
66
+	 * Constructor for Certificate Image Request Handler
67
+	 *
68
+	 * @param ModuleService $module_service
69
+	 */
70
+	public function __construct(
71
+		ModuleService $module_service,
72
+		CertificateFilesystemService $certif_filesystem,
73
+		CertificateDataService $certif_data_service,
74
+		UrlObfuscatorService $url_obfuscator_service
75
+	) {
76
+		$this->module = $module_service->findByInterface(CertificatesModule::class)->first();
77
+		$this->certif_filesystem = $certif_filesystem;
78
+		$this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem);
79
+		$this->certif_data_service = $certif_data_service;
80
+		$this->url_obfuscator_service = $url_obfuscator_service;
81
+	}
82
+
83
+	/**
84
+	 * {@inheritDoc}
85
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
86
+	 */
87
+	public function handle(ServerRequestInterface $request): ResponseInterface
88
+	{
89
+		if ($this->module === null) {
90
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
91
+		}
92
+
93
+		$tree = $request->getAttribute('tree');
94
+		assert($tree instanceof Tree);
95
+
96
+		$user = $request->getAttribute('user');
97
+		assert($user instanceof UserInterface);
98
+
99
+		$certif_path = $request->getAttribute('cid');
100
+		$certificate = null;
101
+		if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) {
102
+			$certificate = $this->certif_filesystem->certificate($tree, $certif_path);
103
+		}
104
+
105
+		if ($certificate === null) {
106
+			return $this->certif_image_factory
107
+			->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND)
108
+			->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.'))
109
+			;
110
+		}
111
+
112
+		$use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user);
113
+		$watermark = $use_watermark ? $this->watermark($request, $certificate) : null;
114
+
115
+		return $this->certif_image_factory->certificateFileResponse(
116
+			$certificate,
117
+			$use_watermark,
118
+			$watermark
119
+		);
120
+	}
121
+
122
+	/**
123
+	 * Get watermark data for a certificate.
124
+	 *
125
+	 * @param ServerRequestInterface $request
126
+	 * @param Certificate $certificate
127
+	 * @return Watermark
128
+	 */
129
+	private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark
130
+	{
131
+		$color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR);
132
+		$size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE');
133
+		$text = $this->watermarkText($request, $certificate);
134
+
135
+		return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE);
136
+	}
137
+
138
+	/**
139
+	 * Get the text to be watermarked for a certificate.
140
+	 *
141
+	 * @param ServerRequestInterface $request
142
+	 * @param Certificate $certificate
143
+	 * @return string
144
+	 */
145
+	private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string
146
+	{
147
+		$sid = $request->getQueryParams()['sid'] ?? '';
148
+		if ($sid !== '') {
149
+			$source = Registry::sourceFactory()->make($sid, $certificate->tree());
150
+		} else {
151
+			$source = $this->certif_data_service->oneLinkedSource($certificate);
152
+		}
153
+
154
+		if ($source !== null && $source->canShowName()) {
155
+			$repo = $source->facts(['REPO'])->first();
156
+			if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) {
157
+				return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName()));
158
+			}
159
+			return strip_tags($source->fullName());
160
+		}
161
+		$default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT');
162
+		return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.');
163
+	}
164 164
 }
Please login to merge, or discard this patch.
app/Module/Certificates/CertificatesModule.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -46,197 +46,197 @@
 block discarded – undo
46 46
  * Certificates Module.
47 47
  */
48 48
 class CertificatesModule extends AbstractModule implements
49
-    ModuleMyArtJaubInterface,
50
-    ModuleConfigInterface,
51
-    ModuleCustomTagsInterface,
52
-    ModuleGlobalInterface,
53
-    ModuleListInterface,
54
-    ModuleHookSubscriberInterface
49
+	ModuleMyArtJaubInterface,
50
+	ModuleConfigInterface,
51
+	ModuleCustomTagsInterface,
52
+	ModuleGlobalInterface,
53
+	ModuleListInterface,
54
+	ModuleHookSubscriberInterface
55 55
 {
56
-    use ModuleMyArtJaubTrait {
57
-        ModuleMyArtJaubTrait::boot as traitMajBoot;
58
-    }
59
-    use ModuleCustomTagsTrait {
60
-        ModuleCustomTagsTrait::boot as traitCustomTagsBoot;
61
-    }
62
-    use ModuleConfigTrait;
63
-    use ModuleGlobalTrait;
64
-    use ModuleListTrait;
65
-
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
69
-     */
70
-    public function title(): string
71
-    {
72
-        return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
73
-    }
74
-
75
-    /**
76
-     * {@inheritDoc}
77
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
78
-     */
79
-    public function description(): string
80
-    {
81
-        //phpcs:ignore Generic.Files.LineLength.TooLong
82
-        return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
83
-    }
84
-
85
-    /**
86
-     * {@inheritDoc}
87
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
88
-     */
89
-    public function boot(): void
90
-    {
91
-        $this->traitMajBoot();
92
-        $this->traitCustomTagsBoot();
93
-    }
94
-
95
-    /**
96
-     * {@inheritDoc}
97
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
98
-     */
99
-    public function loadRoutes($router): void
100
-    {
101
-        $router->attach('', '', static function (Map $router): void {
102
-
103
-            $router->attach('', '/module-maj/certificates', static function (Map $router): void {
104
-
105
-                $router->attach('', '/admin', static function (Map $router): void {
106
-
107
-                    $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
108
-                    $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class)
109
-                        ->extras([
110
-                            'middleware' => [
111
-                                AuthManager::class,
112
-                            ],
113
-                        ]);
114
-                });
115
-
116
-                $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class)
117
-                    ->extras([
118
-                        'middleware'            =>  [AuthTreePreference::class],
119
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
120
-                    ]);
121
-
122
-                $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
123
-                    ->extras([
124
-                        'middleware'            =>  [AuthTreePreference::class],
125
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
126
-                    ]);
127
-
128
-                $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
129
-
130
-                    $router->extras([
131
-                        'middleware'            =>  [AuthTreePreference::class],
132
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
133
-                    ]);
134
-
135
-                    $router->get(CertificatePage::class, '', CertificatePage::class);
136
-                    $router->get(CertificateImage::class, '/image', CertificateImage::class);
137
-                });
138
-            });
139
-        });
140
-    }
141
-
142
-    /**
143
-     * {@inheritDoc}
144
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
145
-     */
146
-    public function customModuleVersion(): string
147
-    {
148
-        return '2.1.0-v.1';
149
-    }
150
-
151
-    /**
152
-     * {@inheritDoc}
153
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
154
-     */
155
-    public function getConfigLink(): string
156
-    {
157
-        return route(AdminConfigPage::class);
158
-    }
159
-
160
-    /**
161
-     * {@inheritDoc}
162
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags()
163
-     */
164
-    public function customSubTags(): array
165
-    {
166
-        return [
167
-            'FAM:SOUR'      =>  [['_ACT', '0:1']],
168
-            'FAM:*:SOUR'    =>  [['_ACT', '0:1']],
169
-            'INDI:SOUR'     =>  [['_ACT', '0:1']],
170
-            'INDI:*:SOUR'   =>  [['_ACT', '0:1']],
171
-            'OBJE:SOUR'     =>  [['_ACT', '0:1']],
172
-            'OBJE:*:SOUR'   =>  [['_ACT', '0:1']],
173
-            'NOTE:SOUR'     =>  [['_ACT', '0:1']],
174
-            'NOTE:*:SOUR'   =>  [['_ACT', '0:1']]
175
-        ];
176
-    }
177
-
178
-    /**
179
-     * {@inheritDoc}
180
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags()
181
-     */
182
-    public function customTags(): array
183
-    {
184
-        return [
185
-            'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate'), $this),
186
-            'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate'), $this),
187
-            'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
188
-            'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
189
-            'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
190
-            'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
191
-            'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
192
-            'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this)
193
-        ];
194
-    }
195
-
196
-    /**
197
-     * {@inheritDoc}
198
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
199
-     */
200
-    public function headContent(): string
201
-    {
202
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
203
-    }
204
-
205
-    /**
206
-     * {@inheritDoc}
207
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
208
-     */
209
-    public function listUrl(Tree $tree, array $parameters = []): string
210
-    {
211
-        return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
212
-    }
213
-
214
-    /**
215
-     * {@inheritDoc}
216
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
217
-     */
218
-    public function listMenuClass(): string
219
-    {
220
-        return 'menu-maj-certificates';
221
-    }
222
-
223
-    /**
224
-     * {@inheritDoc}
225
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
226
-     */
227
-    public function listIsEmpty(Tree $tree): bool
228
-    {
229
-        return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
230
-    }
231
-
232
-    /**
233
-     * {@inheritDoc}
234
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
235
-     */
236
-    public function listSubscribedHooks(): array
237
-    {
238
-        return [
239
-            app()->makeWith(SourceCertificateIconHook::class, ['module' => $this])
240
-        ];
241
-    }
56
+	use ModuleMyArtJaubTrait {
57
+		ModuleMyArtJaubTrait::boot as traitMajBoot;
58
+	}
59
+	use ModuleCustomTagsTrait {
60
+		ModuleCustomTagsTrait::boot as traitCustomTagsBoot;
61
+	}
62
+	use ModuleConfigTrait;
63
+	use ModuleGlobalTrait;
64
+	use ModuleListTrait;
65
+
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
69
+	 */
70
+	public function title(): string
71
+	{
72
+		return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
73
+	}
74
+
75
+	/**
76
+	 * {@inheritDoc}
77
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
78
+	 */
79
+	public function description(): string
80
+	{
81
+		//phpcs:ignore Generic.Files.LineLength.TooLong
82
+		return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
83
+	}
84
+
85
+	/**
86
+	 * {@inheritDoc}
87
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
88
+	 */
89
+	public function boot(): void
90
+	{
91
+		$this->traitMajBoot();
92
+		$this->traitCustomTagsBoot();
93
+	}
94
+
95
+	/**
96
+	 * {@inheritDoc}
97
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
98
+	 */
99
+	public function loadRoutes($router): void
100
+	{
101
+		$router->attach('', '', static function (Map $router): void {
102
+
103
+			$router->attach('', '/module-maj/certificates', static function (Map $router): void {
104
+
105
+				$router->attach('', '/admin', static function (Map $router): void {
106
+
107
+					$router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
108
+					$router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class)
109
+						->extras([
110
+							'middleware' => [
111
+								AuthManager::class,
112
+							],
113
+						]);
114
+				});
115
+
116
+				$router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class)
117
+					->extras([
118
+						'middleware'            =>  [AuthTreePreference::class],
119
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
120
+					]);
121
+
122
+				$router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
123
+					->extras([
124
+						'middleware'            =>  [AuthTreePreference::class],
125
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
126
+					]);
127
+
128
+				$router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
129
+
130
+					$router->extras([
131
+						'middleware'            =>  [AuthTreePreference::class],
132
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
133
+					]);
134
+
135
+					$router->get(CertificatePage::class, '', CertificatePage::class);
136
+					$router->get(CertificateImage::class, '/image', CertificateImage::class);
137
+				});
138
+			});
139
+		});
140
+	}
141
+
142
+	/**
143
+	 * {@inheritDoc}
144
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
145
+	 */
146
+	public function customModuleVersion(): string
147
+	{
148
+		return '2.1.0-v.1';
149
+	}
150
+
151
+	/**
152
+	 * {@inheritDoc}
153
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
154
+	 */
155
+	public function getConfigLink(): string
156
+	{
157
+		return route(AdminConfigPage::class);
158
+	}
159
+
160
+	/**
161
+	 * {@inheritDoc}
162
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags()
163
+	 */
164
+	public function customSubTags(): array
165
+	{
166
+		return [
167
+			'FAM:SOUR'      =>  [['_ACT', '0:1']],
168
+			'FAM:*:SOUR'    =>  [['_ACT', '0:1']],
169
+			'INDI:SOUR'     =>  [['_ACT', '0:1']],
170
+			'INDI:*:SOUR'   =>  [['_ACT', '0:1']],
171
+			'OBJE:SOUR'     =>  [['_ACT', '0:1']],
172
+			'OBJE:*:SOUR'   =>  [['_ACT', '0:1']],
173
+			'NOTE:SOUR'     =>  [['_ACT', '0:1']],
174
+			'NOTE:*:SOUR'   =>  [['_ACT', '0:1']]
175
+		];
176
+	}
177
+
178
+	/**
179
+	 * {@inheritDoc}
180
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags()
181
+	 */
182
+	public function customTags(): array
183
+	{
184
+		return [
185
+			'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate'), $this),
186
+			'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate'), $this),
187
+			'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
188
+			'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
189
+			'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
190
+			'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
191
+			'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
192
+			'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this)
193
+		];
194
+	}
195
+
196
+	/**
197
+	 * {@inheritDoc}
198
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
199
+	 */
200
+	public function headContent(): string
201
+	{
202
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
203
+	}
204
+
205
+	/**
206
+	 * {@inheritDoc}
207
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
208
+	 */
209
+	public function listUrl(Tree $tree, array $parameters = []): string
210
+	{
211
+		return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
212
+	}
213
+
214
+	/**
215
+	 * {@inheritDoc}
216
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
217
+	 */
218
+	public function listMenuClass(): string
219
+	{
220
+		return 'menu-maj-certificates';
221
+	}
222
+
223
+	/**
224
+	 * {@inheritDoc}
225
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
226
+	 */
227
+	public function listIsEmpty(Tree $tree): bool
228
+	{
229
+		return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
230
+	}
231
+
232
+	/**
233
+	 * {@inheritDoc}
234
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
235
+	 */
236
+	public function listSubscribedHooks(): array
237
+	{
238
+		return [
239
+			app()->makeWith(SourceCertificateIconHook::class, ['module' => $this])
240
+		];
241
+	}
242 242
 }
Please login to merge, or discard this patch.