Failed Conditions
Pull Request — master (#371)
by
unknown
02:27
created
core/process/queries/QueryManagerPostgresql.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 abstract class QueryManagerPostgresql extends QueryManager
8 8
 {
9
-    protected $db;
10
-
11
-    protected function __construct()
12
-    {
13
-        $this->db = pg_connect('host='.SYS_DB_HOST.' port='.SYS_DB_PORT.' dbname='.SYS_DB_NAME.' user='.SYS_DB_USER.' password='.SYS_DB_PSWD);
14
-
15
-        if (false === $this->db) {
16
-            header('Location:'.HOST_URL.'offline.html');
17
-            exit();
18
-        }
19
-    }
20
-
21
-    public function __destruct()
22
-    {
23
-        pg_close($this->db);
24
-    }
25
-
26
-    /////////
27
-    // Misc
28
-    /////////
29
-
30
-    public function getEcapedString($string)
31
-    {
32
-        return pg_escape_string($this->db, $string);
33
-    }
9
+	protected $db;
10
+
11
+	protected function __construct()
12
+	{
13
+		$this->db = pg_connect('host='.SYS_DB_HOST.' port='.SYS_DB_PORT.' dbname='.SYS_DB_NAME.' user='.SYS_DB_USER.' password='.SYS_DB_PSWD);
14
+
15
+		if (false === $this->db) {
16
+			header('Location:'.HOST_URL.'offline.html');
17
+			exit();
18
+		}
19
+	}
20
+
21
+	public function __destruct()
22
+	{
23
+		pg_close($this->db);
24
+	}
25
+
26
+	/////////
27
+	// Misc
28
+	/////////
29
+
30
+	public function getEcapedString($string)
31
+	{
32
+		return pg_escape_string($this->db, $string);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerMysqlRocketmap.php 1 patch
Indentation   +641 added lines, -641 removed lines patch added patch discarded remove patch
@@ -4,193 +4,193 @@  discard block
 block discarded – undo
4 4
 
5 5
 final class QueryManagerMysqlRocketmap 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,22 +199,22 @@  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
-        $trainer_blacklist = '';
214
-        if (!empty(self::$config->system->trainer_blacklist)) {
215
-            $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
216
-        }
217
-        $req = "SELECT trainer_name,
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
+		$trainer_blacklist = '';
214
+		if (!empty(self::$config->system->trainer_blacklist)) {
215
+			$trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
216
+		}
217
+		$req = "SELECT trainer_name,
218 218
 				ROUND((100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV,
219 219
 				move_1, move_2, cp,
220 220
 				DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
@@ -222,202 +222,202 @@  discard block
 block discarded – undo
222 222
 				WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
223 223
 				ORDER BY $best_order_by $best_direction, trainer_name ASC
224 224
 				LIMIT 0,50";
225
-        $result = $this->mysqli->query($req);
226
-        $toptrainer = array();
227
-        while ($data = $result->fetch_object()) {
228
-            $toptrainer[] = $data;
229
-        }
225
+		$result = $this->mysqli->query($req);
226
+		$toptrainer = array();
227
+		while ($data = $result->fetch_object()) {
228
+			$toptrainer[] = $data;
229
+		}
230 230
 
231
-        return $toptrainer;
232
-    }
231
+		return $toptrainer;
232
+	}
233 233
 
234
-    public function getPokemonHeatmap($pokemon_id, $start, $end)
235
-    {
234
+	public function getPokemonHeatmap($pokemon_id, $start, $end)
235
+	{
236 236
 		$req = "SELECT latitude, longitude
237 237
 				FROM pokemon
238 238
 				WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."'
239 239
 				LIMIT 10000";
240
-        $result = $this->mysqli->query($req);
241
-        $points = array();
242
-        while ($data = $result->fetch_object()) {
243
-            $points[] = $data;
244
-        }
245
-
246
-        return $points;
247
-    }
248
-
249
-    public function getPokemonGraph($pokemon_id)
250
-    {
251
-        $req = "SELECT COUNT(*) AS total,
240
+		$result = $this->mysqli->query($req);
241
+		$points = array();
242
+		while ($data = $result->fetch_object()) {
243
+			$points[] = $data;
244
+		}
245
+
246
+		return $points;
247
+	}
248
+
249
+	public function getPokemonGraph($pokemon_id)
250
+	{
251
+		$req = "SELECT COUNT(*) AS total,
252 252
 				HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
253 253
 				FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
254 254
 				GROUP BY disappear_hour
255 255
 				ORDER BY disappear_hour";
256
-        $result = $this->mysqli->query($req);
257
-        $array = array_fill(0, 24, 0);
258
-        while ($result && $data = $result->fetch_object()) {
259
-            $array[$data->disappear_hour] = $data->total;
260
-        }
261
-        // shift array because AM/PM starts at 1AM not 0:00
262
-        $array[] = $array[0];
263
-        array_shift($array);
264
-
265
-        return $array;
266
-    }
267
-
268
-    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
269
-    {
270
-        $inmap_pkms_filter = '';
271
-        $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
272
-        $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
273
-        $resultTestIv = $this->mysqli->query($reqTestIv);
274
-        $testIv = $resultTestIv->fetch_object();
275
-        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
276
-            foreach ($inmap_pokemons as $inmap) {
277
-                $inmap_pkms_filter .= "'".$inmap."',";
278
-            }
279
-            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
280
-            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
281
-        }
282
-        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
283
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
284
-        }
285
-        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
286
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
287
-        }
288
-        $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
256
+		$result = $this->mysqli->query($req);
257
+		$array = array_fill(0, 24, 0);
258
+		while ($result && $data = $result->fetch_object()) {
259
+			$array[$data->disappear_hour] = $data->total;
260
+		}
261
+		// shift array because AM/PM starts at 1AM not 0:00
262
+		$array[] = $array[0];
263
+		array_shift($array);
264
+
265
+		return $array;
266
+	}
267
+
268
+	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
269
+	{
270
+		$inmap_pkms_filter = '';
271
+		$where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
272
+		$reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
273
+		$resultTestIv = $this->mysqli->query($reqTestIv);
274
+		$testIv = $resultTestIv->fetch_object();
275
+		if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
276
+			foreach ($inmap_pokemons as $inmap) {
277
+				$inmap_pkms_filter .= "'".$inmap."',";
278
+			}
279
+			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
280
+			$where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
281
+		}
282
+		if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
283
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
284
+		}
285
+		if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
286
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
287
+		}
288
+		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
289 289
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
290 290
 				individual_attack, individual_defense, individual_stamina, move_1, move_2
291 291
 				FROM pokemon ".$where.'
292 292
 				LIMIT 5000';
293
-        $result = $this->mysqli->query($req);
294
-        $spawns = array();
295
-        while ($data = $result->fetch_object()) {
296
-            $spawns[] = $data;
297
-        }
298
-
299
-        return $spawns;
300
-    }
301
-
302
-    public function getPokemonSliderMinMax()
303
-    {
304
-        $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
305
-        $result = $this->mysqli->query($req);
306
-        $data = $result->fetch_object();
307
-
308
-        return $data;
309
-    }
310
-
311
-    public function getMapsCoords()
312
-    {
313
-        $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
293
+		$result = $this->mysqli->query($req);
294
+		$spawns = array();
295
+		while ($data = $result->fetch_object()) {
296
+			$spawns[] = $data;
297
+		}
298
+
299
+		return $spawns;
300
+	}
301
+
302
+	public function getPokemonSliderMinMax()
303
+	{
304
+		$req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
305
+		$result = $this->mysqli->query($req);
306
+		$data = $result->fetch_object();
307
+
308
+		return $data;
309
+	}
310
+
311
+	public function getMapsCoords()
312
+	{
313
+		$req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
314 314
 				MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude
315 315
 				FROM spawnpoint';
316
-        $result = $this->mysqli->query($req);
317
-        $data = $result->fetch_object();
316
+		$result = $this->mysqli->query($req);
317
+		$data = $result->fetch_object();
318 318
 
319
-        return $data;
320
-    }
319
+		return $data;
320
+	}
321 321
 
322
-    public function getPokemonCount($pokemon_id)
323
-    {
324
-        $req = 'SELECT count, last_seen, latitude, longitude
322
+	public function getPokemonCount($pokemon_id)
323
+	{
324
+		$req = 'SELECT count, last_seen, latitude, longitude
325 325
 				FROM pokemon_stats
326 326
 				WHERE pid = '.$pokemon_id;
327
-        $result = $this->mysqli->query($req);
328
-        $data = $result->fetch_object();
327
+		$result = $this->mysqli->query($req);
328
+		$data = $result->fetch_object();
329 329
 
330
-        return $data;
331
-    }
330
+		return $data;
331
+	}
332 332
 
333
-    public function getRaidCount($pokemon_id)
334
-    {
335
-        $req = 'SELECT count, last_seen, latitude, longitude
333
+	public function getRaidCount($pokemon_id)
334
+	{
335
+		$req = 'SELECT count, last_seen, latitude, longitude
336 336
 				FROM raid_stats
337 337
 				WHERE pid = '.$pokemon_id;
338
-        $result = $this->mysqli->query($req);
339
-        $data = $result->fetch_object();
338
+		$result = $this->mysqli->query($req);
339
+		$data = $result->fetch_object();
340 340
 
341
-        return $data;
342
-    }
341
+		return $data;
342
+	}
343 343
 
344
-    ///////////////
345
-    // Pokestops
346
-    //////////////
344
+	///////////////
345
+	// Pokestops
346
+	//////////////
347 347
 
348
-    public function getTotalPokestops()
349
-    {
350
-        $req = 'SELECT COUNT(*) as total FROM pokestop';
351
-        $result = $this->mysqli->query($req);
352
-        $data = $result->fetch_object();
348
+	public function getTotalPokestops()
349
+	{
350
+		$req = 'SELECT COUNT(*) as total FROM pokestop';
351
+		$result = $this->mysqli->query($req);
352
+		$data = $result->fetch_object();
353 353
 
354
-        return $data;
355
-    }
354
+		return $data;
355
+	}
356 356
 
357
-    public function getAllPokestops()
358
-    {
359
-        $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
357
+	public function getAllPokestops()
358
+	{
359
+		$req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
360 360
 				CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."') AS lure_expiration_real
361 361
 				FROM pokestop";
362
-        $result = $this->mysqli->query($req);
363
-        $pokestops = array();
364
-        while ($data = $result->fetch_object()) {
365
-            $pokestops[] = $data;
366
-        }
367
-
368
-        return $pokestops;
369
-    }
370
-
371
-    /////////
372
-    // Gyms
373
-    /////////
374
-
375
-    public function getTeamGuardians($team_id)
376
-    {
377
-        $req = "SELECT COUNT(*) AS total, guard_pokemon_id
362
+		$result = $this->mysqli->query($req);
363
+		$pokestops = array();
364
+		while ($data = $result->fetch_object()) {
365
+			$pokestops[] = $data;
366
+		}
367
+
368
+		return $pokestops;
369
+	}
370
+
371
+	/////////
372
+	// Gyms
373
+	/////////
374
+
375
+	public function getTeamGuardians($team_id)
376
+	{
377
+		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
378 378
 				FROM gym WHERE team_id = '".$team_id."'
379 379
 				GROUP BY guard_pokemon_id
380 380
 				ORDER BY total DESC
381 381
 				LIMIT 0,3";
382
-        $result = $this->mysqli->query($req);
383
-        $datas = array();
384
-        while ($data = $result->fetch_object()) {
385
-            $datas[] = $data;
386
-        }
387
-
388
-        return $datas;
389
-    }
390
-
391
-    public function getOwnedAndPoints($team_id)
392
-    {
393
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
382
+		$result = $this->mysqli->query($req);
383
+		$datas = array();
384
+		while ($data = $result->fetch_object()) {
385
+			$datas[] = $data;
386
+		}
387
+
388
+		return $datas;
389
+	}
390
+
391
+	public function getOwnedAndPoints($team_id)
392
+	{
393
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
394 394
 				ROUND(AVG(total_cp),0) AS average_points
395 395
 				FROM gym
396 396
 				WHERE team_id = '".$team_id."'";
397
-        $result = $this->mysqli->query($req);
398
-        $data = $result->fetch_object();
397
+		$result = $this->mysqli->query($req);
398
+		$data = $result->fetch_object();
399 399
 
400
-        return $data;
401
-    }
400
+		return $data;
401
+	}
402 402
 
403
-    public function getAllGyms()
404
-    {
405
-        $req = "SELECT gym_id, team_id, latitude, longitude,
403
+	public function getAllGyms()
404
+	{
405
+		$req = "SELECT gym_id, team_id, latitude, longitude,
406 406
 				CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
407 407
 				(6 - slots_available) AS level
408 408
 				FROM gym";
409
-        $result = $this->mysqli->query($req);
410
-        $gyms = array();
411
-        while ($data = $result->fetch_object()) {
412
-            $gyms[] = $data;
413
-        }
414
-
415
-        return $gyms;
416
-    }
417
-
418
-    public function getGymData($gym_id)
419
-    {
420
-        $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
409
+		$result = $this->mysqli->query($req);
410
+		$gyms = array();
411
+		while ($data = $result->fetch_object()) {
412
+			$gyms[] = $data;
413
+		}
414
+
415
+		return $gyms;
416
+	}
417
+
418
+	public function getGymData($gym_id)
419
+	{
420
+		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
421 421
 				CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
422 422
 				gym.guard_pokemon_id AS guard_pokemon_id,
423 423
 				gym.total_cp AS total_cp,
@@ -425,53 +425,53 @@  discard block
 block discarded – undo
425 425
 				FROM gymdetails
426 426
 				LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
427 427
 				WHERE gym.gym_id='".$gym_id."'";
428
-        $result = $this->mysqli->query($req);
429
-        $data = $result->fetch_object();
428
+		$result = $this->mysqli->query($req);
429
+		$data = $result->fetch_object();
430 430
 
431
-        return $data;
432
-    }
431
+		return $data;
432
+	}
433 433
 
434
-    public function getGymDefenders($gym_id)
435
-    {
436
-        $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
434
+	public function getGymDefenders($gym_id)
435
+	{
436
+		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
437 437
 				FROM gympokemon
438 438
 				INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
439 439
 				GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
440 440
 				HAVING gymmember.gym_id='".$gym_id."'
441 441
 				ORDER BY cp DESC";
442
-        $result = $this->mysqli->query($req);
443
-        $defenders = array();
444
-        while ($data = $result->fetch_object()) {
445
-            $defenders[] = $data;
446
-        }
447
-
448
-        return $defenders;
449
-    }
450
-
451
-    ////////////////
452
-    // Gym History
453
-    ////////////////
454
-
455
-    public function getGymHistories($gym_name, $team, $page, $ranking)
456
-    {
457
-        $where = '';
458
-        if (isset($gym_name) && '' != $gym_name) {
459
-            $where = " WHERE name LIKE '%".$gym_name."%'";
460
-        }
461
-        if (isset($team) && '' != $team) {
462
-            $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
463
-        }
464
-        switch ($ranking) {
465
-            case 1:
466
-                $order = ' ORDER BY name, last_modified DESC';
467
-                break;
468
-            case 2:
469
-                $order = ' ORDER BY total_cp DESC, last_modified DESC';
470
-                break;
471
-            default:
472
-                $order = ' ORDER BY last_modified DESC, name';
473
-        }
474
-        $req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
442
+		$result = $this->mysqli->query($req);
443
+		$defenders = array();
444
+		while ($data = $result->fetch_object()) {
445
+			$defenders[] = $data;
446
+		}
447
+
448
+		return $defenders;
449
+	}
450
+
451
+	////////////////
452
+	// Gym History
453
+	////////////////
454
+
455
+	public function getGymHistories($gym_name, $team, $page, $ranking)
456
+	{
457
+		$where = '';
458
+		if (isset($gym_name) && '' != $gym_name) {
459
+			$where = " WHERE name LIKE '%".$gym_name."%'";
460
+		}
461
+		if (isset($team) && '' != $team) {
462
+			$where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
463
+		}
464
+		switch ($ranking) {
465
+			case 1:
466
+				$order = ' ORDER BY name, last_modified DESC';
467
+				break;
468
+			case 2:
469
+				$order = ' ORDER BY total_cp DESC, last_modified DESC';
470
+				break;
471
+			default:
472
+				$order = ' ORDER BY last_modified DESC, name';
473
+		}
474
+		$req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
475 475
 				(6 - slots_available) as pokemon_count,
476 476
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
477 477
 				FROM gymdetails
@@ -479,93 +479,93 @@  discard block
 block discarded – undo
479 479
 				ON gymdetails.gym_id = gym.gym_id
480 480
 				".$where.$order."
481 481
 				LIMIT ".($page * 10).",10";
482
-        $result = $this->mysqli->query($req);
483
-        $gym_history = array();
484
-        while ($data = $result->fetch_object()) {
485
-            $gym_history[] = $data;
486
-        }
487
-
488
-        return $gym_history;
489
-    }
490
-
491
-    public function getGymHistoriesPokemon($gym_id)
492
-    {
493
-        $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
482
+		$result = $this->mysqli->query($req);
483
+		$gym_history = array();
484
+		while ($data = $result->fetch_object()) {
485
+			$gym_history[] = $data;
486
+		}
487
+
488
+		return $gym_history;
489
+	}
490
+
491
+	public function getGymHistoriesPokemon($gym_id)
492
+	{
493
+		$req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
494 494
 				FROM gymmember
495 495
 				LEFT JOIN gympokemon
496 496
 				ON gymmember.pokemon_uid = gympokemon.pokemon_uid
497 497
 				WHERE gymmember.gym_id = '".$gym_id."'
498 498
 				ORDER BY deployment_time";
499
-        $result = $this->mysqli->query($req);
500
-        $pokemons = array();
501
-        while ($data = $result->fetch_object()) {
502
-            $pokemons[] = $data;
503
-        }
504
-
505
-        return $pokemons;
506
-    }
507
-
508
-    public function getHistoryForGym($page, $gym_id)
509
-    {
510
-        if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
511
-            $pageSize = 25;
512
-        } else {
513
-            $pageSize = 10;
514
-        }
515
-        $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
499
+		$result = $this->mysqli->query($req);
500
+		$pokemons = array();
501
+		while ($data = $result->fetch_object()) {
502
+			$pokemons[] = $data;
503
+		}
504
+
505
+		return $pokemons;
506
+	}
507
+
508
+	public function getHistoryForGym($page, $gym_id)
509
+	{
510
+		if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
511
+			$pageSize = 25;
512
+		} else {
513
+			$pageSize = 10;
514
+		}
515
+		$req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
516 516
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
517 517
 				FROM gymhistory
518 518
 				WHERE gym_id='".$gym_id."'
519 519
 				ORDER BY last_modified DESC
520 520
 				LIMIT ".($page * $pageSize).','.($pageSize + 1);
521
-        $result = $this->mysqli->query($req);
522
-        $history = array();
523
-        $count = 0;
524
-        while ($data = $result->fetch_object()) {
525
-            ++$count;
526
-            $pkm = array();
527
-            if (0 == $data->total_cp) {
528
-                $data->pokemon_uids = '';
529
-                $data->pokemon_count = 0;
530
-            }
531
-            if ('' != $data->pokemon_uids) {
532
-                $pkm_uids = explode(',', $data->pokemon_uids);
533
-                $pkm = $this->getHistoryForGymPokemon($pkm_uids);
534
-            }
535
-            $data->pokemon = $pkm;
536
-            $history[] = $data;
537
-        }
538
-        if ($count !== ($pageSize + 1)) {
539
-            $last_page = true;
540
-        } else {
541
-            $last_page = false;
542
-        }
543
-
544
-        return array('last_page' => $last_page, 'data' => $history);
545
-    }
546
-
547
-    private function getHistoryForGymPokemon($pkm_uids)
548
-    {
549
-        $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
521
+		$result = $this->mysqli->query($req);
522
+		$history = array();
523
+		$count = 0;
524
+		while ($data = $result->fetch_object()) {
525
+			++$count;
526
+			$pkm = array();
527
+			if (0 == $data->total_cp) {
528
+				$data->pokemon_uids = '';
529
+				$data->pokemon_count = 0;
530
+			}
531
+			if ('' != $data->pokemon_uids) {
532
+				$pkm_uids = explode(',', $data->pokemon_uids);
533
+				$pkm = $this->getHistoryForGymPokemon($pkm_uids);
534
+			}
535
+			$data->pokemon = $pkm;
536
+			$history[] = $data;
537
+		}
538
+		if ($count !== ($pageSize + 1)) {
539
+			$last_page = true;
540
+		} else {
541
+			$last_page = false;
542
+		}
543
+
544
+		return array('last_page' => $last_page, 'data' => $history);
545
+	}
546
+
547
+	private function getHistoryForGymPokemon($pkm_uids)
548
+	{
549
+		$req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
550 550
 				FROM gympokemon
551 551
 				WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."')
552 552
 				ORDER BY FIND_IN_SET(pokemon_uid, '".implode(',', $pkm_uids)."')";
553
-        $result = $this->mysqli->query($req);
554
-        $pokemons = array();
555
-        while ($data = $result->fetch_object()) {
556
-            $pokemons[$data->pokemon_uid] = $data;
557
-        }
558
-
559
-        return $pokemons;
560
-    }
561
-
562
-    ///////////
563
-    // Raids
564
-    ///////////
565
-
566
-    public function getAllRaids($page)
567
-    {
568
-        $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
553
+		$result = $this->mysqli->query($req);
554
+		$pokemons = array();
555
+		while ($data = $result->fetch_object()) {
556
+			$pokemons[$data->pokemon_uid] = $data;
557
+		}
558
+
559
+		return $pokemons;
560
+	}
561
+
562
+	///////////
563
+	// Raids
564
+	///////////
565
+
566
+	public function getAllRaids($page)
567
+	{
568
+		$req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
569 569
 				CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn,
570 570
 				CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start,
571 571
 				CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end,
@@ -577,121 +577,121 @@  discard block
 block discarded – undo
577 577
 				WHERE raid.end > UTC_TIMESTAMP()
578 578
 				ORDER BY raid.level DESC, raid.start
579 579
 				LIMIT ".($page * 10).",10";
580
-        $result = $this->mysqli->query($req);
581
-        $raids = array();
582
-        while ($data = $result->fetch_object()) {
583
-            $raids[] = $data;
584
-        }
585
-
586
-        return $raids;
587
-    }
588
-
589
-    //////////////
590
-    // Trainers
591
-    //////////////
592
-
593
-    public function getTrainers($trainer_name, $team, $page, $ranking)
594
-    {
595
-        $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
596
-        foreach ($trainers as $trainer) {
597
-            $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
598
-            $active_gyms = 0;
599
-            $pkmCount = 0;
600
-            $trainer->pokemons = array();
601
-            $active_pokemon = $this->getTrainerActivePokemon($trainer->name);
602
-            foreach ($active_pokemon as $pokemon) {
603
-                ++$active_gyms;
604
-                $trainer->pokemons[$pkmCount++] = $pokemon;
605
-            }
606
-            $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
607
-            foreach ($inactive_pokemon as $pokemon) {
608
-                $trainer->pokemons[$pkmCount++] = $pokemon;
609
-            }
610
-            $trainer->gyms = ''.$active_gyms;
611
-        }
612
-
613
-        return $trainers;
614
-    }
615
-
616
-    public function getTrainerLevelCount($team_id)
617
-    {
618
-        $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
619
-        if (!empty(self::$config->system->trainer_blacklist)) {
620
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
621
-        }
622
-        $req .= ' GROUP BY level';
623
-        $result = $this->mysqli->query($req);
624
-        $levelData = array();
625
-        while ($data = $result->fetch_object()) {
626
-            $levelData[$data->level] = $data->count;
627
-        }
628
-        for ($i = 5; $i <= 40; ++$i) {
629
-            if (!isset($levelData[$i])) {
630
-                $levelData[$i] = 0;
631
-            }
632
-        }
633
-        // sort array again
634
-        ksort($levelData);
635
-
636
-        return $levelData;
637
-    }
638
-
639
-    private function getTrainerData($trainer_name, $team, $page, $ranking)
640
-    {
641
-        $where = '';
642
-        if (!empty(self::$config->system->trainer_blacklist)) {
643
-            $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
644
-        }
645
-        if ('' != $trainer_name) {
646
-            $where = " HAVING name LIKE '%".$trainer_name."%'";
647
-        }
648
-        if (0 != $team) {
649
-            $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
650
-        }
651
-        switch ($ranking) {
652
-            case 1:
653
-                $order = ' ORDER BY active DESC, level DESC';
654
-                break;
655
-            case 2:
656
-                $order = ' ORDER BY maxCp DESC, level DESC';
657
-                break;
658
-            default:
659
-                $order = ' ORDER BY level DESC, active DESC';
660
-        }
661
-        $order .= ', last_seen DESC, name ';
662
-        $limit = ' LIMIT '.($page * 10).',10 ';
663
-        $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
580
+		$result = $this->mysqli->query($req);
581
+		$raids = array();
582
+		while ($data = $result->fetch_object()) {
583
+			$raids[] = $data;
584
+		}
585
+
586
+		return $raids;
587
+	}
588
+
589
+	//////////////
590
+	// Trainers
591
+	//////////////
592
+
593
+	public function getTrainers($trainer_name, $team, $page, $ranking)
594
+	{
595
+		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
596
+		foreach ($trainers as $trainer) {
597
+			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
598
+			$active_gyms = 0;
599
+			$pkmCount = 0;
600
+			$trainer->pokemons = array();
601
+			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
602
+			foreach ($active_pokemon as $pokemon) {
603
+				++$active_gyms;
604
+				$trainer->pokemons[$pkmCount++] = $pokemon;
605
+			}
606
+			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
607
+			foreach ($inactive_pokemon as $pokemon) {
608
+				$trainer->pokemons[$pkmCount++] = $pokemon;
609
+			}
610
+			$trainer->gyms = ''.$active_gyms;
611
+		}
612
+
613
+		return $trainers;
614
+	}
615
+
616
+	public function getTrainerLevelCount($team_id)
617
+	{
618
+		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
619
+		if (!empty(self::$config->system->trainer_blacklist)) {
620
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
621
+		}
622
+		$req .= ' GROUP BY level';
623
+		$result = $this->mysqli->query($req);
624
+		$levelData = array();
625
+		while ($data = $result->fetch_object()) {
626
+			$levelData[$data->level] = $data->count;
627
+		}
628
+		for ($i = 5; $i <= 40; ++$i) {
629
+			if (!isset($levelData[$i])) {
630
+				$levelData[$i] = 0;
631
+			}
632
+		}
633
+		// sort array again
634
+		ksort($levelData);
635
+
636
+		return $levelData;
637
+	}
638
+
639
+	private function getTrainerData($trainer_name, $team, $page, $ranking)
640
+	{
641
+		$where = '';
642
+		if (!empty(self::$config->system->trainer_blacklist)) {
643
+			$where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
644
+		}
645
+		if ('' != $trainer_name) {
646
+			$where = " HAVING name LIKE '%".$trainer_name."%'";
647
+		}
648
+		if (0 != $team) {
649
+			$where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
650
+		}
651
+		switch ($ranking) {
652
+			case 1:
653
+				$order = ' ORDER BY active DESC, level DESC';
654
+				break;
655
+			case 2:
656
+				$order = ' ORDER BY maxCp DESC, level DESC';
657
+				break;
658
+			default:
659
+				$order = ' ORDER BY level DESC, active DESC';
660
+		}
661
+		$order .= ', last_seen DESC, name ';
662
+		$limit = ' LIMIT '.($page * 10).',10 ';
663
+		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
664 664
 				FROM trainer
665 665
 				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
666 666
 				FROM gympokemon
667 667
 				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
668 668
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
669 669
 				GROUP BY trainer.name ".$where.$order.$limit;
670
-        $result = $this->mysqli->query($req);
671
-        $trainers = array();
672
-        while ($data = $result->fetch_object()) {
673
-            $data->last_seen = date('Y-m-d', strtotime($data->last_seen));
674
-            $trainers[$data->name] = $data;
675
-        }
676
-
677
-        return $trainers;
678
-    }
679
-
680
-    private function getTrainerLevelRating($level)
681
-    {
682
-        $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
683
-        if (!empty(self::$config->system->trainer_blacklist)) {
684
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
685
-        }
686
-        $result = $this->mysqli->query($req);
687
-        $data = $result->fetch_object();
688
-
689
-        return $data;
690
-    }
691
-
692
-    private function getTrainerActivePokemon($trainer_name)
693
-    {
694
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
670
+		$result = $this->mysqli->query($req);
671
+		$trainers = array();
672
+		while ($data = $result->fetch_object()) {
673
+			$data->last_seen = date('Y-m-d', strtotime($data->last_seen));
674
+			$trainers[$data->name] = $data;
675
+		}
676
+
677
+		return $trainers;
678
+	}
679
+
680
+	private function getTrainerLevelRating($level)
681
+	{
682
+		$req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
683
+		if (!empty(self::$config->system->trainer_blacklist)) {
684
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
685
+		}
686
+		$result = $this->mysqli->query($req);
687
+		$data = $result->fetch_object();
688
+
689
+		return $data;
690
+	}
691
+
692
+	private function getTrainerActivePokemon($trainer_name)
693
+	{
694
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
695 695
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
696 696
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
697 697
 				filtered_gymmember.gym_id,
@@ -702,18 +702,18 @@  discard block
 block discarded – undo
702 702
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
703 703
 				WHERE gympokemon.trainer_name='".$trainer_name."'
704 704
 				ORDER BY gympokemon.cp DESC";
705
-        $result = $this->mysqli->query($req);
706
-        $pokemons = array();
707
-        while ($data = $result->fetch_object()) {
708
-            $pokemons[] = $data;
709
-        }
710
-
711
-        return $pokemons;
712
-    }
713
-
714
-    private function getTrainerInactivePokemon($trainer_name)
715
-    {
716
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
705
+		$result = $this->mysqli->query($req);
706
+		$pokemons = array();
707
+		while ($data = $result->fetch_object()) {
708
+			$pokemons[] = $data;
709
+		}
710
+
711
+		return $pokemons;
712
+	}
713
+
714
+	private function getTrainerInactivePokemon($trainer_name)
715
+	{
716
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
717 717
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
718 718
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
719 719
 				null AS gym_id,
@@ -724,66 +724,66 @@  discard block
 block discarded – undo
724 724
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
725 725
 				WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
726 726
 				ORDER BY gympokemon.cp DESC";
727
-        $result = $this->mysqli->query($req);
728
-        $pokemons = array();
729
-        while ($data = $result->fetch_object()) {
730
-            $pokemons[] = $data;
731
-        }
732
-
733
-        return $pokemons;
734
-    }
735
-
736
-    /////////
737
-    // Cron
738
-    /////////
739
-
740
-    public function getPokemonCountsActive()
741
-    {
742
-        $req = 'SELECT pokemon_id, COUNT(*) as total
727
+		$result = $this->mysqli->query($req);
728
+		$pokemons = array();
729
+		while ($data = $result->fetch_object()) {
730
+			$pokemons[] = $data;
731
+		}
732
+
733
+		return $pokemons;
734
+	}
735
+
736
+	/////////
737
+	// Cron
738
+	/////////
739
+
740
+	public function getPokemonCountsActive()
741
+	{
742
+		$req = 'SELECT pokemon_id, COUNT(*) as total
743 743
 				FROM pokemon
744 744
 				WHERE disappear_time >= UTC_TIMESTAMP()
745 745
 				GROUP BY pokemon_id';
746
-        $result = $this->mysqli->query($req);
747
-        $counts = array();
748
-        while ($data = $result->fetch_object()) {
749
-            $counts[$data->pokemon_id] = $data->total;
750
-        }
751
-
752
-        return $counts;
753
-    }
754
-
755
-    public function getPokemonCountsLastDay()
756
-    {
757
-        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
746
+		$result = $this->mysqli->query($req);
747
+		$counts = array();
748
+		while ($data = $result->fetch_object()) {
749
+			$counts[$data->pokemon_id] = $data->total;
750
+		}
751
+
752
+		return $counts;
753
+	}
754
+
755
+	public function getPokemonCountsLastDay()
756
+	{
757
+		$req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
758 758
 				FROM pokemon
759 759
 				WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
760 760
 				GROUP BY pokemon_id
761 761
 				ORDER BY pokemon_id ASC';
762
-        $result = $this->mysqli->query($req);
763
-        $counts = array();
764
-        while ($data = $result->fetch_object()) {
765
-            $counts[$data->pokemon_id] = $data->spawns_last_day;
766
-        }
767
-
768
-        return $counts;
769
-    }
770
-
771
-    public function getCaptchaCount()
772
-    {
773
-        $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
774
-        $result = $this->mysqli->query($req);
775
-        $data = $result->fetch_object();
776
-
777
-        return $data;
778
-    }
779
-
780
-    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
781
-    {
782
-        $pokemon_exclude_sql = '';
783
-        if (!empty(self::$config->system->nest_exclude_pokemon)) {
784
-            $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
785
-        }
786
-        $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
762
+		$result = $this->mysqli->query($req);
763
+		$counts = array();
764
+		while ($data = $result->fetch_object()) {
765
+			$counts[$data->pokemon_id] = $data->spawns_last_day;
766
+		}
767
+
768
+		return $counts;
769
+	}
770
+
771
+	public function getCaptchaCount()
772
+	{
773
+		$req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
774
+		$result = $this->mysqli->query($req);
775
+		$data = $result->fetch_object();
776
+
777
+		return $data;
778
+	}
779
+
780
+	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
781
+	{
782
+		$pokemon_exclude_sql = '';
783
+		if (!empty(self::$config->system->nest_exclude_pokemon)) {
784
+			$pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
785
+		}
786
+		$req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
787 787
 				MAX(UNIX_TIMESTAMP(disappear_time)) as latest_seen
788 788
 				FROM pokemon
789 789
 				WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL '.$time.' HOUR)
@@ -792,23 +792,23 @@  discard block
 block discarded – undo
792 792
 				GROUP BY spawnpoint_id, pokemon_id 
793 793
 				HAVING COUNT(pokemon_id) >= '.($time / 4).'
794 794
 				ORDER BY pokemon_id';
795
-        $result = $this->mysqli->query($req);
796
-        $nests = array();
797
-        while ($data = $result->fetch_object()) {
798
-            $nests[] = $data;
799
-        }
800
-
801
-        return $nests;
802
-    }
803
-
804
-    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
805
-    {
806
-        $req = 'SELECT COUNT(*) as total 
795
+		$result = $this->mysqli->query($req);
796
+		$nests = array();
797
+		while ($data = $result->fetch_object()) {
798
+			$nests[] = $data;
799
+		}
800
+
801
+		return $nests;
802
+	}
803
+
804
+	public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
805
+	{
806
+		$req = 'SELECT COUNT(*) as total 
807 807
 				FROM spawnpoint
808 808
 				WHERE latitude >= '.$minLatitude.' AND latitude < '.$maxLatitude.' AND longitude >= '.$minLongitude.' AND longitude < '.$maxLongitude;
809
-        $result = $this->mysqli->query($req);
810
-        $data = $result->fetch_object();
809
+		$result = $this->mysqli->query($req);
810
+		$data = $result->fetch_object();
811 811
 
812
-        return $data;
813
-    }
812
+		return $data;
813
+	}
814 814
 }
Please login to merge, or discard this patch.