|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @property array $ownedKeys |
|
4
|
|
|
* @property array $owned |
|
5
|
|
|
* @property array $all |
|
6
|
|
|
* @property integer $percentOwned |
|
7
|
|
|
*/ |
|
8
|
|
|
class BadgeList extends Badge |
|
9
|
|
|
{ |
|
10
|
|
|
private $ownedKeys = []; |
|
|
|
|
|
|
11
|
|
|
private $owned = []; |
|
|
|
|
|
|
12
|
|
|
private $all = []; |
|
|
|
|
|
|
13
|
|
|
private $categoryFirst = [ |
|
14
|
|
|
'max_nrg_100'=>'s', |
|
15
|
|
|
'setpart_30'=>'g' |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
public function getOwnedKeys() |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->ownedKeys; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getOwned() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->owned; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getAll() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->all; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getPercentOwned() |
|
34
|
|
|
{ |
|
35
|
|
|
$redis = Yii::app()->redis->getClient(); |
|
|
|
|
|
|
36
|
|
|
$cntOwned = $redis->sCard("badges:owned:{$this->uid}"); |
|
|
|
|
|
|
37
|
|
|
$cntAll = $redis->zCard("badges:all"); |
|
|
|
|
|
|
38
|
|
|
return round(($cntOwned / $cntAll) * 100); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function fetchOwned() |
|
42
|
|
|
{ |
|
43
|
|
|
if (!$this->uid) { |
|
44
|
|
|
$this->setUid(Yii::app()->player->model->uid); //set default uid |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$redis = Yii::app()->redis->getClient(); |
|
|
|
|
|
|
48
|
|
|
$this->ownedKeys = $redis->zRevRange("badges:added:{$this->uid}", 0, -1); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
foreach ($this->ownedKeys as $item) { |
|
51
|
|
|
$b = $this->getBadge($item); |
|
|
|
|
|
|
52
|
|
|
$this->owned[$item] = $b; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function fetchAll() |
|
57
|
|
|
{ |
|
58
|
|
|
if (!$this->uid) { |
|
59
|
|
|
$this->setUid(Yii::app()->player->model->uid); //set default uid |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$redis = Yii::app()->redis->getClient(); |
|
63
|
|
|
$all = $redis->zRange('badges:all', 0, -1); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$categ = 'b'; |
|
66
|
|
|
foreach ($all as $item) { |
|
67
|
|
|
if (array_key_exists($item, $this->categoryFirst)) { |
|
68
|
|
|
$categ = $this->categoryFirst[$item]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if (array_key_exists($item, $this->owned)) { |
|
72
|
|
|
$b = $this->owned[$item]; |
|
|
|
|
|
|
73
|
|
|
$b['owned'] = 1; |
|
74
|
|
|
} else { |
|
75
|
|
|
$b = $this->getBadge($item); |
|
|
|
|
|
|
76
|
|
|
$b['owned'] = 0; |
|
77
|
|
|
} |
|
78
|
|
|
$this->all[$categ][$item] = $b; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
|
|
|
|
|
82
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.