|
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 eXpansion\Framework\Core\Model\Gui\WindowFactoryContext; |
|
13
|
|
|
use FML\Controls\Frame; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class RecordsWindowFactory |
|
18
|
|
|
* |
|
19
|
|
|
* @package eXpansion\Bundle\LocalRecords\Plugins\Gui; |
|
20
|
|
|
* @author oliver de Cramer <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class RecordsWindowFactory extends WindowFactory |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var Record[] */ |
|
25
|
|
|
protected $recordsData = []; |
|
26
|
|
|
|
|
27
|
|
|
/** @var GridBuilderFactory */ |
|
28
|
|
|
protected $gridBuilderFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** @var DataCollectionFactory */ |
|
31
|
|
|
protected $dataCollectionFactory; |
|
32
|
|
|
|
|
33
|
|
|
/** @var Time */ |
|
34
|
|
|
protected $timeFormatter; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
38
|
|
|
$name, |
|
39
|
|
|
$sizeX, |
|
40
|
|
|
$sizeY, |
|
41
|
|
|
$posX, |
|
42
|
|
|
$posY, |
|
43
|
|
|
WindowFactoryContext $context, |
|
44
|
|
|
GridBuilderFactory $gridBuilderFactory, |
|
45
|
|
|
DataCollectionFactory $dataCollectionFactory, |
|
46
|
|
|
Time $time |
|
47
|
|
|
) { |
|
48
|
|
|
parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
|
49
|
|
|
|
|
50
|
|
|
$this->gridBuilderFactory = $gridBuilderFactory; |
|
51
|
|
|
$this->dataCollectionFactory = $dataCollectionFactory; |
|
52
|
|
|
$this->timeFormatter = $time; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
View Code Duplication |
protected function createContent(ManialinkInterface $manialink) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$collection = $this->dataCollectionFactory->create($this->getRecordsData()); |
|
61
|
|
|
$collection->setPageSize(20); |
|
62
|
|
|
|
|
63
|
|
|
$gridBuilder = $this->gridBuilderFactory->create(); |
|
64
|
|
|
$gridBuilder->setManialink($manialink) |
|
65
|
|
|
->setDataCollection($collection) |
|
66
|
|
|
->setManialinkFactory($this) |
|
67
|
|
|
->addTextColumn( |
|
68
|
|
|
'position', |
|
69
|
|
|
'expansion_local_records.gui.race.window.column.position', |
|
70
|
|
|
'1', |
|
71
|
|
|
true |
|
72
|
|
|
)->addTextColumn( |
|
73
|
|
|
'score', |
|
74
|
|
|
'expansion_local_records.gui.race.window.column.score', |
|
75
|
|
|
'3', |
|
76
|
|
|
true |
|
77
|
|
|
)->addTextColumn( |
|
78
|
|
|
'nickname', |
|
79
|
|
|
'expansion_local_records.gui.race.window.column.nickname', |
|
80
|
|
|
'4' |
|
81
|
|
|
)->addTextColumn( |
|
82
|
|
|
'login', |
|
83
|
|
|
'expansion_local_records.gui.race.window.column.login', |
|
84
|
|
|
'4', |
|
85
|
|
|
true |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$manialink->setData('grid', $gridBuilder); |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
protected function updateContent(ManialinkInterface $manialink) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
/** @var Frame $contentFrame */ |
|
98
|
|
|
$contentFrame = $manialink->getContentFrame(); |
|
99
|
|
|
$contentFrame->removeAllChildren(); |
|
100
|
|
|
|
|
101
|
|
|
$collection = $this->dataCollectionFactory->create($this->getRecordsData()); |
|
102
|
|
|
$collection->setPageSize(20); |
|
103
|
|
|
|
|
104
|
|
|
/** @var GridBuilder $gridBuilder */ |
|
105
|
|
|
$gridBuilder = $manialink->getData('grid'); |
|
106
|
|
|
$contentFrame->addChild($gridBuilder->build($contentFrame->getWidth(), $contentFrame->getHeight())); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function getRecordsData() |
|
113
|
|
|
{ |
|
114
|
|
|
$recordsData = []; |
|
115
|
|
|
|
|
116
|
|
|
foreach ($this->recordsData as $i => $record) { |
|
117
|
|
|
$recordsData[] = [ |
|
118
|
|
|
'position' => $i + 1, |
|
119
|
|
|
'nickname' => $record->getPlayerLogin(), |
|
120
|
|
|
'login' => $record->getPlayerLogin(), |
|
121
|
|
|
'score' => $this->timeFormatter->timeToText($record->getScore(), true), |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $recordsData; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param Record[] $records |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setRecordsData($records) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->recordsData = $records; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
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.