AbstractGeoAnalysisView::useFlags()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage GeoDispersion
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-2022, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\GeoDispersion\Views;
16
17
use Fisharebest\Webtrees\Tree;
18
use Fisharebest\Webtrees\Module\ModuleInterface;
19
use Illuminate\Support\Collection;
20
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisResult;
21
use MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface;
22
use MyArtJaub\Webtrees\Module\GeoDispersion\GeoDispersionModule;
23
use Psr\Http\Message\ServerRequestInterface;
24
25
/**
26
 * Abstract class for Geographical dispersion analysis Views
27
 */
28
abstract class AbstractGeoAnalysisView
29
{
30
    private int $id;
31
    private Tree $tree;
32
    private bool $enabled;
33
    private string $description;
34
    private GeoAnalysisInterface $geoanalysis;
35
    private int $depth;
36
    private int $detailed_top_places;
37
    private bool $use_flags;
38
39
    /**
40
     * Constructor for AbstractGeoAnalysisView
41
     *
42
     * @param int $id
43
     * @param Tree $tree
44
     * @param bool $enabled
45
     * @param string $description
46
     * @param GeoAnalysisInterface $geoanalysis
47
     * @param int $depth
48
     * @param int $detailed_top_places
49
     * @param bool $use_flags
50
     */
51
    final public function __construct(
52
        int $id,
53
        Tree $tree,
54
        bool $enabled,
55
        string $description,
56
        GeoAnalysisInterface $geoanalysis,
57
        int $depth,
58
        int $detailed_top_places = 0,
59
        bool $use_flags = false
60
    ) {
61
        $this->id = $id;
62
        $this->tree = $tree;
63
        $this->enabled = $enabled;
64
        $this->description = $description;
65
        $this->geoanalysis = $geoanalysis;
66
        $this->depth = $depth;
67
        $this->detailed_top_places = $detailed_top_places;
68
        $this->use_flags = $use_flags;
69
    }
70
71
    /**
72
     * Create a copy of the view with a new ID.
73
     *
74
     * @param int $id
75
     * @return static
76
     */
77
    public function withId(int $id): self
78
    {
79
        $new = clone $this;
80
        $new->id = $id;
81
        return $new;
82
    }
83
84
    /**
85
     * Create a copy of the view with new properties.
86
     *
87
     * @param bool $enabled
88
     * @param string $description
89
     * @param GeoAnalysisInterface $geoanalysis
90
     * @param int $depth
91
     * @param int $detailed_top_places
92
     * @param bool $use_flags
93
     * @return static
94
     */
95
    public function with(
96
        bool $enabled,
97
        string $description,
98
        GeoAnalysisInterface $geoanalysis,
99
        int $depth,
100
        int $detailed_top_places = 0,
101
        bool $use_flags = false
102
    ): self {
103
        $new = clone $this;
104
        $new->enabled = $enabled;
105
        $new->description = $description;
106
        $new->geoanalysis = $geoanalysis;
107
        $new->depth = $depth;
108
        $new->detailed_top_places = $detailed_top_places;
109
        $new->use_flags = $use_flags;
110
        return $new;
111
    }
112
113
    /**
114
     * Get the view ID
115
     *
116
     * @return int
117
     */
118
    public function id(): int
119
    {
120
        return $this->id;
121
    }
122
123
    /**
124
     * Get the view type for display
125
     *
126
     * @return string
127
     */
128
    abstract public function type(): string;
129
130
    /**
131
     * Get the icon for the view type
132
     *
133
     * @param ModuleInterface $module
134
     * @return string
135
     */
136
    abstract public function icon(ModuleInterface $module): string;
137
138
    /**
139
     * Return the content of the global settings section of the config page
140
     *
141
     * @param ModuleInterface $module
142
     * @return string
143
     */
144
    abstract public function globalSettingsContent(ModuleInterface $module): string;
145
146
    /**
147
     * Return a view with global settings updated according to the view rules
148
     *
149
     * @param ServerRequestInterface $request
150
     * @return static
151
     */
152
    abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self;
153
154
    /**
155
     * Returns the content of the view global tab
156
     *
157
     * @param GeoDispersionModule $module
158
     * @param GeoAnalysisResult $result
159
     * @param array<string, mixed> $params
160
     * @return string
161
     */
162
    abstract public function globalTabContent(
163
        GeoDispersionModule $module,
164
        GeoAnalysisResult $result,
165
        array $params
166
    ): string;
167
168
    /**
169
     * Returns the content of the view detailed tab
170
     *
171
     * @param ModuleInterface $module
172
     * @param Collection<string, GeoAnalysisResult> $results
173
     * @param array<string, mixed> $params
174
     * @return string
175
     */
176
    public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string
177
    {
178
        return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results'   =>  $results ]);
179
    }
180
181
    /**
182
     * Get the tree to which the view belongs
183
     *
184
     * @return Tree
185
     */
186
    public function tree(): Tree
187
    {
188
        return $this->tree;
189
    }
190
191
    /**
192
     * Get the description of the view
193
     *
194
     * @return string
195
     */
196
    public function description(): string
197
    {
198
        return $this->description;
199
    }
200
201
    /**
202
     * Get whether the view is enabled
203
     *
204
     * @return bool
205
     */
206
    public function isEnabled(): bool
207
    {
208
        return $this->enabled;
209
    }
210
211
    /**
212
     * Get the geographical dispersion analysis for the view
213
     *
214
     * @return GeoAnalysisInterface
215
     */
216
    public function analysis(): GeoAnalysisInterface
217
    {
218
        return $this->geoanalysis;
219
    }
220
221
    /**
222
     * Get the place hierarchy depth for the view
223
     *
224
     * @return int
225
     */
226
    public function placesDepth(): int
227
    {
228
        return $this->depth;
229
    }
230
231
    /**
232
     * Get the number of places to display in the detailed tab
233
     *
234
     * @return int
235
     */
236
    public function numberTopPlaces(): int
237
    {
238
        return $this->detailed_top_places;
239
    }
240
241
    /**
242
     * Get whether flags should be used in the detailed tab
243
     *
244
     * @return bool
245
     */
246
    public function useFlags(): bool
247
    {
248
        return $this->use_flags;
249
    }
250
}
251