Failed Conditions
Pull Request — master (#374)
by Michael
02:01
created
core/js/dashboard.graph.js.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -59,83 +59,83 @@  discard block
 block discarded – undo
59 59
 $captcha_accs = array();
60 60
 
61 61
 foreach ($stats as $data) {
62
-    if ($data->timestamp > $lastweek) {
63
-        $labels_global[] = '"'.date('D H:i', $data->timestamp).'"';
64
-        $total[] = $data->pokemon_now;
65
-        if (isset($data->pokemon_now_iv)) {
66
-            $total_iv[] = $data->pokemon_now_iv;
67
-        } else {
68
-            $total_iv[] = null;
69
-        }
70
-    }
62
+	if ($data->timestamp > $lastweek) {
63
+		$labels_global[] = '"'.date('D H:i', $data->timestamp).'"';
64
+		$total[] = $data->pokemon_now;
65
+		if (isset($data->pokemon_now_iv)) {
66
+			$total_iv[] = $data->pokemon_now_iv;
67
+		} else {
68
+			$total_iv[] = null;
69
+		}
70
+	}
71 71
 
72
-    if ($data->timestamp > $yesterday) {
73
-        $labels[] = '"'.date('H:i', $data->timestamp).'"';
74
-
75
-        if (isset($data->rarity_spawn->{'Very common'})) {
76
-            $veco[] = $data->rarity_spawn->{'Very common'};
77
-        } else {
78
-            $veco[] = 0;
79
-        }
80
-
81
-        if (isset($data->rarity_spawn->Common)) {
82
-            $commo[] = $data->rarity_spawn->Common;
83
-        } else {
84
-            $commo[] = 0;
85
-        }
86
-
87
-        if (isset($data->rarity_spawn->Rare)) {
88
-            $rare[] = $data->rarity_spawn->Rare;
89
-        } else {
90
-            $rare[] = 0;
91
-        }
92
-
93
-        if (isset($data->rarity_spawn->Mythic)) {
94
-            $myth[] = $data->rarity_spawn->Mythic;
95
-        } else {
96
-            $myth[] = 0;
97
-        }
98
-    }
72
+	if ($data->timestamp > $yesterday) {
73
+		$labels[] = '"'.date('H:i', $data->timestamp).'"';
74
+
75
+		if (isset($data->rarity_spawn->{'Very common'})) {
76
+			$veco[] = $data->rarity_spawn->{'Very common'};
77
+		} else {
78
+			$veco[] = 0;
79
+		}
80
+
81
+		if (isset($data->rarity_spawn->Common)) {
82
+			$commo[] = $data->rarity_spawn->Common;
83
+		} else {
84
+			$commo[] = 0;
85
+		}
86
+
87
+		if (isset($data->rarity_spawn->Rare)) {
88
+			$rare[] = $data->rarity_spawn->Rare;
89
+		} else {
90
+			$rare[] = 0;
91
+		}
92
+
93
+		if (isset($data->rarity_spawn->Mythic)) {
94
+			$myth[] = $data->rarity_spawn->Mythic;
95
+		} else {
96
+			$myth[] = 0;
97
+		}
98
+	}
99 99
 }
100 100
 
101 101
 $stats_file = SYS_PATH.'/core/json/gym.stats.json';
102 102
 $stats = json_decode(file_get_contents($stats_file));
103 103
 
104 104
 foreach ($stats as $data) {
105
-    if ($data->timestamp > $lastweek) {
106
-        $labels_gym[] = '"'.date('D H:i', $data->timestamp).'"';
105
+	if ($data->timestamp > $lastweek) {
106
+		$labels_gym[] = '"'.date('D H:i', $data->timestamp).'"';
107 107
 
108
-        $mystic_average[] = $data->team->mystic->average;
109
-        $mystic_owned[] = $data->team->mystic->gym_owned;
108
+		$mystic_average[] = $data->team->mystic->average;
109
+		$mystic_owned[] = $data->team->mystic->gym_owned;
110 110
 
111
-        $valor_average[] = $data->team->valor->average;
112
-        $valor_owned[] = $data->team->valor->gym_owned;
111
+		$valor_average[] = $data->team->valor->average;
112
+		$valor_owned[] = $data->team->valor->gym_owned;
113 113
 
114
-        $instinct_average[] = $data->team->instinct->average;
115
-        $instinct_owned[] = $data->team->instinct->gym_owned;
116
-    }
114
+		$instinct_average[] = $data->team->instinct->average;
115
+		$instinct_owned[] = $data->team->instinct->gym_owned;
116
+	}
117 117
 }
118 118
 
119 119
 $stats_file = SYS_PATH.'/core/json/pokestop.stats.json';
120 120
 $stats = json_decode(file_get_contents($stats_file));
121 121
 
122 122
 foreach ($stats as $data) {
123
-    if ($data->timestamp > $lastweek) {
124
-        $labels_stops[] = '"'.date('D H:i', $data->timestamp).'"';
125
-        $lure[] = $data->lured;
126
-    }
123
+	if ($data->timestamp > $lastweek) {
124
+		$labels_stops[] = '"'.date('D H:i', $data->timestamp).'"';
125
+		$lure[] = $data->lured;
126
+	}
127 127
 }
128 128
 
129 129
 if ($config->system->captcha_support) {
130
-    $stats_file = SYS_PATH.'/core/json/captcha.stats.json';
131
-    $stats = json_decode(file_get_contents($stats_file));
132
-
133
-    foreach ($stats as $data) {
134
-        if ($data->timestamp > $lastweek) {
135
-            $labels_captcha[] = '"'.date('D H:i', $data->timestamp).'"';
136
-            $captcha_accs[] = $data->captcha_accs;
137
-        }
138
-    }
130
+	$stats_file = SYS_PATH.'/core/json/captcha.stats.json';
131
+	$stats = json_decode(file_get_contents($stats_file));
132
+
133
+	foreach ($stats as $data) {
134
+		if ($data->timestamp > $lastweek) {
135
+			$labels_captcha[] = '"'.date('D H:i', $data->timestamp).'"';
136
+			$captcha_accs[] = $data->captcha_accs;
137
+		}
138
+	}
139 139
 }
140 140
 
141 141
 ?>
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 // -------------
595 595
 
596 596
 <?php if ($config->system->captcha_support) {
597
-    ?>
597
+	?>
598 598
 var ctx_captcha_accs = $('#captcha');
599 599
 
600 600
 var data_captcha_accs = {
Please login to merge, or discard this patch.
pages/pokemon.page.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		<div class="col-sm-1 hidden-xs">
19 19
 
20 20
 				<?php if ($pokemon->id - 1 > 0) {
21
-    ?>
21
+	?>
22 22
 
23 23
 				<p class="nav-links"><a href="pokemon/<?= $pokemon->id - 1; ?>"><i class="fa fa-chevron-left"></i></a></p>
24 24
 
@@ -44,19 +44,19 @@  discard block
 block discarded – undo
44 44
 		<div class="col-sm-1 hidden-xs">
45 45
 
46 46
 			<?php if ($pokemon->id + 1 < $config->system->max_pokemon) {
47
-        ?>
47
+		?>
48 48
 
49 49
 			<p class="nav-links"><a href="pokemon/<?= $pokemon->id + 1; ?>"><i class="fa fa-chevron-right"></i></a></p>
50 50
 
51 51
 			<?php
52
-    } ?>
52
+	} ?>
53 53
 		</div>
54 54
 
55 55
 	</div>
56 56
 <?php
57
-    $form_array = array('Unset', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'W', 'X', 'Y', 'Z');
58
-    $form_array = array_values($form_array);
59
-    ?>
57
+	$form_array = array('Unset', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'W', 'X', 'Y', 'Z');
58
+	$form_array = array_values($form_array);
59
+	?>
60 60
 
61 61
 </header>
62 62
 <!-- /Header -->
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 
79 79
 				<p>
80 80
 				<?php foreach ($pokemon->types as $type) {
81
-        ?>
81
+		?>
82 82
 					<span class="label label-default" style="background-color:<?= $pokemons->typecolors->$type; ?>"><?= $type; ?></span>
83 83
 				<?php
84
-    }?>
84
+	}?>
85 85
 				</p>
86 86
 
87 87
 			</div>
@@ -110,28 +110,28 @@  discard block
 block discarded – undo
110 110
 				<td class="col-md-4 col-xs-4">
111 111
 
112 112
 				<?php
113
-                if (isset($pokemon->last_seen) || isset($pokemon->last_seen_day)) {
113
+				if (isset($pokemon->last_seen) || isset($pokemon->last_seen_day)) {
114 114
 
115
-                    if (isset($pokemon->last_seen)) {
116
-                        $time_ago = time_ago($pokemon->last_seen, $locales);
117
-                    } else {
118
-                        $time_ago = time_ago_day($pokemon->last_seen_day, $locales);
119
-                    }
115
+					if (isset($pokemon->last_seen)) {
116
+						$time_ago = time_ago($pokemon->last_seen, $locales);
117
+					} else {
118
+						$time_ago = time_ago_day($pokemon->last_seen_day, $locales);
119
+					}
120 120
 
121
-                    if (isset($pokemon->last_position)) {
122
-                        ?>
121
+					if (isset($pokemon->last_position)) {
122
+						?>
123 123
                         <a href="https://maps.google.com/?q=<?= $pokemon->last_position->latitude; ?>,<?= $pokemon->last_position->longitude; ?>&ll=<?= $pokemon->last_position->latitude; ?>,<?= $pokemon->last_position->longitude; ?>&z=16" target="_blank"><?= $time_ago ?></a>
124 124
                         <?php
125
-                    } else {
126
-                        echo $time_ago;
127
-                    }
128
-                    ?>
125
+					} else {
126
+						echo $time_ago;
127
+					}
128
+					?>
129 129
 
130 130
 				    <?php
131
-                } else {
132
-                    echo $locales->NEVER;
133
-                }
134
-                ?>
131
+				} else {
132
+					echo $locales->NEVER;
133
+				}
134
+				?>
135 135
 
136 136
 				</td>
137 137
 			</tr>
@@ -146,15 +146,15 @@  discard block
 block discarded – undo
146 146
 			<tr>
147 147
 				<td class="col-md-8 col-xs-8">
148 148
                     <?php
149
-                    if (isset($pokemon->protected_gyms)) {
150
-                        echo '<strong>'.$locales->POKEMON_GYM.$pokemon->name.'</strong>';
151
-                    } ?>
149
+					if (isset($pokemon->protected_gyms)) {
150
+						echo '<strong>'.$locales->POKEMON_GYM.$pokemon->name.'</strong>';
151
+					} ?>
152 152
                 </td>
153 153
 				<td class="col-md-4 col-xs-4">
154 154
                     <?php
155
-                    if (isset($pokemon->protected_gyms)) {
156
-                        echo $pokemon->protected_gyms;
157
-                    }?>
155
+					if (isset($pokemon->protected_gyms)) {
156
+						echo $pokemon->protected_gyms;
157
+					}?>
158 158
                 </td>
159 159
 			</tr>
160 160
 		</table>
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
 				<td class="col-md-4 col-xs-4">
170 170
 
171 171
                     <?php
172
-                    if (isset($pokemon->last_raid_position)) {
173
-                        ?>
172
+					if (isset($pokemon->last_raid_position)) {
173
+						?>
174 174
 
175 175
 					    <a href="https://maps.google.com/?q=<?= $pokemon->last_raid_position->latitude; ?>,<?= $pokemon->last_raid_position->longitude; ?>&ll=<?= $pokemon->last_raid_position->latitude; ?>,<?= $pokemon->last_raid_position->longitude; ?>&z=16" target="_blank"><?= time_ago($pokemon->last_raid_seen, $locales); ?></a>
176 176
 
177 177
 					    <?php
178
-                    } else {
179
-                        echo $locales->NEVER;
180
-                    }
181
-                    ?>
178
+					} else {
179
+						echo $locales->NEVER;
180
+					}
181
+					?>
182 182
 
183 183
 				</td>
184 184
 			</tr>
@@ -301,25 +301,25 @@  discard block
 block discarded – undo
301 301
 	<div class="col-md-12 flex-container-tree results">
302 302
 
303 303
 		<?php
304
-        $tree = array($pokemon->tree);
305
-        $depth = get_depth($tree);
306
-        $skip = false;
307
-        for ($i = 0; $i < $depth; ++$i) {
308
-            $i_id = intval(($i + 1) / 2);
309
-            $data = get_tree_at_depth($tree, $i_id, $config->system->max_pokemon); ?>
304
+		$tree = array($pokemon->tree);
305
+		$depth = get_depth($tree);
306
+		$skip = false;
307
+		for ($i = 0; $i < $depth; ++$i) {
308
+			$i_id = intval(($i + 1) / 2);
309
+			$data = get_tree_at_depth($tree, $i_id, $config->system->max_pokemon); ?>
310 310
 
311 311
 			<?php
312
-            if (!is_null($data) && 0 != sizeof($data) && !$skip) {
313
-                ?>
312
+			if (!is_null($data) && 0 != sizeof($data) && !$skip) {
313
+				?>
314 314
 				<div class="col-md-12 flex-item-tree">
315 315
 					<?php
316
-                    foreach ($data as $obj) {
317
-                        $obj_id = $obj->id;
318
-                        $tree_pokemon = $pokemons->pokemon->$obj_id;
319
-                        $link = 'pokemon/'.$obj_id;
316
+					foreach ($data as $obj) {
317
+						$obj_id = $obj->id;
318
+						$tree_pokemon = $pokemons->pokemon->$obj_id;
319
+						$link = 'pokemon/'.$obj_id;
320 320
 
321
-                        if (0 == $i % 2) {
322
-                            ?>
321
+						if (0 == $i % 2) {
322
+							?>
323 323
 
324 324
 							<div>
325 325
 								<a href="<?= $link; ?>"><img src="<?= $tree_pokemon->img; ?>" alt="<?= $tree_pokemon->name; ?>" class="img"></a>
@@ -327,42 +327,42 @@  discard block
 block discarded – undo
327 327
 							</div>
328 328
 
329 329
 						<?php
330
-                        } else {
331
-                            ?>
330
+						} else {
331
+							?>
332 332
 
333 333
 							<div>
334 334
 								<img src="core/img/arrow<?=$obj->array_sufix; ?>.png" alt="Arrow" class="img">
335 335
 								<p class="pkmn-name">
336 336
 									<?php
337
-                                    if (isset($obj->candies)) {
338
-                                        echo $obj->candies.' '.$locales->POKEMON_CANDIES;
339
-                                    } else {
340
-                                        echo '? '.$locales->POKEMON_CANDIES;
341
-                                    }
342
-
343
-                            if (isset($obj->item)) {
344
-                                $itemName = 'ITEM_'.$obj->item;
345
-                                echo '<br>+ '.$locales->$itemName;
346
-                            } elseif (isset($obj->info)) {
347
-                                $infoName = 'INFO_'.$obj->info;
348
-                                echo '<br>('.$locales->$infoName.')';
349
-                            } else {
350
-                                echo '<br> </br>';
351
-                            } ?>
337
+									if (isset($obj->candies)) {
338
+										echo $obj->candies.' '.$locales->POKEMON_CANDIES;
339
+									} else {
340
+										echo '? '.$locales->POKEMON_CANDIES;
341
+									}
342
+
343
+							if (isset($obj->item)) {
344
+								$itemName = 'ITEM_'.$obj->item;
345
+								echo '<br>+ '.$locales->$itemName;
346
+							} elseif (isset($obj->info)) {
347
+								$infoName = 'INFO_'.$obj->info;
348
+								echo '<br>('.$locales->$infoName.')';
349
+							} else {
350
+								echo '<br> </br>';
351
+							} ?>
352 352
 								</p>
353 353
 							</div>
354 354
                             <?php
355
-                        }
356
-                    } ?>
355
+						}
356
+					} ?>
357 357
                 </div>
358 358
             <?php
359
-            } elseif ($skip) {
360
-                $skip = false;
361
-            } else {
362
-                $skip = true;
363
-            }
364
-        }
365
-        ?>
359
+			} elseif ($skip) {
360
+				$skip = false;
361
+			} else {
362
+				$skip = true;
363
+			}
364
+		}
365
+		?>
366 366
 	</div>
367 367
 </div>
368 368
 
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 
378 378
 		<?php
379 379
 
380
-        foreach ($related as $related_mon) {
381
-            ?>
380
+		foreach ($related as $related_mon) {
381
+			?>
382 382
 
383 383
 			<div class="col-md-1 col-sm-2 col-xs-3 pokemon-single">
384 384
 
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
 
391 391
 
392 392
 			<?php
393
-        }
393
+		}
394 394
 
395
-        ?>
395
+		?>
396 396
 
397 397
 		</div>
398 398
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 
403 403
 
404 404
 <?php if (!empty($top)) {
405
-            ?>
405
+			?>
406 406
 	<div class="row area" id="top50">
407 407
 		<div class="col-md-12">
408 408
 			<h2 class="text-center sub-title">Top 50 <strong><?= $pokemon->name; ?></strong></h2>
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 							<th><a href="pokemon/<?= $pokemon->id; ?>?order=move_2<?php echo 'move_2' == $top_order && !isset($_GET['direction']) ? '&direction=desc' : ''; ?>#top50">2. <?= $locales->MOVE; ?> <i class="fa fa-sort" aria-hidden="true"></i></a></th>
421 421
 							<th><a href="pokemon/<?= $pokemon->id; ?>?order=disappear_time<?php echo 'disappear_time' == $top_order && !isset($_GET['direction']) ? '&direction=desc' : ''; ?>#top50"><?= $locales->DATE; ?> <i class="fa fa-sort" aria-hidden="true"></i></a></th>
422 422
 							<?php if (201 == $pokemon->id) {
423
-                ?>
423
+				?>
424 424
 								<th>Form</th>
425 425
 							<?php
426
-            } ?>
426
+			} ?>
427 427
 						</tr>
428 428
 					</thead>
429 429
 				
430 430
 					<tbody>
431 431
 						<?php
432
-                        $i = 0;
433
-            foreach ($top as $top50) {
434
-                ++$i;
435
-                $move1 = $top50->move_1;
436
-                $move2 = $top50->move_2; ?>
432
+						$i = 0;
433
+			foreach ($top as $top50) {
434
+				++$i;
435
+				$move1 = $top50->move_1;
436
+				$move2 = $top50->move_2; ?>
437 437
 
438 438
 							<tr>
439 439
 								<td><?= $i; ?></td>
@@ -447,17 +447,17 @@  discard block
 block discarded – undo
447 447
 								<td><a href="https://maps.google.com/?q=<?= $top50->latitude; ?>,<?= $top50->longitude; ?>&ll=<?= $top50->latitude; ?>,<?= $top50->longitude; ?>&z=16"
448 448
 									target="_blank"><?=$top50->distime; ?></a></td>
449 449
 								<?php if (201 == $pokemon->id && $top50->form) {
450
-                    ?>
450
+					?>
451 451
 									<td><?php echo $form_array[$top50->form]; ?></td>
452 452
 								<?php
453
-                } else {
454
-                    ?>
453
+				} else {
454
+					?>
455 455
 									<td></td>
456 456
 								<?php
457
-                } ?>
457
+				} ?>
458 458
 							</tr>
459 459
 							<?php
460
-            } ?>
460
+			} ?>
461 461
 				</tbody>
462 462
 			</table>
463 463
 		</div>
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 </div>
466 466
 
467 467
 <?php
468
-        } if ($toptrainer) {
469
-            ?>
468
+		} if ($toptrainer) {
469
+			?>
470 470
 	<div class="row" id="trainer">
471 471
 		<div class="col-md-12">
472 472
 			<h2 class="text-center sub-title"><?= $locales->POKEMON_TOPTRAINER; ?> <strong><?= $pokemon->name; ?></strong></h2>
@@ -485,11 +485,11 @@  discard block
 block discarded – undo
485 485
 					</thead>
486 486
 					<tbody>
487 487
 						<?php
488
-                        $i = 0;
489
-            foreach ($toptrainer as $besttrainer) {
490
-                ++$i;
491
-                $move1 = $besttrainer->move_1;
492
-                $move2 = $besttrainer->move_2; ?>
488
+						$i = 0;
489
+			foreach ($toptrainer as $besttrainer) {
490
+				++$i;
491
+				$move1 = $besttrainer->move_1;
492
+				$move2 = $besttrainer->move_2; ?>
493 493
 
494 494
 							<tr>
495 495
 								<td><?= $i; ?></td>
@@ -501,11 +501,11 @@  discard block
 block discarded – undo
501 501
 								<td><?=$besttrainer->lasttime; ?></td>
502 502
 							</tr>
503 503
 							<?php
504
-            } ?>
504
+			} ?>
505 505
 				</tbody>
506 506
 			</table>
507 507
 		</div>
508 508
 	</div>
509 509
 </div>
510 510
 <?php
511
-        } ?>
511
+		} ?>
Please login to merge, or discard this patch.
core/process/queries/QueryManager.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -8,143 +8,143 @@
 block discarded – undo
8 8
 
9 9
 abstract class QueryManager
10 10
 {
11
-    protected static $time_offset;
12
-    protected static $config;
13
-
14
-    private static $current;
15
-
16
-    public static function current()
17
-    {
18
-        global $time_offset;
19
-
20
-        if (null == self::$current) {
21
-            $variables = realpath(dirname(__FILE__)).'/../../json/variables.json';
22
-            self::$config = json_decode(file_get_contents($variables));
23
-
24
-            include_once SYS_PATH.'/core/process/timezone.loader.php';
25
-            self::$time_offset = $time_offset;
26
-
27
-            switch (strtolower(SYS_DB_TYPE)) {
28
-                case 'rdm':
29
-                case 'realdevicemap':
30
-                    self::$current = new QueryManagerMysqlRealDeviceMap();
31
-                    break;
32
-                case 'monocle-alt':
33
-                case 'monocle-alt-mysql':
34
-                    self::$current = new QueryManagerMysqlMonocleAlternate();
35
-                    break;
36
-                case 'monocle-alt-pgsql':
37
-                    self::$current = new QueryManagerPostgresqlMonocleAlternate();
38
-                    break;
11
+	protected static $time_offset;
12
+	protected static $config;
13
+
14
+	private static $current;
15
+
16
+	public static function current()
17
+	{
18
+		global $time_offset;
19
+
20
+		if (null == self::$current) {
21
+			$variables = realpath(dirname(__FILE__)).'/../../json/variables.json';
22
+			self::$config = json_decode(file_get_contents($variables));
23
+
24
+			include_once SYS_PATH.'/core/process/timezone.loader.php';
25
+			self::$time_offset = $time_offset;
26
+
27
+			switch (strtolower(SYS_DB_TYPE)) {
28
+				case 'rdm':
29
+				case 'realdevicemap':
30
+					self::$current = new QueryManagerMysqlRealDeviceMap();
31
+					break;
32
+				case 'monocle-alt':
33
+				case 'monocle-alt-mysql':
34
+					self::$current = new QueryManagerMysqlMonocleAlternate();
35
+					break;
36
+				case 'monocle-alt-pgsql':
37
+					self::$current = new QueryManagerPostgresqlMonocleAlternate();
38
+					break;
39 39
 				case 'mad':
40
-                    self::$current = new QueryManagerMysqlMAD();
41
-                    break;
42
-                default: //rocketmap
43
-                    self::$current = new QueryManagerMysqlRocketmap();
44
-                    break;
45
-            }
46
-        }
40
+					self::$current = new QueryManagerMysqlMAD();
41
+					break;
42
+				default: //rocketmap
43
+					self::$current = new QueryManagerMysqlRocketmap();
44
+					break;
45
+			}
46
+		}
47 47
 
48
-        return self::$current;
49
-    }
48
+		return self::$current;
49
+	}
50 50
 
51
-    private function __construct()
52
-    {
53
-    }
51
+	private function __construct()
52
+	{
53
+	}
54 54
 
55
-    // Misc
56
-    abstract public function getEcapedString($string);
55
+	// Misc
56
+	abstract public function getEcapedString($string);
57 57
 
58
-    // Tester
59
-    abstract public function testTotalPokemon();
58
+	// Tester
59
+	abstract public function testTotalPokemon();
60 60
 
61
-    abstract public function testTotalGyms();
61
+	abstract public function testTotalGyms();
62 62
 
63
-    abstract public function testTotalPokestops();
63
+	abstract public function testTotalPokestops();
64 64
 
65
-    // Homepage
66
-    abstract public function getTotalPokemon();
65
+	// Homepage
66
+	abstract public function getTotalPokemon();
67 67
 
68
-    abstract public function getTotalLures();
68
+	abstract public function getTotalLures();
69 69
 
70
-    abstract public function getTotalGyms();
70
+	abstract public function getTotalGyms();
71 71
 
72
-    abstract public function getTotalRaids();
72
+	abstract public function getTotalRaids();
73 73
 
74
-    abstract public function getTotalGymsForTeam($team_id);
74
+	abstract public function getTotalGymsForTeam($team_id);
75 75
 
76
-    abstract public function getRecentAll();
76
+	abstract public function getRecentAll();
77 77
 
78
-    abstract public function getRecentMythic($mythic_pokemon);
78
+	abstract public function getRecentMythic($mythic_pokemon);
79 79
 
80
-    // Single Pokemon
81
-    abstract public function getGymsProtectedByPokemon($pokemon_id);
80
+	// Single Pokemon
81
+	abstract public function getGymsProtectedByPokemon($pokemon_id);
82 82
 
83
-    abstract public function getPokemonLastSeen($pokemon_id);
83
+	abstract public function getPokemonLastSeen($pokemon_id);
84 84
 
85
-    abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
85
+	abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
86 86
 
87
-    abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
87
+	abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
88 88
 
89
-    abstract public function getPokemonHeatmap($pokemon_id, $start, $end);
89
+	abstract public function getPokemonHeatmap($pokemon_id, $start, $end);
90 90
 
91
-    abstract public function getPokemonGraph($pokemon_id);
91
+	abstract public function getPokemonGraph($pokemon_id);
92 92
 
93
-    abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
93
+	abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
94 94
 
95
-    abstract public function getPokemonSliderMinMax();
95
+	abstract public function getPokemonSliderMinMax();
96 96
 
97
-    abstract public function getMapsCoords();
97
+	abstract public function getMapsCoords();
98 98
 
99
-    abstract public function getPokemonCount($pokemon_id);
99
+	abstract public function getPokemonCount($pokemon_id);
100 100
 
101
-    abstract public function getPokemonCountAll();
101
+	abstract public function getPokemonCountAll();
102 102
 
103
-    abstract public function getRaidCount($pokemon_id);
103
+	abstract public function getRaidCount($pokemon_id);
104 104
 
105
-    abstract public function getRaidCountAll();
105
+	abstract public function getRaidCountAll();
106 106
 
107
-    // Pokestops
108
-    abstract public function getTotalPokestops();
107
+	// Pokestops
108
+	abstract public function getTotalPokestops();
109 109
 
110
-    abstract public function getAllPokestops();
110
+	abstract public function getAllPokestops();
111 111
 
112
-    // Gyms
113
-    abstract public function getTeamGuardians($team_id);
112
+	// Gyms
113
+	abstract public function getTeamGuardians($team_id);
114 114
 
115
-    abstract public function getOwnedAndPoints($team_id);
115
+	abstract public function getOwnedAndPoints($team_id);
116 116
 
117
-    abstract public function getAllGyms();
117
+	abstract public function getAllGyms();
118 118
 
119
-    abstract public function getGymData($gym_id);
119
+	abstract public function getGymData($gym_id);
120 120
 
121
-    abstract public function getGymDefenders($gym_id);
121
+	abstract public function getGymDefenders($gym_id);
122 122
 
123
-    // Gym History
124
-    abstract public function getGymHistories($gym_name, $team, $page, $ranking);
123
+	// Gym History
124
+	abstract public function getGymHistories($gym_name, $team, $page, $ranking);
125 125
 
126
-    abstract public function getGymHistoriesPokemon($gym_id);
126
+	abstract public function getGymHistoriesPokemon($gym_id);
127 127
 
128
-    abstract public function getHistoryForGym($page, $gym_id);
128
+	abstract public function getHistoryForGym($page, $gym_id);
129 129
 
130
-    // Raids
131
-    abstract public function getAllRaids($page);
130
+	// Raids
131
+	abstract public function getAllRaids($page);
132 132
 
133
-    // Trainers
134
-    abstract public function getTrainers($trainer_name, $team, $page, $ranking);
133
+	// Trainers
134
+	abstract public function getTrainers($trainer_name, $team, $page, $ranking);
135 135
 
136
-    abstract public function getTrainerLevelCount($team_id);
136
+	abstract public function getTrainerLevelCount($team_id);
137 137
 
138
-    // Cron
139
-    abstract public function getPokemonCountsActive();
138
+	// Cron
139
+	abstract public function getPokemonCountsActive();
140 140
 
141
-    abstract public function getTotalPokemonIV();
141
+	abstract public function getTotalPokemonIV();
142 142
 
143
-    abstract public function getPokemonCountsLastDay();
143
+	abstract public function getPokemonCountsLastDay();
144 144
 
145
-    abstract public function getCaptchaCount();
145
+	abstract public function getCaptchaCount();
146 146
 
147
-    abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
147
+	abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
148 148
 
149
-    abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
149
+	abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
150 150
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerMysqlMAD.php 1 patch
Indentation   +664 added lines, -664 removed lines patch added patch discarded remove patch
@@ -4,193 +4,193 @@  discard block
 block discarded – undo
4 4
 
5 5
 final class QueryManagerMysqlMAD extends QueryManagerMysql
6 6
 {
7
-    public function __construct()
8
-    {
9
-        parent::__construct();
10
-    }
11
-
12
-    public function __destruct()
13
-    {
14
-        parent::__destruct();
15
-    }
16
-
17
-    ///////////
18
-    // Tester
19
-    ///////////
20
-
21
-    public function testTotalPokemon()
22
-    {
23
-        $req = 'SELECT COUNT(*) as total FROM pokemon';
24
-        $result = $this->mysqli->query($req);
25
-        if (!is_object($result)) {
26
-            return 1;
27
-        } else {
28
-            $data = $result->fetch_object();
29
-            $total = $data->total;
30
-
31
-            if (0 == $total) {
32
-                return 2;
33
-            }
34
-        }
35
-
36
-        return 0;
37
-    }
38
-
39
-    public function testTotalGyms()
40
-    {
41
-        $req = 'SELECT COUNT(*) as total FROM gym';
42
-        $result = $this->mysqli->query($req);
43
-        if (!is_object($result)) {
44
-            return 1;
45
-        } else {
46
-            $data = $result->fetch_object();
47
-            $total = $data->total;
48
-
49
-            if (0 == $total) {
50
-                return 2;
51
-            }
52
-        }
53
-
54
-        return 0;
55
-    }
56
-
57
-    public function testTotalPokestops()
58
-    {
59
-        $req = 'SELECT COUNT(*) as total FROM pokestop';
60
-        $result = $this->mysqli->query($req);
61
-        if (!is_object($result)) {
62
-            return 1;
63
-        } else {
64
-            $data = $result->fetch_object();
65
-            $total = $data->total;
66
-
67
-            if (0 == $total) {
68
-                return 2;
69
-            }
70
-        }
71
-
72
-        return 0;
73
-    }
74
-
75
-    /////////////
76
-    // Homepage
77
-    /////////////
78
-
79
-    public function getTotalPokemon()
80
-    {
81
-        $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()';
82
-        $result = $this->mysqli->query($req);
83
-        $data = $result->fetch_object();
84
-
85
-        return $data;
86
-    }
87
-
88
-    public function getTotalLures()
89
-    {
90
-        $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()';
91
-        $result = $this->mysqli->query($req);
92
-        $data = $result->fetch_object();
93
-
94
-        return $data;
95
-    }
96
-
97
-    public function getTotalGyms()
98
-    {
99
-        $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym';
100
-        $result = $this->mysqli->query($req);
101
-        $data = $result->fetch_object();
102
-
103
-        return $data;
104
-    }
105
-
106
-    public function getTotalRaids()
107
-    {
108
-        $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()';
109
-        $result = $this->mysqli->query($req);
110
-        $data = $result->fetch_object();
111
-
112
-        return $data;
113
-    }
114
-
115
-    public function getTotalGymsForTeam($team_id)
116
-    {
117
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
118
-        $result = $this->mysqli->query($req);
119
-        $data = $result->fetch_object();
120
-
121
-        return $data;
122
-    }
123
-
124
-    public function getRecentAll()
125
-    {
126
-        $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
7
+	public function __construct()
8
+	{
9
+		parent::__construct();
10
+	}
11
+
12
+	public function __destruct()
13
+	{
14
+		parent::__destruct();
15
+	}
16
+
17
+	///////////
18
+	// Tester
19
+	///////////
20
+
21
+	public function testTotalPokemon()
22
+	{
23
+		$req = 'SELECT COUNT(*) as total FROM pokemon';
24
+		$result = $this->mysqli->query($req);
25
+		if (!is_object($result)) {
26
+			return 1;
27
+		} else {
28
+			$data = $result->fetch_object();
29
+			$total = $data->total;
30
+
31
+			if (0 == $total) {
32
+				return 2;
33
+			}
34
+		}
35
+
36
+		return 0;
37
+	}
38
+
39
+	public function testTotalGyms()
40
+	{
41
+		$req = 'SELECT COUNT(*) as total FROM gym';
42
+		$result = $this->mysqli->query($req);
43
+		if (!is_object($result)) {
44
+			return 1;
45
+		} else {
46
+			$data = $result->fetch_object();
47
+			$total = $data->total;
48
+
49
+			if (0 == $total) {
50
+				return 2;
51
+			}
52
+		}
53
+
54
+		return 0;
55
+	}
56
+
57
+	public function testTotalPokestops()
58
+	{
59
+		$req = 'SELECT COUNT(*) as total FROM pokestop';
60
+		$result = $this->mysqli->query($req);
61
+		if (!is_object($result)) {
62
+			return 1;
63
+		} else {
64
+			$data = $result->fetch_object();
65
+			$total = $data->total;
66
+
67
+			if (0 == $total) {
68
+				return 2;
69
+			}
70
+		}
71
+
72
+		return 0;
73
+	}
74
+
75
+	/////////////
76
+	// Homepage
77
+	/////////////
78
+
79
+	public function getTotalPokemon()
80
+	{
81
+		$req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()';
82
+		$result = $this->mysqli->query($req);
83
+		$data = $result->fetch_object();
84
+
85
+		return $data;
86
+	}
87
+
88
+	public function getTotalLures()
89
+	{
90
+		$req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()';
91
+		$result = $this->mysqli->query($req);
92
+		$data = $result->fetch_object();
93
+
94
+		return $data;
95
+	}
96
+
97
+	public function getTotalGyms()
98
+	{
99
+		$req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym';
100
+		$result = $this->mysqli->query($req);
101
+		$data = $result->fetch_object();
102
+
103
+		return $data;
104
+	}
105
+
106
+	public function getTotalRaids()
107
+	{
108
+		$req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()';
109
+		$result = $this->mysqli->query($req);
110
+		$data = $result->fetch_object();
111
+
112
+		return $data;
113
+	}
114
+
115
+	public function getTotalGymsForTeam($team_id)
116
+	{
117
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
118
+		$result = $this->mysqli->query($req);
119
+		$data = $result->fetch_object();
120
+
121
+		return $data;
122
+	}
123
+
124
+	public function getRecentAll()
125
+	{
126
+		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
127 127
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
128 128
 				latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
129 129
 				FROM pokemon
130 130
 				ORDER BY last_modified DESC
131 131
 				LIMIT 0,12";
132
-        $result = $this->mysqli->query($req);
133
-        $data = array();
134
-        if ($result->num_rows > 0) {
135
-            while ($row = $result->fetch_object()) {
136
-                $data[] = $row;
137
-            }
138
-        }
139
-
140
-        return $data;
141
-    }
142
-
143
-    public function getRecentMythic($mythic_pokemons)
144
-    {
145
-        $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
132
+		$result = $this->mysqli->query($req);
133
+		$data = array();
134
+		if ($result->num_rows > 0) {
135
+			while ($row = $result->fetch_object()) {
136
+				$data[] = $row;
137
+			}
138
+		}
139
+
140
+		return $data;
141
+	}
142
+
143
+	public function getRecentMythic($mythic_pokemons)
144
+	{
145
+		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
146 146
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
147 147
 				latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
148 148
 				FROM pokemon
149 149
 				WHERE pokemon_id IN (".implode(',', $mythic_pokemons).')
150 150
 				ORDER BY last_modified DESC
151 151
 				LIMIT 0,12';
152
-        $result = $this->mysqli->query($req);
153
-        $data = array();
154
-        if ($result->num_rows > 0) {
155
-            while ($row = $result->fetch_object()) {
156
-                $data[] = $row;
157
-            }
158
-        }
159
-
160
-        return $data;
161
-    }
162
-
163
-    ///////////////////
164
-    // Single Pokemon
165
-    ///////////////////
166
-
167
-    public function getGymsProtectedByPokemon($pokemon_id)
168
-    {
169
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
170
-        $result = $this->mysqli->query($req);
171
-        $data = $result->fetch_object();
172
-
173
-        return $data;
174
-    }
175
-
176
-    public function getPokemonLastSeen($pokemon_id)
177
-    {
178
-        $req = "SELECT disappear_time,
152
+		$result = $this->mysqli->query($req);
153
+		$data = array();
154
+		if ($result->num_rows > 0) {
155
+			while ($row = $result->fetch_object()) {
156
+				$data[] = $row;
157
+			}
158
+		}
159
+
160
+		return $data;
161
+	}
162
+
163
+	///////////////////
164
+	// Single Pokemon
165
+	///////////////////
166
+
167
+	public function getGymsProtectedByPokemon($pokemon_id)
168
+	{
169
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
170
+		$result = $this->mysqli->query($req);
171
+		$data = $result->fetch_object();
172
+
173
+		return $data;
174
+	}
175
+
176
+	public function getPokemonLastSeen($pokemon_id)
177
+	{
178
+		$req = "SELECT disappear_time,
179 179
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
180 180
 				latitude, longitude
181 181
 				FROM pokemon
182 182
 				WHERE pokemon_id = '".$pokemon_id."'
183 183
 				ORDER BY disappear_time DESC
184 184
 				LIMIT 0,1";
185
-        $result = $this->mysqli->query($req);
186
-        $data = $result->fetch_object();
185
+		$result = $this->mysqli->query($req);
186
+		$data = $result->fetch_object();
187 187
 
188
-        return $data;
189
-    }
188
+		return $data;
189
+	}
190 190
 
191
-    public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
192
-    {
193
-        $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime,
191
+	public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
192
+	{
193
+		$req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime,
194 194
 				pokemon_id, disappear_time, latitude, longitude,
195 195
 				cp, individual_attack, individual_defense, individual_stamina,
196 196
 				ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV,
@@ -199,235 +199,235 @@  discard block
 block discarded – undo
199 199
 				WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
200 200
 				ORDER BY $top_order_by $top_direction, disappear_time DESC
201 201
 				LIMIT 0,50";
202
-        $result = $this->mysqli->query($req);
203
-        $top = array();
204
-        while ($data = $result->fetch_object()) {
205
-            $top[] = $data;
206
-        }
207
-
208
-        return $top;
209
-    }
210
-
211
-    public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
212
-    {
213
-         return null;
214
-    }
215
-
216
-    public function getPokemonHeatmap($pokemon_id, $start, $end)
217
-    {
202
+		$result = $this->mysqli->query($req);
203
+		$top = array();
204
+		while ($data = $result->fetch_object()) {
205
+			$top[] = $data;
206
+		}
207
+
208
+		return $top;
209
+	}
210
+
211
+	public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
212
+	{
213
+		 return null;
214
+	}
215
+
216
+	public function getPokemonHeatmap($pokemon_id, $start, $end)
217
+	{
218 218
 		$req = "SELECT latitude, longitude
219 219
 				FROM pokemon
220 220
 				WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."'
221 221
 				LIMIT 10000";
222
-        $result = $this->mysqli->query($req);
223
-        $points = array();
224
-        while ($data = $result->fetch_object()) {
225
-            $points[] = $data;
226
-        }
227
-
228
-        return $points;
229
-    }
230
-
231
-    public function getPokemonGraph($pokemon_id)
232
-    {
233
-        $req = "SELECT COUNT(*) AS total,
222
+		$result = $this->mysqli->query($req);
223
+		$points = array();
224
+		while ($data = $result->fetch_object()) {
225
+			$points[] = $data;
226
+		}
227
+
228
+		return $points;
229
+	}
230
+
231
+	public function getPokemonGraph($pokemon_id)
232
+	{
233
+		$req = "SELECT COUNT(*) AS total,
234 234
 				HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
235 235
 				FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
236 236
 				GROUP BY disappear_hour
237 237
 				ORDER BY disappear_hour";
238
-        $result = $this->mysqli->query($req);
239
-        $array = array_fill(0, 24, 0);
240
-        while ($result && $data = $result->fetch_object()) {
241
-            $array[$data->disappear_hour] = $data->total;
242
-        }
243
-        // shift array because AM/PM starts at 1AM not 0:00
244
-        $array[] = $array[0];
245
-        array_shift($array);
246
-
247
-        return $array;
248
-    }
249
-
250
-    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
251
-    {
252
-        $inmap_pkms_filter = '';
253
-        $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
254
-        $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
255
-        $resultTestIv = $this->mysqli->query($reqTestIv);
256
-        $testIv = $resultTestIv->fetch_object();
257
-        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
258
-            foreach ($inmap_pokemons as $inmap) {
259
-                $inmap_pkms_filter .= "'".$inmap."',";
260
-            }
261
-            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
262
-            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
263
-        }
264
-        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
265
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
266
-        }
267
-        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
268
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
269
-        }
270
-        $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
238
+		$result = $this->mysqli->query($req);
239
+		$array = array_fill(0, 24, 0);
240
+		while ($result && $data = $result->fetch_object()) {
241
+			$array[$data->disappear_hour] = $data->total;
242
+		}
243
+		// shift array because AM/PM starts at 1AM not 0:00
244
+		$array[] = $array[0];
245
+		array_shift($array);
246
+
247
+		return $array;
248
+	}
249
+
250
+	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
251
+	{
252
+		$inmap_pkms_filter = '';
253
+		$where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
254
+		$reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
255
+		$resultTestIv = $this->mysqli->query($reqTestIv);
256
+		$testIv = $resultTestIv->fetch_object();
257
+		if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
258
+			foreach ($inmap_pokemons as $inmap) {
259
+				$inmap_pkms_filter .= "'".$inmap."',";
260
+			}
261
+			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
262
+			$where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
263
+		}
264
+		if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
265
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
266
+		}
267
+		if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
268
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
269
+		}
270
+		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
271 271
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
272 272
 				individual_attack, individual_defense, individual_stamina, move_1, move_2
273 273
 				FROM pokemon ".$where.'
274 274
 				LIMIT 5000';
275
-        $result = $this->mysqli->query($req);
276
-        $spawns = array();
277
-        while ($data = $result->fetch_object()) {
278
-            $spawns[] = $data;
279
-        }
280
-
281
-        return $spawns;
282
-    }
283
-
284
-    public function getPokemonSliderMinMax()
285
-    {
286
-        $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
287
-        $result = $this->mysqli->query($req);
288
-        $data = $result->fetch_object();
289
-
290
-        return $data;
291
-    }
292
-
293
-    public function getMapsCoords()
294
-    {
295
-        $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
275
+		$result = $this->mysqli->query($req);
276
+		$spawns = array();
277
+		while ($data = $result->fetch_object()) {
278
+			$spawns[] = $data;
279
+		}
280
+
281
+		return $spawns;
282
+	}
283
+
284
+	public function getPokemonSliderMinMax()
285
+	{
286
+		$req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
287
+		$result = $this->mysqli->query($req);
288
+		$data = $result->fetch_object();
289
+
290
+		return $data;
291
+	}
292
+
293
+	public function getMapsCoords()
294
+	{
295
+		$req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
296 296
 				MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude
297 297
 				FROM trs_spawn';
298
-        $result = $this->mysqli->query($req);
299
-        $data = $result->fetch_object();
298
+		$result = $this->mysqli->query($req);
299
+		$data = $result->fetch_object();
300 300
 
301
-        return $data;
302
-    }
301
+		return $data;
302
+	}
303 303
 
304
-    public function getPokemonCount($pokemon_id)
305
-    {
306
-        $req = 'SELECT count, last_seen, latitude, longitude
304
+	public function getPokemonCount($pokemon_id)
305
+	{
306
+		$req = 'SELECT count, last_seen, latitude, longitude
307 307
 				FROM pokemon_stats
308 308
 				WHERE pid = '.$pokemon_id;
309
-        $result = $this->mysqli->query($req);
310
-        $data = $result->fetch_object();
309
+		$result = $this->mysqli->query($req);
310
+		$data = $result->fetch_object();
311 311
 
312
-        return $data;
313
-    }
312
+		return $data;
313
+	}
314 314
 
315
-    public function getPokemonCountAll()
316
-    {
317
-        $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude
315
+	public function getPokemonCountAll()
316
+	{
317
+		$req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude
318 318
 				FROM pokemon_stats
319 319
 				GROUP BY pid';
320
-        $result = $this->mysqli->query($req);
321
-        $array = array();
322
-        while ($data = $result->fetch_object()) {
323
-            $array[] = $data;
324
-        }
325
-
326
-        return $array;
327
-    }
328
-
329
-    public function getRaidCount($pokemon_id)
330
-    {
331
-        $req = 'SELECT count, last_seen, latitude, longitude
320
+		$result = $this->mysqli->query($req);
321
+		$array = array();
322
+		while ($data = $result->fetch_object()) {
323
+			$array[] = $data;
324
+		}
325
+
326
+		return $array;
327
+	}
328
+
329
+	public function getRaidCount($pokemon_id)
330
+	{
331
+		$req = 'SELECT count, last_seen, latitude, longitude
332 332
 				FROM raid_stats
333 333
 				WHERE pid = '.$pokemon_id;
334
-        $result = $this->mysqli->query($req);
335
-        $data = $result->fetch_object();
334
+		$result = $this->mysqli->query($req);
335
+		$data = $result->fetch_object();
336 336
 
337
-        return $data;
338
-    }
337
+		return $data;
338
+	}
339 339
 
340
-    public function getRaidCountAll()
341
-    {
342
-        $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude
340
+	public function getRaidCountAll()
341
+	{
342
+		$req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude
343 343
 				FROM raid_stats
344 344
 				GROUP BY pid';
345
-        $result = $this->mysqli->query($req);
346
-        $array = array();
347
-        while ($data = $result->fetch_object()) {
348
-            $array[] = $data;
349
-        }
350
-
351
-        return $array;
352
-    }
353
-
354
-    ///////////////
355
-    // Pokestops
356
-    //////////////
357
-
358
-    public function getTotalPokestops()
359
-    {
360
-        $req = 'SELECT COUNT(*) as total FROM pokestop';
361
-        $result = $this->mysqli->query($req);
362
-        $data = $result->fetch_object();
363
-
364
-        return $data;
365
-    }
366
-
367
-    public function getAllPokestops()
368
-    {
369
-        $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
345
+		$result = $this->mysqli->query($req);
346
+		$array = array();
347
+		while ($data = $result->fetch_object()) {
348
+			$array[] = $data;
349
+		}
350
+
351
+		return $array;
352
+	}
353
+
354
+	///////////////
355
+	// Pokestops
356
+	//////////////
357
+
358
+	public function getTotalPokestops()
359
+	{
360
+		$req = 'SELECT COUNT(*) as total FROM pokestop';
361
+		$result = $this->mysqli->query($req);
362
+		$data = $result->fetch_object();
363
+
364
+		return $data;
365
+	}
366
+
367
+	public function getAllPokestops()
368
+	{
369
+		$req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
370 370
 				CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."') AS lure_expiration_real
371 371
 				FROM pokestop";
372
-        $result = $this->mysqli->query($req);
373
-        $pokestops = array();
374
-        while ($data = $result->fetch_object()) {
375
-            $pokestops[] = $data;
376
-        }
377
-
378
-        return $pokestops;
379
-    }
380
-
381
-    /////////
382
-    // Gyms
383
-    /////////
384
-
385
-    public function getTeamGuardians($team_id)
386
-    {
387
-        $req = "SELECT COUNT(*) AS total, guard_pokemon_id
372
+		$result = $this->mysqli->query($req);
373
+		$pokestops = array();
374
+		while ($data = $result->fetch_object()) {
375
+			$pokestops[] = $data;
376
+		}
377
+
378
+		return $pokestops;
379
+	}
380
+
381
+	/////////
382
+	// Gyms
383
+	/////////
384
+
385
+	public function getTeamGuardians($team_id)
386
+	{
387
+		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
388 388
 				FROM gym WHERE team_id = '".$team_id."'
389 389
 				GROUP BY guard_pokemon_id
390 390
 				ORDER BY total DESC
391 391
 				LIMIT 0,3";
392
-        $result = $this->mysqli->query($req);
393
-        $datas = array();
394
-        while ($data = $result->fetch_object()) {
395
-            $datas[] = $data;
396
-        }
397
-
398
-        return $datas;
399
-    }
400
-
401
-    public function getOwnedAndPoints($team_id)
402
-    {
403
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
392
+		$result = $this->mysqli->query($req);
393
+		$datas = array();
394
+		while ($data = $result->fetch_object()) {
395
+			$datas[] = $data;
396
+		}
397
+
398
+		return $datas;
399
+	}
400
+
401
+	public function getOwnedAndPoints($team_id)
402
+	{
403
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
404 404
 				ROUND(AVG(total_cp),0) AS average_points
405 405
 				FROM gym
406 406
 				WHERE team_id = '".$team_id."'";
407
-        $result = $this->mysqli->query($req);
408
-        $data = $result->fetch_object();
407
+		$result = $this->mysqli->query($req);
408
+		$data = $result->fetch_object();
409 409
 
410
-        return $data;
411
-    }
410
+		return $data;
411
+	}
412 412
 
413
-    public function getAllGyms()
414
-    {
415
-        $req = "SELECT gym_id, team_id, latitude, longitude,
413
+	public function getAllGyms()
414
+	{
415
+		$req = "SELECT gym_id, team_id, latitude, longitude,
416 416
 				CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
417 417
 				(6 - slots_available) AS level
418 418
 				FROM gym";
419
-        $result = $this->mysqli->query($req);
420
-        $gyms = array();
421
-        while ($data = $result->fetch_object()) {
422
-            $gyms[] = $data;
423
-        }
424
-
425
-        return $gyms;
426
-    }
427
-
428
-    public function getGymData($gym_id)
429
-    {
430
-        $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
419
+		$result = $this->mysqli->query($req);
420
+		$gyms = array();
421
+		while ($data = $result->fetch_object()) {
422
+			$gyms[] = $data;
423
+		}
424
+
425
+		return $gyms;
426
+	}
427
+
428
+	public function getGymData($gym_id)
429
+	{
430
+		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
431 431
 				CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
432 432
 				gym.guard_pokemon_id AS guard_pokemon_id,
433 433
 				gym.total_cp AS total_cp,
@@ -435,53 +435,53 @@  discard block
 block discarded – undo
435 435
 				FROM gymdetails
436 436
 				LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
437 437
 				WHERE gym.gym_id='".$gym_id."'";
438
-        $result = $this->mysqli->query($req);
439
-        $data = $result->fetch_object();
438
+		$result = $this->mysqli->query($req);
439
+		$data = $result->fetch_object();
440 440
 
441
-        return $data;
442
-    }
441
+		return $data;
442
+	}
443 443
 
444
-    public function getGymDefenders($gym_id)
445
-    {
446
-        $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
444
+	public function getGymDefenders($gym_id)
445
+	{
446
+		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
447 447
 				FROM gympokemon
448 448
 				INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
449 449
 				GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
450 450
 				HAVING gymmember.gym_id='".$gym_id."'
451 451
 				ORDER BY cp DESC";
452
-        $result = $this->mysqli->query($req);
453
-        $defenders = array();
454
-        while ($data = $result->fetch_object()) {
455
-            $defenders[] = $data;
456
-        }
457
-
458
-        return $defenders;
459
-    }
460
-
461
-    ////////////////
462
-    // Gym History
463
-    ////////////////
464
-
465
-    public function getGymHistories($gym_name, $team, $page, $ranking)
466
-    {
467
-        $where = '';
468
-        if (isset($gym_name) && '' != $gym_name) {
469
-            $where = " WHERE name LIKE '%".$gym_name."%'";
470
-        }
471
-        if (isset($team) && '' != $team) {
472
-            $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
473
-        }
474
-        switch ($ranking) {
475
-            case 1:
476
-                $order = ' ORDER BY name, last_modified DESC';
477
-                break;
478
-            case 2:
479
-                $order = ' ORDER BY total_cp DESC, last_modified DESC';
480
-                break;
481
-            default:
482
-                $order = ' ORDER BY last_modified DESC, name';
483
-        }
484
-        $req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
452
+		$result = $this->mysqli->query($req);
453
+		$defenders = array();
454
+		while ($data = $result->fetch_object()) {
455
+			$defenders[] = $data;
456
+		}
457
+
458
+		return $defenders;
459
+	}
460
+
461
+	////////////////
462
+	// Gym History
463
+	////////////////
464
+
465
+	public function getGymHistories($gym_name, $team, $page, $ranking)
466
+	{
467
+		$where = '';
468
+		if (isset($gym_name) && '' != $gym_name) {
469
+			$where = " WHERE name LIKE '%".$gym_name."%'";
470
+		}
471
+		if (isset($team) && '' != $team) {
472
+			$where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
473
+		}
474
+		switch ($ranking) {
475
+			case 1:
476
+				$order = ' ORDER BY name, last_modified DESC';
477
+				break;
478
+			case 2:
479
+				$order = ' ORDER BY total_cp DESC, last_modified DESC';
480
+				break;
481
+			default:
482
+				$order = ' ORDER BY last_modified DESC, name';
483
+		}
484
+		$req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
485 485
 				(6 - slots_available) as pokemon_count,
486 486
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
487 487
 				FROM gymdetails
@@ -489,93 +489,93 @@  discard block
 block discarded – undo
489 489
 				ON gymdetails.gym_id = gym.gym_id
490 490
 				".$where.$order."
491 491
 				LIMIT ".($page * 10).",10";
492
-        $result = $this->mysqli->query($req);
493
-        $gym_history = array();
494
-        while ($data = $result->fetch_object()) {
495
-            $gym_history[] = $data;
496
-        }
497
-
498
-        return $gym_history;
499
-    }
500
-
501
-    public function getGymHistoriesPokemon($gym_id)
502
-    {
503
-        $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
492
+		$result = $this->mysqli->query($req);
493
+		$gym_history = array();
494
+		while ($data = $result->fetch_object()) {
495
+			$gym_history[] = $data;
496
+		}
497
+
498
+		return $gym_history;
499
+	}
500
+
501
+	public function getGymHistoriesPokemon($gym_id)
502
+	{
503
+		$req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
504 504
 				FROM gymmember
505 505
 				LEFT JOIN gympokemon
506 506
 				ON gymmember.pokemon_uid = gympokemon.pokemon_uid
507 507
 				WHERE gymmember.gym_id = '".$gym_id."'
508 508
 				ORDER BY deployment_time";
509
-        $result = $this->mysqli->query($req);
510
-        $pokemons = array();
511
-        while ($data = $result->fetch_object()) {
512
-            $pokemons[] = $data;
513
-        }
514
-
515
-        return $pokemons;
516
-    }
517
-
518
-    public function getHistoryForGym($page, $gym_id)
519
-    {
520
-        if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
521
-            $pageSize = 25;
522
-        } else {
523
-            $pageSize = 10;
524
-        }
525
-        $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
509
+		$result = $this->mysqli->query($req);
510
+		$pokemons = array();
511
+		while ($data = $result->fetch_object()) {
512
+			$pokemons[] = $data;
513
+		}
514
+
515
+		return $pokemons;
516
+	}
517
+
518
+	public function getHistoryForGym($page, $gym_id)
519
+	{
520
+		if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
521
+			$pageSize = 25;
522
+		} else {
523
+			$pageSize = 10;
524
+		}
525
+		$req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
526 526
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
527 527
 				FROM gymhistory
528 528
 				WHERE gym_id='".$gym_id."'
529 529
 				ORDER BY last_modified DESC
530 530
 				LIMIT ".($page * $pageSize).','.($pageSize + 1);
531
-        $result = $this->mysqli->query($req);
532
-        $history = array();
533
-        $count = 0;
534
-        while ($data = $result->fetch_object()) {
535
-            ++$count;
536
-            $pkm = array();
537
-            if (0 == $data->total_cp) {
538
-                $data->pokemon_uids = '';
539
-                $data->pokemon_count = 0;
540
-            }
541
-            if ('' != $data->pokemon_uids) {
542
-                $pkm_uids = explode(',', $data->pokemon_uids);
543
-                $pkm = $this->getHistoryForGymPokemon($pkm_uids);
544
-            }
545
-            $data->pokemon = $pkm;
546
-            $history[] = $data;
547
-        }
548
-        if ($count !== ($pageSize + 1)) {
549
-            $last_page = true;
550
-        } else {
551
-            $last_page = false;
552
-        }
553
-
554
-        return array('last_page' => $last_page, 'data' => $history);
555
-    }
556
-
557
-    private function getHistoryForGymPokemon($pkm_uids)
558
-    {
559
-        $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
531
+		$result = $this->mysqli->query($req);
532
+		$history = array();
533
+		$count = 0;
534
+		while ($data = $result->fetch_object()) {
535
+			++$count;
536
+			$pkm = array();
537
+			if (0 == $data->total_cp) {
538
+				$data->pokemon_uids = '';
539
+				$data->pokemon_count = 0;
540
+			}
541
+			if ('' != $data->pokemon_uids) {
542
+				$pkm_uids = explode(',', $data->pokemon_uids);
543
+				$pkm = $this->getHistoryForGymPokemon($pkm_uids);
544
+			}
545
+			$data->pokemon = $pkm;
546
+			$history[] = $data;
547
+		}
548
+		if ($count !== ($pageSize + 1)) {
549
+			$last_page = true;
550
+		} else {
551
+			$last_page = false;
552
+		}
553
+
554
+		return array('last_page' => $last_page, 'data' => $history);
555
+	}
556
+
557
+	private function getHistoryForGymPokemon($pkm_uids)
558
+	{
559
+		$req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
560 560
 				FROM gympokemon
561 561
 				WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."')
562 562
 				ORDER BY FIND_IN_SET(pokemon_uid, '".implode(',', $pkm_uids)."')";
563
-        $result = $this->mysqli->query($req);
564
-        $pokemons = array();
565
-        while ($data = $result->fetch_object()) {
566
-            $pokemons[$data->pokemon_uid] = $data;
567
-        }
568
-
569
-        return $pokemons;
570
-    }
571
-
572
-    ///////////
573
-    // Raids
574
-    ///////////
575
-
576
-    public function getAllRaids($page)
577
-    {
578
-        $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
563
+		$result = $this->mysqli->query($req);
564
+		$pokemons = array();
565
+		while ($data = $result->fetch_object()) {
566
+			$pokemons[$data->pokemon_uid] = $data;
567
+		}
568
+
569
+		return $pokemons;
570
+	}
571
+
572
+	///////////
573
+	// Raids
574
+	///////////
575
+
576
+	public function getAllRaids($page)
577
+	{
578
+		$req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
579 579
 				CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn,
580 580
 				CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start,
581 581
 				CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end,
@@ -587,121 +587,121 @@  discard block
 block discarded – undo
587 587
 				WHERE raid.end > UTC_TIMESTAMP()
588 588
 				ORDER BY raid.level DESC, raid.start
589 589
 				LIMIT ".($page * 10).",10";
590
-        $result = $this->mysqli->query($req);
591
-        $raids = array();
592
-        while ($data = $result->fetch_object()) {
593
-            $raids[] = $data;
594
-        }
595
-
596
-        return $raids;
597
-    }
598
-
599
-    //////////////
600
-    // Trainers
601
-    //////////////
602
-
603
-    public function getTrainers($trainer_name, $team, $page, $ranking)
604
-    {
605
-        $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
606
-        foreach ($trainers as $trainer) {
607
-            $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
608
-            $active_gyms = 0;
609
-            $pkmCount = 0;
610
-            $trainer->pokemons = array();
611
-            $active_pokemon = $this->getTrainerActivePokemon($trainer->name);
612
-            foreach ($active_pokemon as $pokemon) {
613
-                ++$active_gyms;
614
-                $trainer->pokemons[$pkmCount++] = $pokemon;
615
-            }
616
-            $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
617
-            foreach ($inactive_pokemon as $pokemon) {
618
-                $trainer->pokemons[$pkmCount++] = $pokemon;
619
-            }
620
-            $trainer->gyms = ''.$active_gyms;
621
-        }
622
-
623
-        return $trainers;
624
-    }
625
-
626
-    public function getTrainerLevelCount($team_id)
627
-    {
628
-        $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
629
-        if (!empty(self::$config->system->trainer_blacklist)) {
630
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
631
-        }
632
-        $req .= ' GROUP BY level';
633
-        $result = $this->mysqli->query($req);
634
-        $levelData = array();
635
-        while ($data = $result->fetch_object()) {
636
-            $levelData[$data->level] = $data->count;
637
-        }
638
-        for ($i = 5; $i <= 40; ++$i) {
639
-            if (!isset($levelData[$i])) {
640
-                $levelData[$i] = 0;
641
-            }
642
-        }
643
-        // sort array again
644
-        ksort($levelData);
645
-
646
-        return $levelData;
647
-    }
648
-
649
-    private function getTrainerData($trainer_name, $team, $page, $ranking)
650
-    {
651
-        $where = '';
652
-        if (!empty(self::$config->system->trainer_blacklist)) {
653
-            $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
654
-        }
655
-        if ('' != $trainer_name) {
656
-            $where = " HAVING name LIKE '%".$trainer_name."%'";
657
-        }
658
-        if (0 != $team) {
659
-            $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
660
-        }
661
-        switch ($ranking) {
662
-            case 1:
663
-                $order = ' ORDER BY active DESC, level DESC';
664
-                break;
665
-            case 2:
666
-                $order = ' ORDER BY maxCp DESC, level DESC';
667
-                break;
668
-            default:
669
-                $order = ' ORDER BY level DESC, active DESC';
670
-        }
671
-        $order .= ', last_seen DESC, name ';
672
-        $limit = ' LIMIT '.($page * 10).',10 ';
673
-        $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
590
+		$result = $this->mysqli->query($req);
591
+		$raids = array();
592
+		while ($data = $result->fetch_object()) {
593
+			$raids[] = $data;
594
+		}
595
+
596
+		return $raids;
597
+	}
598
+
599
+	//////////////
600
+	// Trainers
601
+	//////////////
602
+
603
+	public function getTrainers($trainer_name, $team, $page, $ranking)
604
+	{
605
+		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
606
+		foreach ($trainers as $trainer) {
607
+			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
608
+			$active_gyms = 0;
609
+			$pkmCount = 0;
610
+			$trainer->pokemons = array();
611
+			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
612
+			foreach ($active_pokemon as $pokemon) {
613
+				++$active_gyms;
614
+				$trainer->pokemons[$pkmCount++] = $pokemon;
615
+			}
616
+			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
617
+			foreach ($inactive_pokemon as $pokemon) {
618
+				$trainer->pokemons[$pkmCount++] = $pokemon;
619
+			}
620
+			$trainer->gyms = ''.$active_gyms;
621
+		}
622
+
623
+		return $trainers;
624
+	}
625
+
626
+	public function getTrainerLevelCount($team_id)
627
+	{
628
+		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
629
+		if (!empty(self::$config->system->trainer_blacklist)) {
630
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
631
+		}
632
+		$req .= ' GROUP BY level';
633
+		$result = $this->mysqli->query($req);
634
+		$levelData = array();
635
+		while ($data = $result->fetch_object()) {
636
+			$levelData[$data->level] = $data->count;
637
+		}
638
+		for ($i = 5; $i <= 40; ++$i) {
639
+			if (!isset($levelData[$i])) {
640
+				$levelData[$i] = 0;
641
+			}
642
+		}
643
+		// sort array again
644
+		ksort($levelData);
645
+
646
+		return $levelData;
647
+	}
648
+
649
+	private function getTrainerData($trainer_name, $team, $page, $ranking)
650
+	{
651
+		$where = '';
652
+		if (!empty(self::$config->system->trainer_blacklist)) {
653
+			$where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
654
+		}
655
+		if ('' != $trainer_name) {
656
+			$where = " HAVING name LIKE '%".$trainer_name."%'";
657
+		}
658
+		if (0 != $team) {
659
+			$where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
660
+		}
661
+		switch ($ranking) {
662
+			case 1:
663
+				$order = ' ORDER BY active DESC, level DESC';
664
+				break;
665
+			case 2:
666
+				$order = ' ORDER BY maxCp DESC, level DESC';
667
+				break;
668
+			default:
669
+				$order = ' ORDER BY level DESC, active DESC';
670
+		}
671
+		$order .= ', last_seen DESC, name ';
672
+		$limit = ' LIMIT '.($page * 10).',10 ';
673
+		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
674 674
 				FROM trainer
675 675
 				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
676 676
 				FROM gympokemon
677 677
 				INNER JOIN (SELECT gymmember.pokemon_uid, gymmember.gym_id FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
678 678
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
679 679
 				GROUP BY trainer.name ".$where.$order.$limit;
680
-        $result = $this->mysqli->query($req);
681
-        $trainers = array();
682
-        while ($data = $result->fetch_object()) {
683
-            $data->last_seen = date('Y-m-d', strtotime($data->last_seen));
684
-            $trainers[$data->name] = $data;
685
-        }
686
-
687
-        return $trainers;
688
-    }
689
-
690
-    private function getTrainerLevelRating($level)
691
-    {
692
-        $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
693
-        if (!empty(self::$config->system->trainer_blacklist)) {
694
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
695
-        }
696
-        $result = $this->mysqli->query($req);
697
-        $data = $result->fetch_object();
698
-
699
-        return $data;
700
-    }
701
-
702
-    private function getTrainerActivePokemon($trainer_name)
703
-    {
704
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
680
+		$result = $this->mysqli->query($req);
681
+		$trainers = array();
682
+		while ($data = $result->fetch_object()) {
683
+			$data->last_seen = date('Y-m-d', strtotime($data->last_seen));
684
+			$trainers[$data->name] = $data;
685
+		}
686
+
687
+		return $trainers;
688
+	}
689
+
690
+	private function getTrainerLevelRating($level)
691
+	{
692
+		$req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
693
+		if (!empty(self::$config->system->trainer_blacklist)) {
694
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
695
+		}
696
+		$result = $this->mysqli->query($req);
697
+		$data = $result->fetch_object();
698
+
699
+		return $data;
700
+	}
701
+
702
+	private function getTrainerActivePokemon($trainer_name)
703
+	{
704
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
705 705
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
706 706
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
707 707
 				filtered_gymmember.gym_id,
@@ -712,18 +712,18 @@  discard block
 block discarded – undo
712 712
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
713 713
 				WHERE gympokemon.trainer_name='".$trainer_name."'
714 714
 				ORDER BY gympokemon.cp DESC";
715
-        $result = $this->mysqli->query($req);
716
-        $pokemons = array();
717
-        while ($data = $result->fetch_object()) {
718
-            $pokemons[] = $data;
719
-        }
720
-
721
-        return $pokemons;
722
-    }
723
-
724
-    private function getTrainerInactivePokemon($trainer_name)
725
-    {
726
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
715
+		$result = $this->mysqli->query($req);
716
+		$pokemons = array();
717
+		while ($data = $result->fetch_object()) {
718
+			$pokemons[] = $data;
719
+		}
720
+
721
+		return $pokemons;
722
+	}
723
+
724
+	private function getTrainerInactivePokemon($trainer_name)
725
+	{
726
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
727 727
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
728 728
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
729 729
 				null AS gym_id,
@@ -734,78 +734,78 @@  discard block
 block discarded – undo
734 734
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
735 735
 				WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
736 736
 				ORDER BY gympokemon.cp DESC";
737
-        $result = $this->mysqli->query($req);
738
-        $pokemons = array();
739
-        while ($data = $result->fetch_object()) {
740
-            $pokemons[] = $data;
741
-        }
742
-
743
-        return $pokemons;
744
-    }
745
-
746
-    /////////
747
-    // Cron
748
-    /////////
749
-
750
-    public function getPokemonCountsActive()
751
-    {
752
-        $req = 'SELECT pokemon_id, COUNT(*) as total
737
+		$result = $this->mysqli->query($req);
738
+		$pokemons = array();
739
+		while ($data = $result->fetch_object()) {
740
+			$pokemons[] = $data;
741
+		}
742
+
743
+		return $pokemons;
744
+	}
745
+
746
+	/////////
747
+	// Cron
748
+	/////////
749
+
750
+	public function getPokemonCountsActive()
751
+	{
752
+		$req = 'SELECT pokemon_id, COUNT(*) as total
753 753
 				FROM pokemon
754 754
 				WHERE disappear_time >= UTC_TIMESTAMP()
755 755
 				GROUP BY pokemon_id';
756
-        $result = $this->mysqli->query($req);
757
-        $counts = array();
758
-        while ($data = $result->fetch_object()) {
759
-            $counts[$data->pokemon_id] = $data->total;
760
-        }
756
+		$result = $this->mysqli->query($req);
757
+		$counts = array();
758
+		while ($data = $result->fetch_object()) {
759
+			$counts[$data->pokemon_id] = $data->total;
760
+		}
761 761
 
762
-        return $counts;
763
-    }
762
+		return $counts;
763
+	}
764 764
 
765 765
 
766
-    public function getTotalPokemonIV()
767
-    {
768
-        $req = 'SELECT COUNT(*) as total
766
+	public function getTotalPokemonIV()
767
+	{
768
+		$req = 'SELECT COUNT(*) as total
769 769
 				FROM pokemon
770 770
 				WHERE disappear_time >= UTC_TIMESTAMP() AND cp IS NOT NULL';
771
-        $result = $this->mysqli->query($req);
772
-        $data = $result->fetch_object();
771
+		$result = $this->mysqli->query($req);
772
+		$data = $result->fetch_object();
773 773
 
774
-        return $data;
775
-    }
774
+		return $data;
775
+	}
776 776
 
777
-    public function getPokemonCountsLastDay()
778
-    {
779
-        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
777
+	public function getPokemonCountsLastDay()
778
+	{
779
+		$req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
780 780
 				FROM pokemon
781 781
 				WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
782 782
 				GROUP BY pokemon_id
783 783
 				ORDER BY pokemon_id ASC';
784
-        $result = $this->mysqli->query($req);
785
-        $counts = array();
786
-        while ($data = $result->fetch_object()) {
787
-            $counts[$data->pokemon_id] = $data->spawns_last_day;
788
-        }
789
-
790
-        return $counts;
791
-    }
792
-
793
-    public function getCaptchaCount()
794
-    {
795
-        $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
796
-        $result = $this->mysqli->query($req);
797
-        $data = $result->fetch_object();
798
-
799
-        return $data;
800
-    }
801
-
802
-    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
803
-    {
804
-        $pokemon_exclude_sql = '';
805
-        if (!empty(self::$config->system->nest_exclude_pokemon)) {
806
-            $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
807
-        }
808
-        $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
784
+		$result = $this->mysqli->query($req);
785
+		$counts = array();
786
+		while ($data = $result->fetch_object()) {
787
+			$counts[$data->pokemon_id] = $data->spawns_last_day;
788
+		}
789
+
790
+		return $counts;
791
+	}
792
+
793
+	public function getCaptchaCount()
794
+	{
795
+		$req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
796
+		$result = $this->mysqli->query($req);
797
+		$data = $result->fetch_object();
798
+
799
+		return $data;
800
+	}
801
+
802
+	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
803
+	{
804
+		$pokemon_exclude_sql = '';
805
+		if (!empty(self::$config->system->nest_exclude_pokemon)) {
806
+			$pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
807
+		}
808
+		$req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
809 809
 				MAX(UNIX_TIMESTAMP(disappear_time)) as latest_seen
810 810
 				FROM pokemon
811 811
 				WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL '.$time.' HOUR)
@@ -814,23 +814,23 @@  discard block
 block discarded – undo
814 814
 				GROUP BY spawnpoint_id, pokemon_id 
815 815
 				HAVING COUNT(pokemon_id) >= '.($time / 4).'
816 816
 				ORDER BY pokemon_id';
817
-        $result = $this->mysqli->query($req);
818
-        $nests = array();
819
-        while ($data = $result->fetch_object()) {
820
-            $nests[] = $data;
821
-        }
822
-
823
-        return $nests;
824
-    }
825
-
826
-    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
827
-    {
828
-        $req = 'SELECT COUNT(*) as total 
817
+		$result = $this->mysqli->query($req);
818
+		$nests = array();
819
+		while ($data = $result->fetch_object()) {
820
+			$nests[] = $data;
821
+		}
822
+
823
+		return $nests;
824
+	}
825
+
826
+	public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
827
+	{
828
+		$req = 'SELECT COUNT(*) as total 
829 829
 				FROM trs_spawn
830 830
 				WHERE latitude >= '.$minLatitude.' AND latitude < '.$maxLatitude.' AND longitude >= '.$minLongitude.' AND longitude < '.$maxLongitude;
831
-        $result = $this->mysqli->query($req);
832
-        $data = $result->fetch_object();
831
+		$result = $this->mysqli->query($req);
832
+		$data = $result->fetch_object();
833 833
 
834
-        return $data;
835
-    }
834
+		return $data;
835
+	}
836 836
 }
Please login to merge, or discard this patch.