Completed
Push — master ( d36035...2c3438 )
by
unknown
03:03
created

GridWindowFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 2
dl 0
loc 129
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createContent() 0 13 1
createGrid() 0 1 ?
B updateContent() 0 26 3
A setData() 0 5 1
A getData() 0 4 1
A setTimerFormatter() 0 4 1
A setGridSize() 0 5 1
A setGridPosition() 0 5 1
1
<?php
2
3
4
namespace eXpansion\Framework\Core\Plugins\Gui;
5
6
use eXpansion\Framework\Core\Helpers\Time;
7
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory;
8
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilder;
9
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory;
10
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
11
use FML\Controls\Frame;
12
13
/**
14
 * Class RecordsWindowFactory
15
 *
16
 * @author  reaby
17
 */
18
abstract class GridWindowFactory extends WindowFactory
19
{
20
    /** @var array */
21
    protected $genericData = [];
22
23
    /** @var GridBuilderFactory */
24
    protected $gridBuilderFactory;
25
26
    /** @var DataCollectionFactory */
27
    protected $dataCollectionFactory;
28
29
    /** @var Time */
30
    protected $timeFormatter;
31
32
    /**
33
     * @var GridBuilder
34
     */
35
    protected $gridBuilder;
36
37
    /** @var  Frame */
38
    protected $gridFrame;
39
40
    /** @var  float|null */
41
    protected $gridWidth;
42
43
    /** @var  float|null */
44
    protected $gridHeight;
45
46
    /** @var  float|null */
47
    protected $gridPosX = 0.;
48
49
    /** @var  float|null */
50
    protected $gridPosY = 0;
51
52
    /**
53
     * @inheritdoc
54
     */
55
    protected function createContent(ManialinkInterface $manialink)
56
    {
57
        parent::createContent($manialink);
58
        $gridFrame = new Frame();
59
        $manialink->setData("gridFrame", $gridFrame);
60
61
        $manialink->getContentFrame()->addChild($manialink->getData('gridFrame'));
62
63
        $collection = $this->dataCollectionFactory->create([]);
64
        $manialink->setData("dataCollection", $collection);
65
66
        $this->createGrid($manialink);
67
    }
68
69
70
    /**
71
     * @param ManialinkInterface $manialink
72
     */
73
    abstract protected function createGrid(ManialinkInterface $manialink);
74
75
76
    /**
77
     * @inheritdoc
78
     */
79
    protected function updateContent(ManialinkInterface $manialink)
80
    {
81
        /** @var Frame $contentFrame */
82
        $contentFrame = $manialink->getContentFrame();
83
84
        $manialink->getData('gridFrame')->removeAllChildren();
85
86
        /** @var GridBuilder $gridBuilder */
87
        $gridBuilder = $manialink->getData('grid');
88
        $gridBuilder->setDataCollection($manialink->getData('dataCollection'));
89
90
        if (!$this->gridHeight) {
91
            $this->gridHeight = $contentFrame->getHeight();
92
        }
93
94
        if (!$this->gridWidth) {
95
            $this->gridWidth = $contentFrame->getWidth();
96
        }
97
98
        $manialink->getData('gridFrame')->setPosition($this->gridPosX, $this->gridPosY);
99
100
        $manialink->getData("gridFrame")->addChild($gridBuilder->build($this->gridWidth,
101
            $this->gridHeight));
102
103
        parent::updateContent($manialink);
104
    }
105
106
    /**
107
     * @param ManialinkInterface $manialink
108
     * @param array $data
109
     */
110
    public function setData(ManialinkInterface $manialink, $data)
111
    {
112
        $collection = $this->dataCollectionFactory->create($data);
113
        $manialink->setData('dataCollection', $collection);
114
    }
115
116
    /**
117
     * @param ManialinkInterface $manialink
118
     * @return array
119
     */
120
    public function getData(ManialinkInterface $manialink)
121
    {
122
        return $manialink->getData('dataCollection')->getAll();
123
    }
124
125
    /**
126
     * @param Time $time
127
     */
128
    public function setTimerFormatter(Time $time)
129
    {
130
        $this->timeFormatter = $time;
131
    }
132
133
134
    public function setGridSize($x, $y)
135
    {
136
        $this->gridWidth = $x;
137
        $this->gridHeight = $y;
138
    }
139
140
    public function setGridPosition($x, $y)
141
    {
142
        $this->gridPosX = $x;
143
        $this->gridPosY = $y;
144
    }
145
146
}
147