|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 15.06.2017 11:56 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Alliance; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
use Player\TablePlayer; |
|
10
|
|
|
|
|
11
|
|
|
class AllianceStatic { |
|
12
|
|
|
|
|
13
|
|
|
public static function parseTitleList($string) { |
|
14
|
|
|
global $ally_rights; |
|
15
|
|
|
|
|
16
|
|
|
$result = []; |
|
17
|
|
|
|
|
18
|
|
|
$titleList = explode(';', $string); |
|
19
|
|
|
foreach ($titleList as $titleIndex => $titleString) { |
|
20
|
|
|
if (empty($titleString)) { |
|
21
|
|
|
continue; |
|
22
|
|
|
} |
|
23
|
|
|
$accessList = explode(',', $titleString); |
|
24
|
|
|
$result[$titleIndex] = array_combine($ally_rights, $accessList); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return $result; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public static function getMemberList($allyId) { |
|
31
|
|
|
$allyId_safe = \classSupernova::$db->db_escape($allyId); |
|
32
|
|
|
|
|
33
|
|
|
return db_user_list("`ally_id`= {$allyId_safe} ORDER BY `ally_rank_id`", false, |
|
|
|
|
|
|
34
|
|
|
'id, username, galaxy, system, planet, onlinetime, ally_rank_id, ally_register_time, total_points'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function compileTitleRights(&$titleList) { |
|
38
|
|
|
foreach ($titleList as &$titleDesc) { |
|
39
|
|
|
$titleRights = []; |
|
40
|
|
|
foreach ($titleDesc as $rightId => $rightValue) { |
|
41
|
|
|
if ($rightValue == 1) { |
|
42
|
|
|
$titleRights[] = $rightId; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
$titleDesc['rights'] = implode(',', $titleRights); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public static function titleMembers($memberList, TableAlliance $alliance) { |
|
51
|
|
|
global $ally_rights; |
|
52
|
|
|
|
|
53
|
|
|
$copy = $ally_rights; |
|
54
|
|
|
array_shift($copy); |
|
55
|
|
|
|
|
56
|
|
|
$result = []; |
|
57
|
|
|
if (empty($memberList)) { |
|
58
|
|
|
return $result; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$titleList = self::parseTitleList($alliance->titleList); |
|
62
|
|
|
self::compileTitleRights($titleList); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
foreach ($memberList as $playerRecord) { |
|
66
|
|
|
$temp = [ |
|
67
|
|
|
'PLAYER_ID' => $playerRecord['id'], |
|
68
|
|
|
'PLAYER_NAME' => $playerRecord['username'], |
|
69
|
|
|
'ONLINE' => $playerRecord['onlinetime'], |
|
70
|
|
|
'ONLINE_SQL' => date(FMT_DATE_TIME_SQL, $playerRecord['onlinetime']), |
|
71
|
|
|
'VACATION' => $playerRecord['vacation'], |
|
72
|
|
|
'VACATION_SQL' => date(FMT_DATE_TIME_SQL, $playerRecord['vacation']), |
|
73
|
|
|
'BAN' => $playerRecord['banaday'], |
|
74
|
|
|
'BAN_SQL' => date(FMT_DATE_TIME_SQL, $playerRecord['banaday']), |
|
75
|
|
|
'TITLE' => $titleList[$playerRecord['ally_rank_id']]['name'], |
|
76
|
|
|
'TITLE_ID' => $playerRecord['ally_rank_id'], |
|
77
|
|
|
'RIGHTS' => $titleList[$playerRecord['ally_rank_id']]['rights'], |
|
78
|
|
|
]; |
|
79
|
|
|
if ($playerRecord['id'] == $alliance->ownerId) { |
|
80
|
|
|
$temp = array_merge($temp, [ |
|
81
|
|
|
'TITLE' => $alliance->ownerRankName, |
|
82
|
|
|
'TITLE_ID' => -1, |
|
83
|
|
|
'RIGHTS' => implode(',', $copy), |
|
84
|
|
|
'OWNER' => true, |
|
85
|
|
|
]); |
|
86
|
|
|
} |
|
87
|
|
|
$result[] = $temp; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $result; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public static function passAlliance($allyId, $newOwnerId) { |
|
95
|
|
|
try { |
|
96
|
|
|
sn_db_transaction_start(); |
|
97
|
|
|
if (empty($alliance = \Alliance\TableAlliance::findOne($allyId))) { |
|
98
|
|
|
throw new \Exception('{ Альянс с указанным ID не найден }', ERR_ERROR); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if ($newOwnerId == $alliance->ownerId) { |
|
102
|
|
|
throw new \Exception('{ Указанный пользователь уже является владельцем указанного Альянса }', ERR_NOTICE); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if (!empty($oldOwner = TablePlayer::findOne($alliance->ownerId))) { |
|
106
|
|
|
$oldOwner->ally_rank_id = 0; |
|
|
|
|
|
|
107
|
|
|
if (!$oldOwner->update()) { |
|
108
|
|
|
throw new \Exception('{ Ошибка изменения ранга у старого владельца }', ERR_ERROR); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if (empty($newOwner = TablePlayer::findOne($newOwnerId))) { |
|
113
|
|
|
throw new \Exception('{ Новый владелец Альянса не найден }', ERR_ERROR); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$newOwner->ally_rank_id = 0; |
|
|
|
|
|
|
117
|
|
|
if (!$newOwner->update()) { |
|
118
|
|
|
throw new \Exception('{ Ошибка изменения ранга у нового владельца }', ERR_ERROR); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$alliance->ownerId = $newOwnerId; |
|
122
|
|
|
if (!$alliance->update()) { |
|
123
|
|
|
throw new \Exception('{ Ошибка изменения владельца Альянса }', ERR_ERROR); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
sn_db_transaction_commit(); |
|
127
|
|
|
} catch (\Exception $e) { |
|
128
|
|
|
sn_db_transaction_rollback(); |
|
129
|
|
|
|
|
130
|
|
|
throw $e; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return true; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
This function has been deprecated.