Completed
Pull Request — master (#152)
by
unknown
02:44
created

UpdateVoteWidgetFactory::createContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\VoteManager\Plugins\Gui\Widget;
4
5
use eXpansion\Bundle\VoteManager\Plugins\VoteManager;
6
use eXpansion\Bundle\VoteManager\Services\VoteService;
7
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
8
use eXpansion\Framework\Core\Model\Gui\Widget;
9
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
10
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
11
use FML\Controls\Quad;
12
use FML\Script\Script;
13
use FML\Script\ScriptLabel;
14
15
class UpdateVoteWidgetFactory extends WidgetFactory
16
{
17
18
    /**
19
     * @var VoteManager
20
     */
21
    private $voteManager;
0 ignored issues
show
Unused Code introduced by
The property $voteManager is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
    /**
23
     * @var VoteService
24
     */
25
    private $voteService;
26
27
    /***
28
     * MenuFactory constructor.
29
     *
30
     * @param $name
31
     * @param $sizeX
32
     * @param $sizeY
33
     * @param null $posX
34
     * @param null $posY
35
     * @param WidgetFactoryContext $context
36
     * @param VoteService $voteService
37
     */
38
    public function __construct(
39
        $name,
40
        $sizeX,
41
        $sizeY,
42
        $posX,
43
        $posY,
44
        WidgetFactoryContext $context,
45
        VoteService $voteService
46
    ) {
47
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
48
        $this->voteService = $voteService;
49
    }
50
51
    /**
52
     * @param Widget|ManialinkInterface $manialink
53
     */
54
    protected function createContent(ManialinkInterface $manialink)
55
    {
56
        $quad = Quad::create();
57
        $quad->setPosition(900, 900);
58
        $manialink->addChild($quad);
59
    }
60
61
62
    /**
63
     * @param Widget|ManialinkInterface $manialink
64
     */
65
    protected function updateContent(ManialinkInterface $manialink)
66
    {
67
        $vote = $this->voteService->getCurrentVote();
68
69
        if ($vote) {
70
            $yes = number_format($vote->getYes(), 1, ".", "");
71
            $no = number_format($vote->getNo(), 1, ".", "");
72
            $elapsed = number_format($vote->getElapsedTime(), 1, ".", "");
73
            $total = number_format($vote->getTotalTime(), 1, ".", "");
74
            $hash = uniqid("exp2_");
75
76
            $script = new Script();
77
            $script->addCustomScriptLabel(ScriptLabel::OnInit,
78
                <<<EOL
79
            declare Real Exp_Vote_Yes for This = 1.;
80
            Exp_Vote_Yes = $yes;
81
            declare Real Exp_Vote_No for This = 0.;
82
            Exp_Vote_No = $no;            
83
            declare Real Exp_Vote_TimeElapsed for This = 1.;
84
            Exp_Vote_TimeElapsed = $elapsed;            
85
            declare Real Exp_Vote_TimeTotal for This = 30.;
86
            Exp_Vote_TimeTotal = $total;
87
            declare Text Exp_Vote_check for This = "";  
88
            Exp_Vote_check = "$hash";                                                                                       
89
EOL
90
            );
91
92
            $manialink->getFmlManialink()->setScript($script);
93
94
        }
95
    }
96
97
}
98