Completed
Branch master (220ce5)
by De Cramer
16:11
created

GridWindowFactory::updateContent()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 19
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 1
crap 12
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
 * @package eXpansion\Bundle\LocalRecords\Plugins\Gui;
17
 * @author  reaby
18
 */
19
abstract class GridWindowFactory extends WindowFactory
20
{
21
    /** @var array */
22
    protected $genericData = [];
23
24
    /** @var GridBuilderFactory */
25
    protected $gridBuilderFactory;
26
27
    /** @var DataCollectionFactory */
28
    protected $dataCollectionFactory;
29
30
    /** @var Time */
31
    protected $timeFormatter;
32
33
    /**
34
     * @var GridBuilder
35
     */
36
    protected $gridBuilder;
37
38
    /** @var  Frame */
39
    protected $gridFrame;
40
41
    /** @var  float|null */
42
    protected $gridWidth;
43
44
    /** @var  float|null */
45
    protected $gridHeight;
46
47
    /** @var  float|null */
48
    protected $gridPosX = 0.;
49
50
    /** @var  float|null */
51
    protected $gridPosY = 0;
52
53
    /**
54
     * @inheritdoc
55
     */
56
    protected function createContent(ManialinkInterface $manialink)
57
    {
58
        parent::createContent($manialink);
59
        $gridFrame = new Frame();
60
        $manialink->setData("gridFrame", $gridFrame);
61
62
        $manialink->getContentFrame()->addChild($manialink->getData('gridFrame'));
63
        $this->createGrid($manialink);
64
    }
65
66
67
    /**
68
     * @param ManialinkInterface $manialink
69
     * @return mixed
70
     */
71
    abstract protected function createGrid(ManialinkInterface $manialink);
72
73
74
    /**
75
     * @inheritdoc
76
     */
77
    protected function updateContent(ManialinkInterface $manialink)
78
    {
79
        /** @var Frame $contentFrame */
80
        $contentFrame = $manialink->getContentFrame();
81
82
        $manialink->getData('gridFrame')->removeAllChildren();
83
84
        $collection = $this->dataCollectionFactory->create($this->getData());
85
        $collection->setPageSize(20);
86
87
        /** @var GridBuilder $gridBuilder */
88
        $gridBuilder = $manialink->getData('grid');
89
        $gridBuilder->setDataCollection($collection);
90
91
        if (!$this->gridHeight) {
92
            $this->gridHeight = $contentFrame->getHeight();
93
        }
94
95
        if (!$this->gridWidth) {
96
            $this->gridWidth = $contentFrame->getWidth();
97
        }
98
99
        $manialink->getData('gridFrame')->setPosition($this->gridPosX, $this->gridPosY);
100
101
        $manialink->getData("gridFrame")->addChild($gridBuilder->build($this->gridWidth,
102
            $this->gridHeight));
103
104
        parent::updateContent($manialink);
105
    }
106
107
    /**
108
     * @param array $data
109
     */
110
    public function setData($data)
111
    {
112
        $this->genericData = $data;
113
    }
114
115
    /**
116
     * @return array
117
     */
118
    public function getData()
119
    {
120
        return $this->genericData;
121
    }
122
123
    /**
124
     * @param GridBuilderFactory $gridBuilderFactory
125
     */
126
    public function setGridBuilderFactory($gridBuilderFactory)
127
    {
128
        $this->gridBuilderFactory = $gridBuilderFactory;
129
    }
130
131
    /**
132
     * @param DataCollectionFactory $dataCollectionFactory
133
     */
134
    public function setDataCollectionFactory($dataCollectionFactory)
135
    {
136
        $this->dataCollectionFactory = $dataCollectionFactory;
137
    }
138
139
    /**
140
     * @param Time $time
141
     */
142
    public function setTimerFormatter(Time $time)
143
    {
144
        $this->timeFormatter = $time;
145
    }
146
147
148
    public function setGridSize($x, $y)
149
    {
150
        $this->gridWidth = $x;
151
        $this->gridHeight = $y;
152
    }
153
154
    public function setGridPosition($x, $y)
155
    {
156
        $this->gridPosX = $x;
157
        $this->gridPosY = $y;
158
    }
159
160
}
161