Completed
Push — master ( b2309d...0cebbd )
by De Cramer
15s
created

UpdaterWidgetFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 66
rs 10
c 0
b 0
f 0
ccs 0
cts 18
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A createContent() 0 4 1
A updateContent() 0 16 1
A setLocalRecord() 0 9 2
1
<?php
2
3
namespace eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui;
4
5
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
6
use eXpansion\Framework\Core\Model\Gui\Widget;
7
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
8
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
9
use FML\Script\Builder;
10
use FML\Script\Script;
11
use FML\Script\ScriptLabel;
12
13
class UpdaterWidgetFactory extends WidgetFactory
14
{
15
    private $localRecordCheckpoints = "Integer[Integer]";
16
17
    /***
18
     * MenuFactory constructor.
19
     *
20
     * @param                      $name
21
     * @param                      $sizeX
22
     * @param                      $sizeY
23
     * @param null                 $posX
24
     * @param null                 $posY
25
     * @param WidgetFactoryContext $context
26
     */
27
    public function __construct(
28
        $name,
29
        $sizeX,
30
        $sizeY,
31
        $posX,
32
        $posY,
33
        WidgetFactoryContext $context
34
    ) {
35
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
36
37
    }
38
39
    /**
40
     * @param Widget|ManialinkInterface $manialink
41
     */
42
    protected function createContent(ManialinkInterface $manialink)
43
    {
44
45
    }
46
47
    /**
48
     * @param ManialinkInterface|Widget $manialink
49
     */
50
    protected function updateContent(ManialinkInterface $manialink)
51
    {
52
        $checkpoints = $this->localRecordCheckpoints;
53
        $id = uniqid("exp_");
54
55
        $manialink->getFmlManialink()->setScript(new Script());
56
        $manialink->getFmlManialink()->getScript()->addCustomScriptLabel(ScriptLabel::OnInit, <<<EOL
57
            declare Integer[Integer] BestCp_LocalRecordCheckpoints for LocalUser = Integer[Integer];
58
            declare Text BestCp_LocalRecord_Check for LocalUser = "";
59
            BestCp_LocalRecord_Check = "$id";
60
            BestCp_LocalRecordCheckpoints = $checkpoints;            
61
EOL
62
        );
63
64
65
    }
66
67
    public function setLocalRecord($checkpoints)
68
    {
69
70
        if (count($checkpoints) > 0) {
71
            $this->localRecordCheckpoints = Builder::getArray($checkpoints, true);
72
        } else {
73
            $this->localRecordCheckpoints = "Integer[Integer]";
74
        }
75
    }
76
77
78
}
79