Failed Conditions
Pull Request — master (#353)
by Florian
04:15 queued 01:16
created

getPokemonLive()   C

Complexity

Conditions 11
Paths 16

Size

Total Lines 34
Code Lines 22

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
cc 11
eloc 22
nc 16
nop 4
dl 34
loc 34
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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." 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."' 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
					LIMIT 5000";
258
		$result = $this->mysqli->query($req);
259
		$spawns = array();
260
		while ($data = $result->fetch_object()) {
261
			$spawns[] = $data;
262
		}
263
		return $spawns;
264
	}
265
266
	public function getPokemonSliderMinMax() {
267
		$req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings";
268
		$result = $this->mysqli->query($req);
269
		$data = $result->fetch_object();
270
		return $data;
271
	}
272
273
	public function getMapsCoords() {
274
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
275
		$result = $this->mysqli->query($req);
276
		$data = $result->fetch_object();
277
		return $data;
278
	}
279
280
281
	///////////////
282
	// Pokestops
283
	//////////////
284
285
286
	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...
287
		$req = "SELECT COUNT(*) as total FROM pokestops";
288
		$result = $this->mysqli->query($req);
289
		$data = $result->fetch_object();
290
		return $data;
291
	}
292
293
	public function getAllPokestops() {
294
		$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops";
295
		$result = $this->mysqli->query($req);
296
		$pokestops = array();
297
		while ($data = $result->fetch_object()) {
298
			$pokestops[] = $data;
299
		}
300
		return $pokestops;
301
	}
302
303
304
	/////////
305
	// Gyms
306
	/////////
307
308
	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...
309
		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
310
					FROM forts f
311
					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))
312
					WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
313
		$result = $this->mysqli->query($req);
314
315
		$datas = array();
316
		while ($data = $result->fetch_object()) {
317
			$datas[] = $data;
318
		}
319
320
		return $datas;
321
	}
322
323
	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...
324
		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points
325
        			FROM forts f
326
					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))
327
        			WHERE fs.team = '" . $team_id . "'";
328
		$result = $this->mysqli->query($req);
329
		$data = $result->fetch_object();
330
		return $data;
331
	}
332
333
	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...
334
		$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
335
					FROM forts f
336
					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));";
337
		$result = $this->mysqli->query($req);
338
		$gyms = array();
339
		while ($data = $result->fetch_object()) {
340
			$gyms[] = $data;
341
		}
342
		return $gyms;
343
	}
344
345
	public function getGymData($gym_id) {
346
		$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
347
			FROM forts f
348
			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))
349
			WHERE f.id ='".$gym_id."'";
350
		$result = $this->mysqli->query($req);
351
		$data = $result->fetch_object();
352
		return $data;
353
	}
354
355
	public function getGymDefenders($gym_id) {
356
		$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
357
			FROM gym_defenders
358
			WHERE fort_id='".$gym_id."'
359
			ORDER BY deployment_time";
360
		$result = $this->mysqli->query($req);
361
		$defenders = array();
362
		while ($data = $result->fetch_object()) {
363
			$defenders[] = $data;
364
		}
365
		return $defenders;
366
	}
367
368
369
	///////////
370
	// Raids
371
	///////////
372
373 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...
374
		$limit = " LIMIT ".($page * 10).",10";
375
		$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
376
					FROM forts f
377
					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))
378
				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
379
					WHERE r.time_end > UNIX_TIMESTAMP()
380
					ORDER BY r.level DESC, r.time_battle" . $limit;
381
		$result = $this->mysqli->query($req);
382
		$raids = array();
383
		while ($data = $result->fetch_object()) {
384
			$raids[] = $data;
385
		}
386
		return $raids;
387
	}
388
389
390
391
	////////////////
392
	// Gym History
393
	////////////////
394
395 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...
396
	{
397
		$where = "";
398
		if (isset($gym_name) && $gym_name != '') {
399
			$where = " WHERE name LIKE '%".$gym_name."%'";
400
		}
401
		if (isset($team) && $team != '') {
402
			$where .= ($where === "" ? " WHERE" : " AND")." fs.team = ".$team;
403
		}
404
		switch ($ranking) {
405
			case 1:
406
				$order = " ORDER BY name, last_modified DESC";
407
				break;
408
			case 2:
409
				$order = " ORDER BY total_cp DESC, last_modified DESC";
410
				break;
411
			default:
412
				$order = " ORDER BY last_modified DESC, name";
413
		}
414
415
		$limit = " LIMIT ".($page * 10).",10";
416
417
		$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
418
			FROM forts f
419
			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))
420
			".$where.$order.$limit;
421
		$result = $this->mysqli->query($req);
422
		$gym_history = array();
423
		while ($data = $result->fetch_object()) {
424
			$gym_history[] = $data;
425
		}
426
		return $gym_history;
427
	}
428
429
	public function getGymHistoriesPokemon($gym_id)
430
	{
431
		$req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
432
					FROM gym_defenders
433
					WHERE fort_id = '". $gym_id ."'
434
					ORDER BY deployment_time";
435
		$result = $this->mysqli->query($req);
436
		$pokemons = array();
437
		while ($data = $result->fetch_object()) {
438
			$pokemons[] = $data;
439
		}
440
		return $pokemons;
441
	}
442
443 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...
444
	{
445
		if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) {
446
			$pageSize = 25;
447
		} else {
448
			$pageSize = 10;
449
		}
450
		$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
451
					FROM fort_sightings fs
452
					LEFT JOIN forts f ON f.id = fs.fort_id
453
					WHERE f.id = '". $gym_id ."'
454
					ORDER BY fs.last_modified DESC
455
					LIMIT ".($page * $pageSize).",".($pageSize+1);
456
		$result = $this->mysqli->query($req);
457
		$history = array();
458
		$count = 0;
459
		while ($data = $result->fetch_object()) {
460
			$count++;
461
			if ($data->total_cp == 0) {
462
				$data->pokemon = array();
463
				$data->pokemon_count = 0;
464
				$data->pokemon_uids = "";
465
			} else {
466
				$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
467
				$data->pokemon_count = count($data->pokemon);
468
				$data->pokemon_uids = implode(",", array_keys($data->pokemon));
469
			}
470
			if ($data->total_cp === 0 || $data->pokemon_count !== 0) {
471
				$history[] = $data;
472
			}
473
		}
474
		if ($count !== ($pageSize + 1)) {
475
			$last_page = true;
476
		} else {
477
			$last_page = false;
478
		}
479
		return array("last_page" => $last_page, "data" => $history);
480
	}
481
482 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...
483
	{
484
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
485
					FROM gym_history_defenders ghd
486
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
487
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
488
					ORDER BY gd.deployment_time";
489
		$result = $this->mysqli->query($req);
490
		$pokemons = array();
491
		while ($data = $result->fetch_object()) {
492
			$pokemons[$data->defender_id] = $data;
493
		}
494
		return $pokemons;
495
	}
496
497
498
499
	//////////////
500
	// Trainers
501
	//////////////
502
503 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...
504
		$ranking = $this->getTrainerLevelRanking();
505
		$where = "";
506
		if (!empty(self::$config->system->trainer_blacklist)) {
507
			$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
508
		}
509
		if ($trainer_name != "") {
510
			$where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
511
		}
512
		if ($team != 0) {
513
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
514
		}
515
		switch ($rankingNumber) {
516
			case 1:
517
				$order = " ORDER BY active DESC, level DESC";
518
				break;
519
			case 2:
520
				$order = " ORDER BY maxCp DESC, level DESC";
521
				break;
522
			default:
523
				$order = " ORDER BY level DESC, active DESC";
524
		}
525
		$order .= ", last_seen DESC, name ";
526
		$limit = " LIMIT ".($page * 10).",10 ";
527
		$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
528
				  	FROM gym_defenders gd
529
				  	LEFT JOIN (
530
				  		SELECT owner_name, COUNT(*) as active
531
				  		FROM gym_defenders gd2
532
						WHERE fort_id IS NOT NULL
533
				  		GROUP BY owner_name
534
				  	) active ON active.owner_name = gd.owner_name
535
				  	WHERE gd.owner_level IS NOT NULL " . $where . "
536
				  	GROUP BY gd.owner_name" . $order  . $limit;
537
		$result = $this->mysqli->query($req);
538
		$trainers = array();
539
		while ($data = $result->fetch_object()) {
540
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
541
            if (is_null($data->active)) {
542
                $data->active = 0;
543
            }
544
			$trainers[$data->name] = $data;
545
546
			$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...
547
548
			$trainers[$data->name]->gyms = $data->active;
549
			$trainers[$data->name]->pokemons = $pokemon;
550
			$trainers[$data->name]->rank = $ranking[$data->level];
551
		}
552
		return $trainers;
553
	}
554
555 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...
556
		$exclue = "";
557
		if (!empty(self::$config->system->trainer_blacklist)) {
558
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
559
		}
560
		$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";
561
		$result = $this->mysqli->query($req);
562
		$levelData = array();
563
		while ($data = $result->fetch_object()) {
564
			$levelData[$data->level] = $data->count;
565
		}
566
		for ($i = 5; $i <= 40; $i++) {
567
			if (!isset($levelData[$i])) {
568
				$levelData[$i] = 0;
569
			}
570
		}
571
		# sort array again
572
		ksort($levelData);
573
		return $levelData;
574
	}
575
576
	public function getActivePokemon($trainer_name) {
577
		$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
578
						FROM gym_defenders
579
						WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL
580
						ORDER BY deployment_time";
581
		$result = $this->mysqli->query($req);
582
		$pokemon = array();
583
		while ($data = $result->fetch_object()) {
584
			$pokemon[] = $data;
585
		}
586
		return $pokemon;
587
	}
588
589
	public function getInactivePokemon($trainer_name) {
590
		$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
591
					FROM gym_defenders
592
					WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL
593
					ORDER BY last_scanned";
594
		$result = $this->mysqli->query($req);
595
		$pokemon = array();
596
		while ($data = $result->fetch_object()) {
597
			$pokemon[] = $data;
598
		}
599
		return $pokemon;
600
	}
601
602 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...
603
		$exclue = "";
604
		if (!empty(self::$config->system->trainer_blacklist)) {
605
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
606
		}
607
		$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";
608
		$result = $this->mysqli->query($req);
609
		$levelData = array();
610
		while ($data = $result->fetch_object()) {
611
			$levelData[$data->level] = $data->count;
612
		}
613
		for ($i = 5; $i <= 40; $i++) {
614
			if (!isset($levelData[$i])) {
615
				$levelData[$i] = 0;
616
			}
617
		}
618
		# sort array again
619
		ksort($levelData);
620
		return $levelData;
621
	}
622
623
624
	/////////
625
	// Cron
626
	/////////
627
628
	public function getPokemonCountsActive() {
629
		$req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id";
630
		$result = $this->mysqli->query($req);
631
		$counts = array();
632
		while ($data = $result->fetch_object()) {
633
			$counts[$data->pokemon_id] = $data->total;
634
		}
635
		return $counts;
636
	}
637
638
	public function getPokemonCountsLastDay() {
639
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
640
					FROM sightings
641
					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings)
642
					GROUP BY pokemon_id
643
				  	ORDER BY pokemon_id ASC";
644
		$result = $this->mysqli->query($req);
645
		$counts = array();
646
		while ($data = $result->fetch_object()) {
647
			$counts[$data->pokemon_id] = $data->spawns_last_day;
648
		}
649
		return $counts;
650
	}
651
652 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...
653
		$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."'";
654
		$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
655
					FROM sightings p
656
					LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
657
					JOIN (SELECT COUNT(*) AS count
658
						FROM sightings p
659
						LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
660
                    	" . $where."
661
                    ) x
662
					" . $where . "
663
					ORDER BY last_timestamp DESC
664
					LIMIT 0 , 1";
665
		$result = $this->mysqli->query($req);
666
		$data = $result->fetch_object();
667
		return $data;
668
	}
669
670 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...
671
		$where = "WHERE pokemon_id = '".$pokemon_id."AND".$last_update."'";
672
		$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
673
					FROM raids r
674
					JOIN forts g
675
					JOIN (SELECT COUNT(*) AS count
676
						FROM raids
677
                    	" . $where."
678
                    ) x
679
					ON r.fort_id = g.id
680
                    " . $where . "
681
                    ORDER BY time_battle DESC
682
					LIMIT 0 , 1";
683
		$result = $this->mysqli->query($req);
684
		$data = $result->fetch_object();
685
		return $data;
686
	}
687
688
	public function getCaptchaCount() {
689
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
690
		$result = $this->mysqli->query($req);
691
		$data = $result->fetch_object();
692
		return $data;
693
	}
694
695 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...
696
		$pokemon_exclude_sql = "";
697
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
698
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")";
699
		}
700
		$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
701
			          FROM sightings p
702
			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
703
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400
704
			          " . $pokemon_exclude_sql . "
705
			          GROUP BY p.spawn_id, p.pokemon_id
706
			          HAVING COUNT(p.pokemon_id) >= 6
707
			          ORDER BY p.pokemon_id";
708
		$result = $this->mysqli->query($req);
709
		$nests = array();
710
		while ($data = $result->fetch_object()) {
711
			$nests[] = $data;
712
		}
713
		return $nests;
714
	}
715
716
}
717