|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace eXpansion\Bundle\Maps\Plugins\Gui; |
|
5
|
|
|
|
|
6
|
|
|
use eXpansion\Bundle\Acme\Plugins\Gui\WindowFactory; |
|
7
|
|
|
use eXpansion\Bundle\LocalRecords\Entity\Record; |
|
8
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory; |
|
10
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilder; |
|
11
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory; |
|
12
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
13
|
|
|
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext; |
|
14
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\GridWindowFactory; |
|
15
|
|
|
use FML\Controls\Frame; |
|
16
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class RecordsWindowFactory |
|
21
|
|
|
* |
|
22
|
|
|
* @package eXpansion\Bundle\LocalRecords\Plugins\Gui; |
|
23
|
|
|
* @author reaby |
|
24
|
|
|
*/ |
|
25
|
|
|
class MapsWindowFactory extends GridWindowFactory |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var GridBuilderFactory */ |
|
28
|
|
|
protected $gridBuilderFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** @var DataCollectionFactory */ |
|
31
|
|
|
protected $dataCollectionFactory; |
|
32
|
|
|
|
|
33
|
|
|
/** @var Time */ |
|
34
|
|
|
protected $timeFormatter; |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
37
|
|
|
$name, |
|
38
|
|
|
$sizeX, |
|
39
|
|
|
$sizeY, |
|
40
|
|
|
$posX, |
|
41
|
|
|
$posY, |
|
42
|
|
|
WindowFactoryContext $context, |
|
43
|
|
|
GridBuilderFactory $gridBuilderFactory, |
|
44
|
|
|
DataCollectionFactory $dataCollectionFactory, |
|
45
|
|
|
Time $time |
|
46
|
|
|
) { |
|
47
|
|
|
parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
|
48
|
|
|
|
|
49
|
|
|
$this->gridBuilderFactory = $gridBuilderFactory; |
|
50
|
|
|
$this->dataCollectionFactory = $dataCollectionFactory; |
|
51
|
|
|
$this->timeFormatter = $time; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ManialinkInterface $manialink |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
View Code Duplication |
protected function createGrid(ManialinkInterface $manialink) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$collection = $this->dataCollectionFactory->create($this->getData()); |
|
62
|
|
|
$collection->setPageSize(20); |
|
63
|
|
|
|
|
64
|
|
|
$gridBuilder = $this->gridBuilderFactory->create(); |
|
65
|
|
|
$gridBuilder->setManialink($manialink) |
|
66
|
|
|
->setDataCollection($collection) |
|
67
|
|
|
->setManialinkFactory($this) |
|
68
|
|
|
->addTextColumn( |
|
69
|
|
|
'index', |
|
70
|
|
|
'expansion_maps.gui.window.column.index', |
|
71
|
|
|
'1', |
|
72
|
|
|
true |
|
73
|
|
|
)->addTextColumn( |
|
74
|
|
|
'name', |
|
75
|
|
|
'expansion_maps.gui.window.column.name', |
|
76
|
|
|
'3', |
|
77
|
|
|
true |
|
78
|
|
|
)->addTextColumn( |
|
79
|
|
|
'author', |
|
80
|
|
|
'expansion_maps.gui.window.column.author', |
|
81
|
|
|
'4' |
|
82
|
|
|
)->addTextColumn( |
|
83
|
|
|
'time', |
|
84
|
|
|
'expansion_maps.gui.window.column.goldtime', |
|
85
|
|
|
'3', |
|
86
|
|
|
true |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$manialink->setData('grid', $gridBuilder); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
public function setMaps($maps) |
|
94
|
|
|
{ |
|
95
|
|
|
/** |
|
96
|
|
|
* @var string $i |
|
97
|
|
|
* @var Map $map |
|
98
|
|
|
*/ |
|
99
|
|
|
$i = 1; |
|
100
|
|
|
foreach ($maps as $uid => $map) { |
|
101
|
|
|
$this->genericData[] = [ |
|
102
|
|
|
'index' => $i++, |
|
103
|
|
|
'name' => $map->name, |
|
104
|
|
|
'author' => $map->author, |
|
105
|
|
|
'time' => $this->timeFormatter->timeToText($map->goldTime, true), |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
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.