GeoAnalysisViewPage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
A __construct() 0 6 1
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\Http\RequestHandlers;
16
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Tree;
19
use Fisharebest\Webtrees\Validator;
20
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
21
use Fisharebest\Webtrees\Http\ViewResponseTrait;
22
use Fisharebest\Webtrees\Services\ModuleService;
23
use MyArtJaub\Webtrees\Module\GeoDispersion\GeoDispersionModule;
24
use MyArtJaub\Webtrees\Module\GeoDispersion\Services\GeoAnalysisViewDataService;
25
use Psr\Http\Message\ResponseInterface;
26
use Psr\Http\Message\ServerRequestInterface;
27
use Psr\Http\Server\RequestHandlerInterface;
28
29
/**
30
 * Request handler for displaying  a geographical dispersion analysis view
31
 *
32
 */
33
class GeoAnalysisViewPage implements RequestHandlerInterface
34
{
35
    use ViewResponseTrait;
36
37
    private ?GeoDispersionModule $module;
38
    private GeoAnalysisViewDataService $geoviewdata_service;
39
40
    /**
41
     * Constructor for GeoAnalysisViewPage Request Handler
42
     *
43
     * @param ModuleService $module_service
44
     */
45
    public function __construct(
46
        ModuleService $module_service,
47
        GeoAnalysisViewDataService $geoviewdata_service
48
    ) {
49
        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
        $this->geoviewdata_service = $geoviewdata_service;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
     */
57
    public function handle(ServerRequestInterface $request): ResponseInterface
58
    {
59
        if ($this->module === null) {
60
            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
        }
62
63
        $tree = Validator::attributes($request)->tree();
64
        $view_id = Validator::attributes($request)->integer('view_id', 0);
65
66
        return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
67
            'module_name'           =>  $this->module->name(),
68
            'title'                 =>  I18N::translate('Geographical dispersion'),
69
            'tree'                  =>  $tree,
70
            'view'                  =>  $this->geoviewdata_service->find($tree, $view_id)
71
        ]);
72
    }
73
}
74