1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15
16 class LeaguesController extends AppController {
17
18 19 20 21 22
23 public $uses = array('League', 'Player', 'Penalty');
24
25 26 27 28 29
30 public $helpers = array(
31 'Number',
32 'Html',
33 'Text',
34 'Form',
35 'Js' => array(
36 'Jquery',
37 )
38 );
39
40 41 42 43 44
45 public $components = array(
46 'GeoIP',
47 'RequestHandler',
48 'DataTable',
49 'Paginator',
50 );
51
52
53
54 55 56 57
58 public function index() {
59 }
60
61
62
63 64 65 66 67
68 public function view($leagueID = null) {
69
70 if (!isset($leagueID) || (!array_key_exists($leagueID, Configure::read('league')) && $leagueID != 0)) {
71 $this->Session->setFlash(__('That League does not exist...'), null, null, 'error');
72 $this->redirect(array('plugin' => null, 'admin' => false, 'controller' => 'pages', 'action' => 'display', 'server' => Configure::read('server_id'), 'home'));
73 }
74
75 $leagueValue = $this->__getLeagueValues($leagueID);
76 $this->set('leagueValue', $leagueValue);
77 $this->set('leagueID', $leagueID);
78 $minimumConnections = Configure::read('options.min_connections');
79 $this->set('minimumConnections', $minimumConnections);
80 $minimumKills = Configure::read('options.min_kills');
81 $this->set('minimumKills', $minimumKills);
82 }
83
84
85
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
134 public function leaguesJson($leagueID = null) {
135 $leagueValue = $this->__getLeagueValues($leagueID);
136 $this->set('leagueValue', $leagueValue);
137
138
139 $conditions = array(
140 $leagueValue[0] . ' BETWEEN ? AND ?' => array($leagueValue[1], $leagueValue[2]),
141 'League.hide' => 0,
142 );
143
144
145 $minimumConnections = Configure::read('options.min_connections');
146 $minimumKills = Configure::read('options.min_kills');
147 if ($leagueValue[0] != 'Player.connections') {
148 $conditions['Player.connections >'] = $minimumConnections;
149 $conditions['League.kills >'] = $minimumKills;
150 }
151
152
153 $maxDays = Configure::read('options.max_days');
154 if ($maxDays != '' && $maxDays != 0) {
155 $conditions['(' . gmdate('U') . ' - Player.time_edit) <'] = $maxDays * 60 * 60 * 24;
156 }
157
158
159 $hideBanned = (bool)Configure::read('options.hide_banned');
160
161 if ($hideBanned) {
162 $currentTime = gmdate('U');
163 $conditionsSubQuery = array(
164 'OR' => array(
165 'Penalty.type' => array(
166 'Ban',
167 'TempBan',
168 )
169 ),
170 'AND' => array(
171 'OR' => array(
172 'Penalty.time_expire' => -1,
173 'Penalty.time_expire >' => $currentTime
174 ),
175 ),
176 'Penalty.inactive' => 0
177 );
178
179 $db = $this->Penalty->getDataSource();
180 $subQuery = $db->buildStatement(
181 array(
182 'fields' => array(
183 'DISTINCT(Penalty.client_id)',
184 ),
185 'table' => $db->fullTableName($this->Penalty),
186 'alias' => 'Penalty',
187 'conditions' => $conditionsSubQuery,
188 ),
189 $this->Penalty
190 );
191 $subQuery = ' `Player`.`id` NOT IN (' . $subQuery . ') ';
192 $subQueryExpression = $db->expression($subQuery);
193 $conditions[] = $subQueryExpression;
194 }
195
196 $this->paginate = array(
197
198 'fields' => array(
199 'Player.name',
200 'League.skill',
201 'League.ratio',
202 'League.kills',
203 'League.deaths',
204
205 'League.teamkills',
206 'League.winstreak',
207 'League.rounds',
208 'League.suicides',
209 'League.teamdeaths',
210 'League.losestreak',
211 'Player.connections',
212 'Player.ip',
213 'Player.group_bits',
214 'League.id',
215 ),
216 'conditions' => $conditions,
217 218 219 220
221 'order' => 'League.skill desc',
222 'limit' => 5,
223 );
224
225 $data = $this->DataTable->getResponse('League');
226
227
228 $dataLength = count($data['aaData']);
229 for ($i = 0; $i < $dataLength; $i++) {
230 array_unshift($data['aaData'][$i], 'pos#');
231 }
232
233
234 foreach ($data['aaData'] as $k => $v) {
235 array_push(
236 $data['aaData'][$k],
237 $this->XlrFunctions->getRank($v[4]),
238 $this->XlrFunctions->getLeague($v[2]),
239 $this->XlrFunctions->getFlag($v[13]),
240 $this->XlrFunctions->getLevel($v[14])
241 );
242 }
243
244
245
246 $nrRows = $this->League->getAffectedRows();
247
248 if ($this->request->is('requested')) {
249 return array($data, $nrRows);
250 } else {
251 $this->set('xlrLeague', $data);
252 }
253 return null;
254 }
255
256
257
258 259 260 261
262 public function getAwards($leagueID = 0) {
263 $leagueValue = $this->__getLeagueValues($leagueID);
264 $this->set('leagueID', $leagueID);
265
266
267 $awardLeague = 'leagueawards-' . Configure::read('server_id') . '-' . $leagueID;
268 $data = Cache::read($awardLeague, '1hour');
269 if (!$data) {
270
271 $conditions = array(
272 $leagueValue[0] . ' BETWEEN ? AND ?' => array($leagueValue[1], $leagueValue[2]),
273 'League.hide' => 0,
274 );
275
276
277 $minimumConnections = Configure::read('options.min_connections');
278 $minimumKills = Configure::read('options.min_kills');
279 if ($leagueValue[0] != 'Player.connections') {
280 $conditions['Player.connections >'] = $minimumConnections;
281 $conditions['League.kills >'] = $minimumKills;
282 }
283
284
285 $maxDays = Configure::read('options.max_days');
286 if ($maxDays != '' && $maxDays != 0) {
287 $conditions['(' . gmdate('U') . ' - Player.time_edit) <'] = $maxDays * 60 * 60 * 24;
288 }
289
290
291 $hideBanned = (bool)Configure::read('options.hide_banned');
292
293 if ($hideBanned) {
294 $currentTime = gmdate('U');
295 $conditionsSubQuery = array(
296 'OR' => array(
297 'Penalty.type' => array(
298 'Ban',
299 'TempBan',
300 )
301 ),
302 'AND' => array(
303 'OR' => array(
304 'Penalty.time_expire' => -1,
305 'Penalty.time_expire >' => $currentTime
306 ),
307 ),
308 'Penalty.inactive' => 0
309 );
310
311 $db = $this->Penalty->getDataSource();
312 $subQuery = $db->buildStatement(
313 array(
314 'fields' => array(
315 'DISTINCT(Penalty.client_id)',
316 ),
317 'table' => $db->fullTableName($this->Penalty),
318 'alias' => 'Penalty',
319 'conditions' => $conditionsSubQuery,
320 ),
321 $this->Penalty
322 );
323 $subQuery = ' `Player`.`id` NOT IN (' . $subQuery . ') ';
324 $subQueryExpression = $db->expression($subQuery);
325 $conditions[] = $subQueryExpression;
326 }
327
328 $data[] = $this->League->find('first',
329 array(
330 'fields' => array(
331 'Player.name',
332 'League.skill',
333 'League.id',
334 ),
335 'conditions' => $conditions,
336 'order' => 'League.skill DESC'
337 )
338 );
339 $data[] = $this->League->find('first',
340 array(
341 'fields' => array(
342 'Player.name',
343 'League.kills',
344 'League.id',
345 ),
346 'conditions' => $conditions,
347 'order' => 'League.kills DESC'
348 )
349 );
350 $data[] = $this->League->find('first',
351 array(
352 'fields' => array(
353 'Player.name',
354 'League.ratio',
355 'League.id',
356 ),
357 'conditions' => $conditions,
358 'order' => 'League.ratio DESC'
359 )
360 );
361 $data[] = $this->League->find('first',
362 array(
363 'fields' => array(
364 'Player.name',
365 'League.winstreak',
366 'League.id',
367 ),
368 'conditions' => $conditions,
369 'order' => 'League.winstreak DESC'
370 )
371 );
372 $data[] = $this->League->find('first',
373 array(
374 'fields' => array(
375 'Player.name',
376 'League.rounds',
377 'League.id',
378 ),
379 'conditions' => $conditions,
380 'order' => 'League.rounds DESC'
381 )
382 );
383 $data[] = $this->League->find('first',
384 array(
385 'fields' => array(
386 'Player.name',
387 '(League.kills / League.rounds) as efficiency',
388 'League.id',
389 ),
390 'conditions' => $conditions,
391 'order' => 'efficiency DESC'
392 )
393 );
394
395
396 Cache::write($awardLeague, $data, '1hour');
397 }
398
399
400 if ($this->request->is('requested')) {
401 return array($data);
402 } else {
403 $this->set('leagueawards', $data);
404 }
405 return null;
406 }
407
408
409
410 411 412 413 414 415 416 417
418 public function getMia($leagueID = 0, $random = false, $limit = 15) {
419 $leagueValue = $this->__getLeagueValues($leagueID);
420 $this->set('leagueValue', $leagueValue);
421
422
423 $conditions = array(
424 $leagueValue[0] . ' BETWEEN ? AND ?' => array($leagueValue[1], $leagueValue[2]),
425 'League.hide' => 0,
426 );
427
428
429 $minimumConnections = Configure::read('options.min_connections');
430 $minimumKills = Configure::read('options.min_kills');
431 if ($leagueValue[0] != 'Player.connections') {
432 $conditions['Player.connections >'] = $minimumConnections;
433 $conditions['League.kills >'] = $minimumKills;
434 }
435
436
437 $maxDays = Configure::read('options.max_days');
438 if ($maxDays != '' && $maxDays != 0) {
439 $conditions['(' . gmdate('U') . ' - Player.time_edit) >='] = $maxDays * 60 * 60 * 24;
440 } else {
441
442 return null;
443 }
444
445
446 $hideBanned = (bool)Configure::read('options.hide_banned');
447
448 if ($hideBanned) {
449 $currentTime = gmdate('U');
450 $conditionsSubQuery = array(
451 'OR' => array(
452 'Penalty.type' => array(
453 'Ban',
454 'TempBan',
455 )
456 ),
457 'AND' => array(
458 'OR' => array(
459 'Penalty.time_expire' => -1,
460 'Penalty.time_expire >' => $currentTime
461 ),
462 ),
463 'Penalty.inactive' => 0
464 );
465
466 $db = $this->Penalty->getDataSource();
467 $subQuery = $db->buildStatement(
468 array(
469 'fields' => array(
470 'DISTINCT(Penalty.client_id)',
471 ),
472 'table' => $db->fullTableName($this->Penalty),
473 'alias' => 'Penalty',
474 'conditions' => $conditionsSubQuery,
475 ),
476 $this->Penalty
477 );
478 $subQuery = ' `Player`.`id` NOT IN (' . $subQuery . ') ';
479 $subQueryExpression = $db->expression($subQuery);
480 $conditions[] = $subQueryExpression;
481 }
482
483
484 if ($random) {
485 $order = 'RAND()';
486 } else {
487 $order = 'League.skill desc';
488 }
489
490 $data = $this->League->find('all',
491 array(
492 'conditions' => $conditions,
493 'order' => $order,
494 'limit' => $limit,
495 )
496 );
497 $nrRows = $this->League->getAffectedRows();
498
499
500 if ($this->request->is('requested')) {
501 return array($data, $nrRows);
502 } else {
503 $this->set('leagueawards', $data);
504 }
505 return null;
506 }
507
508
509
510 511 512 513 514 515 516
517 public function getLastSeen($leagueID = 0, $limit = 15) {
518 $leagueValue = $this->__getLeagueValues($leagueID);
519 $this->set('leagueValue', $leagueValue);
520
521
522 $conditions = array(
523 $leagueValue[0] . ' BETWEEN ? AND ?' => array($leagueValue[1], $leagueValue[2]),
524 'League.hide' => 0,
525 );
526
527
528 $minimumConnections = Configure::read('options.min_connections');
529 $minimumKills = Configure::read('options.min_kills');
530 if ($leagueValue[0] != 'Player.connections') {
531 $conditions['Player.connections >'] = $minimumConnections;
532 $conditions['League.kills >'] = $minimumKills;
533 }
534
535
536 $hideBanned = (bool)Configure::read('options.hide_banned');
537
538 if ($hideBanned) {
539 $currentTime = gmdate('U');
540 $conditionsSubQuery = array(
541 'OR' => array(
542 'Penalty.type' => array(
543 'Ban',
544 'TempBan',
545 )
546 ),
547 'AND' => array(
548 'OR' => array(
549 'Penalty.time_expire' => -1,
550 'Penalty.time_expire >' => $currentTime
551 ),
552 ),
553 'Penalty.inactive' => 0
554 );
555
556 $db = $this->Penalty->getDataSource();
557 $subQuery = $db->buildStatement(
558 array(
559 'fields' => array(
560 'DISTINCT(Penalty.client_id)',
561 ),
562 'table' => $db->fullTableName($this->Penalty),
563 'alias' => 'Penalty',
564 'conditions' => $conditionsSubQuery,
565 ),
566 $this->Penalty
567 );
568 $subQuery = ' `Player`.`id` NOT IN (' . $subQuery . ') ';
569 $subQueryExpression = $db->expression($subQuery);
570 $conditions[] = $subQueryExpression;
571 }
572
573
574 $order = 'Player.time_edit desc';
575
576 $data = $this->League->find('all',
577 array(
578 'conditions' => $conditions,
579 'order' => $order,
580 'limit' => $limit,
581 )
582 );
583 $nrRows = $this->League->getAffectedRows();
584
585
586 if ($this->request->is('requested')) {
587 return array($data, $nrRows);
588 } else {
589 $this->set('leagueawards', $data);
590 }
591 return null;
592 }
593
594
595
596 597 598 599 600 601 602
603 private function __getLeagueValues($leagueID = 0) {
604 $leagueValuesAll = array();
605 if ($leagueID == 0) {
606 $leagueValuesAll[0] = array('League.skill', 0, 9999999, __('All stats'), __('A complete list of all qualified players.'));
607 } else {
608 $leagueValuesAll = Configure::read('league');
609 }
610
611 $leagueValues = $leagueValuesAll[$leagueID];
612
613 return $leagueValues;
614 }
615
616 }