|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 28.11.2017 7:14 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Alliance; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AllianceTitle |
|
10
|
|
|
* |
|
11
|
|
|
* Alliance title and access rights |
|
12
|
|
|
* |
|
13
|
|
|
* @package Alliance |
|
14
|
|
|
*/ |
|
15
|
|
|
class AllianceTitle { |
|
16
|
|
|
public $name = ''; |
|
17
|
|
|
|
|
18
|
|
|
public $index = -2; |
|
19
|
|
|
|
|
20
|
|
|
public $mail = false; |
|
21
|
|
|
public $online = false; |
|
22
|
|
|
public $invite = false; |
|
23
|
|
|
public $kick = false; |
|
24
|
|
|
public $admin = false; |
|
25
|
|
|
public $forum = false; |
|
26
|
|
|
public $diplomacy = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Alliance $alliance |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $alliance; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* AllianceTitle constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Alliance $alliance |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(Alliance $alliance) { |
|
40
|
|
|
$this->alliance = $alliance; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Fills title info from string |
|
45
|
|
|
* |
|
46
|
|
|
* @param int $titleIndex - Internal Ally ID of title or -1 for owner |
|
47
|
|
|
* @param string $titleString - Title name and access rights or '' for owner |
|
48
|
|
|
*/ |
|
49
|
|
|
public function fromString($titleIndex, $titleString) { |
|
50
|
|
|
$this->index = $titleIndex; |
|
51
|
|
|
|
|
52
|
|
|
if ($titleIndex == Alliance::OWNER_INDEX) { |
|
53
|
|
|
$accessList = array_fill(1, count(Alliance::RIGHTS_ALL) - 1, 1); |
|
54
|
|
|
$this->name = $this->alliance->ownerRankName; |
|
55
|
|
|
} else { |
|
56
|
|
|
$accessList = explode(',', $titleString); |
|
57
|
|
|
$this->name = $accessList[0]; |
|
58
|
|
|
unset($accessList[0]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
foreach ($accessList as $key => $access) { |
|
62
|
|
|
$this->{Alliance::RIGHTS_ALL[$key]} = $access == 1; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// var_dump($this->rightsAsString()); |
|
|
|
|
|
|
66
|
|
|
// var_dump($this->getWeight()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Compact title name and access rights into string |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __toString() { |
|
75
|
|
|
$result = []; |
|
76
|
|
|
foreach (Alliance::RIGHTS_ALL as $index => $rightName) { |
|
77
|
|
|
$result[] = $index == 0 ? $this->$rightName : ($this->$rightName ? 1 : 0); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return implode(',', $result); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Compiles string with right lists for title |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function rightsAsString() { |
|
89
|
|
|
$result = []; |
|
90
|
|
|
foreach (Alliance::RIGHT_WEIGHTS as $rightName => $weight) { |
|
91
|
|
|
$this->$rightName ? $result[] = $rightName : false; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return implode(',', $result); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get title right weight |
|
99
|
|
|
* |
|
100
|
|
|
* @return int |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getWeight() { |
|
103
|
|
|
$totalWeight = 0; |
|
104
|
|
|
foreach (Alliance::RIGHT_WEIGHTS as $rightName => $weight) { |
|
105
|
|
|
$this->$rightName ? $totalWeight += $weight : false; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return $totalWeight; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.