Completed
Pull Request — master (#404)
by De Cramer
03:04
created

ServerInfoWindow::updateContent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace eXpansion\Bundle\ServerInformation\Plugins\Gui;
4
5
use eXpansion\Bundle\ServerInformation\Services\ServerInformationInterface;
6
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
7
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext;
8
use eXpansion\Framework\Core\Plugins\Gui\WindowFactory;
9
use eXpansion\Framework\Gui\Ui\Factory;
10
use FML\Controls\Frame;
11
12
class ServerInfoWindow extends WindowFactory
13
{
14
    /** @var ServerInformationInterface[] */
15
    protected $serverInfos;
16
17
    /** @var Factory */
18
    protected $factory;
19
20
    public function __construct(
21
        $name,
22
        $sizeX,
23
        $sizeY,
24
        $posX = null,
25
        $posY = null,
26
        WindowFactoryContext $context,
27
        $serverInfos = [],
28
        Factory $factory
29
    ) {
30
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
31
32
        $this->serverInfos = $serverInfos;
33
        $this->factory = $factory;
34
    }
35
36
    /**
37
     * @param ManialinkInterface $manialink
38
     */
39
    protected function updateContent(ManialinkInterface $manialink)
40
    {
41
        parent::updateContent($manialink);
42
43
        /** @var Frame $contentFrame */
44
        $contentFrame = $manialink->getContentFrame();
45
        $contentFrame->removeAllChildren();
46
47
        $login = $manialink->getUserGroup()->getLogins()[0];
48
49
        $elements = [];
50
        foreach ($this->serverInfos as $serverInfo) {
51
            if ($serverInfo->canShow($login)) {
52
                $elements[] = $serverInfo->getInformation($login);
53
            }
54
        }
55
56
        $contentFrame->addChild($this->factory->createLayoutRow(0, 0, $elements));
57
    }
58
59
60
}