|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Asylamba\Modules\Zeus\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Asylamba\Classes\Entity\AbstractRepository; |
|
6
|
|
|
|
|
7
|
|
|
use Asylamba\Modules\Zeus\Model\Player; |
|
8
|
|
|
|
|
9
|
|
|
class PlayerRepository extends AbstractRepository { |
|
10
|
|
|
|
|
11
|
|
|
public function get($id) |
|
12
|
|
|
{ |
|
13
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, $id)) !== null) { |
|
14
|
|
|
return $p; |
|
15
|
|
|
} |
|
16
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE id = :id'); |
|
17
|
|
|
$query->execute(['id' => $id]); |
|
18
|
|
|
|
|
19
|
|
|
if (($row = $query->fetch()) === false) { |
|
20
|
|
|
return null; |
|
21
|
|
|
} |
|
22
|
|
|
$player = $this->format($row); |
|
23
|
|
|
$this->unitOfWork->addObject($player); |
|
24
|
|
|
return $player; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getByName($name) |
|
28
|
|
|
{ |
|
29
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE name = :name'); |
|
30
|
|
|
$query->execute(['name' => $name]); |
|
31
|
|
|
|
|
32
|
|
|
if (($row = $query->fetch()) === false) { |
|
33
|
|
|
return null; |
|
34
|
|
|
} |
|
35
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
36
|
|
|
return $p; |
|
37
|
|
|
} |
|
38
|
|
|
$player = $this->format($row); |
|
39
|
|
|
$this->unitOfWork->addObject($player); |
|
40
|
|
|
return $player; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getByBindKey($bindKey) |
|
44
|
|
|
{ |
|
45
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE bind = :bind_key'); |
|
46
|
|
|
$query->execute(['bind_key' => $bindKey]); |
|
47
|
|
|
|
|
48
|
|
|
if (($row = $query->fetch()) === false) { |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
52
|
|
|
return $p; |
|
53
|
|
|
} |
|
54
|
|
|
$player = $this->format($row); |
|
55
|
|
|
$this->unitOfWork->addObject($player); |
|
56
|
|
|
return $player; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getGodSons($playerId) |
|
60
|
|
|
{ |
|
61
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rGodFather = :god_father_id'); |
|
62
|
|
|
$query->execute(['god_father_id' => $playerId]); |
|
63
|
|
|
|
|
64
|
|
|
$data = []; |
|
65
|
|
|
while ($row = $query->fetch()) { |
|
66
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
67
|
|
|
$data[] = $p; |
|
68
|
|
|
continue; |
|
69
|
|
|
} |
|
70
|
|
|
$player = $this->format($row); |
|
71
|
|
|
$this->unitOfWork->addObject($player); |
|
72
|
|
|
$data[] = $player; |
|
73
|
|
|
} |
|
74
|
|
|
return $data; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getByIdsAndStatements($ids, $statements) |
|
78
|
|
|
{ |
|
79
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE id IN (' . implode(',', $ids) . ') AND statement IN (' . implode(',', $statements) . ')'); |
|
80
|
|
|
$query->execute(); |
|
81
|
|
|
|
|
82
|
|
|
$data = []; |
|
83
|
|
|
while ($row = $query->fetch()) { |
|
84
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
85
|
|
|
$data[] = $p; |
|
86
|
|
|
continue; |
|
87
|
|
|
} |
|
88
|
|
|
$player = $this->format($row); |
|
89
|
|
|
$this->unitOfWork->addObject($player); |
|
90
|
|
|
$data[] = $player; |
|
91
|
|
|
} |
|
92
|
|
|
return $data; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param array $statements |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getByStatements($statements) |
|
99
|
|
|
{ |
|
100
|
|
|
$query = $this->connection->query('SELECT * FROM player WHERE statement IN (' . implode(',', $statements) . ')'); |
|
101
|
|
|
|
|
102
|
|
|
$data = []; |
|
103
|
|
|
while ($row = $query->fetch()) { |
|
104
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
105
|
|
|
$data[] = $p; |
|
106
|
|
|
continue; |
|
107
|
|
|
} |
|
108
|
|
|
$player = $this->format($row); |
|
109
|
|
|
$this->unitOfWork->addObject($player); |
|
110
|
|
|
$data[] = $player; |
|
111
|
|
|
} |
|
112
|
|
|
return $data; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return int |
|
117
|
|
|
*/ |
|
118
|
|
|
public function countActivePlayers() |
|
119
|
|
|
{ |
|
120
|
|
|
$query = $this->connection->prepare('SELECT COUNT(*) as nb_players FROM player WHERE statement = :statement_active'); |
|
121
|
|
|
$query->execute(['statement_active' => Player::ACTIVE]); |
|
122
|
|
|
return (int) $query->fetch()['nb_players']; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return int |
|
127
|
|
|
*/ |
|
128
|
|
|
public function countAllPlayers() |
|
129
|
|
|
{ |
|
130
|
|
|
$query = $this->connection->prepare('SELECT COUNT(*) as nb_players FROM player WHERE statement IN (:statement_active, :statement_inactive)'); |
|
131
|
|
|
$query->execute(['statement_active' => Player::ACTIVE, 'statement_inactive' => Player::INACTIVE]); |
|
132
|
|
|
return (int) $query->fetch()['nb_players']; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param int $factionId |
|
137
|
|
|
* @param array $statements |
|
138
|
|
|
* @return int |
|
139
|
|
|
*/ |
|
140
|
|
|
public function countByFactionAndStatements($factionId, $statements) |
|
141
|
|
|
{ |
|
142
|
|
|
$query = $this->connection->prepare('SELECT COUNT(*) as nb_players FROM player WHERE rColor = :faction_id AND statement IN (' . implode(',', $statements) . ')'); |
|
143
|
|
|
$query->execute(['faction_id' => $factionId]); |
|
144
|
|
|
return (int) $query->fetch()['nb_players']; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param int $factionId |
|
149
|
|
|
* @return array |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getFactionPlayers($factionId) |
|
152
|
|
|
{ |
|
153
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND statement != :dead_statement'); |
|
154
|
|
|
$query->execute(['faction_id' => $factionId, 'dead_statement' => Player::DEAD]); |
|
155
|
|
|
|
|
156
|
|
|
$data = []; |
|
157
|
|
|
while ($row = $query->fetch()) { |
|
158
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
159
|
|
|
$data[] = $p; |
|
160
|
|
|
continue; |
|
161
|
|
|
} |
|
162
|
|
|
$player = $this->format($row); |
|
163
|
|
|
$this->unitOfWork->addObject($player); |
|
164
|
|
|
$data[] = $player; |
|
165
|
|
|
} |
|
166
|
|
|
return $data; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param int $factionId |
|
171
|
|
|
* @return array |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getFactionPlayersByRanking($factionId) |
|
174
|
|
|
{ |
|
175
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND statement != :dead_statement ORDER BY factionPoint DESC'); |
|
176
|
|
|
$query->execute(['faction_id' => $factionId, 'dead_statement' => Player::DEAD]); |
|
177
|
|
|
|
|
178
|
|
|
$data = []; |
|
179
|
|
|
while ($row = $query->fetch()) { |
|
180
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
181
|
|
|
$data[] = $p; |
|
182
|
|
|
continue; |
|
183
|
|
|
} |
|
184
|
|
|
$player = $this->format($row); |
|
185
|
|
|
$this->unitOfWork->addObject($player); |
|
186
|
|
|
$data[] = $player; |
|
187
|
|
|
} |
|
188
|
|
|
return $data; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param int $factionId |
|
193
|
|
|
* @return array |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getFactionPlayersByName($factionId) |
|
196
|
|
|
{ |
|
197
|
|
|
$query = $this->connection->prepare( |
|
198
|
|
|
'SELECT * FROM player WHERE rColor = :faction_id AND statement IN (' . |
|
199
|
|
|
implode(',', [Player::ACTIVE, Player::INACTIVE, Player::HOLIDAY]) . ') |
|
200
|
|
|
ORDER BY name ASC' |
|
201
|
|
|
); |
|
202
|
|
|
$query->execute(['faction_id' => $factionId]); |
|
203
|
|
|
|
|
204
|
|
|
$data = []; |
|
205
|
|
|
while ($row = $query->fetch()) { |
|
206
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
207
|
|
|
$data[] = $p; |
|
208
|
|
|
continue; |
|
209
|
|
|
} |
|
210
|
|
|
$player = $this->format($row); |
|
211
|
|
|
$this->unitOfWork->addObject($player); |
|
212
|
|
|
$data[] = $player; |
|
213
|
|
|
} |
|
214
|
|
|
return $data; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* |
|
219
|
|
|
* @param int $factionId |
|
220
|
|
|
* @return Player |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getFactionAccount($factionId) |
|
223
|
|
|
{ |
|
224
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND status = :dead_status ORDER BY id ASC LIMIT 0,1'); |
|
225
|
|
|
$query->execute(['faction_id' => $factionId, 'dead_status' => Player::DEAD]); |
|
226
|
|
|
|
|
227
|
|
|
if (($row = $query->fetch()) === false) { |
|
228
|
|
|
return null; |
|
229
|
|
|
} |
|
230
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
231
|
|
|
return $p; |
|
232
|
|
|
} |
|
233
|
|
|
$player = $this->format($row); |
|
234
|
|
|
$this->unitOfWork->addObject($player); |
|
235
|
|
|
return $player; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param int $factionId |
|
240
|
|
|
* @return array |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getLastFactionPlayers($factionId) |
|
243
|
|
|
{ |
|
244
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND statement != :dead_statement ORDER BY dInscription DESC LIMIT 0,25'); |
|
245
|
|
|
$query->execute(['faction_id' => $factionId, 'dead_statement' => Player::DEAD]); |
|
246
|
|
|
|
|
247
|
|
|
$data = []; |
|
248
|
|
|
while ($row = $query->fetch()) { |
|
249
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
250
|
|
|
$data[] = $p; |
|
251
|
|
|
continue; |
|
252
|
|
|
} |
|
253
|
|
|
$player = $this->format($row); |
|
254
|
|
|
$this->unitOfWork->addObject($player); |
|
255
|
|
|
$data[] = $player; |
|
256
|
|
|
} |
|
257
|
|
|
return $data; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param int $factionId |
|
262
|
|
|
* @return array |
|
263
|
|
|
*/ |
|
264
|
|
|
public function getParliamentMembers($factionId) |
|
265
|
|
|
{ |
|
266
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND status = :status'); |
|
267
|
|
|
$query->execute(['faction_id' => $factionId, 'status' => Player::PARLIAMENT]); |
|
268
|
|
|
|
|
269
|
|
|
$data = []; |
|
270
|
|
|
while ($row = $query->fetch()) { |
|
271
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
272
|
|
|
$data[] = $p; |
|
273
|
|
|
continue; |
|
274
|
|
|
} |
|
275
|
|
|
$player = $this->format($row); |
|
276
|
|
|
$this->unitOfWork->addObject($player); |
|
277
|
|
|
$data[] = $player; |
|
278
|
|
|
} |
|
279
|
|
|
return $data; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @param int $factionId |
|
284
|
|
|
* @param int $status |
|
285
|
|
|
* @return Player |
|
286
|
|
|
*/ |
|
287
|
|
|
public function getGovernmentMember($factionId, $status) |
|
288
|
|
|
{ |
|
289
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND status = :status AND statement != :dead_statement'); |
|
290
|
|
|
$query->execute(['faction_id' => $factionId, 'status' => $status, 'dead_statement' => Player::DEAD]); |
|
291
|
|
|
|
|
292
|
|
|
if (($row = $query->fetch()) === false) { |
|
293
|
|
|
return null; |
|
294
|
|
|
} |
|
295
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
296
|
|
|
return $p; |
|
297
|
|
|
} |
|
298
|
|
|
$player = $this->format($row); |
|
299
|
|
|
$this->unitOfWork->addObject($player); |
|
300
|
|
|
return $player; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @param int $factionId |
|
305
|
|
|
* @return array |
|
306
|
|
|
*/ |
|
307
|
|
|
public function getGovernmentMembers($factionId) |
|
308
|
|
|
{ |
|
309
|
|
|
$query = $this->connection->prepare( |
|
310
|
|
|
'SELECT * FROM player WHERE rColor = :faction_id AND statement != :dead_statement AND status IN (' . implode(',', [Player::TREASURER, Player::WARLORD, Player::MINISTER, Player::CHIEF]) . ') ORDER BY status DESC' |
|
311
|
|
|
); |
|
312
|
|
|
$query->execute(['faction_id' => $factionId, 'dead_statement' => Player::DEAD]); |
|
313
|
|
|
|
|
314
|
|
|
$data = []; |
|
315
|
|
|
while ($row = $query->fetch()) { |
|
316
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
317
|
|
|
$data[] = $p; |
|
318
|
|
|
continue; |
|
319
|
|
|
} |
|
320
|
|
|
$player = $this->format($row); |
|
321
|
|
|
$this->unitOfWork->addObject($player); |
|
322
|
|
|
$data[] = $player; |
|
323
|
|
|
} |
|
324
|
|
|
return $data; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @param int $factionId |
|
329
|
|
|
* @return Player |
|
330
|
|
|
*/ |
|
331
|
|
|
public function getFactionLeader($factionId) |
|
332
|
|
|
{ |
|
333
|
|
|
$query = $this->connection->prepare('SELECT * FROM player WHERE rColor = :faction_id AND status = :status AND statement != :dead_statement'); |
|
334
|
|
|
$query->execute(['faction_id' => $factionId, 'status' => Player::CHIEF, 'dead_statement' => Player::DEAD]); |
|
335
|
|
|
|
|
336
|
|
|
if (($row = $query->fetch()) === false) { |
|
337
|
|
|
return null; |
|
338
|
|
|
} |
|
339
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
340
|
|
|
return $p; |
|
341
|
|
|
} |
|
342
|
|
|
$player = $this->format($row); |
|
343
|
|
|
$this->unitOfWork->addObject($player); |
|
344
|
|
|
return $player; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
public function getActivePlayers() |
|
348
|
|
|
{ |
|
349
|
|
|
$query = $this->connection->prepare( |
|
350
|
|
|
'SELECT * FROM player WHERE statement = :statement' |
|
351
|
|
|
); |
|
352
|
|
|
$query->execute(['statement' => Player::ACTIVE]); |
|
353
|
|
|
|
|
354
|
|
|
$data = []; |
|
355
|
|
|
while ($row = $query->fetch()) { |
|
356
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
357
|
|
|
$data[] = $p; |
|
358
|
|
|
continue; |
|
359
|
|
|
} |
|
360
|
|
|
$player = $this->format($row); |
|
361
|
|
|
$this->unitOfWork->addObject($player); |
|
362
|
|
|
$data[] = $player; |
|
363
|
|
|
} |
|
364
|
|
|
return $data; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
public function search($search) |
|
368
|
|
|
{ |
|
369
|
|
|
$query = $this->connection->prepare( |
|
370
|
|
|
'SELECT p.* FROM player AS p WHERE LOWER(name) LIKE LOWER(:search) ORDER BY experience DESC LIMIT 0,20' |
|
371
|
|
|
); |
|
372
|
|
|
$query->execute(['search' => "%$search%"]); |
|
373
|
|
|
|
|
374
|
|
|
$data = []; |
|
375
|
|
|
while ($row = $query->fetch()) { |
|
376
|
|
|
if (($p = $this->unitOfWork->getObject(Player::class, (int) $row['id'])) !== null) { |
|
377
|
|
|
$data[] = $p; |
|
378
|
|
|
continue; |
|
379
|
|
|
} |
|
380
|
|
|
$player = $this->format($row); |
|
381
|
|
|
$this->unitOfWork->addObject($player); |
|
382
|
|
|
$data[] = $player; |
|
383
|
|
|
} |
|
384
|
|
|
return $data; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* @param Player $player |
|
389
|
|
|
*/ |
|
390
|
|
|
public function insert($player) |
|
391
|
|
|
{ |
|
392
|
|
|
$query = $this->connection->prepare('INSERT INTO |
|
393
|
|
|
player(bind, rColor, name, sex, description, avatar, status, rGodfather, |
|
394
|
|
|
credit, uPlayer, experience, factionPoint, level, victory, defeat, stepTutorial, |
|
395
|
|
|
stepDone, iUniversity, partNaturalSciences, partLifeSciences, partSocialPoliticalSciences, |
|
396
|
|
|
partInformaticEngineering, dInscription, dLastConnection, dLastActivity, premium, statement) |
|
397
|
|
|
VALUES(:bind, :faction_id, :name, :gender, :description, :avatar, :status, |
|
398
|
|
|
:god_father_id, :credits, :u_player, :experience, :faction_points, :level, |
|
399
|
|
|
:nb_victories, :nb_defeats, :tutorial_step, :tutorial_step_is_done, :university_investment, |
|
400
|
|
|
:natural_science_investment, :life_science_investment, :social_political_science_investment, |
|
401
|
|
|
:informatic_engineering_investment, :created_at, :last_connected_at, :last_acted_at, :is_premium, :statement)'); |
|
402
|
|
|
$query->execute(array( |
|
403
|
|
|
'bind' => $player->getBind(), |
|
404
|
|
|
'faction_id' => $player->getRColor(), |
|
405
|
|
|
'name' => $player->getName(), |
|
406
|
|
|
'gender' => $player->sex, |
|
407
|
|
|
'description' => $player->description, |
|
408
|
|
|
'avatar' => $player->getAvatar(), |
|
409
|
|
|
'status' => $player->getStatus(), |
|
410
|
|
|
'god_father_id' => $player->rGodfather, |
|
411
|
|
|
'credits' => $player->getCredit(), |
|
412
|
|
|
'u_player' => $player->uPlayer, |
|
413
|
|
|
'experience' => $player->getExperience(), |
|
414
|
|
|
'faction_points' => $player->factionPoint, |
|
415
|
|
|
'level' => $player->getLevel(), |
|
416
|
|
|
'nb_victories' => $player->getVictory(), |
|
417
|
|
|
'nb_defeats' => $player->getDefeat(), |
|
418
|
|
|
'tutorial_step' => $player->getStepTutorial(), |
|
419
|
|
|
'tutorial_step_is_done' => $player->stepDone, |
|
420
|
|
|
'university_investment' => $player->iUniversity, |
|
421
|
|
|
'natural_science_investment' => $player->partNaturalSciences, |
|
422
|
|
|
'life_science_investment' => $player->partLifeSciences, |
|
423
|
|
|
'social_political_science_investment' => $player->partSocialPoliticalSciences, |
|
424
|
|
|
'informatic_engineering_investment' => $player->partInformaticEngineering, |
|
425
|
|
|
'created_at' => $player->getDInscription(), |
|
426
|
|
|
'last_connected_at' => $player->getDLastConnection(), |
|
427
|
|
|
'last_acted_at' => $player->getDLastActivity(), |
|
428
|
|
|
'is_premium' => $player->getPremium(), |
|
429
|
|
|
'statement' => $player->getStatement() |
|
430
|
|
|
)); |
|
431
|
|
|
$player->setId((int) $this->connection->lastInsertId()); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* @param Player $player |
|
436
|
|
|
*/ |
|
437
|
|
|
public function update($player) |
|
438
|
|
|
{ |
|
439
|
|
|
$query = $this->connection->prepare('UPDATE player SET |
|
440
|
|
|
description = :description, |
|
441
|
|
|
status = :status, |
|
442
|
|
|
uPlayer = :u_player, |
|
443
|
|
|
experience = :experience, |
|
444
|
|
|
factionPoint = :faction_points, |
|
445
|
|
|
level = :level, |
|
446
|
|
|
victory = :nb_victories, |
|
447
|
|
|
defeat = :nb_defeats, |
|
448
|
|
|
stepTutorial = :tutorial_step, |
|
449
|
|
|
stepDone = :tutorial_step_is_done, |
|
450
|
|
|
partNaturalSciences = :natural_science_investment, |
|
451
|
|
|
partLifeSciences = :life_science_investment, |
|
452
|
|
|
partSocialPoliticalSciences = :social_political_investment, |
|
453
|
|
|
partInformaticEngineering = :informatic_engineering_investment, |
|
454
|
|
|
dLastConnection = :last_connected_at, |
|
455
|
|
|
dLastActivity = :last_acted_at, |
|
456
|
|
|
statement = :statement |
|
457
|
|
|
WHERE id = :id'); |
|
458
|
|
|
$query->execute(array( |
|
459
|
|
|
'description' => $player->description, |
|
460
|
|
|
'status' => $player->getStatus(), |
|
461
|
|
|
'u_player' => $player->uPlayer, |
|
462
|
|
|
'experience' => $player->getExperience(), |
|
463
|
|
|
'faction_points' => $player->factionPoint, |
|
464
|
|
|
'level' => $player->getLevel(), |
|
465
|
|
|
'nb_victories' => $player->getVictory(), |
|
466
|
|
|
'nb_defeats' => $player->getDefeat(), |
|
467
|
|
|
'tutorial_step' => $player->getStepTutorial(), |
|
468
|
|
|
'tutorial_step_is_done' => $player->stepDone, |
|
469
|
|
|
'natural_science_investment' => $player->partNaturalSciences, |
|
470
|
|
|
'life_science_investment' => $player->partLifeSciences, |
|
471
|
|
|
'social_political_investment' => $player->partSocialPoliticalSciences, |
|
472
|
|
|
'informatic_engineering_investment' => $player->partInformaticEngineering, |
|
473
|
|
|
'last_connected_at' => $player->getDLastConnection(), |
|
474
|
|
|
'last_acted_at' => $player->getDLastActivity(), |
|
475
|
|
|
'statement' => $player->getStatement(), |
|
476
|
|
|
'id' => $player->getId() |
|
477
|
|
|
)); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* @param Player $player |
|
482
|
|
|
* @param int $credits |
|
483
|
|
|
* @param string $operator |
|
484
|
|
|
*/ |
|
485
|
|
|
public function updatePlayerCredits(Player $player, $credits, $operator) |
|
486
|
|
|
{ |
|
487
|
|
|
$query = $this->connection->prepare("UPDATE player SET credit = credit $operator $credits, uPlayer = :updated_at WHERE id = :id"); |
|
488
|
|
|
$query->execute(array( |
|
489
|
|
|
'updated_at' => $player->uPlayer, |
|
490
|
|
|
'id' => $player->getId() |
|
491
|
|
|
)); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
/** |
|
495
|
|
|
* @param int $playerId |
|
496
|
|
|
* @param int $investment |
|
497
|
|
|
*/ |
|
498
|
|
|
public function updateUniversityInvestment($playerId, $investment) |
|
499
|
|
|
{ |
|
500
|
|
|
$query = $this->connection->prepare("UPDATE player SET iUniversity = :investment WHERE id = :id"); |
|
501
|
|
|
$query->execute(array( |
|
502
|
|
|
'investment' => $investment, |
|
503
|
|
|
'id' => $playerId |
|
504
|
|
|
)); |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
public function remove($entity) |
|
508
|
|
|
{ |
|
509
|
|
|
|
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
public function format($data) |
|
513
|
|
|
{ |
|
514
|
|
|
$player = new Player(); |
|
515
|
|
|
|
|
516
|
|
|
$player->setId((int) $data['id']); |
|
517
|
|
|
$player->setBind($data['bind']); |
|
518
|
|
|
$player->setRColor((int) $data['rColor']); |
|
519
|
|
|
$player->setName($data['name']); |
|
520
|
|
|
$player->sex = $data['sex']; |
|
521
|
|
|
$player->description = $data['description']; |
|
522
|
|
|
$player->setAvatar($data['avatar']); |
|
523
|
|
|
$player->setStatus((int) $data['status']); |
|
524
|
|
|
$player->rGodfather = $data['rGodfather']; |
|
525
|
|
|
$player->setCredit((int) $data['credit']); |
|
526
|
|
|
$player->uPlayer = $data['uPlayer']; |
|
527
|
|
|
$player->setExperience((int) $data['experience']); |
|
528
|
|
|
$player->factionPoint = (int) $data['factionPoint']; |
|
529
|
|
|
$player->setLevel((int) $data['level']); |
|
530
|
|
|
$player->setVictory((int) $data['victory']); |
|
531
|
|
|
$player->setDefeat((int) $data['defeat']); |
|
532
|
|
|
$player->setStepTutorial((int) $data['stepTutorial']); |
|
533
|
|
|
$player->stepDone = (int) $data['stepDone']; |
|
|
|
|
|
|
534
|
|
|
$player->iUniversity = (int) $data['iUniversity']; |
|
535
|
|
|
$player->partNaturalSciences = (int) $data['partNaturalSciences']; |
|
536
|
|
|
$player->partLifeSciences = (int) $data['partLifeSciences']; |
|
537
|
|
|
$player->partSocialPoliticalSciences = (int) $data['partSocialPoliticalSciences']; |
|
538
|
|
|
$player->partInformaticEngineering = (int) $data['partInformaticEngineering']; |
|
539
|
|
|
$player->setDInscription($data['dInscription']); |
|
540
|
|
|
$player->setDLastConnection($data['dLastConnection']); |
|
541
|
|
|
$player->setDLastActivity($data['dLastActivity']); |
|
542
|
|
|
$player->setPremium($data['premium']); |
|
543
|
|
|
$player->setStatement($data['statement']); |
|
544
|
|
|
|
|
545
|
|
|
return $player; |
|
546
|
|
|
} |
|
547
|
|
|
} |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.