Passed
Push — master ( 55cfd1...cb4d54 )
by Nico
22:41
created

ShowMapEditor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 54
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 38 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Admin\View\Map;
6
7
use request;
8
use Stu\Component\Map\MapEnum;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Control\ViewControllerInterface;
11
use Stu\Orm\Repository\LayerRepositoryInterface;
12
use Stu\Orm\Repository\StarSystemRepositoryInterface;
13
14
final class ShowMapEditor implements ViewControllerInterface
15
{
16
    public const VIEW_IDENTIFIER = 'SHOW_MAP_EDITOR';
17
18
    private LayerRepositoryInterface $layerRepository;
19
20
    private StarSystemRepositoryInterface $starSystemRepository;
21
22
    public function __construct(
23
        LayerRepositoryInterface $layerRepository,
24
        StarSystemRepositoryInterface $starSystemRepository
25
    ) {
26
        $this->layerRepository = $layerRepository;
27
        $this->starSystemRepository = $starSystemRepository;
28
    }
29
30
    public function handle(GameControllerInterface $game): void
31
    {
32
        $game->setTemplateFile('html/admin/mapeditor_overview.twig');
33
        $game->appendNavigationPart('/admin/?SHOW_MAP_EDITOR=1', _('Karteneditor'));
34
        $game->setPageTitle(_('Karteneditor'));
35
36
        //LAYER
37
        $layers = $this->layerRepository->findAllIndexed();
38
39
        $layerId = request::getInt('layerid');
40
        $layer = $layerId === 0 ? $layers[MapEnum::DEFAULT_LAYER] : $layers[$layerId];
41
42
        //HEADROW
43
        $xHeadRow = [];
44
        for ($j = 1; $j <= (int)ceil($layer->getWidth() / MapEnum::FIELDS_PER_SECTION); $j++) {
45
            $xHeadRow[] = $j;
46
        }
47
48
        //SECTIONS
49
        $sections = [];
50
        $k = 1;
51
        for ($i = 1; $i <= (int)ceil($layer->getHeight() / MapEnum::FIELDS_PER_SECTION); $i++) {
52
            for ($j = 1; $j <= (int)ceil($layer->getWidth() / MapEnum::FIELDS_PER_SECTION); $j++) {
53
                $sections[$i][$j] = $k;
54
                $k++;
55
            }
56
        }
57
58
        $systemList = $this->starSystemRepository->getByLayer($layer->getId());
59
        $numberOfSystemsToGenerate = $this->starSystemRepository->getNumberOfSystemsToGenerate($layer);
60
61
        $game->setTemplateVar('LAYERID', $layer->getId());
62
        $game->setTemplateVar('LAYERS', $layers);
63
        $game->setTemplateVar('X_HEAD_ROW', $xHeadRow);
64
        $game->setTemplateVar('SECTIONS', $sections);
65
        $game->setTemplateVar('FIELDS_PER_SECTION', MapEnum::FIELDS_PER_SECTION);
66
        $game->setTemplateVar('SYSTEM_LIST', $systemList);
67
        $game->setTemplateVar('NUMBER_OF_SYSTEMS_TO_GENERATE', $numberOfSystemsToGenerate);
68
    }
69
}
70