|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\LocalMapRatings\Plugin\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Bundle\LocalMapRatings\Services\MapRatingsService; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\Widget; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext; |
|
9
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory; |
|
10
|
|
|
use eXpansion\Framework\Gui\Components\uiLabel; |
|
11
|
|
|
|
|
12
|
|
|
class MapRatingsWidget extends WidgetFactory |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** @var uiLabel */ |
|
16
|
|
|
private $lblRatings; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var MapRatingsService |
|
19
|
|
|
*/ |
|
20
|
|
|
private $mapRatingsService; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
$name, |
|
24
|
|
|
$sizeX, |
|
25
|
|
|
$sizeY, |
|
26
|
|
|
$posX, |
|
27
|
|
|
$posY, |
|
28
|
|
|
WidgetFactoryContext $context, |
|
29
|
|
|
MapRatingsService $mapRatingsService |
|
30
|
|
|
) { |
|
31
|
|
|
parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
|
32
|
|
|
|
|
33
|
|
|
$this->mapRatingsService = $mapRatingsService; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function createContent(ManialinkInterface $manialink) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::createContent($manialink); |
|
39
|
|
|
|
|
40
|
|
|
$this->lblRatings = $this->uiFactory->createLabel("", uiLabel::TYPE_NORMAL); |
|
41
|
|
|
$this->lblRatings->setPosition(0, 0)->setSize(40, 6) |
|
42
|
|
|
->setTextSize(2)->setAlign("right", "top"); |
|
43
|
|
|
$manialink->addChild($this->lblRatings); |
|
44
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
protected function updateContent(ManialinkInterface $manialink) |
|
49
|
|
|
{ |
|
50
|
|
|
$ratings = $this->mapRatingsService->getRatingsPerPlayer(); |
|
51
|
|
|
$total = count($ratings); |
|
|
|
|
|
|
52
|
|
|
$yes = 0; |
|
53
|
|
|
$no = 0; |
|
54
|
|
|
foreach ($ratings as $login => $rating) { |
|
55
|
|
|
$score = $rating->getScore(); |
|
56
|
|
|
|
|
57
|
|
|
if ($score === 1) { |
|
58
|
|
|
$yes++; |
|
59
|
|
|
} |
|
60
|
|
|
if ($score === -1) { |
|
61
|
|
|
$no++; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->lblRatings->setText('$0d0 $fff'.$yes.' $d00 $fff'.$no); // for total add ." 👥 ".$total |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param ManialinkInterface|Widget $manialink |
|
70
|
|
|
* @param string $login |
|
71
|
|
|
* @param array $entries |
|
72
|
|
|
* @param array $args |
|
73
|
|
|
*/ |
|
74
|
|
|
public function callbackVoteYes(ManialinkInterface $manialink, $login, $entries, $args) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->mapRatingsService->changeRating($login, 1); |
|
77
|
|
|
$this->update($manialink->getUserGroup()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param ManialinkInterface|Widget $manialink |
|
82
|
|
|
* @param string $login |
|
83
|
|
|
* @param array $entries |
|
84
|
|
|
* @param array $args |
|
85
|
|
|
*/ |
|
86
|
|
|
public function callbackVoteNo(ManialinkInterface $manialink, $login, $entries, $args) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->mapRatingsService->changeRating($login, -1); |
|
89
|
|
|
$this->update($manialink->getUserGroup()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.