|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Core\Plugins\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Core\DataProviders\Listener\UserGroupDataListenerInterface; |
|
6
|
|
|
use eXpansion\Core\Model\Gui\Manialink; |
|
7
|
|
|
use eXpansion\Core\Model\Gui\ManialinkInerface; |
|
8
|
|
|
use eXpansion\Core\Model\UserGroups\Group; |
|
9
|
|
|
use eXpansion\Core\Plugins\GuiHandler; |
|
10
|
|
|
use eXpansion\Core\Plugins\UserGroups\Factory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ManialiveFactory allow the creation of manialinks. |
|
14
|
|
|
* |
|
15
|
|
|
* @package eXpansion\Core\Plugins\Gui |
|
16
|
|
|
* @author Oliver de Cramer |
|
17
|
|
|
*/ |
|
18
|
|
|
class ManialinkFactory implements UserGroupDataListenerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var GuiHandler */ |
|
21
|
|
|
protected $guiHandler; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Factory */ |
|
24
|
|
|
protected $groupFactory; |
|
25
|
|
|
|
|
26
|
|
|
/** @var ActionFactory */ |
|
27
|
|
|
protected $actionFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** @var string */ |
|
30
|
|
|
protected $name; |
|
31
|
|
|
|
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
protected $className; |
|
34
|
|
|
|
|
35
|
|
|
/** @var ManialinkInerface[] */ |
|
36
|
|
|
protected $manialinks = []; |
|
37
|
|
|
|
|
38
|
|
|
/** @var Group[] */ |
|
39
|
|
|
protected $groups = []; |
|
40
|
|
|
|
|
41
|
|
|
/** @var float */ |
|
42
|
|
|
protected $sizeX; |
|
43
|
|
|
|
|
44
|
|
|
/** @var float */ |
|
45
|
|
|
protected $sizeY; |
|
46
|
|
|
|
|
47
|
|
|
/** @var float */ |
|
48
|
|
|
protected $posX; |
|
49
|
|
|
|
|
50
|
|
|
/** @var float */ |
|
51
|
|
|
protected $posY; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* GroupManialinkFactory constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param GuiHandler $guiHandler |
|
57
|
|
|
* @param Factory $groupFactory |
|
58
|
|
|
* @param ActionFactory $actionFactory |
|
59
|
|
|
* @param $name |
|
60
|
|
|
* @param $sizeX |
|
61
|
|
|
* @param $sizeY |
|
62
|
|
|
* @param null $posX |
|
63
|
|
|
* @param null $posY |
|
64
|
|
|
* @param string $className |
|
65
|
|
|
*/ |
|
66
|
6 |
|
public function __construct( |
|
67
|
|
|
GuiHandler $guiHandler, |
|
68
|
|
|
Factory $groupFactory, |
|
69
|
|
|
ActionFactory $actionFactory, |
|
70
|
|
|
$name, |
|
71
|
|
|
$sizeX, |
|
72
|
|
|
$sizeY, |
|
73
|
|
|
$posX = null, |
|
74
|
|
|
$posY = null, |
|
75
|
|
|
$className = Manialink::class |
|
76
|
|
|
) { |
|
77
|
6 |
|
if (is_null($posX)) { |
|
78
|
6 |
|
$posX = $sizeX/-2; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
6 |
|
if (is_null($posY)) { |
|
82
|
6 |
|
$posY = $sizeY/2; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
6 |
|
$this->guiHandler = $guiHandler; |
|
86
|
6 |
|
$this->groupFactory = $groupFactory; |
|
87
|
6 |
|
$this->actionFactory = $actionFactory; |
|
88
|
6 |
|
$this->name = $name; |
|
89
|
6 |
|
$this->className = $className; |
|
90
|
6 |
|
$this->sizeX = $sizeX; |
|
91
|
6 |
|
$this->sizeY = $sizeY; |
|
92
|
6 |
|
$this->posX = $posX; |
|
|
|
|
|
|
93
|
6 |
|
$this->posY = $posY; |
|
|
|
|
|
|
94
|
6 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Create & display manialink for user. |
|
98
|
|
|
* |
|
99
|
|
|
* @param Group|string|string[] $group |
|
100
|
|
|
* |
|
101
|
|
|
* @return Group |
|
102
|
|
|
*/ |
|
103
|
5 |
|
final public function create($group) |
|
104
|
|
|
{ |
|
105
|
5 |
|
if (is_string($group)) { |
|
106
|
1 |
|
$group = $this->groupFactory->createForPlayer($group); |
|
107
|
4 |
|
} else if (is_array($group)) { |
|
108
|
3 |
|
$group = $this->groupFactory->createForPlayers($group); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
5 |
|
$this->manialinks[$group->getName()] = $this->createManialink($group); |
|
112
|
5 |
|
$this->guiHandler->addToDisplay($this->manialinks[$group->getName()]); |
|
113
|
|
|
|
|
114
|
5 |
|
$this->updateContent($this->manialinks[$group->getName()]); |
|
115
|
|
|
|
|
116
|
5 |
|
return $group; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
final public function update($group) |
|
120
|
|
|
{ |
|
121
|
|
|
if (isset($this->manialinks[$group->getName()])) { |
|
122
|
|
|
$this->guiHandler->addToDisplay($this->manialinks[$group->getName()]); |
|
123
|
|
|
$this->updateContent($this->manialinks[$group->getName()]); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
5 |
|
protected function updateContent(ManialinkInerface $manialink) |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
// Put content in the manialink here. |
|
130
|
5 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Hide & destoy manialink fr user. |
|
134
|
|
|
* |
|
135
|
|
|
* @param Group $group |
|
136
|
|
|
* |
|
137
|
|
|
* @return void |
|
138
|
|
|
*/ |
|
139
|
1 |
|
final public function destroy(Group $group) |
|
140
|
|
|
{ |
|
141
|
1 |
|
if (isset($this->manialinks[$group->getName()])) { |
|
142
|
1 |
|
$this->guiHandler->addToHide($this->manialinks[$group->getName()]); |
|
143
|
1 |
|
$this->actionFactory->destroyManialinkActions($this->manialinks[$group->getName()]); |
|
144
|
1 |
|
unset($this->manialinks[$group->getName()]); |
|
145
|
|
|
} |
|
146
|
1 |
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Create manialink object for user group. |
|
150
|
|
|
* |
|
151
|
|
|
* @param Group $group |
|
152
|
|
|
* |
|
153
|
|
|
* @return mixed |
|
154
|
|
|
*/ |
|
155
|
5 |
|
protected function createManialink(Group $group) |
|
156
|
|
|
{ |
|
157
|
5 |
|
$className = $this->className; |
|
158
|
5 |
|
return new $className($group, $this->name, $this->sizeX, $this->sizeY, $this->posX, $this->posY); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* When a gup is destroyed, destroy manialinks of the group. |
|
163
|
|
|
* |
|
164
|
|
|
* @param Group $group |
|
165
|
|
|
* @param $lastLogin |
|
166
|
|
|
* |
|
167
|
|
|
* @return void |
|
168
|
|
|
*/ |
|
169
|
1 |
|
public function onExpansionGroupDestroy(Group $group, $lastLogin) |
|
170
|
|
|
{ |
|
171
|
1 |
|
if (isset($this->manialinks[$group->getName()])) { |
|
172
|
|
|
// Gui Handler will handle delete by it's own. |
|
173
|
1 |
|
$this->actionFactory->destroyManialinkActions($this->manialinks[$group->getName()]); |
|
174
|
1 |
|
unset($this->manialinks[$group->getName()]); |
|
175
|
|
|
} |
|
176
|
1 |
|
} |
|
177
|
|
|
|
|
178
|
1 |
|
public function onExpansionGroupAddUser(Group $group, $loginAdded) |
|
179
|
|
|
{ |
|
180
|
|
|
// nothing to do here. |
|
181
|
1 |
|
} |
|
182
|
|
|
|
|
183
|
1 |
|
public function onExpansionGroupRemoveUser(Group $group, $loginRemoved) |
|
184
|
|
|
{ |
|
185
|
|
|
// nothing to do here. |
|
186
|
1 |
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.