|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Plugins\Gui; |
|
4
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerExpWidgetPosition; |
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\Factory\WidgetFrameFactoryInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\Gui\FmlManialink; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\Window; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ManialiveFactory allow the creation of manialinks. |
|
13
|
|
|
* |
|
14
|
|
|
* @package eXpansion\Framework\Core\Plugins\Gui |
|
15
|
|
|
* @author Oliver de Cramer |
|
16
|
|
|
*/ |
|
17
|
|
|
class WidgetFactory extends FmlManialinkFactory implements ListenerExpWidgetPosition |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var WidgetFrameFactoryInterface */ |
|
20
|
|
|
protected $widgetFrameFactory; |
|
21
|
|
|
|
|
22
|
|
|
/** @var float */ |
|
23
|
|
|
protected $defaultPositionX; |
|
24
|
|
|
|
|
25
|
|
|
/** @var float */ |
|
26
|
|
|
protected $defaultPositionY; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* WidgetFactory constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param $name |
|
32
|
|
|
* @param $sizeX |
|
33
|
|
|
* @param $sizeY |
|
34
|
|
|
* @param null $posX |
|
35
|
|
|
* @param null $posY |
|
36
|
|
|
* @param WidgetFactoryContext $context |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
$name, |
|
40
|
|
|
$sizeX, |
|
41
|
|
|
$sizeY, |
|
42
|
|
|
$posX, |
|
43
|
|
|
$posY, |
|
44
|
|
|
WidgetFactoryContext $context |
|
45
|
|
|
) { |
|
46
|
|
|
parent::__construct( |
|
47
|
|
|
$name, |
|
48
|
|
|
$sizeX, |
|
49
|
|
|
$sizeY, |
|
50
|
|
|
$posX, |
|
51
|
|
|
$posY, |
|
52
|
|
|
$context |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
$this->translationsHelper = $context->getTranslationsHelper(); |
|
56
|
|
|
$this->uiFactory = $context->getUiFactory(); |
|
57
|
|
|
$this->widgetFrameFactory = $context->getWidgetFrameFactory(); |
|
58
|
|
|
|
|
59
|
|
|
$this->defaultPositionX = $posX; |
|
60
|
|
|
$this->defaultPositionY = $posY; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Group $group |
|
65
|
|
|
* |
|
66
|
|
|
* @return Window |
|
67
|
|
|
*/ |
|
68
|
|
View Code Duplication |
protected function createManialink(Group $group, $hideable = true) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
|
|
71
|
|
|
$className = $this->className; |
|
72
|
|
|
$manialink = new $className( |
|
73
|
|
|
$this, |
|
74
|
|
|
$group, |
|
75
|
|
|
$this->translationsHelper, |
|
76
|
|
|
$this->widgetFrameFactory, |
|
77
|
|
|
$this->name, |
|
78
|
|
|
$this->sizeX, |
|
79
|
|
|
$this->sizeY, |
|
80
|
|
|
$this->posX, |
|
81
|
|
|
$this->posY, |
|
82
|
|
|
$hideable |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
return $manialink; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @inheritdoc |
|
90
|
|
|
*/ |
|
91
|
|
|
public function updateOptions($posX, $posY, $options) |
|
92
|
|
|
{ |
|
93
|
|
|
$posX = !is_null($posX) ? $posX : $this->defaultPositionX; |
|
94
|
|
|
$posY = !is_null($posY) ? $posY : $this->defaultPositionY; |
|
95
|
|
|
|
|
96
|
|
|
// Check if changed. |
|
97
|
|
|
if ($this->posX == $posX && $this->posY == $posY) { |
|
98
|
|
|
return; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Update position for future widgets. |
|
102
|
|
|
$this->posX = $posX; |
|
103
|
|
|
$this->posY = $posY; |
|
104
|
|
|
|
|
105
|
|
|
// Update current widgets. |
|
106
|
|
|
foreach ($this->guiHandler->getFactoryManialinks($this) as $manialink) { |
|
107
|
|
|
if ($manialink instanceof FmlManialink) { |
|
|
|
|
|
|
108
|
|
|
$manialink->setPosition($this->posX, $this->posY); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$this->update($manialink->getUserGroup()); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
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.