|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace eXpansion\Bundle\LocalRecords\Plugins\Gui; |
|
5
|
|
|
use eXpansion\Bundle\Acme\Plugins\Gui\WindowFactory; |
|
6
|
|
|
use eXpansion\Bundle\LocalRecords\Entity\Record; |
|
7
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilder; |
|
10
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory; |
|
11
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
12
|
|
|
use FML\Controls\Frame; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class RecordsWindowFactory |
|
17
|
|
|
* |
|
18
|
|
|
* @package eXpansion\Bundle\LocalRecords\Plugins\Gui; |
|
19
|
|
|
* @author oliver de Cramer <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class RecordsWindowFactory extends WindowFactory |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var Record[] */ |
|
24
|
|
|
protected $recordsData = []; |
|
25
|
|
|
|
|
26
|
|
|
/** @var GridBuilderFactory */ |
|
27
|
|
|
protected $gridBuilderFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** @var DataCollectionFactory */ |
|
30
|
|
|
protected $dataCollectionFactory; |
|
31
|
|
|
|
|
32
|
|
|
/** @var Time */ |
|
33
|
|
|
protected $timeFormatter; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function createContent(ManialinkInterface $manialink) |
|
39
|
|
|
{ |
|
40
|
|
|
$collection = $this->dataCollectionFactory->create($this->getRecordsData()); |
|
41
|
|
|
$collection->setPageSize(20); |
|
42
|
|
|
|
|
43
|
|
|
$gridBuilder = $this->gridBuilderFactory->create(); |
|
44
|
|
|
$gridBuilder->setManialink($manialink) |
|
45
|
|
|
->setDataCollection($collection) |
|
46
|
|
|
->setManialinkFactory($this) |
|
47
|
|
|
->addTextColumn( |
|
48
|
|
|
'position', |
|
49
|
|
|
'expansion_local_records.gui.race.window.column.position', |
|
50
|
|
|
'1' |
|
51
|
|
|
)->addTextColumn( |
|
52
|
|
|
'nickname', |
|
53
|
|
|
'expansion_local_records.gui.race.window.column.nickname', |
|
54
|
|
|
'4' |
|
55
|
|
|
)->addTextColumn( |
|
56
|
|
|
'login', |
|
57
|
|
|
'expansion_local_records.gui.race.window.column.login', |
|
58
|
|
|
'4' |
|
59
|
|
|
)->addTextColumn( |
|
60
|
|
|
'score', |
|
61
|
|
|
'expansion_local_records.gui.race.window.column.score', |
|
62
|
|
|
'3' |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$manialink->setData('grid', $gridBuilder); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
*/ |
|
71
|
|
View Code Duplication |
protected function updateContent(ManialinkInterface $manialink) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
/** @var Frame $contentFrame */ |
|
74
|
|
|
$contentFrame = $manialink->getContentFrame(); |
|
|
|
|
|
|
75
|
|
|
$contentFrame->removeAllChildren(); |
|
76
|
|
|
|
|
77
|
|
|
$collection = $this->dataCollectionFactory->create($this->getRecordsData()); |
|
78
|
|
|
$collection->setPageSize(20); |
|
79
|
|
|
|
|
80
|
|
|
/** @var GridBuilder $gridBuilder */ |
|
81
|
|
|
$gridBuilder = $manialink->getData('grid'); |
|
82
|
|
|
$contentFrame->addChild($gridBuilder->build($contentFrame->getWidth(), $contentFrame->getHeight())); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function getRecordsData() |
|
89
|
|
|
{ |
|
90
|
|
|
$recordsData = []; |
|
91
|
|
|
|
|
92
|
|
|
foreach ($this->recordsData as $i => $record) { |
|
93
|
|
|
$recordsData[] = [ |
|
94
|
|
|
'position' => $i + 1, |
|
95
|
|
|
'nickname' => $record->getPlayerLogin(), |
|
96
|
|
|
'login' => $record->getPlayerLogin(), |
|
97
|
|
|
'score' => $this->timeFormatter->milisecondsToTrackmania($record->getScore(), true), |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $recordsData; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param GridBuilderFactory $gridBuilderFactory |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setGridBuilderFactory($gridBuilderFactory) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->gridBuilderFactory = $gridBuilderFactory; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param DataCollectionFactory $dataCollectionFactory |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setDataCollectionFactory($dataCollectionFactory) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->dataCollectionFactory = $dataCollectionFactory; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param Time $time |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setTimerFormatter(Time $time) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->timeFormatter = $time; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param Record[] $records |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setRecordsData($records) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->recordsData = $records; |
|
134
|
|
|
} |
|
135
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.