1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui; |
4
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext; |
6
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
7
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\ScriptVariableUpdateFactory; |
8
|
|
|
use FML\Script\Builder; |
9
|
|
|
|
10
|
|
|
class UpdaterWidgetFactory extends ScriptVariableUpdateFactory |
11
|
|
|
{ |
12
|
|
|
protected $playerGroup; |
13
|
|
|
|
14
|
|
|
public function __construct( |
15
|
|
|
$name, |
16
|
|
|
array $variables, |
17
|
|
|
float $maxUpdateFrequency = 0.5, |
18
|
|
|
WidgetFactoryContext $context, |
19
|
|
|
Group $playerGroup |
20
|
|
|
) { |
21
|
|
|
parent::__construct($name, $variables, $maxUpdateFrequency, $context); |
22
|
|
|
$this->playerGroup = $playerGroup; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Update with new local record. |
27
|
|
|
* |
28
|
|
|
* @param array $checkpoints |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function setLocalRecord($nick, $checkpoints) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
if (count($checkpoints) > 0) { |
33
|
|
|
$this->updateValue($this->playerGroup, 'LocalRecordCheckpoints', Builder::getArray($checkpoints, true)); |
34
|
|
|
$this->updateValue($this->playerGroup, 'LocalRecordHolder', Builder::escapeText($nick)); |
35
|
|
|
} else { |
36
|
|
|
$this->updateValue($this->playerGroup, 'LocalRecordCheckpoints', "Integer[Integer]"); |
37
|
|
|
$this->updateValue($this->playerGroup, 'LocalRecordHolder', Builder::escapeText("-")); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function setDedimaniaRecord($nick, $checkpoints) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
if (count($checkpoints) > 0) { |
44
|
|
|
$this->updateValue($this->playerGroup, 'DedimaniaCheckpoints', Builder::getArray($checkpoints, true)); |
45
|
|
|
$this->updateValue($this->playerGroup, 'DedimaniaHolder', Builder::escapeText($nick)); |
46
|
|
|
} else { |
47
|
|
|
$this->updateValue($this->playerGroup, 'DedimaniaCheckpoints', "Integer[Integer]"); |
48
|
|
|
$this->updateValue($this->playerGroup, 'DedimaniaHolder', Builder::escapeText($nick)); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
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.