Failed Conditions
Pull Request — master (#353)
by Florian
06:18 queued 03:18
created

QueryManagerMysqlMonocleAlternate::testTotalGyms()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
	public function __construct() {
6
		parent::__construct();
7
	}
8
9
	public function __destruct() {
10
		parent::__destruct();
11
	}
12
13
	///////////
14
	// Tester
15
	///////////
16
17 View Code Duplication
	function testTotalPokemon() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
18
		$req = "SELECT COUNT(*) as total FROM sightings";
19
		$result = $this->mysqli->query($req);
20
		if (!is_object($result)) {
21
			return 1;
22
		} else {
23
			$data = $result->fetch_object();
24
			$total = $data->total;
25
26
			if ($total == 0) {
27
				return 2;
28
			}
29
		}
30
		return 0;
31
	}
32
33 View Code Duplication
	function testTotalGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
34
		$req = "SELECT COUNT(*) as total FROM forts";
35
		$result = $this->mysqli->query($req);
36
		if (!is_object($result)) {
37
			return 1;
38
		} else {
39
			$data = $result->fetch_object();
40
			$total = $data->total;
41
42
			if ($total == 0) {
43
				return 2;
44
			}
45
		}
46
		return 0;
47
	}
48
49 View Code Duplication
	function testTotalPokestops() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalPokestops.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
50
		$req = "SELECT COUNT(*) as total FROM pokestops";
51
		$result = $this->mysqli->query($req);
52
		if (!is_object($result)) {
53
			return 1;
54
		} else {
55
			$data = $result->fetch_object();
56
			$total = $data->total;
57
58
			if ($total == 0) {
59
				return 2;
60
			}
61
		}
62
		return 0;
63
	}
64
	
65
	
66
	/////////////
67
	// Homepage
68
	/////////////
69
70
	function getTotalPokemon() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
71
		$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()";
72
		$result = $this->mysqli->query($req);
73
		$data = $result->fetch_object();
74
		return $data;
75
	}
76
77
	function getTotalLures() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalLures.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
78
		$data = (object) array("total" => 0);
79
		return $data;
80
	}
81
82
	function getTotalGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
83
		$req = "SELECT COUNT(*) AS total FROM forts";
84
		$result = $this->mysqli->query($req);
85
		$data = $result->fetch_object();
86
		return $data;
87
	}
88
89
	function getTotalRaids() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalRaids.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
90
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()";
91
		$result = $this->mysqli->query($req);
92
		$data = $result->fetch_object();
93
		return $data;
94
	}
95
96
97
	function getTotalGymsForTeam($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalGymsForTeam.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
98
		$req = "SELECT COUNT(*) AS total 
99
					FROM forts f
100
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
101
					WHERE team = '$team_id'";
102
		$result = $this->mysqli->query($req);
103
		$data = $result->fetch_object();
104
		return $data;
105
	}
106
107
	function getRecentAll() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getRecentAll.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
108
		$req = "SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
109
              lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
110
              FROM sightings
111
              ORDER BY updated DESC
112
              LIMIT 0,12";
113
		$result = $this->mysqli->query($req);
114
		$data = array();
115
		if ($result->num_rows > 0) {
116
			while ($row = $result->fetch_object()) {
117
				$data[] = $row;
118
			}
119
		}
120
		return $data;
121
	}
122
123
	function getRecentMythic($mythic_pokemon) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getRecentMythic.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
124
		$req = "SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
125
                lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
126
                FROM sightings
127
                WHERE pokemon_id IN (".implode(",", $mythic_pokemon).")
128
                ORDER BY updated DESC
129
                LIMIT 0,12";
130
		$result = $this->mysqli->query($req);
131
		$data = array();
132
		if ($result->num_rows > 0) {
133
			while ($row = $result->fetch_object()) {
134
				$data[] = $row;
135
			}
136
		}
137
		return $data;
138
	}
139
140
	///////////////////
141
	// Single Pokemon
142
	///////////////////
143
144 View Code Duplication
	function getGymsProtectedByPokemon($pokemon_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getGymsProtectedByPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
145
		$req = "SELECT COUNT(f.id) AS total 
146
					FROM forts f
147
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
148
					WHERE guard_pokemon_id = '".$pokemon_id."'";
149
		$result = $this->mysqli->query($req);
150
		$data = $result->fetch_object();
151
		return $data;
152
	}
153
154 View Code Duplication
	function getPokemonLastSeen($pokemon_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getPokemonLastSeen.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
155
		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
156
                FROM sightings
157
                WHERE pokemon_id = '".$pokemon_id."'
158
                ORDER BY expire_timestamp DESC
159
                LIMIT 0,1";
160
		$result = $this->mysqli->query($req);
161
		$data = $result->fetch_object();
162
		return $data;
163
	}
164
165
	function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTop50Pokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
166
		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
167
                cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina,
168
                ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form
169
                FROM sightings
170
	            WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0'
171
	            ORDER BY $top_order_by $top_direction, expire_timestamp DESC
172
	            LIMIT 0,50";
173
174
		$result = $this->mysqli->query($req);
175
		$top = array();
176
		while ($data = $result->fetch_object()) {
177
			$top[] = $data;
178
		}
179
		return $top;
180
	}
181
182 View Code Duplication
	function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTop50Trainers.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
183
		$trainer_blacklist = "";
184
		if (!empty(self::$config->system->trainer_blacklist)) {
185
			$trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')";
186
		}
187
188
		$req = "SELECT owner_name as trainer_name, ROUND((100*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS IV, move_1, move_2, cp as cp,
189
                FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen
190
                FROM gym_defenders
191
				WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . "
192
				ORDER BY $best_order_by $best_direction, owner_name ASC
193
				LIMIT 0,50";
194
195
		$result = $this->mysqli->query($req);
196
		$toptrainer = array();
197
		while ($data = $result->fetch_object()) {
198
			$toptrainer[] = $data;
199
		}
200
		return $toptrainer;
201
	}
202
203 View Code Duplication
	public function getPokemonHeatmap($pokemon_id, $start, $end) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204
		$where = " WHERE pokemon_id = ".$pokemon_id." "
205
			. "AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
206
		$req 		= "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." ORDER BY expire_timestamp DESC LIMIT 100000";
207
		$result = $this->mysqli->query($req);
208
		$points = array();
209
		while ($data = $result->fetch_object()) {
210
			$points[] = $data;
211
		}
212
		return $points;
213
	}
214
215 View Code Duplication
	public function getPokemonGraph($pokemon_id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
		$req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
217
					FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
218
				GROUP BY disappear_hour
219
				ORDER BY disappear_hour";
220
		$result = $this->mysqli->query($req);
221
		$array = array_fill(0, 24, 0);
222
		while ($result && $data = $result->fetch_object()) {
223
			$array[$data->disappear_hour] = $data->total;
224
		}
225
		// shift array because AM/PM starts at 1AM not 0:00
226
		$array[] = $array[0];
227
		array_shift($array);
228
		return $array;
229
	}
230
231 View Code Duplication
	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
		$inmap_pkms_filter = "";
233
		$where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id;
234
235
		$reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where;
236
		$resultTestIv = $this->mysqli->query($reqTestIv);
237
		$testIv = $resultTestIv->fetch_object();
238
		if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) {
239
			foreach ($inmap_pokemons as $inmap) {
240
				$inmap_pkms_filter .= "'".$inmap."',";
241
			}
242
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
243
			$where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") ";
244
		}
245
		if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) {
246
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") ";
247
		}
248
		if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) {
249
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") ";
250
		}
251
		$req = "SELECT pokemon_id, lat AS latitude, lon AS longitude,
252
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time,
253
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
254
    					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
255
   						move_1, move_2
256
					FROM sightings " . $where . "
257
					ORDER BY disappear_time DESC
258
					LIMIT 5000";
259
		$result = $this->mysqli->query($req);
260
		$spawns = array();
261
		while ($data = $result->fetch_object()) {
262
			$spawns[] = $data;
263
		}
264
		return $spawns;
265
	}
266
267
	public function getPokemonSliderMinMax() {
268
		$req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings";
269
		$result = $this->mysqli->query($req);
270
		$data = $result->fetch_object();
271
		return $data;
272
	}
273
274
	public function getMapsCoords() {
275
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
276
		$result = $this->mysqli->query($req);
277
		$data = $result->fetch_object();
278
		return $data;
279
	}
280
281
282
	///////////////
283
	// Pokestops
284
	//////////////
285
286
287
	function getTotalPokestops() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalPokestops.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
288
		$req = "SELECT COUNT(*) as total FROM pokestops";
289
		$result = $this->mysqli->query($req);
290
		$data = $result->fetch_object();
291
		return $data;
292
	}
293
294
	public function getAllPokestops() {
295
		$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops";
296
		$result = $this->mysqli->query($req);
297
		$pokestops = array();
298
		while ($data = $result->fetch_object()) {
299
			$pokestops[] = $data;
300
		}
301
		return $pokestops;
302
	}
303
304
305
	/////////
306
	// Gyms
307
	/////////
308
309
	function getTeamGuardians($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTeamGuardians.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
310
		$req = "SELECT COUNT(*) AS total, guard_pokemon_id 
311
					FROM forts f
312
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
313
					WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
314
		$result = $this->mysqli->query($req);
315
316
		$datas = array();
317
		while ($data = $result->fetch_object()) {
318
			$datas[] = $data;
319
		}
320
321
		return $datas;
322
	}
323
324
	function getOwnedAndPoints($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getOwnedAndPoints.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
325
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points
326
        			FROM forts f
327
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
328
        			WHERE fs.team = '" . $team_id . "'";
329
		$result = $this->mysqli->query($req);
330
		$data = $result->fetch_object();
331
		return $data;
332
	}
333
334
	function getAllGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getAllGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
335
		$req = "SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level 
336
					FROM forts f
337
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id));";
338
		$result = $this->mysqli->query($req);
339
		$gyms = array();
340
		while ($data = $result->fetch_object()) {
341
			$gyms[] = $data;
342
		}
343
		return $gyms;
344
	}
345
346
	public function getGymData($gym_id) {
347
		$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, FROM_UNIXTIME(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp	
348
			FROM forts f
349
			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
350
			WHERE f.id ='".$gym_id."'";
351
		$result = $this->mysqli->query($req);
352
		$data = $result->fetch_object();
353
		return $data;
354
	}
355
356
	public function getGymDefenders($gym_id) {
357
		$req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
358
			FROM gym_defenders 
359
			WHERE fort_id='".$gym_id."'
360
			ORDER BY deployment_time";
361
		$result = $this->mysqli->query($req);
362
		$defenders = array();
363
		while ($data = $result->fetch_object()) {
364
			$defenders[] = $data;
365
		}
366
		return $defenders;
367
	}
368
369
370
	///////////
371
	// Raids
372
	///////////
373
374 View Code Duplication
	public function getAllRaids($page) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
375
		$limit = " LIMIT ".($page * 10).",10";
376
		$req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude 
377
					FROM forts f
378
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
379
				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
380
					WHERE r.time_end > UNIX_TIMESTAMP() 
381
					ORDER BY r.level DESC, r.time_battle" . $limit;
382
		$result = $this->mysqli->query($req);
383
		$raids = array();
384
		while ($data = $result->fetch_object()) {
385
			$raids[] = $data;
386
		}
387
		return $raids;
388
	}
389
390
391
392
	////////////////
393
	// Gym History
394
	////////////////
395
396 View Code Duplication
	public function getGymHistories($gym_name, $team, $page, $ranking)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
	{
398
		$where = "";
399
		if (isset($gym_name) && $gym_name != '') {
400
			$where = " WHERE name LIKE '%".$gym_name."%'";
401
		}
402
		if (isset($team) && $team != '') {
403
			$where .= ($where === "" ? " WHERE" : " AND")." fs.team = ".$team;
404
		}
405
		switch ($ranking) {
406
			case 1:
407
				$order = " ORDER BY name, last_modified DESC";
408
				break;
409
			case 2:
410
				$order = " ORDER BY total_cp DESC, last_modified DESC";
411
				break;
412
			default:
413
				$order = " ORDER BY last_modified DESC, name";
414
		}
415
416
		$limit = " LIMIT ".($page * 10).",10";
417
418
		$req = "SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified 
419
			FROM forts f
420
			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
421
			".$where.$order.$limit;
422
		$result = $this->mysqli->query($req);
423
		$gym_history = array();
424
		while ($data = $result->fetch_object()) {
425
			$gym_history[] = $data;
426
		}
427
		return $gym_history;
428
	}
429
430
	public function getGymHistoriesPokemon($gym_id)
431
	{
432
		$req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
433
					FROM gym_defenders
434
					WHERE fort_id = '". $gym_id ."'
435
					ORDER BY deployment_time";
436
		$result = $this->mysqli->query($req);
437
		$pokemons = array();
438
		while ($data = $result->fetch_object()) {
439
			$pokemons[] = $data;
440
		}
441
		return $pokemons;
442
	}
443
444 View Code Duplication
	public function getHistoryForGym($page, $gym_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
445
	{
446
		if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) {
447
			$pageSize = 25;
448
		} else {
449
			$pageSize = 10;
450
		}
451
		$req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real
452
					FROM fort_sightings fs
453
					LEFT JOIN forts f ON f.id = fs.fort_id
454
					WHERE f.id = '". $gym_id ."'
455
					ORDER BY fs.last_modified DESC
456
					LIMIT ".($page * $pageSize).",".($pageSize+1);
457
		$result = $this->mysqli->query($req);
458
		$history = array();
459
		$count = 0;
460
		while ($data = $result->fetch_object()) {
461
			$count++;
462
			if ($data->total_cp == 0) {
463
				$data->pokemon = array();
464
				$data->pokemon_count = 0;
465
				$data->pokemon_uids = "";
466
			} else {
467
				$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
468
				$data->pokemon_count = count($data->pokemon);
469
				$data->pokemon_uids = implode(",", array_keys($data->pokemon));
470
			}
471
			if ($data->total_cp === 0 || $data->pokemon_count !== 0) {
472
				$history[] = $data;
473
			}
474
		}
475
		if ($count !== ($pageSize + 1)) {
476
			$last_page = true;
477
		} else {
478
			$last_page = false;
479
		}
480
		return array("last_page" => $last_page, "data" => $history);
481
	}
482
483 View Code Duplication
	private function getHistoryForGymPokemon($gym_id, $last_modified)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
484
	{
485
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
486
					FROM gym_history_defenders ghd
487
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
488
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
489
					ORDER BY gd.deployment_time";
490
		$result = $this->mysqli->query($req);
491
		$pokemons = array();
492
		while ($data = $result->fetch_object()) {
493
			$pokemons[$data->defender_id] = $data;
494
		}
495
		return $pokemons;
496
	}
497
498
499
500
	//////////////
501
	// Trainers
502
	//////////////
503
504 View Code Duplication
	public function getTrainers($trainer_name, $team, $page, $rankingNumber) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
505
		$ranking = $this->getTrainerLevelRanking();
506
		$where = "";
507
		if (!empty(self::$config->system->trainer_blacklist)) {
508
			$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
509
		}
510
		if ($trainer_name != "") {
511
			$where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
512
		}
513
		if ($team != 0) {
514
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
515
		}
516
		switch ($rankingNumber) {
517
			case 1:
518
				$order = " ORDER BY active DESC, level DESC";
519
				break;
520
			case 2:
521
				$order = " ORDER BY maxCp DESC, level DESC";
522
				break;
523
			default:
524
				$order = " ORDER BY level DESC, active DESC";
525
		}
526
		$order .= ", last_seen DESC, name ";
527
		$limit = " LIMIT ".($page * 10).",10 ";
528
		$req = "SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, FROM_UNIXTIME(MAX(last_modified)) as last_seen
529
				  	FROM gym_defenders gd
530
				  	LEFT JOIN (
531
				  		SELECT owner_name, COUNT(*) as active
532
				  		FROM gym_defenders gd2
533
						WHERE fort_id IS NOT NULL
534
				  		GROUP BY owner_name
535
				  	) active ON active.owner_name = gd.owner_name
536
				  	WHERE gd.owner_level IS NOT NULL " . $where . "
537
				  	GROUP BY gd.owner_name" . $order  . $limit;
538
		$result = $this->mysqli->query($req);
539
		$trainers = array();
540
		while ($data = $result->fetch_object()) {
541
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
542
            if (is_null($data->active)) {
543
                $data->active = 0;
544
            }
545
			$trainers[$data->name] = $data;
546
547
			$pokemon = array_merge($this->getActivePokemon($data->name),  $this->getInactivePokemon($data->name));
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
548
549
			$trainers[$data->name]->gyms = $data->active;
550
			$trainers[$data->name]->pokemons = $pokemon;
551
			$trainers[$data->name]->rank = $ranking[$data->level];
552
		}
553
		return $trainers;
554
	}
555
556 View Code Duplication
	public function getTrainerLevelRanking() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557
		$exclue = "";
558
		if (!empty(self::$config->system->trainer_blacklist)) {
559
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
560
		}
561
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
562
		$result = $this->mysqli->query($req);
563
		$levelData = array();
564
		while ($data = $result->fetch_object()) {
565
			$levelData[$data->level] = $data->count;
566
		}
567
		for ($i = 5; $i <= 40; $i++) {
568
			if (!isset($levelData[$i])) {
569
				$levelData[$i] = 0;
570
			}
571
		}
572
		# sort array again
573
		ksort($levelData);
574
		return $levelData;
575
	}
576
577
	public function getActivePokemon($trainer_name) {
578
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
579
						FROM gym_defenders 
580
						WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL
581
						ORDER BY deployment_time";
582
		$result = $this->mysqli->query($req);
583
		$pokemon = array();
584
		while ($data = $result->fetch_object()) {
585
			$pokemon[] = $data;
586
		}
587
		return $pokemon;
588
	}
589
590
	public function getInactivePokemon($trainer_name) {
591
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
592
					FROM gym_defenders 
593
					WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL
594
					ORDER BY last_scanned";
595
		$result = $this->mysqli->query($req);
596
		$pokemon = array();
597
		while ($data = $result->fetch_object()) {
598
			$pokemon[] = $data;
599
		}
600
		return $pokemon;
601
	}
602
603 View Code Duplication
	public function getTrainerLevelCount($team_id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
604
		$exclue = "";
605
		if (!empty(self::$config->system->trainer_blacklist)) {
606
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
607
		}
608
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
609
		$result = $this->mysqli->query($req);
610
		$levelData = array();
611
		while ($data = $result->fetch_object()) {
612
			$levelData[$data->level] = $data->count;
613
		}
614
		for ($i = 5; $i <= 40; $i++) {
615
			if (!isset($levelData[$i])) {
616
				$levelData[$i] = 0;
617
			}
618
		}
619
		# sort array again
620
		ksort($levelData);
621
		return $levelData;
622
	}
623
624
625
	/////////
626
	// Cron
627
	/////////
628
629
	public function getPokemonCountsActive() {
630
		$req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id";
631
		$result = $this->mysqli->query($req);
632
		$counts = array();
633
		while ($data = $result->fetch_object()) {
634
			$counts[$data->pokemon_id] = $data->total;
635
		}
636
		return $counts;
637
	}
638
639
	public function getPokemonCountsLastDay() {
640
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
641
					FROM sightings
642
					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings)
643
					GROUP BY pokemon_id
644
				  	ORDER BY pokemon_id ASC";
645
		$result = $this->mysqli->query($req);
646
		$counts = array();
647
		while ($data = $result->fetch_object()) {
648
			$counts[$data->pokemon_id] = $data->spawns_last_day;
649
		}
650
		return $counts;
651
	}
652
653 View Code Duplication
	public function getPokemonSinceLastUpdate($pokemon_id, $last_update) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
654
		$where = "WHERE p.pokemon_id = '".$pokemon_id."' AND p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) > '".$last_update."'";
655
		$req = "SELECT count, p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) AS last_timestamp, (FROM_UNIXTIME(p.expire_timestamp)) AS disappear_time_real, p.lat as latitude, p.lon as longitude
656
					FROM sightings p
657
					LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
658
					JOIN (SELECT COUNT(*) AS count
659
						FROM sightings p
660
						LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
661
                    	" . $where."
662
                    ) x
663
					" . $where . "
664
					ORDER BY last_timestamp DESC
665
					LIMIT 0 , 1";
666
		$result = $this->mysqli->query($req);
667
		$data = $result->fetch_object();
668
		return $data;
669
	}
670
671 View Code Duplication
	public function getRaidsSinceLastUpdate($pokemon_id, $last_update) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
672
		$where = "WHERE pokemon_id = '".$pokemon_id."AND".$last_update."'";
673
		$req = "SELECT time_battle AS start_timestamp, time_end as end, (FROM_UNIXTIME(time_end)) AS end_time_real, lat as latitude, lon as longitude, count
674
					FROM raids r
675
					JOIN forts g
676
					JOIN (SELECT COUNT(*) AS count
677
						FROM raids
678
                    	" . $where."
679
                    ) x 
680
					ON r.fort_id = g.id
681
                    " . $where . "
682
                    ORDER BY time_battle DESC
683
					LIMIT 0 , 1";
684
		$result = $this->mysqli->query($req);
685
		$data = $result->fetch_object();
686
		return $data;
687
	}
688
689
	public function getCaptchaCount() {
690
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
691
		$result = $this->mysqli->query($req);
692
		$data = $result->fetch_object();
693
		return $data;
694
	}
695
696 View Code Duplication
	public function getNestData() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
697
		$pokemon_exclude_sql = "";
698
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
699
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")";
700
		}
701
		$req = "SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
702
			          FROM sightings p
703
			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
704
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400
705
			          " . $pokemon_exclude_sql . "
706
			          GROUP BY p.spawn_id, p.pokemon_id
707
			          HAVING COUNT(p.pokemon_id) >= 6
708
			          ORDER BY p.pokemon_id";
709
		$result = $this->mysqli->query($req);
710
		$nests = array();
711
		while ($data = $result->fetch_object()) {
712
			$nests[] = $data;
713
		}
714
		return $nests;
715
	}
716
717
}
718